pull/188/head
nielsandriesse 5 years ago
parent e286871791
commit def0e9e2f9

@ -21,23 +21,13 @@ public final class SessionMetaProtocol : NSObject {
// MARK: - Sending // MARK: - Sending
// MARK: Message Destination // 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) @objc(getDestinationsForOutgoingSyncMessage)
public static func objc_getDestinationsForOutgoingSyncMessage() -> NSMutableSet { public static func objc_getDestinationsForOutgoingSyncMessage() -> NSMutableSet {
return NSMutableSet(set: getDestinationsForOutgoingSyncMessage()) return NSMutableSet(set: getDestinationsForOutgoingSyncMessage())
} }
public static func getDestinationsForOutgoingSyncMessage() -> Set<String> { public static func getDestinationsForOutgoingSyncMessage() -> Set<String> {
return getOurDevices() return MultiDeviceProtocol.getUserLinkedDevices()
} }
@objc(getDestinationsForOutgoingGroupMessage:inThread:) @objc(getDestinationsForOutgoingGroupMessage:inThread:)
@ -59,7 +49,7 @@ public final class SessionMetaProtocol : NSObject {
} else { } else {
result = Set(outgoingGroupMessage.sendingRecipientIds()) result = Set(outgoingGroupMessage.sendingRecipientIds())
.intersection(thread.groupModel.groupMemberIds) .intersection(thread.groupModel.groupMemberIds)
.subtracting(getOurDevices()) .subtracting(MultiDeviceProtocol.getUserLinkedDevices())
} }
return result return result
} }

@ -259,6 +259,14 @@ public final class MultiDeviceProtocol : NSObject {
} }
// MARK: - General // 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 { @objc public static func isSlaveThread(_ thread: TSThread) -> Bool {
guard let thread = thread as? TSContactThread else { return false } guard let thread = thread as? TSContactThread else { return false }
var isSlaveThread = false var isSlaveThread = false

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

Loading…
Cancel
Save