diff options
author | Daniel Schalla <daniel@schalla.me> | 2018-07-20 23:00:58 +0200 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2018-07-20 17:00:58 -0400 |
commit | 3539a9a60b24bd9c0c1360b17c8fe3e6ebf8cf3c (patch) | |
tree | d4913b503841b94b435d75febabb43a0e55c4ed3 /app/channel.go | |
parent | 6104c37761deb8f06ea4af8838db12b8158318be (diff) | |
download | chat-3539a9a60b24bd9c0c1360b17c8fe3e6ebf8cf3c.tar.gz chat-3539a9a60b24bd9c0c1360b17c8fe3e6ebf8cf3c.tar.bz2 chat-3539a9a60b24bd9c0c1360b17c8fe3e6ebf8cf3c.zip |
Default Channel Functionality + Test Suite (#9068)
gofmt
Make skipping for non public channels default
Deduplication of Default Channels; Only post join to townsquare
Post join channel message for all custom default channels
Diffstat (limited to 'app/channel.go')
-rw-r--r-- | app/channel.go | 109 |
1 files changed, 55 insertions, 54 deletions
diff --git a/app/channel.go b/app/channel.go index ce183e6a9..619cc09eb 100644 --- a/app/channel.go +++ b/app/channel.go @@ -45,71 +45,72 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, shouldBeAdmin } } - if result := <-a.Srv.Store.Channel().GetByName(teamId, "town-square", true); result.Err != nil { - err = result.Err - } else { - townSquare := result.Data.(*model.Channel) - - cm := &model.ChannelMember{ - ChannelId: townSquare.Id, - UserId: user.Id, - SchemeUser: true, - SchemeAdmin: shouldBeAdmin, - NotifyProps: model.GetDefaultChannelNotifyProps(), - } - - if cmResult := <-a.Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil { - err = cmResult.Err - } - if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(user.Id, townSquare.Id, model.GetMillis()); result.Err != nil { - mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err)) - } + defaultChannelList := []string{"town-square"} - if *a.Config().ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages { - if requestor == nil { - if err := a.postJoinTeamMessage(user, townSquare); err != nil { - mlog.Error(fmt.Sprint("Failed to post join/leave message", err)) - } - } else { - if err := a.postAddToTeamMessage(requestor, user, townSquare, ""); err != nil { - mlog.Error(fmt.Sprint("Failed to post join/leave message", err)) - } + if len(a.Config().TeamSettings.ExperimentalDefaultChannels) == 0 { + defaultChannelList = append(defaultChannelList, "off-topic") + } else { + seenChannels := map[string]bool{} + for _, channelName := range a.Config().TeamSettings.ExperimentalDefaultChannels { + if seenChannels[channelName] != true { + defaultChannelList = append(defaultChannelList, channelName) + seenChannels[channelName] = true } } - - a.InvalidateCacheForChannelMembers(result.Data.(*model.Channel).Id) } - if result := <-a.Srv.Store.Channel().GetByName(teamId, "off-topic", true); result.Err != nil { - err = result.Err - } else if offTopic := result.Data.(*model.Channel); offTopic.Type == model.CHANNEL_OPEN { + for _, channelName := range defaultChannelList { + if result := <-a.Srv.Store.Channel().GetByName(teamId, channelName, true); result.Err != nil { + err = result.Err + } else { - cm := &model.ChannelMember{ - ChannelId: offTopic.Id, - UserId: user.Id, - SchemeUser: true, - SchemeAdmin: shouldBeAdmin, - NotifyProps: model.GetDefaultChannelNotifyProps(), - } + channel := result.Data.(*model.Channel) - if cmResult := <-a.Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil { - err = cmResult.Err - } - if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(user.Id, offTopic.Id, model.GetMillis()); result.Err != nil { - mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err)) - } + if channel.Type != model.CHANNEL_OPEN { + continue + } + + cm := &model.ChannelMember{ + ChannelId: channel.Id, + UserId: user.Id, + SchemeUser: true, + SchemeAdmin: shouldBeAdmin, + NotifyProps: model.GetDefaultChannelNotifyProps(), + } - if requestor == nil { - if err := a.postJoinChannelMessage(user, offTopic); err != nil { - mlog.Error(fmt.Sprint("Failed to post join/leave message", err)) + if cmResult := <-a.Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil { + err = cmResult.Err } - } else { - if err := a.PostAddToChannelMessage(requestor, user, offTopic, ""); err != nil { - mlog.Error(fmt.Sprint("Failed to post join/leave message", err)) + if result := <-a.Srv.Store.ChannelMemberHistory().LogJoinEvent(user.Id, channel.Id, model.GetMillis()); result.Err != nil { + mlog.Warn(fmt.Sprintf("Failed to update ChannelMemberHistory table %v", result.Err)) } - } - a.InvalidateCacheForChannelMembers(result.Data.(*model.Channel).Id) + if *a.Config().ServiceSettings.ExperimentalEnableDefaultChannelLeaveJoinMessages { + if channel.Name == model.DEFAULT_CHANNEL { + if requestor == nil { + if err := a.postJoinTeamMessage(user, channel); err != nil { + mlog.Error(fmt.Sprint("Failed to post join/leave message", err)) + } + } else { + if err := a.postAddToTeamMessage(requestor, user, channel, ""); err != nil { + mlog.Error(fmt.Sprint("Failed to post join/leave message", err)) + } + } + } else { + if requestor == nil { + if err := a.postJoinChannelMessage(user, channel); err != nil { + mlog.Error(fmt.Sprint("Failed to post join/leave message", err)) + } + } else { + if err := a.PostAddToChannelMessage(requestor, user, channel, ""); err != nil { + mlog.Error(fmt.Sprint("Failed to post join/leave message", err)) + } + } + } + } + + a.InvalidateCacheForChannelMembers(result.Data.(*model.Channel).Id) + } } return err |