mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Addressed PR feedback
This commit is contained in:
parent
c77d465438
commit
b7744f4f2d
@ -69,15 +69,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
||||
return Profile(displayName, profileKey, profilePictureUrl)
|
||||
}
|
||||
|
||||
override fun setUserProfilePictureURL(newValue: String) {
|
||||
val ourRecipient = fromSerialized(getUserPublicKey()!!).let {
|
||||
Recipient.from(context, it, false)
|
||||
}
|
||||
TextSecurePreferences.setProfilePictureURL(context, newValue)
|
||||
JobQueue.shared.add(RetrieveProfileAvatarJob(newValue, ourRecipient.address))
|
||||
}
|
||||
|
||||
override fun setProfileAvatar(recipient: Recipient, profileAvatar: String) {
|
||||
override fun setProfileAvatar(recipient: Recipient, profileAvatar: String?) {
|
||||
val database = DatabaseComponent.get(context).recipientDatabase()
|
||||
database.setProfileAvatar(recipient, profileAvatar)
|
||||
}
|
||||
|
@ -37,8 +37,7 @@ interface StorageProtocol {
|
||||
fun getUserPublicKey(): String?
|
||||
fun getUserX25519KeyPair(): ECKeyPair
|
||||
fun getUserProfile(): Profile
|
||||
fun setUserProfilePictureURL(newProfilePicture: String)
|
||||
fun setProfileAvatar(recipient: Recipient, profileAvatar: String)
|
||||
fun setProfileAvatar(recipient: Recipient, profileAvatar: String?)
|
||||
// Signal
|
||||
fun getOrGenerateRegistrationID(): Int
|
||||
|
||||
|
@ -9,6 +9,8 @@ import org.session.libsession.utilities.TextSecurePreferences.Companion.setProfi
|
||||
import org.session.libsession.utilities.Util.copy
|
||||
import org.session.libsession.utilities.Util.equals
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsession.utilities.TextSecurePreferences.Companion.setProfilePictureURL
|
||||
import org.session.libsession.utilities.recipients.Recipient
|
||||
import org.session.libsignal.streams.ProfileCipherInputStream
|
||||
import org.session.libsignal.utilities.Log
|
||||
@ -18,7 +20,7 @@ import java.io.FileOutputStream
|
||||
import java.io.InputStream
|
||||
import java.security.SecureRandom
|
||||
|
||||
class RetrieveProfileAvatarJob(val profileAvatar: String, val recipientAddress: Address): Job {
|
||||
class RetrieveProfileAvatarJob(val profileAvatar: String?, val recipientAddress: Address): Job {
|
||||
override var delegate: JobDelegate? = null
|
||||
override var id: String? = null
|
||||
override var failureCount: Int = 0
|
||||
@ -49,10 +51,16 @@ class RetrieveProfileAvatarJob(val profileAvatar: String, val recipientAddress:
|
||||
return
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(profileAvatar)) {
|
||||
if (profileAvatar.isNullOrEmpty()) {
|
||||
Log.w(TAG, "Removing profile avatar for: " + recipient.address.serialize())
|
||||
|
||||
if (recipient.isLocalNumber) {
|
||||
setProfileAvatarId(context, SecureRandom().nextInt())
|
||||
setProfilePictureURL(context, null)
|
||||
}
|
||||
|
||||
AvatarHelper.delete(context, recipient.address)
|
||||
storage.setProfileAvatar(recipient, profileAvatar)
|
||||
storage.setProfileAvatar(recipient, null)
|
||||
return
|
||||
}
|
||||
|
||||
@ -70,7 +78,9 @@ class RetrieveProfileAvatarJob(val profileAvatar: String, val recipientAddress:
|
||||
|
||||
if (recipient.isLocalNumber) {
|
||||
setProfileAvatarId(context, SecureRandom().nextInt())
|
||||
setProfilePictureURL(context, profileAvatar)
|
||||
}
|
||||
|
||||
storage.setProfileAvatar(recipient, profileAvatar)
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import org.session.libsession.avatars.AvatarHelper
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
import org.session.libsession.messaging.jobs.BackgroundGroupAddJob
|
||||
import org.session.libsession.messaging.jobs.JobQueue
|
||||
import org.session.libsession.messaging.jobs.RetrieveProfileAvatarJob
|
||||
import org.session.libsession.messaging.messages.Message
|
||||
import org.session.libsession.messaging.messages.control.CallMessage
|
||||
import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage
|
||||
@ -183,7 +184,7 @@ private fun handleConfigurationMessage(message: ConfigurationMessage) {
|
||||
ProfileKeyUtil.setEncodedProfileKey(context, profileKey)
|
||||
profileManager.setProfileKey(context, recipient, message.profileKey)
|
||||
if (!message.profilePicture.isNullOrEmpty() && TextSecurePreferences.getProfilePictureURL(context) != message.profilePicture) {
|
||||
storage.setUserProfilePictureURL(message.profilePicture!!)
|
||||
JobQueue.shared.add(RetrieveProfileAvatarJob(message.profilePicture!!, recipient.address))
|
||||
}
|
||||
}
|
||||
storage.addContacts(message.contacts)
|
||||
|
Loading…
Reference in New Issue
Block a user