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