From 0685afd1d197584e78a111934754d7111bb2dbe8 Mon Sep 17 00:00:00 2001 From: George Goldberg Date: Tue, 17 Jan 2017 20:45:18 +0000 Subject: PLT-2978: Add channel purpose change system message. (#5094) Completes original patch by David Lu. --- app/channel.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'app/channel.go') diff --git a/app/channel.go b/app/channel.go index 9451ca974..aa84e12be 100644 --- a/app/channel.go +++ b/app/channel.go @@ -316,6 +316,41 @@ func PostUpdateChannelHeaderMessage(userId string, channelId string, teamId stri return nil } +func PostUpdateChannelPurposeMessage(userId string, channelId string, teamId string, oldChannelPurpose string, newChannelPurpose string) *model.AppError { + uc := Srv.Store.User().Get(userId) + + if uresult := <-uc; uresult.Err != nil { + return model.NewLocAppError("PostUpdateChannelPurposeMessage", "app.channel.post_update_channel_purpose_message.retrieve_user.error", nil, uresult.Err.Error()) + } else { + user := uresult.Data.(*model.User) + + var message string + if oldChannelPurpose == "" { + message = fmt.Sprintf(utils.T("app.channel.post_update_channel_purpose_message.updated_to"), user.Username, newChannelPurpose) + } else if newChannelPurpose == "" { + message = fmt.Sprintf(utils.T("app.channel.post_update_channel_purpose_message.removed"), user.Username, oldChannelPurpose) + } else { + message = fmt.Sprintf(utils.T("app.channel.post_update_channel_purpose_message.updated_from"), user.Username, oldChannelPurpose, newChannelPurpose) + } + + post := &model.Post{ + ChannelId: channelId, + Message: message, + Type: model.POST_PURPOSE_CHANGE, + UserId: userId, + Props: model.StringInterface{ + "old_purpose": oldChannelPurpose, + "new_purpose": newChannelPurpose, + }, + } + if _, err := CreatePost(post, teamId, false); err != nil { + return model.NewLocAppError("", "app.channel.post_update_channel_purpose_message.post.error", nil, err.Error()) + } + } + + return nil +} + func PostUpdateChannelDisplayNameMessage(userId string, channelId string, teamId string, oldChannelDisplayName, newChannelDisplayName string) *model.AppError { uc := Srv.Store.User().Get(userId) -- cgit v1.2.3-1-g7c22