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
// linked devices that we don't know about.
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
@ -1141,7 +1147,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
messages:deviceMessages
timeStamp:message.timestamp
udAccessKey:udAccessKey];
*/
*/
}
udAuthFailureBlock:^{
// Note the UD auth failure so subsequent retries
@ -1516,7 +1522,13 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
messageSend.isLocalNumber,
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];
*/
OWSAssertDebug(deviceIds);
if (messageSend.isLocalNumber) {

@ -356,7 +356,7 @@ NS_ASSUME_NONNULL_BEGIN
// Loki: Convert Signal JSON messages to Loki messages
// Refer to OWSMessageServiceParams for the Signal JSON params
+ (NSDictionary *)lokiMessagesFromMessages:(NSArray *)messages
+ (NSArray *)lokiMessagesFromMessages:(NSArray *)messages
nonceArray:(NSArray *)nonceArray
ttl:(NSNumber *)ttl {
NSMutableArray *modifiedMessages = [NSMutableArray new];
@ -393,14 +393,19 @@ NS_ASSUME_NONNULL_BEGIN
nonceArray:(NSArray *)nonceArray
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(messages.count > 0);
// Convert to Loki JSON format
NSArray *lokiMessages = [self lokiMessagesFromMessages:messages nonceArray:nonceArray ttl:ttl];
OWSAssertDebug(lokiMessages.count > 0);
NSDictionary *lokiMessages = [self lokiMessagesFromMessages:messages nonceArray:nonceArray ttl:ttl];
// Loki: Just send the first message
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];
return request;
}

Loading…
Cancel
Save