Add support for storing systemNickname from storage service.

This commit is contained in:
Greyson Parrelli
2023-02-14 11:21:26 -05:00
parent 07234443c6
commit 4397b5af25
9 changed files with 54 additions and 7 deletions

View File

@@ -150,6 +150,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
const val SYSTEM_JOINED_NAME = "system_display_name"
const val SYSTEM_FAMILY_NAME = "system_family_name"
const val SYSTEM_GIVEN_NAME = "system_given_name"
const val SYSTEM_NICKNAME = "system_nickname"
private const val SYSTEM_PHOTO_URI = "system_photo_uri"
const val SYSTEM_PHONE_TYPE = "system_phone_type"
const val SYSTEM_PHONE_LABEL = "system_phone_label"
@@ -248,7 +249,8 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
$NEEDS_PNI_SIGNATURE INTEGER DEFAULT 0,
$UNREGISTERED_TIMESTAMP INTEGER DEFAULT 0,
$HIDDEN INTEGER DEFAULT 0,
$REPORTING_TOKEN BLOB DEFAULT NULL
$REPORTING_TOKEN BLOB DEFAULT NULL,
$SYSTEM_NICKNAME TEXT DEFAULT NULL
)
""".trimIndent()
@@ -1136,6 +1138,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
""".trimIndent()
val out: MutableList<RecipientRecord> = ArrayList()
val columns: Array<String> = TYPED_RECIPIENT_PROJECTION + arrayOf(
SYSTEM_NICKNAME,
"$TABLE_NAME.$STORAGE_PROTO",
"$TABLE_NAME.$UNREGISTERED_TIMESTAMP",
"${GroupTable.TABLE_NAME}.${GroupTable.V2_MASTER_KEY}",
@@ -3844,6 +3847,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
put(SYSTEM_GIVEN_NAME, systemName.givenName)
put(SYSTEM_FAMILY_NAME, systemName.familyName)
put(SYSTEM_JOINED_NAME, systemName.toString())
put(SYSTEM_NICKNAME, contact.systemNickname.orElse(null))
put(PROFILE_KEY, contact.profileKey.map { source -> Base64.encodeBytes(source) }.orElse(null))
put(USERNAME, if (TextUtils.isEmpty(username)) null else username)
put(PROFILE_SHARING, if (contact.isProfileSharingEnabled) "1" else "0")
@@ -4174,6 +4178,7 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
val identityKey = cursor.optionalString(IDENTITY_KEY).map { Base64.decodeOrThrow(it) }.orElse(null)
val identityStatus = cursor.optionalInt(IDENTITY_STATUS).map { VerifiedStatus.forState(it) }.orElse(VerifiedStatus.DEFAULT)
val unregisteredTimestamp = cursor.optionalLong(UNREGISTERED_TIMESTAMP).orElse(0)
val systemNickname = cursor.optionalString(SYSTEM_NICKNAME).orElse(null)
return RecipientRecord.SyncExtras(
storageProto = storageProto,
@@ -4182,7 +4187,8 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
identityStatus = identityStatus,
isArchived = archived,
isForcedUnread = forcedUnread,
unregisteredTimestamp = unregisteredTimestamp
unregisteredTimestamp = unregisteredTimestamp,
systemNickname = systemNickname
)
}

View File

@@ -35,6 +35,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V176_AddScheduledDa
import org.thoughtcrime.securesms.database.helpers.migration.V177_MessageSendLogTableCleanupMigration
import org.thoughtcrime.securesms.database.helpers.migration.V178_ReportingTokenColumnMigration
import org.thoughtcrime.securesms.database.helpers.migration.V179_CleanupDanglingMessageSendLogMigration
import org.thoughtcrime.securesms.database.helpers.migration.V180_RecipientNicknameMigration
/**
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
@@ -43,7 +44,7 @@ object SignalDatabaseMigrations {
val TAG: String = Log.tag(SignalDatabaseMigrations.javaClass)
const val DATABASE_VERSION = 179
const val DATABASE_VERSION = 180
@JvmStatic
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
@@ -170,6 +171,10 @@ object SignalDatabaseMigrations {
if (oldVersion < 179) {
V179_CleanupDanglingMessageSendLogMigration.migrate(context, db, oldVersion, newVersion)
}
if (oldVersion < 180) {
V180_RecipientNicknameMigration.migrate(context, db, oldVersion, newVersion)
}
}
@JvmStatic

View File

@@ -0,0 +1,13 @@
package org.thoughtcrime.securesms.database.helpers.migration
import android.app.Application
import net.zetetic.database.sqlcipher.SQLiteDatabase
/**
* Adds support for storing the systemNickname from storage service.
*/
object V180_RecipientNicknameMigration : SignalDatabaseMigration {
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
db.execSQL("ALTER TABLE recipient ADD COLUMN system_nickname TEXT DEFAULT NULL")
}
}

