From 80a2e1e3ccc5cd2088364b97775889cabea4d218 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Wed, 9 Feb 2022 10:03:31 -0500 Subject: [PATCH] Support syncing dontNotifyIfMuted on GV2Records. --- .../securesms/database/RecipientDatabase.kt | 5 +++- .../storage/GroupV2RecordProcessor.java | 24 +++++++++++-------- .../securesms/storage/StorageSyncModels.java | 1 + .../api/storage/SignalGroupV2Record.java | 13 ++++++++++ .../src/main/proto/StorageService.proto | 13 +++++----- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.kt index 4b982b0e4..92a2df684 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/RecipientDatabase.kt @@ -899,7 +899,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) : fun applyStorageSyncGroupV2Update(update: StorageRecordUpdate) { 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())) diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/GroupV2RecordProcessor.java b/app/src/main/java/org/thoughtcrime/securesms/storage/GroupV2RecordProcessor.java index 3e40627ea..18f007f9f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/GroupV2RecordProcessor.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/GroupV2RecordProcessor.java @@ -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(); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncModels.java b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncModels.java index eaa0f9aef..95a51fe2a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncModels.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/StorageSyncModels.java @@ -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(); } diff --git a/libsignal/service/src/main/java/org/whispersystems/signalservice/api/storage/SignalGroupV2Record.java b/libsignal/service/src/main/java/org/whispersystems/signalservice/api/storage/SignalGroupV2Record.java index 0dc904d20..e5da4fb14 100644 --- a/libsignal/service/src/main/java/org/whispersystems/signalservice/api/storage/SignalGroupV2Record.java +++ b/libsignal/service/src/main/java/org/whispersystems/signalservice/api/storage/SignalGroupV2Record.java @@ -74,6 +74,10 @@ public final class SignalGroupV2Record implements SignalRecord { diff.add("MuteUntil"); } + if (!Objects.equals(this.notifyForMentionsWhenMuted(), that.notifyForMentionsWhenMuted())) { + diff.add("NotifyForMentionsWhenMuted"); + } + if (!Objects.equals(this.hasUnknownFields(), that.hasUnknownFields())) { diff.add("UnknownFields"); } @@ -124,6 +128,10 @@ public final class SignalGroupV2Record implements SignalRecord { return proto.getMutedUntilTimestamp(); } + public boolean notifyForMentionsWhenMuted() { + return !proto.getDontNotifyForMentionsIfMuted(); + } + GroupV2Record toProto() { return proto; @@ -188,6 +196,11 @@ public final class SignalGroupV2Record implements SignalRecord { return this; } + public Builder setNotifyForMentionsWhenMuted(boolean value) { + builder.setDontNotifyForMentionsIfMuted(!value); + return this; + } + private static GroupV2Record.Builder parseUnknowns(byte[] serializedUnknowns) { try { return GroupV2Record.parseFrom(serializedUnknowns).toBuilder(); diff --git a/libsignal/service/src/main/proto/StorageService.proto b/libsignal/service/src/main/proto/StorageService.proto index 14ace4e3f..15299c229 100644 --- a/libsignal/service/src/main/proto/StorageService.proto +++ b/libsignal/service/src/main/proto/StorageService.proto @@ -94,12 +94,13 @@ message GroupV1Record { } message GroupV2Record { - bytes masterKey = 1; - bool blocked = 2; - bool whitelisted = 3; - bool archived = 4; - bool markedUnread = 5; - uint64 mutedUntilTimestamp = 6; + bytes masterKey = 1; + bool blocked = 2; + bool whitelisted = 3; + bool archived = 4; + bool markedUnread = 5; + uint64 mutedUntilTimestamp = 6; + bool dontNotifyForMentionsIfMuted = 7; } message Payments {