From 88a328421fbfc2db2a1747da955deea68e86da2a Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 3 May 2017 11:52:36 -0400 Subject: [PATCH] Update channel patch to post the correct system messages (#6290) --- api4/channel.go | 2 +- app/channel.go | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/api4/channel.go b/api4/channel.go index c8235c5f12..493b012a0d 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -170,7 +170,7 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) { return } - if rchannel, err := app.PatchChannel(oldChannel, patch); err != nil { + if rchannel, err := app.PatchChannel(oldChannel, patch, c.Session.UserId); err != nil { c.Err = err return } else { diff --git a/app/channel.go b/app/channel.go index 0d9cb5a949..ee53ace45a 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) {