diff options
author | Wim <wim@42.be> | 2023-03-09 22:48:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-09 22:48:00 +0100 |
commit | 08779c29099e8940493df56d28d8aa131ac8342e (patch) | |
tree | 7ad8ce25cf371e582137e1706dd671a6bf4342d0 /vendor/github.com/matterbridge | |
parent | d5f9cdf912d43cd2a5cb243e086fbdab9a9073b0 (diff) | |
download | matterbridge-msglm-08779c29099e8940493df56d28d8aa131ac8342e.tar.gz matterbridge-msglm-08779c29099e8940493df56d28d8aa131ac8342e.tar.bz2 matterbridge-msglm-08779c29099e8940493df56d28d8aa131ac8342e.zip |
Update dependencies (#2007)
* Update dependencies
Diffstat (limited to 'vendor/github.com/matterbridge')
-rw-r--r-- | vendor/github.com/matterbridge/matterclient/channels.go | 39 | ||||
-rw-r--r-- | vendor/github.com/matterbridge/matterclient/matterclient.go | 41 |
2 files changed, 58 insertions, 22 deletions
diff --git a/vendor/github.com/matterbridge/matterclient/channels.go b/vendor/github.com/matterbridge/matterclient/channels.go index 6bf22a68..c1facf8b 100644 --- a/vendor/github.com/matterbridge/matterclient/channels.go +++ b/vendor/github.com/matterbridge/matterclient/channels.go @@ -80,7 +80,14 @@ func (m *Client) getChannelIDTeam(name string, teamID string) string { } } - return "" + // Fallback if it's not found in the t.Channels or t.MoreChannels cache. + // This also let's us join private channels. + channel, _, err := m.Client.GetChannelByName(name, teamID, "") + if err != nil { + return "" + } + + return channel.Id } func (m *Client) GetChannelName(channelID string) string { @@ -224,8 +231,13 @@ func (m *Client) UpdateChannelsTeam(teamID string) error { } } + idx := 0 + max := 200 + + var moreChannels []*model.Channel + for { - mmchannels, resp, err = m.Client.GetPublicChannelsForTeam(teamID, 0, 5000, "") + mmchannels, resp, err = m.Client.GetPublicChannelsForTeam(teamID, idx, max, "") if err == nil { break } @@ -235,10 +247,27 @@ func (m *Client) UpdateChannelsTeam(teamID string) error { } } + for len(mmchannels) > 0 { + moreChannels = append(moreChannels, mmchannels...) + + for { + mmchannels, resp, err = m.Client.GetPublicChannelsForTeam(teamID, idx, max, "") + if err == nil { + idx++ + + break + } + + if err := m.HandleRatelimit("GetPublicChannelsForTeam", resp); err != nil { + return err + } + } + } + for idx, t := range m.OtherTeams { if t.ID == teamID { m.Lock() - m.OtherTeams[idx].MoreChannels = mmchannels + m.OtherTeams[idx].MoreChannels = moreChannels m.Unlock() } } @@ -252,6 +281,10 @@ func (m *Client) UpdateChannels() error { } for _, t := range m.OtherTeams { + // We've already populated users/channels for team in the above. + if t.ID == m.Team.ID { + continue + } if err := m.UpdateChannelsTeam(t.ID); err != nil { return err } diff --git a/vendor/github.com/matterbridge/matterclient/matterclient.go b/vendor/github.com/matterbridge/matterclient/matterclient.go index 0652fe73..fe845efc 100644 --- a/vendor/github.com/matterbridge/matterclient/matterclient.go +++ b/vendor/github.com/matterbridge/matterclient/matterclient.go @@ -144,6 +144,10 @@ func (m *Client) Login() error { return err } + if err := m.initUserChannels(); err != nil { + return err + } + if m.Team == nil { validTeamNames := make([]string, len(m.OtherTeams)) for i, t := range m.OtherTeams { @@ -332,8 +336,11 @@ func (m *Client) initUser() error { time.Sleep(time.Millisecond * 200) } - - m.logger.Infof("found %d users in team %s", len(usermap), team.Name) + m.logger.Debugf("found %d users in team %s", len(usermap), team.Name) + // add all users + for k, v := range usermap { + m.Users[k] = v + } t := &Team{ Team: team, @@ -341,29 +348,25 @@ func (m *Client) initUser() error { ID: team.Id, } - mmchannels, _, err := m.Client.GetChannelsForTeamForUser(team.Id, m.User.Id, false, "") - if err != nil { - return err - } - - t.Channels = mmchannels - - mmchannels, _, err = m.Client.GetPublicChannelsForTeam(team.Id, 0, 5000, "") - if err != nil { - return err - } - - t.MoreChannels = mmchannels m.OtherTeams = append(m.OtherTeams, t) if team.Name == m.Credentials.Team { m.Team = t m.logger.Debugf("initUser(): found our team %s (id: %s)", team.Name, team.Id) } - // add all users - for k, v := range t.Users { - m.Users[k] = v - } + } + + return nil +} + +func (m *Client) initUserChannels() error { + if err := m.UpdateChannels(); err != nil { + return err + } + + for _, t := range m.OtherTeams { + m.logger.Debugf("found %d channels for user in team %s", len(t.Channels), t.Team.Name) + m.logger.Debugf("found %d public channels in team %s", len(t.MoreChannels), t.Team.Name) } return nil |