diff --git a/SignalServiceKit/src/Loki/Database/LokiDatabaseUtilities.swift b/SignalServiceKit/src/Loki/Database/LokiDatabaseUtilities.swift index 4c29c8128..2952040b4 100644 --- a/SignalServiceKit/src/Loki/Database/LokiDatabaseUtilities.swift +++ b/SignalServiceKit/src/Loki/Database/LokiDatabaseUtilities.swift @@ -19,4 +19,9 @@ public final class LokiDatabaseUtilities : NSObject { }, with: transaction).first as! TSMessage? else { return 0 } return message.groupChatServerID } + + @objc(getMasterHexEncodedPublicKeyFor:in:) + public static func objc_getMasterHexEncodedPublicKey(for slaveHexEncodedPublicKey: String, in transaction: YapDatabaseReadTransaction) -> String? { + return OWSPrimaryStorage.shared().getMasterHexEncodedPublicKey(for: slaveHexEncodedPublicKey, in: transaction) + } } diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index af448a537..34ad2406a 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -56,6 +56,7 @@ #import #import #import +#import NS_ASSUME_NONNULL_BEGIN @@ -1436,14 +1437,18 @@ NS_ASSUME_NONNULL_BEGIN } } } else { + // PMKHang([LKAPI getDestinationsFor:envelope.source]); // This should always be called from OWSBatchMessageProcessor.serialQueue, which is a background thread + + NSString *hexEncodedPublicKey = ([LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:envelope.source in:transaction] ?: envelope.source); + OWSLogDebug( - @"incoming message from: %@ with timestamp: %lu", envelopeAddress(envelope), (unsigned long)timestamp); + @"incoming message from: %@ with timestamp: %lu", hexEncodedPublicKey, (unsigned long)timestamp); TSContactThread *thread = - [TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction]; + [TSContactThread getOrCreateThreadWithContactId:hexEncodedPublicKey transaction:transaction]; [[OWSDisappearingMessagesJob sharedJob] becomeConsistentWithDisappearingDuration:dataMessage.expireTimer thread:thread - createdByRemoteRecipientId:envelope.source + createdByRemoteRecipientId:hexEncodedPublicKey createdInExistingGroup:NO transaction:transaction]; @@ -1498,18 +1503,18 @@ NS_ASSUME_NONNULL_BEGIN if (body.length == 0 && attachmentPointers.count < 1 && !contact) { OWSLogWarn(@"ignoring empty incoming message from: %@ with timestamp: %lu", - envelopeAddress(envelope), + hexEncodedPublicKey, (unsigned long)timestamp); return nil; } // Loki: If we received a message from a contact in the last 2 minutes that wasn't P2P, then we need to ping them. // We assume this occurred because they don't have our P2P details. - if (!envelope.isPtpMessage && envelope.source != nil) { + if (!envelope.isPtpMessage && hexEncodedPublicKey != nil) { uint64_t timestamp = envelope.timestamp; uint64_t now = NSDate.ows_millisecondTimeStamp; uint64_t ageInSeconds = (now - timestamp) / 1000; - if (ageInSeconds <= 120) { [LKP2PAPI pingContact:envelope.source]; } + if (ageInSeconds <= 120) { [LKP2PAPI pingContact:hexEncodedPublicKey]; } } [self finalizeIncomingMessage:incomingMessage @@ -1617,7 +1622,7 @@ NS_ASSUME_NONNULL_BEGIN } // Any messages sent from the current user - from this device or another - should be automatically marked as read. - if ([envelope.source isEqualToString:self.tsAccountManager.localNumber]) { + if ([(thread.contactIdentifier ?: envelope.source) isEqualToString:self.tsAccountManager.localNumber]) { // Don't send a read receipt for messages sent by ourselves. [incomingMessage markAsReadAtTimestamp:envelope.timestamp sendReadReceipt:NO transaction:transaction]; } @@ -1679,7 +1684,7 @@ NS_ASSUME_NONNULL_BEGIN dispatch_async(dispatch_get_main_queue(), ^{ [self.typingIndicators didReceiveIncomingMessageInThread:thread - recipientId:envelope.source + recipientId:(thread.contactIdentifier ?: envelope.source) deviceId:envelope.sourceDevice]; }); }