pull/56/head
Niels Andriesse 6 years ago
parent 7f17a9cb22
commit 66baf996a5

@ -20,5 +20,6 @@
#import <SignalServiceKit/SSKAsserts.h> #import <SignalServiceKit/SSKAsserts.h>
#import <SignalServiceKit/OWSAnalytics.h> #import <SignalServiceKit/OWSAnalytics.h>
#import <SignalServiceKit/NSArray+Functional.h> #import <SignalServiceKit/NSArray+Functional.h>
#import <SignalServiceKit/NSSet+Functional.h>
#import <SignalServiceKit/NSObject+Casting.h> #import <SignalServiceKit/NSObject+Casting.h>
#endif #endif

@ -52,6 +52,17 @@ public final class LokiAPI : NSObject {
self.hexEncodedPublicKey = hexEncodedPublicKey self.hexEncodedPublicKey = hexEncodedPublicKey
self.objc_kind = kind self.objc_kind = kind
} }
override public func isEqual(_ other: Any?) -> Bool {
guard let other = other as? Destination else { return false }
return hexEncodedPublicKey == other.hexEncodedPublicKey && kind == other.kind
}
override public var hash: Int { // Override NSObject.hash and not Hashable.hashValue or Hashable.hash(into:)
return hexEncodedPublicKey.hashValue ^ kind.hashValue
}
override public var description: String { return "\(kind.rawValue)(\(hexEncodedPublicKey))" }
} }
public typealias MessageListPromise = Promise<[SSKProtoEnvelope]> public typealias MessageListPromise = Promise<[SSKProtoEnvelope]>

@ -2,5 +2,6 @@
@interface NSArray (Functional) @interface NSArray (Functional)
- (NSArray *)filtered:(BOOL (^)(NSObject *))isIncluded; - (NSArray *)filtered:(BOOL (^)(NSObject *))isIncluded;
- (NSArray *)map:(NSObject *(^)(NSObject *))transform;
@end @end

@ -12,4 +12,13 @@
return result; return result;
} }
- (NSArray *)map:(NSObject *(^)(NSObject *))transform {
NSMutableArray *result = [NSMutableArray new];
for (NSObject *object in self) {
NSObject *transformedObject = transform(object);
[result addObject:transformedObject];
}
return result;
}
@end @end

@ -0,0 +1,7 @@
@interface NSSet (Functional)
- (BOOL)contains:(BOOL (^)(NSObject *))predicate;
- (NSSet *)filtered:(BOOL (^)(NSObject *))isIncluded;
@end

@ -0,0 +1,23 @@
#import "NSSet+Functional.h"
@implementation NSSet (Functional)
-(BOOL)contains:(BOOL (^)(NSObject *))predicate {
for (NSObject *object in self) {
BOOL isPredicateSatisfied = predicate(object);
if (isPredicateSatisfied) { return YES; }
}
return NO;
}
- (NSSet *)filtered:(BOOL (^)(NSObject *))isIncluded {
NSMutableSet *result = [NSMutableSet new];
for (NSObject *object in self) {
if (isIncluded(object)) {
[result addObject:object];
}
}
return result;
}
@end

@ -901,6 +901,22 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
return deviceMessages; return deviceMessages;
} }
- (LKFriendRequestMessage *)getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:(NSString *)hexEncodedPublicKey
{
TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:hexEncodedPublicKey];
return [[LKFriendRequestMessage alloc] initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp
inThread:thread
messageBody:@"Test"
attachmentIds:[NSMutableArray new]
expiresInSeconds:0
expireStartedAt:0
isVoiceMessage:NO
groupMetaMessage:TSGroupMetaMessageUnspecified
quotedMessage:nil
contactShare:nil
linkPreview:nil];
}
- (void)sendMessageToRecipient:(OWSMessageSend *)messageSend - (void)sendMessageToRecipient:(OWSMessageSend *)messageSend
{ {
if (messageSend.thread.isGroupThread) { if (messageSend.thread.isGroupThread) {
@ -914,16 +930,28 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
return [destination.kind isEqual:@"slave"]; return [destination.kind isEqual:@"slave"];
}]; }];
for (LKDestination *slaveDestination in slaveDestinations) { for (LKDestination *slaveDestination in slaveDestinations) {
OWSMessageSend *messageSendCopy = [messageSend copyWithDestination:slaveDestination]; TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:slaveDestination.hexEncodedPublicKey];
[self sendMessage:messageSendCopy]; if (thread.isContactFriend) {
OWSMessageSend *messageSendCopy = [messageSend copyWithDestination:slaveDestination];
[self sendMessage:messageSendCopy];
} else {
LKFriendRequestMessage *friendRequestMessage = [self getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:slaveDestination.hexEncodedPublicKey];
[self sendMessage:friendRequestMessage success:^{ } failure:^(NSError *error) { }];
}
} }
LKDestination *masterDestination = [destinations filtered:^BOOL(NSObject *object) { LKDestination *masterDestination = [destinations filtered:^BOOL(NSObject *object) {
LKDestination *destination = [object as:LKDestination.class]; LKDestination *destination = [object as:LKDestination.class];
return [destination.kind isEqual:@"master"]; return [destination.kind isEqual:@"master"];
}].firstObject; }].firstObject;
if (masterDestination != nil) { if (masterDestination != nil) {
OWSMessageSend *messageSendCopy = [messageSend copyWithDestination:masterDestination]; TSContactThread *thread = [TSContactThread getOrCreateThreadWithContactId:masterDestination.hexEncodedPublicKey];
[self sendMessage:messageSendCopy]; if (thread.isContactFriend) {
OWSMessageSend *messageSendCopy = [messageSend copyWithDestination:masterDestination];
[self sendMessage:messageSendCopy];
} else {
LKFriendRequestMessage *friendRequestMessage = [self getMultiDeviceFriendRequestMessageForHexEncodedPublicKey:masterDestination.hexEncodedPublicKey];
[self sendMessage:friendRequestMessage success:messageSend.success failure:messageSend.failure];
}
} }
}) })
.catchOn(OWSDispatch.sendingQueue, ^(NSError *error) { .catchOn(OWSDispatch.sendingQueue, ^(NSError *error) {

@ -13,6 +13,7 @@ static const NSUInteger ddLogLevel = DDLogLevelInfo;
#endif #endif
#import "OWSAnalytics.h" #import "OWSAnalytics.h"
#import "NSArray+Functional.h" #import "NSArray+Functional.h"
#import "NSSet+Functional.h"
#import "NSObject+Casting.h" #import "NSObject+Casting.h"
#import "SSKAsserts.h" #import "SSKAsserts.h"
#import "TSConstants.h" #import "TSConstants.h"

Loading…
Cancel
Save