[MM-24828] Take into account group synced state of team and channel when sending notifications (#14477)

* MM-24828 Take into account group synced state of team and channel when getting groups for mentions

* Update app/notification_test.go

* i18n-extract

* Revert "i18n-extract"

This reverts commit dcb0426b98afa4646c26870c0e3a1236f99fda17.

* Trigger CI

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Farhan Munshi
2020-05-08 16:32:48 -04:00
коммит произвёл GitHub
родитель 0d1eb02341
Коммит 8fe003876d
2 изменённых файлов: 137 добавлений и 7 удалений

Просмотреть файл

@@ -40,13 +40,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
if a.allowGroupMentions(post) {
gchan = make(chan store.StoreResult, 1)
go func() {
groups, err := a.Srv().Store.Group().GetGroups(0, 0, model.GroupSearchOpts{FilterAllowReference: true})
groupsMap := make(map[string]*model.Group)
if err == nil {
for _, group := range groups {
groupsMap[group.Name] = group
}
}
groupsMap, err := a.getGroupsAllowedForReferenceInChannel(channel, team)
gchan <- store.StoreResult{Data: groupsMap, Err: err}
close(gchan)
}()
@@ -755,6 +749,39 @@ func (a *App) allowGroupMentions(post *model.Post) bool {
return true
}
// getGroupsAllowedForReferenceInChannel returns a map of groups allowed for reference in a given channel and team.
func (a *App) getGroupsAllowedForReferenceInChannel(channel *model.Channel, team *model.Team) (map[string]*model.Group, *model.AppError) {
var err *model.AppError
groupsMap := make(map[string]*model.Group)
opts := model.GroupSearchOpts{FilterAllowReference: true}
if channel.IsGroupConstrained() || team.IsGroupConstrained() {
var groups []*model.GroupWithSchemeAdmin
if channel.IsGroupConstrained() {
groups, err = a.Srv().Store.Group().GetGroupsByChannel(channel.Id, opts)
} else {
groups, err = a.Srv().Store.Group().GetGroupsByTeam(team.Id, opts)
}
if err != nil {
return nil, err
}
for _, group := range groups {
groupsMap[group.Group.Name] = &group.Group
}
return groupsMap, nil
}
groups, err := a.Srv().Store.Group().GetGroups(0, 0, opts)
if err != nil {
return nil, err
}
for _, group := range groups {
groupsMap[group.Name] = group
}
return groupsMap, nil
}
// Given a map of user IDs to profiles, returns a list of mention
// keywords for all users in the channel.
func (a *App) getMentionKeywordsInChannel(profiles map[string]*model.User, allowChannelMentions bool, channelMemberNotifyPropsMap map[string]model.StringMap) map[string][]string {