Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 5d6b02d4e5168747c02029df701a8a9c50843528 Author: Wim <wim@42.be> Date: Wed Aug 30 14:01:17 2017 +0000 Fix private channel joining bug (mattermost). Closes #248 diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index 6bc1ebb..fc4fdb9 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -26 +27 @@ package bmattermost    import (   "errors" + "fmt"   "github.com/42wim/matterbridge/bridge/config"   "github.com/42wim/matterbridge/matterclient"   "github.com/42wim/matterbridge/matterhook" @@ -1327 +13311 @@ func (b *Bmattermost) Disconnect() error {  func (b *Bmattermost) JoinChannel(channel config.ChannelInfo) error {   // we can only join channels using the API   if b.Config.WebhookURL == "" && b.Config.WebhookBindAddress == "" { - return b.mc.JoinChannel(b.mc.GetChannelId(channel.Name, "")) + id := b.mc.GetChannelId(channel.Name, "") + if id == "" { + return fmt.Errorf("Could not find channel ID for channel %s", channel.Name) + } + return b.mc.JoinChannel(id)   }   return nil  } diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go index f6b942a..d52a428 100644 --- a/matterclient/matterclient.go +++ b/matterclient/matterclient.go @@ -4817 +4817 @@ func (m *MMClient) JoinChannel(channelId string) error {   m.log.Debug("Joining ", channelId)   _, resp := m.Client.AddChannelMember(channelId, m.User.Id)   if resp.Error != nil { - return errors.New("failed to join") + return resp.Error   }   return nil  } @@ -81213 +81219 @@ func (m *MMClient) initUser() error {   for _, user := range mmusers {   usermap[user.Id] = user   } +   t := &Team{Team: team, Users: usermap, Id: team.Id}   - mmchannels, resp := m.Client.GetPublicChannelsForTeam(team.Id, 0, 5000, "") + mmchannels, resp := m.Client.GetChannelsForTeamForUser(team.Id, m.User.Id, "")   if resp.Error != nil { - return errors.New(resp.Error.DetailedError) + return resp.Error   }   t.Channels = mmchannels + mmchannels, resp = m.Client.GetPublicChannelsForTeam(team.Id, 0, 5000, "") + if resp.Error != nil { + return resp.Error + } + t.MoreChannels = mmchannels   m.OtherTeams = append(m.OtherTeams, t)   if team.Name == m.Credentials.Team {   m.Team = t