|
|
|
@ -959,7 +959,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
|
NSString *contactID = messageSend.recipient.recipientId;
|
|
|
|
|
BOOL isGroupMessage = messageSend.thread.isGroupThread;
|
|
|
|
|
BOOL isDeviceLinkMessage = [message isKindOfClass:LKDeviceLinkMessage.class];
|
|
|
|
|
if (isGroupMessage || isDeviceLinkMessage || messageSend.isUDSend) {
|
|
|
|
|
if (isGroupMessage || isDeviceLinkMessage) {
|
|
|
|
|
[self sendMessage:messageSend];
|
|
|
|
|
} else {
|
|
|
|
|
BOOL isSilentMessage = message.isSilent || [message isKindOfClass:LKEphemeralMessage.class] || [message isKindOfClass:OWSOutgoingSyncMessage.class];
|
|
|
|
@ -1259,7 +1259,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
|
[message saveGroupChatServerID:groupMessage.serverID in:transaction];
|
|
|
|
|
[OWSPrimaryStorage.sharedManager setIDForMessageWithServerID:groupMessage.serverID to:message.uniqueId in:transaction];
|
|
|
|
|
}];
|
|
|
|
|
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:false wasSentByWebsocket:false];
|
|
|
|
|
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:messageSend.isUDSend wasSentByWebsocket:false];
|
|
|
|
|
})
|
|
|
|
|
.catchOn(OWSDispatch.sendingQueue, ^(NSError *error) { // The snode is unreachable
|
|
|
|
|
failedMessageSend(error);
|
|
|
|
@ -1281,19 +1281,22 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
|
NSDictionary *signalMessageInfo = deviceMessages.firstObject;
|
|
|
|
|
SSKProtoEnvelopeType type = ((NSNumber *)signalMessageInfo[@"type"]).integerValue;
|
|
|
|
|
uint64_t timestamp = message.timestamp;
|
|
|
|
|
// NSString *senderID = type == SSKProtoEnvelopeTypeUnidentifiedSender ? @"" : userHexEncodedPublicKey;
|
|
|
|
|
// uint32_t senderDeviceID = type == SSKProtoEnvelopeTypeUnidentifiedSender ? 0 : OWSDevicePrimaryDeviceId;
|
|
|
|
|
NSString *senderID = userHexEncodedPublicKey;
|
|
|
|
|
uint32_t senderDeviceID = OWSDevicePrimaryDeviceId;
|
|
|
|
|
NSString *content = signalMessageInfo[@"content"];
|
|
|
|
|
NSString *recipientID = signalMessageInfo[@"destination"];
|
|
|
|
|
uint64_t ttl = ((NSNumber *)signalMessageInfo[@"ttl"]).unsignedIntegerValue;
|
|
|
|
|
BOOL isPing = ((NSNumber *)signalMessageInfo[@"isPing"]).boolValue;
|
|
|
|
|
LKSignalMessage *signalMessage = [[LKSignalMessage alloc] initWithType:type timestamp:timestamp senderID:senderID senderDeviceID:senderDeviceID content:content recipientID:recipientID ttl:ttl isPing:isPing];
|
|
|
|
|
BOOL isFriendRequest = ((NSNumber *)signalMessageInfo[@"isFriendRequest"]).boolValue;
|
|
|
|
|
LKSignalMessage *signalMessage = [[LKSignalMessage alloc] initWithType:type timestamp:timestamp senderID:senderID senderDeviceID:senderDeviceID content:content recipientID:recipientID ttl:ttl isPing:isPing isFriendRequest:isFriendRequest];
|
|
|
|
|
if (!message.skipSave) {
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
// Update the PoW calculation status
|
|
|
|
|
[message saveIsCalculatingProofOfWork:YES withTransaction:transaction];
|
|
|
|
|
// Update the message and thread if needed
|
|
|
|
|
if (signalMessage.type == TSFriendRequestMessageType) {
|
|
|
|
|
if (signalMessage.isFriendRequest) {
|
|
|
|
|
[message.thread saveFriendRequestStatus:LKThreadFriendRequestStatusRequestSending withTransaction:transaction];
|
|
|
|
|
[message saveFriendRequestStatus:LKMessageFriendRequestStatusSendingOrFailed withTransaction:transaction];
|
|
|
|
|
}
|
|
|
|
@ -1305,7 +1308,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
|
if (!message.skipSave) {
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
// Update the message and thread if needed
|
|
|
|
|
if (signalMessage.type == TSFriendRequestMessageType) {
|
|
|
|
|
if (signalMessage.isFriendRequest) {
|
|
|
|
|
[message.thread saveFriendRequestStatus:LKThreadFriendRequestStatusNone withTransaction:transaction];
|
|
|
|
|
[message saveFriendRequestStatus:LKMessageFriendRequestStatusSendingOrFailed withTransaction:transaction];
|
|
|
|
|
}
|
|
|
|
@ -1329,7 +1332,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
|
if (isSuccess) { return; } // Succeed as soon as the first promise succeeds
|
|
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.messageSent object:[[NSNumber alloc] initWithUnsignedLongLong:signalMessage.timestamp]];
|
|
|
|
|
isSuccess = YES;
|
|
|
|
|
if (signalMessage.type == TSFriendRequestMessageType) {
|
|
|
|
|
if (signalMessage.isFriendRequest) {
|
|
|
|
|
if (!message.skipSave) {
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
// Update the thread
|
|
|
|
@ -1347,7 +1350,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Invoke the completion handler
|
|
|
|
|
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:false wasSentByWebsocket:false];
|
|
|
|
|
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:messageSend.isUDSend wasSentByWebsocket:false];
|
|
|
|
|
})
|
|
|
|
|
.catchOn(OWSDispatch.sendingQueue, ^(NSError *error) {
|
|
|
|
|
errorCount += 1;
|
|
|
|
@ -1919,7 +1922,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
|
isOnline:false
|
|
|
|
|
registrationId:0
|
|
|
|
|
ttl:message.ttl
|
|
|
|
|
isPing:false];
|
|
|
|
|
isPing:false
|
|
|
|
|
isFriendRequest:true];
|
|
|
|
|
|
|
|
|
|
NSError *error;
|
|
|
|
|
NSDictionary *jsonDict = [MTLJSONAdapter JSONDictionaryFromModel:messageParams error:&error];
|
|
|
|
@ -1948,12 +1952,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
|
// Loki: Both for friend request messages and device link messages we use fallback encryption as we don't necessarily have a session yet
|
|
|
|
|
BOOL isFriendRequest = [messageSend.message isKindOfClass:LKFriendRequestMessage.class];
|
|
|
|
|
BOOL isDeviceLinkMessage = [messageSend.message isKindOfClass:LKDeviceLinkMessage.class];
|
|
|
|
|
if (isFriendRequest || (isDeviceLinkMessage && ((LKDeviceLinkMessage *)messageSend.message).kind == LKDeviceLinkMessageKindRequest)) {
|
|
|
|
|
if ((isDeviceLinkMessage && ((LKDeviceLinkMessage *)messageSend.message).kind == LKDeviceLinkMessageKindRequest)) {
|
|
|
|
|
return [self throws_encryptedFriendRequestOrDeviceLinkMessageForMessageSend:messageSend deviceId:@(OWSDevicePrimaryDeviceId) plainText:plainText];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This may throw an exception.
|
|
|
|
|
if (![storage containsSession:recipientID deviceId:@(OWSDevicePrimaryDeviceId).intValue protocolContext:transaction]) {
|
|
|
|
|
if (!isFriendRequest && ![storage containsSession:recipientID deviceId:@(OWSDevicePrimaryDeviceId).intValue protocolContext:transaction]) {
|
|
|
|
|
NSString *missingSessionException = @"missingSessionException";
|
|
|
|
|
OWSRaiseException(missingSessionException,
|
|
|
|
|
@"Unexpectedly missing session for recipient: %@, device: %@",
|
|
|
|
@ -1987,6 +1991,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
|
paddedPlaintext:[plainText paddedMessageBody]
|
|
|
|
|
senderCertificate:messageSend.senderCertificate
|
|
|
|
|
protocolContext:transaction
|
|
|
|
|
isFriendRequest:isFriendRequest
|
|
|
|
|
error:&error];
|
|
|
|
|
SCKRaiseIfExceptionWrapperError(error);
|
|
|
|
|
if (!serializedMessage || error) {
|
|
|
|
@ -2016,7 +2021,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
|
isOnline:isOnline
|
|
|
|
|
registrationId:[cipher throws_remoteRegistrationId:transaction]
|
|
|
|
|
ttl:message.ttl
|
|
|
|
|
isPing:isPing];
|
|
|
|
|
isPing:isPing
|
|
|
|
|
isFriendRequest:isFriendRequest];
|
|
|
|
|
|
|
|
|
|
NSError *error;
|
|
|
|
|
NSDictionary *jsonDict = [MTLJSONAdapter JSONDictionaryFromModel:messageParams error:&error];
|
|
|
|
|