Making sure the avatars refresh when changed by other users

This commit is contained in:
ThomasSession
2024-10-24 14:46:39 +11:00
parent 16cca2d3cc
commit 8615c57842
6 changed files with 32 additions and 26 deletions

View File

@@ -131,8 +131,10 @@ class ProfilePictureView @JvmOverloads constructor(
this.recipient = Recipient.from(context, Address.fromSerialized(publicKey), false)
this.recipient!!
}
if (profilePicturesCache[imageView] == recipient) return
profilePicturesCache[imageView] = recipient
// recipient is mutable so without cloning it the line above always returns true as the changes to the underlying recipient happens on both shared instances
profilePicturesCache[imageView] = recipient.clone()
val signalProfilePicture = recipient.contactPhoto
val avatar = (signalProfilePicture as? ProfileContactPhoto)?.avatarObject

View File

@@ -191,11 +191,6 @@ open class Storage(
return Profile(displayName, profileKey, profilePictureUrl)
}
override fun setProfileAvatar(recipient: Recipient, profileAvatar: String?) {
val database = DatabaseComponent.get(context).recipientDatabase()
database.setProfileAvatar(recipient, profileAvatar)
}
override fun setProfilePicture(recipient: Recipient, newProfilePicture: String?, newProfileKey: ByteArray?) {
val db = DatabaseComponent.get(context).recipientDatabase()
db.setProfileAvatar(recipient, newProfilePicture)
@@ -216,7 +211,7 @@ open class Storage(
TextSecurePreferences.setProfilePictureURL(context, newProfilePicture)
if (newProfileKey != null) {
JobQueue.shared.add(RetrieveProfileAvatarJob(newProfilePicture, ourRecipient.address))
JobQueue.shared.add(RetrieveProfileAvatarJob(newProfilePicture, ourRecipient.address, newProfileKey))
}
}

View File

@@ -61,12 +61,9 @@ class ProfileManager(private val context: Context, private val configFactory: Co
.getAllJobs(RetrieveProfileAvatarJob.KEY).any {
(it.value as? RetrieveProfileAvatarJob)?.recipientAddress == recipient.address
}
val resolved = recipient.resolve()
DatabaseComponent.get(context).storage().setProfilePicture(
recipient = resolved,
newProfileKey = profileKey,
newProfilePicture = profilePictureURL
)
recipient.resolve()
val accountID = recipient.address.serialize()
val contactDatabase = DatabaseComponent.get(context).sessionContactDatabase()
var contact = contactDatabase.getContactWithAccountID(accountID)
@@ -79,7 +76,7 @@ class ProfileManager(private val context: Context, private val configFactory: Co
}
contactUpdatedInternal(contact)
if (!hasPendingDownload) {
val job = RetrieveProfileAvatarJob(profilePictureURL, recipient.address)
val job = RetrieveProfileAvatarJob(profilePictureURL, recipient.address, profileKey)
JobQueue.shared.add(job)
}
}