Update channel member notify props to use native JSON (#18114)

* Update channel member notify props to use native JSON

Created a new store method that patches the notify props field.

https://community-daily.mattermost.com/plugins/focalboard/workspace/zyoahc9uapdn3xdptac6jb69ic?id=285b80a3-257d-41f6-8cf4-ed80ca9d92e5&v=495cdb4d-c13a-4992-8eb9-80cfee2819a4&c=91d08676-4a0e-4f02-8dce-d24d4fc56449

```release-note
NONE
```

* cleanup

```release-note
NONE
```

* forgot to commit

```release-note
NONE
```

* Fix edge case

```release-note
NONE
```

* address review comments

```release-note
NONE
```

* fix incorrect order

```release-note
NONE
```

* Address review comments

```release-note
NONE
```

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2021-08-23 10:04:30 +05:30
коммит произвёл GitHub
родитель c4c1fda128
Коммит 7bbcf86531
10 изменённых файлов: 249 добавлений и 12 удалений

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

@@ -1206,40 +1206,51 @@ func (a *App) UpdateChannelMemberSchemeRoles(channelID string, userID string, is
}
func (a *App) UpdateChannelMemberNotifyProps(data map[string]string, channelID string, userID string) (*model.ChannelMember, *model.AppError) {
var member *model.ChannelMember
var err *model.AppError
if member, err = a.GetChannelMember(context.Background(), channelID, userID); err != nil {
return nil, err
}
filteredProps := make(map[string]string)
// update whichever notify properties have been provided, but don't change the others
if markUnread, exists := data[model.MarkUnreadNotifyProp]; exists {
member.NotifyProps[model.MarkUnreadNotifyProp] = markUnread
filteredProps[model.MarkUnreadNotifyProp] = markUnread
}
if desktop, exists := data[model.DesktopNotifyProp]; exists {
member.NotifyProps[model.DesktopNotifyProp] = desktop
filteredProps[model.DesktopNotifyProp] = desktop
}
if email, exists := data[model.EmailNotifyProp]; exists {
member.NotifyProps[model.EmailNotifyProp] = email
filteredProps[model.EmailNotifyProp] = email
}
if push, exists := data[model.PushNotifyProp]; exists {
member.NotifyProps[model.PushNotifyProp] = push
filteredProps[model.PushNotifyProp] = push
}
if ignoreChannelMentions, exists := data[model.IgnoreChannelMentionsNotifyProp]; exists {
member.NotifyProps[model.IgnoreChannelMentionsNotifyProp] = ignoreChannelMentions
filteredProps[model.IgnoreChannelMentionsNotifyProp] = ignoreChannelMentions
}
member, err = a.updateChannelMember(member)
member, err := a.Srv().Store.Channel().UpdateMemberNotifyProps(channelID, userID, filteredProps)
if err != nil {
return nil, err
var appErr *model.AppError
var nfErr *store.ErrNotFound
switch {
case errors.As(err, &appErr):
return nil, appErr
case errors.As(err, &nfErr):
return nil, model.NewAppError("updateMemberNotifyProps", MissingChannelMemberError, nil, nfErr.Error(), http.StatusNotFound)
default:
return nil, model.NewAppError("updateMemberNotifyProps", "app.channel.get_member.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
a.InvalidateCacheForUser(member.UserId)
a.invalidateCacheForChannelMembersNotifyProps(member.ChannelId)
// Notify the clients that the member notify props changed
evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", member.UserId, nil)
evt.Add("channelMember", member.ToJson())
a.Publish(evt)
return member, nil
}