@ -13,6 +13,7 @@
#import "OWSDisappearingMessagesConfiguration . h "
#import "OWSDisappearingMessagesConfiguration . h "
#import "OWSDisappearingMessagesFinder . h "
#import "OWSDisappearingMessagesFinder . h "
#import "OWSPrimaryStorage . h "
#import "OWSPrimaryStorage . h "
#import "SSKEnvironment . h "
#import "TSIncomingMessage . h "
#import "TSIncomingMessage . h "
#import "TSMessage . h "
#import "TSMessage . h "
#import "TSThread . h "
#import "TSThread . h "
@ -110,6 +111,15 @@ void AssertIsOnDisappearingMessagesQueue()
return queue ;
return queue ;
}
}
#pragma mark - Dependencies
- ( id < ContactsManagerProtocol > ) contactsManager
{
return SSKEnvironment . shared . contactsManager ;
}
#pragma mark -
- ( NSUInteger ) deleteExpiredMessages
- ( NSUInteger ) deleteExpiredMessages
{
{
AssertIsOnDisappearingMessagesQueue ( ) ;
AssertIsOnDisappearingMessagesQueue ( ) ;
@ -193,40 +203,25 @@ void AssertIsOnDisappearingMessagesQueue()
} ] ;
} ] ;
}
}
- ( void ) becomeConsistentWithConfigurationForMessage : ( TSMessage * ) message
contactsManager : ( id < ContactsManagerProtocol > ) contactsManager
transaction : ( YapDatabaseReadWriteTransaction * ) transaction
{
TSThread * thread = [ message threadWithTransaction : transaction ] ;
NSString * remoteContactName = nil ;
if ( [ message isKindOfClass : [ TSIncomingMessage class ] ] ) {
TSIncomingMessage * incomingMessage = ( TSIncomingMessage * ) message ;
remoteContactName = [ contactsManager displayNameForPhoneIdentifier : incomingMessage . messageAuthorId ] ;
}
/ / MJK - we can ' t rely on timestampForSorting
#pragma mark - Apply Remote Configuration
[ self becomeConsistentWithDisappearingDuration : message . expiresInSeconds
thread : thread
appearBeforeSenderTimestamp : message . timestampForSorting
createdByRemoteContactName : remoteContactName
createdInExistingGroup : NO
transaction : transaction ] ;
}
/ / MJK - we can ' t rely on timestampForSorting
- ( void ) becomeConsistentWithDisappearingDuration : ( uint32_t ) duration
- ( void ) becomeConsistentWithDisappearingDuration : ( uint32_t ) duration
thread : ( TSThread * ) thread
thread : ( TSThread * ) thread
appearBeforeSenderTimestamp : ( uint64_t ) timestampForSorting
createdByRemoteRecipientId : ( nullable NSString * ) remoteRecipientId
createdByRemoteContactName : ( nullable NSString * ) remoteContactName
createdInExistingGroup : ( BOOL ) createdInExistingGroup
createdInExistingGroup : ( BOOL ) createdInExistingGroup
transaction : ( YapDatabaseReadWriteTransaction * ) transaction
transaction : ( YapDatabaseReadWriteTransaction * ) transaction
{
{
OWSAssertDebug ( thread ) ;
OWSAssertDebug ( thread ) ;
OWSAssertDebug ( timestampForSorting > 0 ) ;
OWSAssertDebug ( transaction ) ;
OWSAssertDebug ( transaction ) ;
OWSBackgroundTask * _Nullable backgroundTask = [ OWSBackgroundTask backgroundTaskWithLabelStr : __PRETTY_FUNCTION__ ] ;
OWSBackgroundTask * _Nullable backgroundTask = [ OWSBackgroundTask backgroundTaskWithLabelStr : __PRETTY_FUNCTION__ ] ;
NSString * _Nullable remoteContactName = nil ;
if ( remoteRecipientId ) {
remoteContactName = [ self . contactsManager displayNameForPhoneIdentifier : remoteRecipientId ] ;
}
/ / Become eventually consistent in the case that the remote changed their settings at the same time .
/ / Become eventually consistent in the case that the remote changed their settings at the same time .
/ / Also in case remote doesn ' t support expiring messages
/ / Also in case remote doesn ' t support expiring messages
OWSDisappearingMessagesConfiguration * disappearingMessagesConfiguration =
OWSDisappearingMessagesConfiguration * disappearingMessagesConfiguration =
@ -248,10 +243,9 @@ void AssertIsOnDisappearingMessagesQueue()
[ disappearingMessagesConfiguration saveWithTransaction : transaction ] ;
[ disappearingMessagesConfiguration saveWithTransaction : transaction ] ;
/ / We want the info message to appear _before_ the message .
/ / MJK TODO - should be safe to remove this senderTimestamp
/ / MJK FIXME - we have to affect ordering by creation sequence , not sender timestamp
OWSDisappearingConfigurationUpdateInfoMessage * infoMessage =
OWSDisappearingConfigurationUpdateInfoMessage * infoMessage =
[ [ OWSDisappearingConfigurationUpdateInfoMessage alloc ] initWithSenderTimestamp : timestampForSorting - 1
[ [ OWSDisappearingConfigurationUpdateInfoMessage alloc ] initWithSenderTimestamp : [ NSDate ows_millisecondTimeStamp ]
thread : thread
thread : thread
configuration : disappearingMessagesConfiguration
configuration : disappearingMessagesConfiguration
createdByRemoteName : remoteContactName
createdByRemoteName : remoteContactName
@ -262,6 +256,8 @@ void AssertIsOnDisappearingMessagesQueue()
backgroundTask = nil ;
backgroundTask = nil ;
}
}
#pragma mark -
- ( void ) startIfNecessary
- ( void ) startIfNecessary
{
{
dispatch_async ( dispatch_get_main_queue ( ) , ^{
dispatch_async ( dispatch_get_main_queue ( ) , ^{