From 0877d6a25edbf87aa4a7c0059fe9337ad9b75f49 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Tue, 8 Feb 2022 11:53:48 -0500 Subject: [PATCH] Improve handling of unknown fields in storage service. Improve handling of unknown fields in storage service. Found a lovely bug today where unmuting chats on mobile didn't sync to my linked devices. Turns out this was a result of the unknown field merging. 1. When a proto has unknown fields, we store the entire proto in a column in our database. 2. After building a proto that we want to write remotely, we merge the saved proto with unknown fields into constructed proto. Most of the time this is fine. 3. _However_, if one of the values you're trying to set happens to be the same as the default value for the given data type (e.g. setting a long like mutedUntil = 0), then when the protos merge, it treats that field as unset and can override it with the field from the proto with unknown fields. 4. Because we currently have unknown fields in every GV2 record, we could never unmute a GV2 group :( This changes the order of things so that unknown fields are the first thing applied in the record builder. I did this by requiring them in the builder constructors. That way start off with the unknown fields and then can manually set whatever you want, and it'll be guaranteed to override it. --- .../storage/AccountRecordProcessor.java | 3 +- .../storage/ContactRecordProcessor.java | 3 +- .../storage/GroupV1RecordProcessor.java | 3 +- .../storage/GroupV2RecordProcessor.java | 3 +- .../securesms/storage/StorageSyncHelper.java | 3 +- .../securesms/storage/StorageSyncModels.java | 9 ++-- .../storage/StorageSyncHelperTest.java | 2 +- .../api/storage/SignalAccountRecord.java | 37 ++++++++--------- .../api/storage/SignalContactRecord.java | 36 ++++++++-------- .../api/storage/SignalGroupV1Record.java | 36 ++++++++-------- .../api/storage/SignalGroupV2Record.java | 41 +++++++++---------- .../api/storage/SignalContactRecordTest.java | 2 +- 12 files changed, 80 insertions(+), 98 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/storage/AccountRecordProcessor.java b/app/src/main/java/org/thoughtcrime/securesms/storage/AccountRecordProcessor.java index 9e49e6931..791fae137 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/storage/AccountRecordProcessor.java +++ b/app/src/main/java/org/thoughtcrime/securesms/storage/AccountRecordProcessor.java @@ -119,8 +119,7 @@ public class AccountRecordProcessor extends DefaultStorageRecordProcessor