diff options
author | Alexander <papatutuwawa@polynom.me> | 2020-05-24 14:07:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-24 14:07:36 +0200 |
commit | 900375679bfa248bcf02c203e9265e5e93a17a73 (patch) | |
tree | fc61b94dc6ba632e01b910a4367645e7ad81c449 /bridge | |
parent | 9440b9e3138805945214aa4d86368bb40da07cc2 (diff) | |
download | matterbridge-msglm-900375679bfa248bcf02c203e9265e5e93a17a73.tar.gz matterbridge-msglm-900375679bfa248bcf02c203e9265e5e93a17a73.tar.bz2 matterbridge-msglm-900375679bfa248bcf02c203e9265e5e93a17a73.zip |
Prevent re-requesting avatar data (xmpp) (#1117)
Prevent asking the server again and again for a
user's avatar if the server does not respond to
our initial request.
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/xmpp/xmpp.go | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index 75b2b598..ed99aac2 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -24,14 +24,16 @@ type Bxmpp struct { connected bool sync.RWMutex - avatarMap map[string]string + avatarAvailability map[string]bool + avatarMap map[string]string } func New(cfg *bridge.Config) bridge.Bridger { return &Bxmpp{ - Config: cfg, - xmppMap: make(map[string]string), - avatarMap: make(map[string]string), + Config: cfg, + xmppMap: make(map[string]string), + avatarAvailability: make(map[string]bool), + avatarMap: make(map[string]string), } } @@ -244,10 +246,14 @@ func (b *Bxmpp) handleXMPP() error { event = config.EventTopicChange } - avatar := getAvatar(b.avatarMap, v.Remote, b.General) - if avatar == "" { + available, sok := b.avatarAvailability[v.Remote] + avatar := "" + if !sok { b.Log.Debugf("Requesting avatar data") + b.avatarAvailability[v.Remote] = false b.xc.AvatarRequestData(v.Remote) + } else if available { + avatar = getAvatar(b.avatarMap, v.Remote, b.General) } msgID := v.ID @@ -278,6 +284,8 @@ func (b *Bxmpp) handleXMPP() error { } case xmpp.AvatarData: b.handleDownloadAvatar(v) + b.avatarAvailability[v.From] = true + b.Log.Debugf("Avatar for %s is now available", v.From) case xmpp.Presence: // Do nothing. } |