[MM-55299] Migrate server/channels/app/notification.go to make use of GenericStoreResult (#25338)

This commit is contained in:
Paul-Stern 2023-11-10 16:45:02 +03:00 committed by GitHub
parent a602dcdfb2
commit 7d92e71daf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,80 +43,80 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea
isCRTAllowed := *a.Config().ServiceSettings.CollapsedThreads != model.CollapsedThreadsDisabled isCRTAllowed := *a.Config().ServiceSettings.CollapsedThreads != model.CollapsedThreadsDisabled
pchan := make(chan store.StoreResult, 1) pchan := make(chan store.GenericStoreResult[map[string]*model.User], 1)
go func() { go func() {
props, err := a.Srv().Store().User().GetAllProfilesInChannel(context.Background(), channel.Id, true) props, err := a.Srv().Store().User().GetAllProfilesInChannel(context.Background(), channel.Id, true)
pchan <- store.StoreResult{Data: props, NErr: err} pchan <- store.GenericStoreResult[map[string]*model.User]{Data: props, NErr: err}
close(pchan) close(pchan)
}() }()
cmnchan := make(chan store.StoreResult, 1) cmnchan := make(chan store.GenericStoreResult[map[string]model.StringMap], 1)
go func() { go func() {
props, err := a.Srv().Store().Channel().GetAllChannelMembersNotifyPropsForChannel(channel.Id, true) props, err := a.Srv().Store().Channel().GetAllChannelMembersNotifyPropsForChannel(channel.Id, true)
cmnchan <- store.StoreResult{Data: props, NErr: err} cmnchan <- store.GenericStoreResult[map[string]model.StringMap]{Data: props, NErr: err}
close(cmnchan) close(cmnchan)
}() }()
var gchan chan store.StoreResult var gchan chan store.GenericStoreResult[map[string]*model.Group]
if a.allowGroupMentions(c, post) { if a.allowGroupMentions(c, post) {
gchan = make(chan store.StoreResult, 1) gchan = make(chan store.GenericStoreResult[map[string]*model.Group], 1)
go func() { go func() {
groupsMap, err := a.getGroupsAllowedForReferenceInChannel(channel, team) groupsMap, err := a.getGroupsAllowedForReferenceInChannel(channel, team)
gchan <- store.StoreResult{Data: groupsMap, NErr: err} gchan <- store.GenericStoreResult[map[string]*model.Group]{Data: groupsMap, NErr: err}
close(gchan) close(gchan)
}() }()
} }
var fchan chan store.StoreResult var fchan chan store.GenericStoreResult[[]*model.FileInfo]
if len(post.FileIds) != 0 { if len(post.FileIds) != 0 {
fchan = make(chan store.StoreResult, 1) fchan = make(chan store.GenericStoreResult[[]*model.FileInfo], 1)
go func() { go func() {
fileInfos, err := a.Srv().Store().FileInfo().GetForPost(post.Id, true, false, true) fileInfos, err := a.Srv().Store().FileInfo().GetForPost(post.Id, true, false, true)
fchan <- store.StoreResult{Data: fileInfos, NErr: err} fchan <- store.GenericStoreResult[[]*model.FileInfo]{Data: fileInfos, NErr: err}
close(fchan) close(fchan)
}() }()
} }
var tchan chan store.StoreResult var tchan chan store.GenericStoreResult[[]string]
if isCRTAllowed && post.RootId != "" { if isCRTAllowed && post.RootId != "" {
tchan = make(chan store.StoreResult, 1) tchan = make(chan store.GenericStoreResult[[]string], 1)
go func() { go func() {
followers, err := a.Srv().Store().Thread().GetThreadFollowers(post.RootId, true) followers, err := a.Srv().Store().Thread().GetThreadFollowers(post.RootId, true)
tchan <- store.StoreResult{Data: followers, NErr: err} tchan <- store.GenericStoreResult[[]string]{Data: followers, NErr: err}
close(tchan) close(tchan)
}() }()
} }
result := <-pchan pResult := <-pchan
if result.NErr != nil { if pResult.NErr != nil {
return nil, result.NErr return nil, pResult.NErr
} }
profileMap := result.Data.(map[string]*model.User) profileMap := pResult.Data
result = <-cmnchan cmnResult := <-cmnchan
if result.NErr != nil { if cmnResult.NErr != nil {
return nil, result.NErr return nil, cmnResult.NErr
} }
channelMemberNotifyPropsMap := result.Data.(map[string]model.StringMap) channelMemberNotifyPropsMap := cmnResult.Data
followers := make(model.StringSet, 0) followers := make(model.StringSet, 0)
if tchan != nil { if tchan != nil {
result = <-tchan tResult := <-tchan
if result.NErr != nil { if tResult.NErr != nil {
return nil, result.NErr return nil, tResult.NErr
} }
for _, v := range result.Data.([]string) { for _, v := range tResult.Data {
followers.Add(v) followers.Add(v)
} }
} }
groups := make(map[string]*model.Group) groups := make(map[string]*model.Group)
if gchan != nil { if gchan != nil {
result = <-gchan gResult := <-gchan
if result.NErr != nil { if gResult.NErr != nil {
return nil, result.NErr return nil, gResult.NErr
} }
groups = result.Data.(map[string]*model.Group) groups = gResult.Data
} }
mentions, keywords := a.getExplicitMentionsAndKeywords(c, post, channel, profileMap, groups, channelMemberNotifyPropsMap, parentPostList) mentions, keywords := a.getExplicitMentionsAndKeywords(c, post, channel, profileMap, groups, channelMemberNotifyPropsMap, parentPostList)
@ -503,10 +503,10 @@ func (a *App) SendNotifications(c request.CTX, post *model.Post, team *model.Tea
message.Add("otherFile", "true") message.Add("otherFile", "true")
var infos []*model.FileInfo var infos []*model.FileInfo
if result := <-fchan; result.NErr != nil { if fResult := <-fchan; fResult.NErr != nil {
mlog.Warn("Unable to get fileInfo for push notifications.", mlog.String("post_id", post.Id), mlog.Err(result.NErr)) mlog.Warn("Unable to get fileInfo for push notifications.", mlog.String("post_id", post.Id), mlog.Err(fResult.NErr))
} else { } else {
infos = result.Data.([]*model.FileInfo) infos = fResult.Data
} }
for _, info := range infos { for _, info := range infos {