mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-25 02:55:23 +00:00
[wip]
fix: trying to consolidate prof pic and key properly
This commit is contained in:
parent
6bb1ad2ca9
commit
fb7dcf58ca
@ -178,11 +178,12 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
|
||||
return Profile(displayName, profileKey, profilePictureUrl)
|
||||
}
|
||||
|
||||
override fun setUserProfilePictureURL(newProfilePicture: String?) {
|
||||
override fun setUserProfilePicture(newProfilePicture: String?, newProfileKey: ByteArray?) {
|
||||
val ourRecipient = fromSerialized(getUserPublicKey()!!).let {
|
||||
Recipient.from(context, it, false)
|
||||
}
|
||||
TextSecurePreferences.setProfilePictureURL(context, newProfilePicture)
|
||||
TextSecurePreferences.setProfileKey(context, newProfileKey?.let { Base64.encodeBytes(it) })
|
||||
ApplicationContext.getInstance(context).jobManager.add(RetrieveProfileAvatarJob(ourRecipient, newProfilePicture))
|
||||
}
|
||||
|
||||
@ -427,10 +428,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
|
||||
clearUserPic()
|
||||
} else if (userPic.key.isNotEmpty() && userPic.url.isNotEmpty()
|
||||
&& TextSecurePreferences.getProfilePictureURL(context) != userPic.url) {
|
||||
val profileKey = Base64.encodeBytes(userPic.key)
|
||||
ProfileKeyUtil.setEncodedProfileKey(context, profileKey)
|
||||
profileManager.setProfileKey(context, recipient, userPic.key)
|
||||
setUserProfilePictureURL(userPic.url)
|
||||
setUserProfilePicture(userPic.url, userPic.key)
|
||||
}
|
||||
if (userProfile.getNtsPriority() == PRIORITY_HIDDEN) {
|
||||
// delete nts thread if needed
|
||||
@ -458,10 +456,9 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
|
||||
TextSecurePreferences.setProfileKey(context, null)
|
||||
TextSecurePreferences.setProfileAvatarId(context, 0)
|
||||
ProfileKeyUtil.setEncodedProfileKey(context, null)
|
||||
SSKEnvironment.shared.profileManager.setProfileKey(context, recipient, null)
|
||||
recipientDatabase.setProfileAvatar(recipient, null)
|
||||
|
||||
setUserProfilePictureURL(null)
|
||||
setUserProfilePicture(null, null)
|
||||
Recipient.removeCached(fromSerialized(userPublicKey))
|
||||
configFactory.user?.setPic(UserPic.DEFAULT)
|
||||
ConfigurationMessageUtilities.forceSyncConfigurationNowIfNeeded(context)
|
||||
@ -1124,9 +1121,8 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
|
||||
if (contact.profilePicture != UserPic.DEFAULT) {
|
||||
val (url, key) = contact.profilePicture
|
||||
if (key.size != ProfileKeyUtil.PROFILE_KEY_BYTES) return@forEach
|
||||
profileManager.setProfileKey(context, recipient, key)
|
||||
profileManager.setProfilePicture(context, recipient, url, key)
|
||||
profileManager.setUnidentifiedAccessMode(context, recipient, Recipient.UnidentifiedAccessMode.UNKNOWN)
|
||||
profileManager.setProfilePictureURL(context, recipient, url)
|
||||
}
|
||||
if (contact.priority == PRIORITY_HIDDEN) {
|
||||
getThreadId(fromSerialized(contact.id))?.let { conversationThreadId ->
|
||||
@ -1342,9 +1338,8 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
|
||||
val profileKeyChanged = (sender.profileKey == null || !MessageDigest.isEqual(sender.profileKey, newProfileKey))
|
||||
|
||||
if ((profileKeyValid && profileKeyChanged) || (profileKeyValid && needsProfilePicture)) {
|
||||
profileManager.setProfileKey(context, sender, newProfileKey!!)
|
||||
profileManager.setProfilePicture(context, sender, profile.profilePictureURL!!, newProfileKey!!)
|
||||
profileManager.setUnidentifiedAccessMode(context, sender, Recipient.UnidentifiedAccessMode.UNKNOWN)
|
||||
profileManager.setProfilePictureURL(context, sender, profile.profilePictureURL!!)
|
||||
}
|
||||
}
|
||||
threadDB.setHasSent(threadId, true)
|
||||
|
@ -106,14 +106,15 @@ public class RetrieveProfileAvatarJob extends BaseJob {
|
||||
|
||||
Util.copy(avatarStream, new FileOutputStream(decryptDestination));
|
||||
decryptDestination.renameTo(AvatarHelper.getAvatarFile(context, recipient.getAddress()));
|
||||
if (recipient.isLocalNumber()) {
|
||||
TextSecurePreferences.setProfileAvatarId(context, new SecureRandom().nextInt());
|
||||
}
|
||||
database.setProfileAvatar(recipient, profileAvatar);
|
||||
} catch (Exception e) {
|
||||
|
||||
} finally {
|
||||
if (downloadDestination != null) downloadDestination.delete();
|
||||
}
|
||||
|
||||
if (recipient.isLocalNumber()) {
|
||||
TextSecurePreferences.setProfileAvatarId(context, new SecureRandom().nextInt());
|
||||
}
|
||||
database.setProfileAvatar(recipient, profileAvatar);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -49,24 +49,12 @@ class ProfileManager(private val context: Context, private val configFactory: Co
|
||||
contactUpdatedInternal(contact)
|
||||
}
|
||||
|
||||
override fun setProfilePictureURL(context: Context, recipient: Recipient, profilePictureURL: String) {
|
||||
val job = RetrieveProfileAvatarJob(recipient, profilePictureURL)
|
||||
val jobManager = ApplicationContext.getInstance(context).jobManager
|
||||
jobManager.add(job)
|
||||
if (recipient.isLocalNumber) return
|
||||
val sessionID = recipient.address.serialize()
|
||||
val contactDatabase = DatabaseComponent.get(context).sessionContactDatabase()
|
||||
var contact = contactDatabase.getContactWithSessionID(sessionID)
|
||||
if (contact == null) contact = Contact(sessionID)
|
||||
contact.threadID = DatabaseComponent.get(context).storage().getThreadId(recipient.address)
|
||||
if (contact.profilePictureURL != profilePictureURL) {
|
||||
contact.profilePictureURL = profilePictureURL
|
||||
contactDatabase.setContact(contact)
|
||||
}
|
||||
contactUpdatedInternal(contact)
|
||||
}
|
||||
|
||||
override fun setProfileKey(context: Context, recipient: Recipient, profileKey: ByteArray?) {
|
||||
override fun setProfilePicture(
|
||||
context: Context,
|
||||
recipient: Recipient,
|
||||
profilePictureURL: String?,
|
||||
profileKey: ByteArray?
|
||||
) {
|
||||
// New API
|
||||
val sessionID = recipient.address.serialize()
|
||||
// Old API
|
||||
@ -78,13 +66,18 @@ class ProfileManager(private val context: Context, private val configFactory: Co
|
||||
var contact = contactDatabase.getContactWithSessionID(sessionID)
|
||||
if (contact == null) contact = Contact(sessionID)
|
||||
contact.threadID = DatabaseComponent.get(context).storage().getThreadId(recipient.address)
|
||||
if (!contact.profilePictureEncryptionKey.contentEquals(profileKey)) {
|
||||
if (!contact.profilePictureEncryptionKey.contentEquals(profileKey) || contact.profilePictureURL != profilePictureURL) {
|
||||
contact.profilePictureEncryptionKey = profileKey
|
||||
contact.profilePictureURL = profilePictureURL
|
||||
contactDatabase.setContact(contact)
|
||||
}
|
||||
val job = RetrieveProfileAvatarJob(recipient, profilePictureURL)
|
||||
val jobManager = ApplicationContext.getInstance(context).jobManager
|
||||
jobManager.add(job)
|
||||
contactUpdatedInternal(contact)
|
||||
}
|
||||
|
||||
|
||||
override fun setUnidentifiedAccessMode(context: Context, recipient: Recipient, unidentifiedAccessMode: Recipient.UnidentifiedAccessMode) {
|
||||
val database = DatabaseComponent.get(context).recipientDatabase()
|
||||
database.setUnidentifiedAccessMode(recipient, unidentifiedAccessMode)
|
||||
|
@ -40,7 +40,7 @@ interface StorageProtocol {
|
||||
fun getUserPublicKey(): String?
|
||||
fun getUserX25519KeyPair(): ECKeyPair
|
||||
fun getUserProfile(): Profile
|
||||
fun setUserProfilePictureURL(newProfilePicture: String?)
|
||||
fun setUserProfilePicture(newProfilePicture: String?, newProfileKey: ByteArray?)
|
||||
fun clearUserPic()
|
||||
// Signal
|
||||
fun getOrGenerateRegistrationID(): Int
|
||||
|
@ -188,10 +188,7 @@ private fun handleConfigurationMessage(message: ConfigurationMessage) {
|
||||
&& TextSecurePreferences.getProfilePictureURL(context) != message.profilePicture) {
|
||||
val profileKey = Base64.encodeBytes(message.profileKey)
|
||||
ProfileKeyUtil.setEncodedProfileKey(context, profileKey)
|
||||
profileManager.setProfileKey(context, recipient, message.profileKey)
|
||||
if (!message.profilePicture.isNullOrEmpty() && TextSecurePreferences.getProfilePictureURL(context) != message.profilePicture) {
|
||||
storage.setUserProfilePictureURL(message.profilePicture!!)
|
||||
}
|
||||
profileManager.setProfilePicture(context, recipient, message.profilePicture, message.profileKey)
|
||||
}
|
||||
storage.addContacts(message.contacts)
|
||||
}
|
||||
@ -264,9 +261,8 @@ fun MessageReceiver.handleVisibleMessage(
|
||||
val profileKeyChanged = (recipient.profileKey == null || !MessageDigest.isEqual(recipient.profileKey, newProfileKey))
|
||||
|
||||
if ((profileKeyValid && profileKeyChanged) || (profileKeyValid && needsProfilePicture)) {
|
||||
profileManager.setProfileKey(context, recipient, newProfileKey!!)
|
||||
profileManager.setProfilePicture(context, recipient, profile.profilePictureURL, newProfileKey)
|
||||
profileManager.setUnidentifiedAccessMode(context, recipient, Recipient.UnidentifiedAccessMode.UNKNOWN)
|
||||
profileManager.setProfilePictureURL(context, recipient, profile.profilePictureURL!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,7 @@ class SSKEnvironment(
|
||||
|
||||
fun setNickname(context: Context, recipient: Recipient, nickname: String?)
|
||||
fun setName(context: Context, recipient: Recipient, name: String?)
|
||||
fun setProfilePictureURL(context: Context, recipient: Recipient, profilePictureURL: String)
|
||||
fun setProfileKey(context: Context, recipient: Recipient, profileKey: ByteArray?)
|
||||
fun setProfilePicture(context: Context, recipient: Recipient, profilePictureURL: String?, profileKey: ByteArray?)
|
||||
fun setUnidentifiedAccessMode(context: Context, recipient: Recipient, unidentifiedAccessMode: Recipient.UnidentifiedAccessMode)
|
||||
fun contactUpdatedInternal(contact: Contact)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user