Only send message to the primary device.

Fail send if sending message to self.

We do this because loki doesn't support multi-device sending at the moment.
pull/6/head^2
Mikunj 6 years ago
parent 0c711d549a
commit e4d612a58e

@ -1118,6 +1118,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// so that we can learn from the service whether or not there are // so that we can learn from the service whether or not there are
// linked devices that we don't know about. // linked devices that we don't know about.
OWSLogWarn(@"Sending a message with no device messages."); OWSLogWarn(@"Sending a message with no device messages.");
// LOKI: We don't handle linked devices yet so it's better to just exit early
// This would only occur if we're sending a message to ourself
NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError();
[error setIsRetryable:NO];
return messageSend.failure(error);
} }
// TODO: Update message here to show the pow cog icon // TODO: Update message here to show the pow cog icon
@ -1514,7 +1520,13 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
messageSend.isLocalNumber, messageSend.isLocalNumber,
messageSend.isUDSend); messageSend.isUDSend);
// LOKI: Since we don't support multi-device sending yet, just send it to the primary device
NSMutableArray<NSNumber *> *deviceIds = @[@(OWSDevicePrimaryDeviceId)];
/* Original code
NSMutableArray<NSNumber *> *deviceIds = [recipient.devices mutableCopy]; NSMutableArray<NSNumber *> *deviceIds = [recipient.devices mutableCopy];
*/
OWSAssertDebug(deviceIds); OWSAssertDebug(deviceIds);
if (messageSend.isLocalNumber) { if (messageSend.isLocalNumber) {

@ -356,7 +356,7 @@ NS_ASSUME_NONNULL_BEGIN
// LOKI: Convert Signal JSON messages to Loki messages // LOKI: Convert Signal JSON messages to Loki messages
// Refer to OWSMessageServiceParams for the Signal JSON params // Refer to OWSMessageServiceParams for the Signal JSON params
+ (NSDictionary *)lokiMessagesFromMessages:(NSArray *)messages + (NSArray *)lokiMessagesFromMessages:(NSArray *)messages
nonceArray:(NSArray *)nonceArray nonceArray:(NSArray *)nonceArray
ttl:(NSNumber *)ttl { ttl:(NSNumber *)ttl {
NSMutableArray *modifiedMessages = [[NSMutableArray alloc] init]; NSMutableArray *modifiedMessages = [[NSMutableArray alloc] init];
@ -394,15 +394,18 @@ NS_ASSUME_NONNULL_BEGIN
ttl: (NSNumber *)ttl ttl: (NSNumber *)ttl
{ {
// NOTE: messages may be empty; See comments in OWSDeviceManager. // NOTE: messages may be empty; See comments in OWSDeviceManager.
// This doesn't apply to loki since we don't have linked device support.
OWSAssertDebug(recipientId.length > 0); OWSAssertDebug(recipientId.length > 0);
OWSAssertDebug(messages.count > 0);
NSDictionary *lokiMessages = [self lokiMessagesFromMessages:messages nonceArray:nonceArray ttl:ttl]; // Convert to loki json format
NSArray *lokiMessages = [self lokiMessagesFromMessages:messages nonceArray:nonceArray ttl:ttl];
NSString *path = [textSecureMessagesAPI stringByAppendingString:recipientId]; OWSAssertDebug(lokiMessages.count > 0);
NSDictionary *parameters = @{
@"messages" : lokiMessages,
};
// Just send the first message
NSString *path = [textSecureMessagesAPI stringByAppendingString:recipientId];
NSDictionary *parameters = [lokiMessages objectAtIndex:0];
TSRequest *request = [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"PUT" parameters:parameters]; TSRequest *request = [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"PUT" parameters:parameters];
return request; return request;
} }

Loading…
Cancel
Save