fix: maybe fix avatar download for new messages

This commit is contained in:
0x330a 2023-06-23 14:26:40 +10:00
parent 96969789cc
commit c741ec5093
3 changed files with 23 additions and 9 deletions

View File

@ -184,6 +184,12 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
database.setProfileAvatar(recipient, profileAvatar)
}
override fun setProfilePicture(recipient: Recipient, newProfilePicture: String?, newProfileKey: ByteArray?) {
val db = DatabaseComponent.get(context).recipientDatabase()
db.setProfileAvatar(recipient, newProfilePicture)
db.setProfileKey(recipient, newProfileKey)
}
override fun setUserProfilePicture(newProfilePicture: String?, newProfileKey: ByteArray?) {
val ourRecipient = fromSerialized(getUserPublicKey()!!).let {
Recipient.from(context, it, false)

View File

@ -55,15 +55,18 @@ class ProfileManager(private val context: Context, private val configFactory: Co
profilePictureURL: String?,
profileKey: ByteArray?
) {
val job = RetrieveProfileAvatarJob(profilePictureURL, recipient.address)
if (DatabaseComponent
.get(context)
.sessionJobDatabase()
.getAllJobs(RetrieveProfileAvatarJob.KEY).none {
(it.value as? RetrieveProfileAvatarJob)?.recipientAddress == recipient.address
}) {
JobQueue.shared.add(job)
}
val hasPendingDownload = DatabaseComponent
.get(context)
.sessionJobDatabase()
.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
)
val sessionID = recipient.address.serialize()
val contactDatabase = DatabaseComponent.get(context).sessionContactDatabase()
var contact = contactDatabase.getContactWithSessionID(sessionID)
@ -75,6 +78,10 @@ class ProfileManager(private val context: Context, private val configFactory: Co
contactDatabase.setContact(contact)
}
contactUpdatedInternal(contact)
if (!hasPendingDownload) {
val job = RetrieveProfileAvatarJob(profilePictureURL, recipient.address)
JobQueue.shared.add(job)
}
}
override fun setUnidentifiedAccessMode(context: Context, recipient: Recipient, unidentifiedAccessMode: Recipient.UnidentifiedAccessMode) {

View File

@ -41,6 +41,7 @@ interface StorageProtocol {
fun getUserX25519KeyPair(): ECKeyPair
fun getUserProfile(): Profile
fun setProfileAvatar(recipient: Recipient, profileAvatar: String?)
fun setProfilePicture(recipient: Recipient, newProfilePicture: String?, newProfileKey: ByteArray?)
fun setUserProfilePicture(newProfilePicture: String?, newProfileKey: ByteArray?)
fun clearUserPic()
// Signal