diff options
author | Wim <wim@42.be> | 2017-07-01 23:02:56 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-07-01 23:02:56 +0200 |
commit | f3e0358de7720dca350f2d9955827707d4810f51 (patch) | |
tree | 86827e72e445639594fb73ff8a5eb0f5048988b5 /matterclient | |
parent | 8064744d3a5fa4e4152ec2a2bca45e21a8c02fe4 (diff) | |
download | matterbridge-msglm-f3e0358de7720dca350f2d9955827707d4810f51.tar.gz matterbridge-msglm-f3e0358de7720dca350f2d9955827707d4810f51.tar.bz2 matterbridge-msglm-f3e0358de7720dca350f2d9955827707d4810f51.zip |
Optimize UpdateUsers usage. (from @recht matterircd fork)
Diffstat (limited to 'matterclient')
-rw-r--r-- | matterclient/matterclient.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go index 61eccacf..1dcab802 100644 --- a/matterclient/matterclient.go +++ b/matterclient/matterclient.go @@ -527,17 +527,15 @@ func (m *MMClient) UpdateLastViewed(channelId string) { } func (m *MMClient) UsernamesInChannel(channelId string) []string { - res, err := m.Client.GetMyChannelMembers() + res, err := m.Client.GetProfilesInChannel(channelId, 0, 50000, "") if err != nil { m.log.Errorf("UsernamesInChannel(%s) failed: %s", channelId, err) return []string{} } - members := res.Data.(*model.ChannelMembers) + members := res.Data.(map[string]*model.User) result := []string{} - for _, channel := range *members { - if channel.ChannelId == channelId { - result = append(result, m.GetUser(channel.UserId).Username) - } + for _, member := range members { + result = append(result, member.Nickname) } return result } @@ -665,6 +663,15 @@ func (m *MMClient) GetUsers() map[string]*model.User { func (m *MMClient) GetUser(userId string) *model.User { m.Lock() defer m.Unlock() + u, ok := m.Users[userId] + if !ok { + res, err := m.Client.GetProfilesByIds([]string{userId}) + if err != nil { + return nil + } + u = res.Data.(map[string]*model.User)[userId] + m.Users[userId] = u + } return m.Users[userId] } |