This commit is contained in:
nielsandriesse 2020-05-08 11:15:53 +10:00
parent e286871791
commit def0e9e2f9
3 changed files with 14 additions and 16 deletions

View File

@ -21,23 +21,13 @@ public final class SessionMetaProtocol : NSObject {
// MARK: - Sending
// MARK: Message Destination
private static func getOurDevices() -> Set<String> {
var result: Set<String> = []
storage.dbReadConnection.read { transaction in
// Aim the message at all linked devices, including this one
// TODO: Should we exclude the current device?
result = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: getUserHexEncodedPublicKey(), in: transaction)
}
return result
}
@objc(getDestinationsForOutgoingSyncMessage)
public static func objc_getDestinationsForOutgoingSyncMessage() -> NSMutableSet {
return NSMutableSet(set: getDestinationsForOutgoingSyncMessage())
}
public static func getDestinationsForOutgoingSyncMessage() -> Set<String> {
return getOurDevices()
return MultiDeviceProtocol.getUserLinkedDevices()
}
@objc(getDestinationsForOutgoingGroupMessage:inThread:)
@ -59,7 +49,7 @@ public final class SessionMetaProtocol : NSObject {
} else {
result = Set(outgoingGroupMessage.sendingRecipientIds())
.intersection(thread.groupModel.groupMemberIds)
.subtracting(getOurDevices())
.subtracting(MultiDeviceProtocol.getUserLinkedDevices())
}
return result
}

View File

@ -259,6 +259,14 @@ public final class MultiDeviceProtocol : NSObject {
}
// MARK: - General
public static func getUserLinkedDevices() -> Set<String> {
var result: Set<String> = []
storage.dbReadConnection.read { transaction in
result = LokiDatabaseUtilities.getLinkedDeviceHexEncodedPublicKeys(for: getUserHexEncodedPublicKey(), in: transaction)
}
return result
}
@objc public static func isSlaveThread(_ thread: TSThread) -> Bool {
guard let thread = thread as? TSContactThread else { return false }
var isSlaveThread = false

View File

@ -506,7 +506,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
OWSAssertDebug(message);
OWSAssertDebug(errorHandle);
NSString *hexEncodedPublicKey = self.tsAccountManager.localNumber;
NSString *userHexEncodedPublicKey = self.tsAccountManager.localNumber;
__block NSMutableSet<NSString *> *recipientIds = [NSMutableSet new];
if ([message isKindOfClass:[OWSOutgoingSyncMessage class]]) {
@ -514,11 +514,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} else if (thread.isGroupThread) {
TSGroupThread *groupThread = (TSGroupThread *)thread;
recipientIds = [LKSessionMetaProtocol getDestinationsForOutgoingGroupMessage:message inThread:thread];
__block NSString *masterHexEncodedPublicKey;
__block NSString *userMasterHexEncodedPublicKey;
[OWSPrimaryStorage.sharedManager.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
masterHexEncodedPublicKey = [LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:hexEncodedPublicKey in:transaction] ?: hexEncodedPublicKey;
userMasterHexEncodedPublicKey = [LKDatabaseUtilities getMasterHexEncodedPublicKeyFor:userHexEncodedPublicKey in:transaction] ?: userHexEncodedPublicKey;
}];
if ([recipientIds containsObject:masterHexEncodedPublicKey]) {
if ([recipientIds containsObject:userMasterHexEncodedPublicKey]) {
OWSFailDebug(@"Message send recipients should not include self.");
}
} else if ([thread isKindOfClass:[TSContactThread class]]) {