From 88a328421fbfc2db2a1747da955deea68e86da2a Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 3 May 2017 11:52:36 -0400 Subject: Update channel patch to post the correct system messages (#6290) --- app/channel.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'app/channel.go') diff --git a/app/channel.go b/app/channel.go index 0d9cb5a94..ee53ace45 100644 --- a/app/channel.go +++ b/app/channel.go @@ -281,9 +281,36 @@ func UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) { } } -func PatchChannel(channel *model.Channel, patch *model.ChannelPatch) (*model.Channel, *model.AppError) { +func PatchChannel(channel *model.Channel, patch *model.ChannelPatch, userId string) (*model.Channel, *model.AppError) { + oldChannelDisplayName := channel.DisplayName + oldChannelHeader := channel.Header + oldChannelPurpose := channel.Purpose + channel.Patch(patch) - return UpdateChannel(channel) + channel, err := UpdateChannel(channel) + if err != nil { + return nil, err + } + + if oldChannelDisplayName != channel.DisplayName { + if err := PostUpdateChannelDisplayNameMessage(userId, channel.Id, channel.TeamId, oldChannelDisplayName, channel.DisplayName); err != nil { + l4g.Error(err.Error()) + } + } + + if channel.Header != oldChannelHeader { + if err := PostUpdateChannelHeaderMessage(userId, channel.Id, channel.TeamId, oldChannelHeader, channel.Header); err != nil { + l4g.Error(err.Error()) + } + } + + if channel.Purpose != oldChannelPurpose { + if err := PostUpdateChannelPurposeMessage(userId, channel.Id, channel.TeamId, oldChannelPurpose, channel.Purpose); err != nil { + l4g.Error(err.Error()) + } + } + + return channel, err } func UpdateChannelMemberRoles(channelId string, userId string, newRoles string) (*model.ChannelMember, *model.AppError) { -- cgit v1.2.3-1-g7c22