summaryrefslogtreecommitdiffstats
path: root/app/channel.go
diff options
context:
space:
mode:
authorEvgeniy <gig177@yandex.ru>2018-01-19 00:05:00 +0300
committerJoram Wilander <jwawilander@gmail.com>2018-01-18 16:05:00 -0500
commit9d6a9ff4be15f673e8364a984ccc2b2c3a465b73 (patch)
tree0450311827328cd0f68282a3491f66803634ea48 /app/channel.go
parente9a9262956bb948532e3d21604059f23cab85066 (diff)
downloadchat-9d6a9ff4be15f673e8364a984ccc2b2c3a465b73.tar.gz
chat-9d6a9ff4be15f673e8364a984ccc2b2c3a465b73.tar.bz2
chat-9d6a9ff4be15f673e8364a984ccc2b2c3a465b73.zip
Post a system message to the affected channel by CLI command (#7877) (#7968)
Diffstat (limited to 'app/channel.go')
-rw-r--r--app/channel.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/channel.go b/app/channel.go
index 4d7eb7ef3..68963a94a 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -343,6 +343,47 @@ func (a *App) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppE
}
}
+func (a *App) UpdateChannelPrivacy(oldChannel *model.Channel, user *model.User) (*model.Channel, *model.AppError) {
+ if channel, err := a.UpdateChannel(oldChannel); err != nil {
+ return channel, err
+ } else {
+ if err := a.postChannelPrivacyMessage(user, channel); err != nil {
+ if channel.Type == model.CHANNEL_OPEN {
+ channel.Type = model.CHANNEL_PRIVATE
+ } else {
+ channel.Type = model.CHANNEL_OPEN
+ }
+ // revert to previous channel privacy
+ a.UpdateChannel(channel)
+ return channel, err
+ }
+
+ return channel, nil
+ }
+}
+
+func (a *App) postChannelPrivacyMessage(user *model.User, channel *model.Channel) *model.AppError {
+ privacy := (map[string]string{
+ model.CHANNEL_OPEN: "private_to_public",
+ model.CHANNEL_PRIVATE: "public_to_private",
+ })[channel.Type]
+ post := &model.Post{
+ ChannelId: channel.Id,
+ Message: fmt.Sprintf(utils.T("api.channel.change_channel_privacy." + privacy)),
+ Type: model.POST_CHANGE_CHANNEL_PRIVACY,
+ UserId: user.Id,
+ Props: model.StringInterface{
+ "username": user.Username,
+ },
+ }
+
+ if _, err := a.CreatePost(post, channel, false); err != nil {
+ return model.NewAppError("postChannelPrivacyMessage", "api.channel.post_channel_privacy_message.error", nil, err.Error(), http.StatusInternalServerError)
+ }
+
+ return nil
+}
+
func (a *App) RestoreChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
if result := <-a.Srv.Store.Channel().Restore(channel.Id, model.GetMillis()); result.Err != nil {
return nil, result.Err