From 1b2feb19e506bc24580d5d61422d0de68349c24e Mon Sep 17 00:00:00 2001 From: Wim Date: Thu, 2 May 2019 00:46:49 +0200 Subject: Update channels of all teams (mattermost) --- matterclient/channels.go | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/matterclient/channels.go b/matterclient/channels.go index 0eac29f8..c09a170f 100644 --- a/matterclient/channels.go +++ b/matterclient/channels.go @@ -167,23 +167,38 @@ func (m *MMClient) JoinChannel(channelId string) error { //nolint:golint return nil } -func (m *MMClient) UpdateChannels() error { - mmchannels, resp := m.Client.GetChannelsForTeamForUser(m.Team.Id, m.User.Id, "") +func (m *MMClient) UpdateChannelsTeam(teamId string) error { + mmchannels, resp := m.Client.GetChannelsForTeamForUser(teamId, m.User.Id, "") if resp.Error != nil { return errors.New(resp.Error.DetailedError) } - m.Lock() - m.Team.Channels = mmchannels - m.Unlock() + for idx, t := range m.OtherTeams { + if t.Id == teamId { + m.Lock() + m.OtherTeams[idx].Channels = mmchannels + m.Unlock() + } + } - mmchannels, resp = m.Client.GetPublicChannelsForTeam(m.Team.Id, 0, 5000, "") + mmchannels, resp = m.Client.GetPublicChannelsForTeam(teamId, 0, 5000, "") if resp.Error != nil { return errors.New(resp.Error.DetailedError) } + for idx, t := range m.OtherTeams { + if t.Id == teamId { + m.Lock() + m.OtherTeams[idx].MoreChannels = mmchannels + m.Unlock() + } + } + return nil +} - m.Lock() - m.Team.MoreChannels = mmchannels - m.Unlock() +func (m *MMClient) UpdateChannels() error { + m.UpdateChannelsTeam(m.Team.Id) + for _, t := range m.OtherTeams { + m.UpdateChannelsTeam(t.Id) + } return nil } -- cgit v1.2.3