@ -255,7 +255,6 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Dynamic Interactions
#pragma mark - Dynamic Interactions
/ / MJK TODO - dynamic interactions
+ ( ThreadDynamicInteractions * ) ensureDynamicInteractionsForThread : ( TSThread * ) thread
+ ( ThreadDynamicInteractions * ) ensureDynamicInteractionsForThread : ( TSThread * ) thread
contactsManager : ( OWSContactsManager * ) contactsManager
contactsManager : ( OWSContactsManager * ) contactsManager
blockingManager : ( OWSBlockingManager * ) blockingManager
blockingManager : ( OWSBlockingManager * ) blockingManager
@ -464,53 +463,48 @@ NS_ASSUME_NONNULL_BEGIN
= ( shouldHaveBlockOffer || shouldHaveAddToContactsOffer || shouldHaveAddToProfileWhitelistOffer ) ;
= ( shouldHaveBlockOffer || shouldHaveAddToContactsOffer || shouldHaveAddToProfileWhitelistOffer ) ;
if ( isContactThread ) {
if ( isContactThread ) {
TSContactThread * contactThread = ( TSContactThread * ) thread ;
TSContactThread * contactThread = ( TSContactThread * ) thread ;
/ / MJK only place where `hasDismissedOffers ` is read
if ( contactThread . hasDismissedOffers ) {
if ( contactThread . hasDismissedOffers ) {
shouldHaveContactOffers = NO ;
shouldHaveContactOffers = NO ;
}
}
}
}
/ / We want the offers to be the first interactions in their
/ / conversation ' s timeline , so we back - date them to slightly before
/ / the first message - or at an aribtrary old timestamp if the
/ / conversation has no messages .
uint64_t contactOffersTimestamp = [ NSDate ows_millisecondTimeStamp ] ;
/ / If the contact offers ' properties have changed , discard the current
/ / one and create a new one .
if ( existingContactOffers ) {
if ( existingContactOffers . hasBlockOffer != shouldHaveBlockOffer
|| existingContactOffers . hasAddToContactsOffer != shouldHaveAddToContactsOffer
|| existingContactOffers . hasAddToProfileWhitelistOffer != shouldHaveAddToProfileWhitelistOffer ) {
OWSLogInfo ( @ "Removing stale contact offers : %@ (%llu)",
existingContactOffers . uniqueId ,
existingContactOffers . timestampForSorting ) ;
/ / Preserve the timestamp of the existing "contact offers " so that
/ / we replace it in the same position in the timeline .
contactOffersTimestamp = existingContactOffers . timestamp ;
[ existingContactOffers removeWithTransaction : transaction ] ;
existingContactOffers = nil ;
}
}
if ( existingContactOffers && !shouldHaveContactOffers ) {
if ( existingContactOffers && !shouldHaveContactOffers ) {
OWSLogInfo ( @ "Removing contact offers : %@ (%llu)",
OWSLogInfo ( @ "Removing contact offers : %@ (%llu)",
existingContactOffers . uniqueId ,
existingContactOffers . uniqueId ,
existingContactOffers . timestampForSorting ) ;
existingContactOffers . timestampForSorting ) ;
[ existingContactOffers removeWithTransaction : transaction ] ;
[ existingContactOffers removeWithTransaction : transaction ] ;
} else if ( !existingContactOffers && shouldHaveContactOffers ) {
} else if ( shouldHaveContactOffers ) {
NSString * recipientId = ( ( TSContactThread * ) thread ) . contactIdentifier ;
if ( existingContactOffers ) {
/ / If the contact offers ' properties have changed , update them
TSInteraction * offersMessage =
if ( existingContactOffers . hasBlockOffer != shouldHaveBlockOffer
[ [ OWSContactOffersInteraction alloc ] initContactOffersWithTimestamp : contactOffersTimestamp
|| existingContactOffers . hasAddToContactsOffer != shouldHaveAddToContactsOffer
thread : thread
|| existingContactOffers . hasAddToProfileWhitelistOffer != shouldHaveAddToProfileWhitelistOffer ) {
hasBlockOffer : shouldHaveBlockOffer
OWSLogInfo ( @ "Updating stale contact offers : %@ (%llu)",
hasAddToContactsOffer : shouldHaveAddToContactsOffer
existingContactOffers . uniqueId ,
hasAddToProfileWhitelistOffer : shouldHaveAddToProfileWhitelistOffer
existingContactOffers . timestampForSorting ) ;
recipientId : recipientId ] ;
[ offersMessage saveWithTransaction : transaction ] ;
[ existingContactOffers updateHasBlockOffer : shouldHaveBlockOffer
hasAddToContactsOffer : shouldHaveAddToContactsOffer
OWSLogInfo (
hasAddToProfileWhitelistOffer : shouldHaveAddToProfileWhitelistOffer
@ "Creating contact offers : %@ (%llu)", offersMessage.uniqueId, offersMessage.timestampForSorting);
transaction : transaction ] ;
}
} else {
NSString * recipientId = ( ( TSContactThread * ) thread ) . contactIdentifier ;
/ / TODO MJK - remove this timestamp
TSInteraction * offersMessage = [ [ OWSContactOffersInteraction alloc ]
initContactOffersWithTimestamp : [ NSDate ows_millisecondTimeStamp ]
thread : thread
hasBlockOffer : shouldHaveBlockOffer
hasAddToContactsOffer : shouldHaveAddToContactsOffer
hasAddToProfileWhitelistOffer : shouldHaveAddToProfileWhitelistOffer
recipientId : recipientId ] ;
[ offersMessage saveWithTransaction : transaction ] ;
OWSLogInfo (
@ "Creating contact offers : %@ (%llu)", offersMessage.uniqueId, offersMessage.timestampForSorting);
}
}
}
[ self ensureUnreadIndicator : result
[ self ensureUnreadIndicator : result