Add support for storing systemNickname from storage service.

main
Greyson Parrelli 2023-02-14 11:21:26 -05:00
rodzic 07234443c6
commit 4397b5af25
9 zmienionych plików z 54 dodań i 7 usunięć

Wyświetl plik

@ -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
)
}

Wyświetl plik

@ -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

Wyświetl plik

@ -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")
}
}

Wyświetl plik

@ -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(

Wyświetl plik

@ -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) &&

Wyświetl plik

@ -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())

Wyświetl plik

@ -78,7 +78,8 @@ object RecipientDatabaseTestUtils {
IdentityTable.VerifiedStatus.DEFAULT,
false,
false,
0
0,
null
),
extras: Recipient.Extras? = null,
hasGroupsInCommon: Boolean = false,

Wyświetl plik

@ -32,6 +32,7 @@ public final class SignalContactRecord implements SignalRecord {
private final Optional<String> profileFamilyName;
private final Optional<String> systemGivenName;
private final Optional<String> systemFamilyName;
private final Optional<String> systemNickname;
private final Optional<byte[]> profileKey;
private final Optional<String> username;
private final Optional<byte[]> identityKey;
@ -48,6 +49,7 @@ public final class SignalContactRecord implements SignalRecord {
this.profileFamilyName = OptionalUtil.absentIfEmpty(proto.getFamilyName());
this.systemGivenName = OptionalUtil.absentIfEmpty(proto.getSystemGivenName());
this.systemFamilyName = OptionalUtil.absentIfEmpty(proto.getSystemFamilyName());
this.systemNickname = OptionalUtil.absentIfEmpty(proto.getSystemNickname());
this.profileKey = OptionalUtil.absentIfEmpty(proto.getProfileKey());
this.username = OptionalUtil.absentIfEmpty(proto.getUsername());
this.identityKey = OptionalUtil.absentIfEmpty(proto.getIdentityKey());
@ -101,6 +103,10 @@ public final class SignalContactRecord implements SignalRecord {
diff.add("SystemFamilyName");
}
if (!Objects.equals(this.systemNickname, that.systemNickname)) {
diff.add("SystemNickname");
}
if (!OptionalUtil.byteArrayEquals(this.profileKey, that.profileKey)) {
diff.add("ProfileKey");
}
@ -195,6 +201,10 @@ public final class SignalContactRecord implements SignalRecord {
return systemFamilyName;
}
public Optional<String> getSystemNickname() {
return systemNickname;
}
public Optional<byte[]> getProfileKey() {
return profileKey;
}
@ -314,6 +324,11 @@ public final class SignalContactRecord implements SignalRecord {
return this;
}
public Builder setSystemNickname(String nickname) {
builder.setSystemNickname(nickname == null ? "" : nickname);
return this;
}
public Builder setProfileKey(byte[] profileKey) {
builder.setProfileKey(profileKey == null ? ByteString.EMPTY : ByteString.copyFrom(profileKey));
return this;

Wyświetl plik

@ -95,6 +95,7 @@ message ContactRecord {
uint64 unregisteredAtTimestamp = 16;
string systemGivenName = 17;
string systemFamilyName = 18;
string systemNickname = 19;
bool hidden = 20;
// NEXT ID: 21
}