MM-56083 Add PatchMultipleMembersNotifyProps plugin API (#25690)
* Add ChannelStore.UpdateMultipleMembersNotifyProps * Make UpdateMultipleMembersNotifyProps return updated values from the DB * Add UpdateChannelMembersNotifications plugin API * Extract i18n * Fix style * Make layers * Change to PatchMultipleMembersNotifyProps * Add limit to PatchChannelMembersNotifyProps * Add additional unit tests * Address feedback * Lowercase decodeJSON * Have PatchMultipleMembersNotifyProps update LastUpdateAt * Fix tests that relied on unreliable return order * Fix i18n
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
aafe7439af
Коммит
4d96c11314
@@ -24,6 +24,10 @@ import (
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
|
||||
)
|
||||
|
||||
const (
|
||||
UpdateMultipleMaximum = 200
|
||||
)
|
||||
|
||||
// channelsWrapper provides an implementation of `product.ChannelService` to be used by products.
|
||||
type channelsWrapper struct {
|
||||
app *App
|
||||
@@ -1360,15 +1364,66 @@ func (a *App) UpdateChannelMemberNotifyProps(c request.CTX, data map[string]stri
|
||||
a.invalidateCacheForChannelMembersNotifyProps(member.ChannelId)
|
||||
|
||||
// Notify the clients that the member notify props changed
|
||||
err = a.sendUpdateChannelMemberNotifyPropsEvent(member)
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("UpdateChannelMemberNotifyProps", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
|
||||
return member, nil
|
||||
}
|
||||
|
||||
func (a *App) PatchChannelMembersNotifyProps(c request.CTX, members []*model.ChannelMemberIdentifier, notifyProps map[string]string) ([]*model.ChannelMember, *model.AppError) {
|
||||
if len(members) > UpdateMultipleMaximum {
|
||||
return nil, model.NewAppError("PatchChannelMembersNotifyProps", "app.channel.patch_channel_members_notify_props.too_many", map[string]any{"Max": UpdateMultipleMaximum}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
updated, err := a.Srv().Store().Channel().PatchMultipleMembersNotifyProps(members, notifyProps)
|
||||
if err != nil {
|
||||
var appErr *model.AppError
|
||||
switch {
|
||||
case errors.As(err, &appErr):
|
||||
return nil, appErr
|
||||
default:
|
||||
return nil, model.NewAppError("UpdateMultipleMembersNotifyProps", "app.channel.patch_channel_members_notify_props.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Invalidate caches for the users and channels that have changed
|
||||
userIds := make(map[string]bool)
|
||||
channelIds := make(map[string]bool)
|
||||
for _, member := range updated {
|
||||
userIds[member.UserId] = true
|
||||
channelIds[member.ChannelId] = true
|
||||
}
|
||||
|
||||
for userId := range userIds {
|
||||
a.InvalidateCacheForUser(userId)
|
||||
}
|
||||
for channelId := range channelIds {
|
||||
a.invalidateCacheForChannelMembersNotifyProps(channelId)
|
||||
}
|
||||
|
||||
// Notify clients that their notify props have changed
|
||||
for _, member := range updated {
|
||||
err := a.sendUpdateChannelMemberNotifyPropsEvent(member)
|
||||
if err != nil {
|
||||
c.Logger().Warn("Failed to send WebSocket event for updated channel member notify props", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
func (a *App) sendUpdateChannelMemberNotifyPropsEvent(member *model.ChannelMember) error {
|
||||
evt := model.NewWebSocketEvent(model.WebsocketEventChannelMemberUpdated, "", "", member.UserId, nil, "")
|
||||
memberJSON, jsonErr := json.Marshal(member)
|
||||
if jsonErr != nil {
|
||||
return nil, model.NewAppError("UpdateChannelMemberNotifyProps", "api.marshal_error", nil, "", http.StatusInternalServerError).Wrap(jsonErr)
|
||||
return jsonErr
|
||||
}
|
||||
evt.Add("channelMember", string(memberJSON))
|
||||
a.Publish(evt)
|
||||
|
||||
return member, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) updateChannelMember(c request.CTX, member *model.ChannelMember) (*model.ChannelMember, *model.AppError) {
|
||||
|
||||
Ссылка в новой задаче
Block a user