From 44e7e456caafee643d7d64df59df2fd034e14128 Mon Sep 17 00:00:00 2001 From: Michelle Linington Date: Fri, 21 Aug 2020 16:42:26 -0700 Subject: [PATCH] IOS-797: Configuration sync messages incorrectly updating local config on nil message fields Configuration sync messages use proto2, so the value for a given field may or may not exist. When we receive an incoming sync message, we should only adopt any properties if they're already set. Otherwise we risk interpreting an unset field as set NO. --- SignalMessaging/contacts/OWSSyncManager.m | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/SignalMessaging/contacts/OWSSyncManager.m b/SignalMessaging/contacts/OWSSyncManager.m index 6aa4432c4a..9de0c9105f 100644 --- a/SignalMessaging/contacts/OWSSyncManager.m +++ b/SignalMessaging/contacts/OWSSyncManager.m @@ -252,12 +252,23 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag - (void)processIncomingConfigurationSyncMessage:(SSKProtoSyncMessageConfiguration *)syncMessage transaction:(SDSAnyWriteTransaction *)transaction { - [SSKEnvironment.shared.readReceiptManager setAreReadReceiptsEnabled:syncMessage.readReceipts transaction:transaction]; - [Environment.shared.preferences - setShouldShowUnidentifiedDeliveryIndicators:syncMessage.unidentifiedDeliveryIndicators - transaction:transaction]; - [self.typingIndicators setTypingIndicatorsEnabledWithValue:syncMessage.typingIndicators transaction:transaction]; - [SSKPreferences setAreLinkPreviewsEnabled:syncMessage.linkPreviews transaction:transaction]; + if (syncMessage.hasReadReceipts) { + [SSKEnvironment.shared.readReceiptManager setAreReadReceiptsEnabled:syncMessage.readReceipts + transaction:transaction]; + } + if (syncMessage.hasUnidentifiedDeliveryIndicators) { + BOOL updatedValue = syncMessage.unidentifiedDeliveryIndicators; + [Environment.shared.preferences setShouldShowUnidentifiedDeliveryIndicators:updatedValue + transaction:transaction]; + } + if (syncMessage.hasTypingIndicators) { + [self.typingIndicators setTypingIndicatorsEnabledWithValue:syncMessage.typingIndicators + transaction:transaction]; + } + if (syncMessage.hasLinkPreviews) { + [SSKPreferences setAreLinkPreviewsEnabled:syncMessage.linkPreviews + transaction:transaction]; + } [transaction addAsyncCompletion:^{ [[NSNotificationCenter defaultCenter] postNotificationNameAsync:OWSSyncManagerConfigurationSyncDidCompleteNotification