diff --git a/go.mod b/go.mod index 8e9df8d9..f594e1f3 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/hashicorp/golang-lru v0.5.4 github.com/jpillora/backoff v1.0.0 github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba - github.com/matterbridge/matterclient v0.0.0-20220624224459-272af20c7ddf + github.com/matterbridge/matterclient v0.0.0-20221106190440-8bcf49695e0d github.com/mattermost/mattermost-server/v5 v5.39.3 github.com/mattermost/mattermost-server/v6 v6.7.2 github.com/mitchellh/mapstructure v1.5.0 diff --git a/go.sum b/go.sum index 7e426775..370c6f00 100644 --- a/go.sum +++ b/go.sum @@ -1048,8 +1048,8 @@ github.com/marstr/guid v0.0.0-20170427235115-8bdf7d1a087c/go.mod h1:74gB1z2wpxxI github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho= github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba h1:XleOY4IjAEIcxAh+IFwT5JT5Ze3RHiYz6m+4ZfZ0rc0= github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba/go.mod h1:iXGEotOvwI1R1SjLxRc+BF5rUORTMtE0iMZBT2lxqAU= -github.com/matterbridge/matterclient v0.0.0-20220624224459-272af20c7ddf h1:vaiRcLFKSD0fzlcLll53LU8HnpVv8XzP7C0mi8Tfvro= -github.com/matterbridge/matterclient v0.0.0-20220624224459-272af20c7ddf/go.mod h1:Zg8PH1P/1CNUxozQ8blnjAV9PA4Qn2qWf33cX5yNKGM= +github.com/matterbridge/matterclient v0.0.0-20221106190440-8bcf49695e0d h1:aI0ANEzy3dMv3vEAMQ80AItNie0fBR9ZxE2sAedORmM= +github.com/matterbridge/matterclient v0.0.0-20221106190440-8bcf49695e0d/go.mod h1:Zg8PH1P/1CNUxozQ8blnjAV9PA4Qn2qWf33cX5yNKGM= github.com/mattermost/go-i18n v1.11.0/go.mod h1:RyS7FDNQlzF1PsjbJWHRI35exqaKGSO9qD4iv8QjE34= github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404 h1:Khvh6waxG1cHc4Cz5ef9n3XVCxRWpAKUtqg9PJl5+y8= github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404/go.mod h1:RyS7FDNQlzF1PsjbJWHRI35exqaKGSO9qD4iv8QjE34= 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 diff --git a/vendor/modules.txt b/vendor/modules.txt index 5aad3bc2..d5ea5a26 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -90,7 +90,7 @@ github.com/magiconair/properties # github.com/matterbridge/logrus-prefixed-formatter v0.5.3-0.20200523233437-d971309a77ba ## explicit github.com/matterbridge/logrus-prefixed-formatter -# github.com/matterbridge/matterclient v0.0.0-20220624224459-272af20c7ddf +# github.com/matterbridge/matterclient v0.0.0-20221106190440-8bcf49695e0d ## explicit; go 1.17 github.com/matterbridge/matterclient # github.com/mattermost/go-i18n v1.11.1-0.20211013152124-5c415071e404