From 164e030d33b03cab347ddcdf064615cb9e144317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Tue, 26 Jun 2018 22:06:01 +0200 Subject: MM-11008: Fix translation and change the code to be auto-extracted (#9009) --- app/channel.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'app/channel.go') diff --git a/app/channel.go b/app/channel.go index 7637e9d21..7394d813b 100644 --- a/app/channel.go +++ b/app/channel.go @@ -397,13 +397,13 @@ func (a *App) UpdateChannelPrivacy(oldChannel *model.Channel, user *model.User) } 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", + message := (map[string]string{ + model.CHANNEL_OPEN: utils.T("api.channel.change_channel_privacy.private_to_public"), + model.CHANNEL_PRIVATE: utils.T("api.channel.change_channel_privacy.public_to_private"), })[channel.Type] post := &model.Post{ ChannelId: channel.Id, - Message: utils.T("api.channel.change_channel_privacy." + privacy), + Message: message, Type: model.POST_CHANGE_CHANNEL_PRIVACY, UserId: user.Id, Props: model.StringInterface{ -- cgit v1.2.3-1-g7c22 From 2d7cd02abcd62ffd60fe3c6e16e5189169de349e Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Tue, 26 Jun 2018 16:46:58 -0400 Subject: MM-10833: send down computed channel props (#8953) * MM-10833: send down computed channel props This allows channel headers to reference channel mentions for a client that doesn't already know about the channels in question. We intentionally don't send down the props for the autocomplete and search endpoints since they aren't used in that context, and would add unnecessary overhead. * update channel props on patch * revert to treating channel purpose as plaintext --- app/channel.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'app/channel.go') diff --git a/app/channel.go b/app/channel.go index 7394d813b..eee27a6de 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1591,3 +1591,67 @@ func (a *App) ToggleMuteChannel(channelId string, userId string) *model.ChannelM a.Srv.Store.Channel().UpdateMember(member) return member } + +func (a *App) FillInChannelProps(channel *model.Channel) *model.AppError { + return a.FillInChannelsProps(&model.ChannelList{channel}) +} + +func (a *App) FillInChannelsProps(channelList *model.ChannelList) *model.AppError { + // Group the channels by team and call GetChannelsByNames just once per team. + channelsByTeam := make(map[string]model.ChannelList) + for _, channel := range *channelList { + channelsByTeam[channel.TeamId] = append(channelsByTeam[channel.TeamId], channel) + } + + for teamId, channelList := range channelsByTeam { + allChannelMentions := make(map[string]bool) + channelMentions := make(map[*model.Channel][]string, len(channelList)) + + // Collect mentions across the channels so as to query just once for this team. + for _, channel := range channelList { + channelMentions[channel] = model.ChannelMentions(channel.Header) + + for _, channelMention := range channelMentions[channel] { + allChannelMentions[channelMention] = true + } + } + + allChannelMentionNames := make([]string, 0, len(allChannelMentions)) + for channelName := range allChannelMentions { + allChannelMentionNames = append(allChannelMentionNames, channelName) + } + + if len(allChannelMentionNames) > 0 { + mentionedChannels, err := a.GetChannelsByNames(allChannelMentionNames, teamId) + if err != nil { + return err + } + + mentionedChannelsByName := make(map[string]*model.Channel) + for _, channel := range mentionedChannels { + mentionedChannelsByName[channel.Name] = channel + } + + for _, channel := range channelList { + channelMentionsProp := make(map[string]interface{}, len(channelMentions[channel])) + for _, channelMention := range channelMentions[channel] { + if mentioned, ok := mentionedChannelsByName[channelMention]; ok { + if mentioned.Type == model.CHANNEL_OPEN { + channelMentionsProp[mentioned.Name] = map[string]interface{}{ + "display_name": mentioned.DisplayName, + } + } + } + } + + if len(channelMentionsProp) > 0 { + channel.AddProp("channel_mentions", channelMentionsProp) + } else if channel.Props != nil { + delete(channel.Props, "channel_mentions") + } + } + } + } + + return nil +} -- cgit v1.2.3-1-g7c22