@@ -867,6 +867,14 @@ func handleListMissing(api *slack.Client, db *sql.DB, cfg Config, cmd slack.Slas
867867 }
868868
869869 monday , nextMonday := ReportWeekRange (cfg , time .Now ().In (cfg .Location ))
870+ weekItems , err := GetItemsByDateRange (db , monday , nextMonday )
871+ if err != nil {
872+ postEphemeral (api , cmd , fmt .Sprintf ("Error loading items: %v" , err ))
873+ log .Printf ("list-missing load error: %v" , err )
874+ return
875+ }
876+ reportedAuthors := uniqueReportedAuthors (weekItems )
877+
870878 reportedAuthorIDs , err := GetSlackAuthorIDsByDateRange (db , monday , nextMonday )
871879 if err != nil {
872880 postEphemeral (api , cmd , fmt .Sprintf ("Error loading items: %v" , err ))
@@ -881,11 +889,22 @@ func handleListMissing(api *slack.Client, db *sql.DB, cfg Config, cmd slack.Slas
881889 var missing []missingMember
882890 var missingIDs []string
883891 for _ , uid := range memberIDs {
884- if reportedAuthorIDs [uid ] {
892+ user , err := api .GetUserInfo (uid )
893+ nameCandidates := []string {uid }
894+ if err == nil {
895+ if user .Profile .DisplayName != "" {
896+ nameCandidates = append (nameCandidates , user .Profile .DisplayName )
897+ }
898+ if user .RealName != "" {
899+ nameCandidates = append (nameCandidates , user .RealName )
900+ }
901+ if user .Name != "" {
902+ nameCandidates = append (nameCandidates , user .Name )
903+ }
904+ }
905+ if memberReportedThisWeek (uid , nameCandidates , reportedAuthorIDs , reportedAuthors ) {
885906 continue
886907 }
887-
888- user , err := api .GetUserInfo (uid )
889908 if err != nil {
890909 missing = append (missing , missingMember {display : uid , userID : uid })
891910 missingIDs = append (missingIDs , uid )
@@ -963,6 +982,38 @@ func handleListMissing(api *slack.Client, db *sql.DB, cfg Config, cmd slack.Slas
963982 log .Printf ("list-missing count=%d" , len (missing )+ len (unresolved ))
964983}
965984
985+ func uniqueReportedAuthors (items []WorkItem ) []string {
986+ seen := make (map [string ]bool )
987+ var out []string
988+ for _ , item := range items {
989+ author := strings .TrimSpace (item .Author )
990+ if author == "" || seen [author ] {
991+ continue
992+ }
993+ seen [author ] = true
994+ out = append (out , author )
995+ }
996+ return out
997+ }
998+
999+ func memberReportedThisWeek (userID string , nameCandidates []string , reportedAuthorIDs map [string ]bool , reportedAuthors []string ) bool {
1000+ if reportedAuthorIDs [userID ] {
1001+ return true
1002+ }
1003+ for _ , candidate := range nameCandidates {
1004+ candidate = strings .TrimSpace (candidate )
1005+ if candidate == "" {
1006+ continue
1007+ }
1008+ for _ , author := range reportedAuthors {
1009+ if strings .EqualFold (candidate , author ) || nameMatches (candidate , author ) || nameMatches (author , candidate ) {
1010+ return true
1011+ }
1012+ }
1013+ }
1014+ return false
1015+ }
1016+
9661017func postEphemeral (api * slack.Client , cmd slack.SlashCommand , text string ) {
9671018 postEphemeralTo (api , cmd .ChannelID , cmd .UserID , text )
9681019}
0 commit comments