Merge branch 'mkirk/become-consistent-with-timer'

pull/1/head
Michael Kirk 7 years ago
commit d32545fc2d

@ -15,6 +15,7 @@
#import "OWSPrimaryStorage.h" #import "OWSPrimaryStorage.h"
#import "TSIncomingMessage.h" #import "TSIncomingMessage.h"
#import "TSMessage.h" #import "TSMessage.h"
#import "TSThread.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -225,27 +226,25 @@ void AssertIsOnDisappearingMessagesQueue()
[OWSDisappearingMessagesConfiguration fetchOrCreateDefaultWithThreadId:message.uniqueThreadId [OWSDisappearingMessagesConfiguration fetchOrCreateDefaultWithThreadId:message.uniqueThreadId
transaction:transaction]; transaction:transaction];
BOOL changed = NO;
if (message.expiresInSeconds == 0) { if (message.expiresInSeconds == 0) {
if (disappearingMessagesConfiguration.isEnabled) { disappearingMessagesConfiguration.enabled = NO;
changed = YES; } else {
DDLogWarn(@"%@ Received remote message which had no expiration set, disabling our expiration to become "
@"consistent.",
self.logTag);
disappearingMessagesConfiguration.enabled = NO;
[disappearingMessagesConfiguration saveWithTransaction:transaction];
}
} else if (message.expiresInSeconds != disappearingMessagesConfiguration.durationSeconds) {
changed = YES;
DDLogInfo(@"%@ Received remote message with different expiration set, updating our expiration to become "
@"consistent.",
self.logTag);
disappearingMessagesConfiguration.enabled = YES; disappearingMessagesConfiguration.enabled = YES;
disappearingMessagesConfiguration.durationSeconds = message.expiresInSeconds; disappearingMessagesConfiguration.durationSeconds = message.expiresInSeconds;
[disappearingMessagesConfiguration saveWithTransaction:transaction];
} }
if (!changed) { if (!disappearingMessagesConfiguration.dictionaryValueDidChange) {
return;
}
DDLogInfo(@"%@ becoming consistent message configuration: %@",
self.logTag,
disappearingMessagesConfiguration.dictionaryValue);
[disappearingMessagesConfiguration saveWithTransaction:transaction];
TSThread *_Nullable thread = [message threadWithTransaction:transaction];
if (!thread) {
// If there's not yet a message thread, we don't create one.
OWSFail(@"%@ in %s thread was unexpectedly nil", self.logTag, __PRETTY_FUNCTION__);
return; return;
} }
@ -255,14 +254,14 @@ void AssertIsOnDisappearingMessagesQueue()
// We want the info message to appear _before_ the message. // We want the info message to appear _before_ the message.
[[[OWSDisappearingConfigurationUpdateInfoMessage alloc] initWithTimestamp:message.timestampForSorting - 1 [[[OWSDisappearingConfigurationUpdateInfoMessage alloc] initWithTimestamp:message.timestampForSorting - 1
thread:message.thread thread:thread
configuration:disappearingMessagesConfiguration configuration:disappearingMessagesConfiguration
createdByRemoteName:contactName] createdByRemoteName:contactName]
saveWithTransaction:transaction]; saveWithTransaction:transaction];
} else { } else {
// We want the info message to appear _before_ the message. // We want the info message to appear _before_ the message.
[[[OWSDisappearingConfigurationUpdateInfoMessage alloc] initWithTimestamp:message.timestampForSorting - 1 [[[OWSDisappearingConfigurationUpdateInfoMessage alloc] initWithTimestamp:message.timestampForSorting - 1
thread:message.thread thread:thread
configuration:disappearingMessagesConfiguration] configuration:disappearingMessagesConfiguration]
saveWithTransaction:transaction]; saveWithTransaction:transaction];
} }

Loading…
Cancel
Save