Prevent re-requesting avatar data

Prevent asking the server again and again for a
user's avatar if the server does not respond to
our initial request.
This commit is contained in:
Alexander PapaTutuWawa
2020-04-19 09:35:11 +02:00
parent a18cb74f03
commit 7e2818692e

View File

@@ -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),
}
}
@@ -237,10 +239,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
@@ -271,6 +277,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.
}