Fix profile picture and display name updating from a slave device

This commit is contained in:
ryanzhao 2020-06-03 17:03:35 +10:00
parent 85e98dbceb
commit 733ed3ff5a
3 changed files with 28 additions and 1 deletions

View File

@ -194,6 +194,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
profileButton.update()
val isMasterDevice = (TextSecurePreferences.getMasterHexEncodedPublicKey(this) == null) val isMasterDevice = (TextSecurePreferences.getMasterHexEncodedPublicKey(this) == null)
val hasViewedSeed = TextSecurePreferences.getHasViewedSeed(this) val hasViewedSeed = TextSecurePreferences.getHasViewedSeed(this)
if (hasViewedSeed || !isMasterDevice) { if (hasViewedSeed || !isMasterDevice) {

View File

@ -197,7 +197,7 @@ object MultiDeviceProtocol {
TextSecurePreferences.setMultiDevice(context, true) TextSecurePreferences.setMultiDevice(context, true)
LokiFileServerAPI.shared.addDeviceLink(deviceLink) LokiFileServerAPI.shared.addDeviceLink(deviceLink)
org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol.handleProfileUpdateIfNeeded(context, content) org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol.handleProfileUpdateIfNeeded(context, content)
org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol.handleProfileKeyUpdateIfNeeded(context, content) org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol.handleProfileKey(context, content)
} }
@JvmStatic @JvmStatic

View File

@ -4,11 +4,15 @@ import android.content.Context
import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.database.Address import org.thoughtcrime.securesms.database.Address
import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.RecipientDatabase
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob
import org.thoughtcrime.securesms.recipients.Recipient import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.util.TextSecurePreferences import org.thoughtcrime.securesms.util.TextSecurePreferences
import org.whispersystems.signalservice.api.messages.SignalServiceContent import org.whispersystems.signalservice.api.messages.SignalServiceContent
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage
import org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol import org.whispersystems.signalservice.loki.protocol.multidevice.MultiDeviceProtocol
import org.whispersystems.signalservice.loki.protocol.todo.LokiThreadFriendRequestStatus import org.whispersystems.signalservice.loki.protocol.todo.LokiThreadFriendRequestStatus
import java.security.MessageDigest
object SessionMetaProtocol { object SessionMetaProtocol {
@ -39,6 +43,28 @@ object SessionMetaProtocol {
if (!allUserDevices.contains(sender)) { if (!allUserDevices.contains(sender)) {
val displayName = rawDisplayName + " (..." + sender.substring(sender.length - 8) + ")" val displayName = rawDisplayName + " (..." + sender.substring(sender.length - 8) + ")"
DatabaseFactory.getLokiUserDatabase(context).setDisplayName(sender, displayName) DatabaseFactory.getLokiUserDatabase(context).setDisplayName(sender, displayName)
} else {
DatabaseFactory.getLokiUserDatabase(context).setDisplayName(sender, rawDisplayName)
}
}
@JvmStatic
fun handleProfileKey(context: Context, content: SignalServiceContent) {
val message = content.dataMessage.get()
if (!message.profileKey.isPresent) { return }
/*
If we get a profile key then we don't need to map it to the primary device.
For now a profile key is mapped one-to-one to avoid secondary devices setting the incorrect avatar for a primary device.
*/
val database = DatabaseFactory.getRecipientDatabase(context)
val recipient = Recipient.from(context, Address.fromSerialized(content.sender), false)
if (recipient.profileKey == null || !MessageDigest.isEqual(recipient.profileKey, message.profileKey.get())) {
database.setProfileKey(recipient, message.profileKey.get())
database.setUnidentifiedAccessMode(recipient, RecipientDatabase.UnidentifiedAccessMode.UNKNOWN)
val url = content.senderProfilePictureURL.or("")
ApplicationContext.getInstance(context).jobManager.add(RetrieveProfileAvatarJob(recipient, url))
handleProfileKeyUpdateIfNeeded(context, content)
} }
} }