Support syncing dontNotifyIfMuted on GV2Records.

This commit is contained in:
Greyson Parrelli
2022-02-09 10:03:31 -05:00
committed by GitHub
parent b91a2e1450
commit 80a2e1e3cc
5 changed files with 39 additions and 17 deletions

View File

@@ -899,7 +899,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
fun applyStorageSyncGroupV2Update(update: StorageRecordUpdate<SignalGroupV2Record>) {
val values = getValuesForStorageGroupV2(update.new, false)
val updateCount = writableDatabase.update(TABLE_NAME, values, STORAGE_SERVICE_ID + " = ?", arrayOf(Base64.encodeBytes(update.old.id.raw)))
val updateCount = writableDatabase.update(TABLE_NAME, values, "$STORAGE_SERVICE_ID = ?", arrayOf(Base64.encodeBytes(update.old.id.raw)))
if (updateCount < 1) {
throw AssertionError("Had an update, but it didn't match any rows!")
}
@@ -1386,7 +1386,9 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
put(MENTION_SETTING, mentionSetting.id)
}
if (update(id, values)) {
rotateStorageId(id)
Recipient.live(id).refresh()
StorageSyncHelper.scheduleSyncForDataChange()
}
}
@@ -2763,6 +2765,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
put(BLOCKED, if (groupV2.isBlocked) "1" else "0")
put(MUTE_UNTIL, groupV2.muteUntil)
put(STORAGE_SERVICE_ID, Base64.encodeBytes(groupV2.id.raw))
put(MENTION_SETTING, if (groupV2.notifyForMentionsWhenMuted()) MentionSetting.ALWAYS_NOTIFY.id else MentionSetting.DO_NOT_NOTIFY.id)
if (groupV2.hasUnknownFields()) {
put(STORAGE_PROTO, Base64.encodeBytes(groupV2.serializeUnknownFields()))

View File

@@ -66,15 +66,16 @@ public final class GroupV2RecordProcessor extends DefaultStorageRecordProcessor<
@Override
@NonNull SignalGroupV2Record merge(@NonNull SignalGroupV2Record remote, @NonNull SignalGroupV2Record local, @NonNull StorageKeyGenerator keyGenerator) {
byte[] unknownFields = remote.serializeUnknownFields();
boolean blocked = remote.isBlocked();
boolean profileSharing = remote.isProfileSharingEnabled();
boolean archived = remote.isArchived();
boolean forcedUnread = remote.isForcedUnread();
long muteUntil = remote.getMuteUntil();
byte[] unknownFields = remote.serializeUnknownFields();
boolean blocked = remote.isBlocked();
boolean profileSharing = remote.isProfileSharingEnabled();
boolean archived = remote.isArchived();
boolean forcedUnread = remote.isForcedUnread();
long muteUntil = remote.getMuteUntil();
boolean notifyForMentionsWhenMuted = remote.notifyForMentionsWhenMuted();
boolean matchesRemote = doParamsMatch(remote, unknownFields, blocked, profileSharing, archived, forcedUnread, muteUntil);
boolean matchesLocal = doParamsMatch(local, unknownFields, blocked, profileSharing, archived, forcedUnread, muteUntil);
boolean matchesRemote = doParamsMatch(remote, unknownFields, blocked, profileSharing, archived, forcedUnread, muteUntil, notifyForMentionsWhenMuted);
boolean matchesLocal = doParamsMatch(local, unknownFields, blocked, profileSharing, archived, forcedUnread, muteUntil, notifyForMentionsWhenMuted);
if (matchesRemote) {
return remote;
@@ -87,6 +88,7 @@ public final class GroupV2RecordProcessor extends DefaultStorageRecordProcessor<
.setArchived(archived)
.setForcedUnread(forcedUnread)
.setMuteUntil(muteUntil)
.setNotifyForMentionsWhenMuted(notifyForMentionsWhenMuted)
.build();
}
}
@@ -133,13 +135,15 @@ public final class GroupV2RecordProcessor extends DefaultStorageRecordProcessor<
boolean profileSharing,
boolean archived,
boolean forcedUnread,
long muteUntil)
long muteUntil,
boolean notifyForMentionsWhenMuted)
{
return Arrays.equals(unknownFields, group.serializeUnknownFields()) &&
blocked == group.isBlocked() &&
profileSharing == group.isProfileSharingEnabled() &&
archived == group.isArchived() &&
forcedUnread == group.isForcedUnread() &&
muteUntil == group.getMuteUntil();
muteUntil == group.getMuteUntil() &&
notifyForMentionsWhenMuted == group.notifyForMentionsWhenMuted();
}
}

View File

@@ -152,6 +152,7 @@ public final class StorageSyncModels {
.setArchived(recipient.getSyncExtras().isArchived())
.setForcedUnread(recipient.getSyncExtras().isForcedUnread())
.setMuteUntil(recipient.getMuteUntil())
.setNotifyForMentionsWhenMuted(recipient.getMentionSetting() == RecipientDatabase.MentionSetting.ALWAYS_NOTIFY)
.build();
}