Merge branch 'message-proof-of-work' of github.com:loki-project/loki-messenger-ios into message-proof-of-work

pull/6/head
Niels Andriesse 6 years ago
commit ca820494dd

@ -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
@ -1141,7 +1147,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
messages:deviceMessages messages:deviceMessages
timeStamp:message.timestamp timeStamp:message.timestamp
udAccessKey:udAccessKey]; udAccessKey:udAccessKey];
*/ */
} }
udAuthFailureBlock:^{ udAuthFailureBlock:^{
// Note the UD auth failure so subsequent retries // Note the UD auth failure so subsequent retries
@ -1516,7 +1522,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 new]; NSMutableArray *modifiedMessages = [NSMutableArray new];
@ -393,13 +393,18 @@ NS_ASSUME_NONNULL_BEGIN
nonceArray:(NSArray *)nonceArray nonceArray:(NSArray *)nonceArray
ttl:(NSNumber *)ttl ttl:(NSNumber *)ttl
{ {
// Messages may be empty; see comments in OWSDeviceManager // 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];
OWSAssertDebug(lokiMessages.count > 0);
// Loki: Just send the first message
NSString *path = [textSecureMessagesAPI stringByAppendingString:recipientId]; NSString *path = [textSecureMessagesAPI stringByAppendingString:recipientId];
NSDictionary *parameters = @{ @"messages" : lokiMessages }; 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