View File

@@ -113,7 +113,8 @@ data class RecipientRecord(
val identityStatus: VerifiedStatus,
val isArchived: Boolean,
val isForcedUnread: Boolean,
val unregisteredTimestamp: Long
val unregisteredTimestamp: Long,
val systemNickname: String?
)
data class Capabilities(

View File

@@ -266,8 +266,9 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
boolean hidden = remote.isHidden();
String systemGivenName = SignalStore.account().isPrimaryDevice() ? local.getSystemGivenName().orElse("") : remote.getSystemGivenName().orElse("");
String systemFamilyName = SignalStore.account().isPrimaryDevice() ? local.getSystemFamilyName().orElse("") : remote.getSystemFamilyName().orElse("");
boolean matchesRemote = doParamsMatch(remote, unknownFields, serviceId, pni, e164, profileGivenName, profileFamilyName, systemGivenName, systemFamilyName, profileKey, username, identityState, identityKey, blocked, profileSharing, archived, forcedUnread, muteUntil, hideStory, unregisteredTimestamp, hidden);
boolean matchesLocal = doParamsMatch(local, unknownFields, serviceId, pni, e164, profileGivenName, profileFamilyName, systemGivenName, systemFamilyName, profileKey, username, identityState, identityKey, blocked, profileSharing, archived, forcedUnread, muteUntil, hideStory, unregisteredTimestamp, hidden);
String systemNickname = remote.getSystemNickname().orElse("");
boolean matchesRemote = doParamsMatch(remote, unknownFields, serviceId, pni, e164, profileGivenName, profileFamilyName, systemGivenName, systemFamilyName, systemNickname, profileKey, username, identityState, identityKey, blocked, profileSharing, archived, forcedUnread, muteUntil, hideStory, unregisteredTimestamp, hidden);
boolean matchesLocal = doParamsMatch(local, unknownFields, serviceId, pni, e164, profileGivenName, profileFamilyName, systemGivenName, systemFamilyName, systemNickname, profileKey, username, identityState, identityKey, blocked, profileSharing, archived, forcedUnread, muteUntil, hideStory, unregisteredTimestamp, hidden);
if (matchesRemote) {
return remote;
@@ -281,6 +282,7 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
.setProfileFamilyName(profileFamilyName)
.setSystemGivenName(systemGivenName)
.setSystemFamilyName(systemFamilyName)
.setSystemNickname(systemNickname)
.setProfileKey(profileKey)
.setUsername(username)
.setIdentityState(identityState)
@@ -328,6 +330,7 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
@NonNull String profileFamilyName,
@NonNull String systemGivenName,
@NonNull String systemFamilyName,
@NonNull String systemNickname,
@Nullable byte[] profileKey,
@NonNull String username,
@Nullable IdentityState identityState,
@@ -349,6 +352,7 @@ public class ContactRecordProcessor extends DefaultStorageRecordProcessor<Signal
Objects.equals(contact.getProfileFamilyName().orElse(""), profileFamilyName) &&
Objects.equals(contact.getSystemGivenName().orElse(""), systemGivenName) &&
Objects.equals(contact.getSystemFamilyName().orElse(""), systemFamilyName) &&
Objects.equals(contact.getSystemNickname().orElse(""), systemNickname) &&
Arrays.equals(contact.getProfileKey().orElse(null), profileKey) &&
Objects.equals(contact.getUsername().orElse(""), username) &&
Objects.equals(contact.getIdentityState(), identityState) &&

View File

@@ -116,6 +116,7 @@ public final class StorageSyncModels {
.setProfileFamilyName(recipient.getProfileName().getFamilyName())
.setSystemGivenName(recipient.getSystemProfileName().getGivenName())
.setSystemFamilyName(recipient.getSystemProfileName().getFamilyName())
.setSystemNickname(recipient.getSyncExtras().getSystemNickname())
.setBlocked(recipient.isBlocked())
.setProfileSharingEnabled(recipient.isProfileSharing() || recipient.getSystemContactUri() != null)
.setIdentityKey(recipient.getSyncExtras().getIdentityKey())