refactor: let the local number update recipient details in profile manager

This commit is contained in:
0x330a 2023-04-06 11:26:15 +10:00
parent e059fdaa19
commit 74f05a166b
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C

View File

@ -50,10 +50,10 @@ class ProfileManager(private val context: Context, private val configFactory: Co
} }
override fun setProfilePictureURL(context: Context, recipient: Recipient, profilePictureURL: String) { override fun setProfilePictureURL(context: Context, recipient: Recipient, profilePictureURL: String) {
if (recipient.isLocalNumber) return
val job = RetrieveProfileAvatarJob(recipient, profilePictureURL) val job = RetrieveProfileAvatarJob(recipient, profilePictureURL)
val jobManager = ApplicationContext.getInstance(context).jobManager val jobManager = ApplicationContext.getInstance(context).jobManager
jobManager.add(job) jobManager.add(job)
if (recipient.isLocalNumber) return
val sessionID = recipient.address.serialize() val sessionID = recipient.address.serialize()
val contactDatabase = DatabaseComponent.get(context).sessionContactDatabase() val contactDatabase = DatabaseComponent.get(context).sessionContactDatabase()
var contact = contactDatabase.getContactWithSessionID(sessionID) var contact = contactDatabase.getContactWithSessionID(sessionID)
@ -67,9 +67,13 @@ class ProfileManager(private val context: Context, private val configFactory: Co
} }
override fun setProfileKey(context: Context, recipient: Recipient, profileKey: ByteArray?) { override fun setProfileKey(context: Context, recipient: Recipient, profileKey: ByteArray?) {
if (recipient.isLocalNumber) return
// New API // New API
val sessionID = recipient.address.serialize() val sessionID = recipient.address.serialize()
// Old API
val database = DatabaseComponent.get(context).recipientDatabase()
database.setProfileKey(recipient, profileKey)
if (recipient.isLocalNumber) return
val contactDatabase = DatabaseComponent.get(context).sessionContactDatabase() val contactDatabase = DatabaseComponent.get(context).sessionContactDatabase()
var contact = contactDatabase.getContactWithSessionID(sessionID) var contact = contactDatabase.getContactWithSessionID(sessionID)
if (contact == null) contact = Contact(sessionID) if (contact == null) contact = Contact(sessionID)
@ -78,9 +82,6 @@ class ProfileManager(private val context: Context, private val configFactory: Co
contact.profilePictureEncryptionKey = profileKey contact.profilePictureEncryptionKey = profileKey
contactDatabase.setContact(contact) contactDatabase.setContact(contact)
} }
// Old API
val database = DatabaseComponent.get(context).recipientDatabase()
database.setProfileKey(recipient, profileKey)
contactUpdatedInternal(contact) contactUpdatedInternal(contact)
} }