|
|
|
@ -672,21 +672,20 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
+ (nullable TSInteraction *)findInteractionInThreadByTimestamp : (uint64_t)timestamp authorId
|
|
|
|
|
: (NSString *)authorId threadUniqueId : (NSString *)threadUniqueId transaction
|
|
|
|
|
: (YapDatabaseReadTransaction *)transaction
|
|
|
|
|
: (YapDatabaseReadTransaction *)transaction;
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(timestamp > 0);
|
|
|
|
|
OWSAssert(authorId.length > 0);
|
|
|
|
|
|
|
|
|
|
NSString *localNumber = [TSAccountManager localNumber];
|
|
|
|
|
if (localNumber.length < 1) {
|
|
|
|
|
OWSFail(@"%@ missing long number.", self.logTag);
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NSArray<TSInteraction *> *interactions =
|
|
|
|
|
[TSInteraction interactionsWithTimestamp:timestamp ofClass:[TSMessage class] withTransaction:transaction];
|
|
|
|
|
|
|
|
|
|
TSInteraction *_Nullable result = nil;
|
|
|
|
|
for (TSInteraction *interaction in interactions) {
|
|
|
|
|
[TSInteraction interactionsWithTimestamp:timestamp
|
|
|
|
|
filter:^(TSInteraction *interaction) {
|
|
|
|
|
NSString *_Nullable messageAuthorId = nil;
|
|
|
|
|
if ([interaction isKindOfClass:[TSIncomingMessage class]]) {
|
|
|
|
|
TSIncomingMessage *incomingMessage = (TSIncomingMessage *)interaction;
|
|
|
|
@ -695,23 +694,27 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
messageAuthorId = localNumber;
|
|
|
|
|
}
|
|
|
|
|
if (messageAuthorId.length < 1) {
|
|
|
|
|
OWSFail(@"%@ Message missing author id.", self.logTag);
|
|
|
|
|
continue;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (![authorId isEqualToString:messageAuthorId]) {
|
|
|
|
|
continue;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
if (![interaction.uniqueThreadId isEqualToString:threadUniqueId]) {
|
|
|
|
|
continue;
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
if (result) {
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
withTransaction:transaction];
|
|
|
|
|
if (interactions.count < 1) {
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
if (interactions.count > 1) {
|
|
|
|
|
// In case of collision, take the first.
|
|
|
|
|
DDLogError(@"%@ more than one matching interaction in thread.", self.logTag);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
result = interaction;
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
return interactions[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|