1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-12-24 13:43:12 +02:00

Making more robust websocket notifications on synthetic memberships (#3598)

* Making more robust websocket notifications on syntetic memberships

* Address PR review comments
This commit is contained in:
Jesús Espino 2022-08-11 09:38:44 +02:00 committed by GitHub
parent 84eabd394a
commit 1e2e3fb055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -283,7 +283,15 @@ func (a *App) CreateBoard(board *model.Board, userID string, addMember bool) (*m
a.blockChangeNotifier.Enqueue(func() error {
a.wsAdapter.BroadcastBoardChange(newBoard.TeamID, newBoard)
if addMember {
if newBoard.ChannelID != "" {
members, err := a.GetMembersForBoard(board.ID)
if err != nil {
a.logger.Error("Unable to get the board members", mlog.Err(err))
}
for _, member := range members {
a.wsAdapter.BroadcastMemberChange(newBoard.TeamID, member.BoardID, member)
}
} else if addMember {
a.wsAdapter.BroadcastMemberChange(newBoard.TeamID, newBoard.ID, member)
}
return nil
@ -293,6 +301,14 @@ func (a *App) CreateBoard(board *model.Board, userID string, addMember bool) (*m
}
func (a *App) PatchBoard(patch *model.BoardPatch, boardID, userID string) (*model.Board, error) {
var oldMembers []*model.BoardMember
if patch.ChannelID != nil && *patch.ChannelID == "" {
var err error
oldMembers, err = a.GetMembersForBoard(boardID)
if err != nil {
a.logger.Error("Unable to get the board members", mlog.Err(err))
}
}
updatedBoard, err := a.store.PatchBoard(boardID, patch, userID)
if err != nil {
return nil, err
@ -300,6 +316,23 @@ func (a *App) PatchBoard(patch *model.BoardPatch, boardID, userID string) (*mode
a.blockChangeNotifier.Enqueue(func() error {
a.wsAdapter.BroadcastBoardChange(updatedBoard.TeamID, updatedBoard)
if patch.ChannelID != nil && *patch.ChannelID != "" {
members, err := a.GetMembersForBoard(updatedBoard.ID)
if err != nil {
a.logger.Error("Unable to get the board members", mlog.Err(err))
}
for _, member := range members {
if member.Synthetic {
a.wsAdapter.BroadcastMemberChange(updatedBoard.TeamID, member.BoardID, member)
}
}
} else if patch.ChannelID != nil && *patch.ChannelID == "" {
for _, oldMember := range oldMembers {
if oldMember.Synthetic {
a.wsAdapter.BroadcastMemberDelete(updatedBoard.TeamID, boardID, oldMember.UserID)
}
}
}
return nil
})
@ -469,7 +502,11 @@ func (a *App) DeleteBoardMember(boardID, userID string) error {
}
a.blockChangeNotifier.Enqueue(func() error {
a.wsAdapter.BroadcastMemberDelete(board.TeamID, boardID, userID)
if synteticMember, _ := a.store.GetMemberForBoard(boardID, userID); synteticMember != nil {
a.wsAdapter.BroadcastMemberChange(board.TeamID, boardID, synteticMember)
} else {
a.wsAdapter.BroadcastMemberDelete(board.TeamID, boardID, userID)
}
return nil
})