Always sync private chat portal meta in background sync

This commit is contained in:
Tulir Asokan 2022-07-05 11:11:43 +03:00
parent c16af35d1b
commit 17a9df3297
2 changed files with 14 additions and 9 deletions

View file

@ -245,9 +245,12 @@ func reuploadAvatar(intent *appservice.IntentAPI, url string) (id.ContentURI, er
return resp.ContentURI, nil
}
func (puppet *Puppet) UpdateAvatar(source *User) bool {
func (puppet *Puppet) UpdateAvatar(source *User, forcePortalSync bool) bool {
changed := source.updateAvatar(puppet.JID, &puppet.Avatar, &puppet.AvatarURL, &puppet.AvatarSet, puppet.log, puppet.DefaultIntent())
if !changed || puppet.Avatar == "unauthorized" {
if forcePortalSync {
go puppet.updatePortalAvatar()
}
return changed
}
err := puppet.DefaultIntent().SetAvatarURL(puppet.AvatarURL)
@ -260,7 +263,7 @@ func (puppet *Puppet) UpdateAvatar(source *User) bool {
return true
}
func (puppet *Puppet) UpdateName(contact types.ContactInfo) bool {
func (puppet *Puppet) UpdateName(contact types.ContactInfo, forcePortalSync bool) bool {
newName, quality := puppet.bridge.Config.Bridge.FormatDisplayname(puppet.JID, contact)
if (puppet.Displayname != newName || !puppet.NameSet) && quality >= puppet.NameQuality {
puppet.Displayname = newName
@ -275,6 +278,8 @@ func (puppet *Puppet) UpdateName(contact types.ContactInfo) bool {
puppet.log.Warnln("Failed to set display name:", err)
}
return true
} else if forcePortalSync {
go puppet.updatePortalName()
}
return false
}
@ -329,10 +334,10 @@ func (puppet *Puppet) SyncContact(source *User, onlyIfNoName, shouldHavePushName
} else if !contact.Found {
puppet.log.Warnfln("No contact info found through %s in SyncContact (sync reason: %s)", source.MXID, reason)
}
puppet.Sync(source, &contact, false)
puppet.Sync(source, &contact, false, false)
}
func (puppet *Puppet) Sync(source *User, contact *types.ContactInfo, forceAvatarSync bool) {
func (puppet *Puppet) Sync(source *User, contact *types.ContactInfo, forceAvatarSync, forcePortalSync bool) {
puppet.syncLock.Lock()
defer puppet.syncLock.Unlock()
err := puppet.DefaultIntent().EnsureRegistered()
@ -347,10 +352,10 @@ func (puppet *Puppet) Sync(source *User, contact *types.ContactInfo, forceAvatar
if puppet.JID.User == source.JID.User {
contact.PushName = source.Client.Store.PushName
}
update = puppet.UpdateName(*contact) || update
update = puppet.UpdateName(*contact, forcePortalSync) || update
}
if len(puppet.Avatar) == 0 || forceAvatarSync || puppet.bridge.Config.Bridge.UserAvatarSync {
update = puppet.UpdateAvatar(source) || update
update = puppet.UpdateAvatar(source, forcePortalSync) || update
}
if update || puppet.LastSync.Add(24*time.Hour).Before(time.Now()) {
puppet.LastSync = time.Now()

View file

@ -339,7 +339,7 @@ func (user *User) doPuppetResync() {
} else if contact.Found {
contactPtr = &contact
}
puppet.Sync(user, contactPtr, info.PictureID != "" && info.PictureID != puppet.Avatar)
puppet.Sync(user, contactPtr, info.PictureID != "" && info.PictureID != puppet.Avatar, true)
}
}
@ -1143,7 +1143,7 @@ func (user *User) ResyncContacts(forceAvatarSync bool) error {
for jid, contact := range contacts {
puppet := user.bridge.GetPuppetByJID(jid)
if puppet != nil {
puppet.Sync(user, &contact, forceAvatarSync)
puppet.Sync(user, &contact, forceAvatarSync, true)
} else {
user.log.Warnfln("Got a nil puppet for %s while syncing contacts", jid)
}
@ -1310,7 +1310,7 @@ func (user *User) handlePictureUpdate(evt *events.Picture) {
puppet := user.bridge.GetPuppetByJID(evt.JID)
user.log.Debugfln("Received picture update for puppet %s (current: %s, new: %s)", evt.JID, puppet.Avatar, evt.PictureID)
if puppet.Avatar != evt.PictureID {
puppet.Sync(user, nil, true)
puppet.Sync(user, nil, true, false)
}
} else if portal := user.GetPortalByJID(evt.JID); portal != nil {
user.log.Debugfln("Received picture update for portal %s (current: %s, new: %s)", evt.JID, portal.Avatar, evt.PictureID)