|
|
@ -927,6 +927,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
LKFriendRequestMessage *message = [[LKFriendRequestMessage alloc] initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"Accept this friend request to enable messages to be synced across devices" attachmentIds:[NSMutableArray new]
|
|
|
|
LKFriendRequestMessage *message = [[LKFriendRequestMessage alloc] initOutgoingMessageWithTimestamp:NSDate.ows_millisecondTimeStamp inThread:thread messageBody:@"Accept this friend request to enable messages to be synced across devices" attachmentIds:[NSMutableArray new]
|
|
|
|
expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil];
|
|
|
|
expiresInSeconds:0 expireStartedAt:0 isVoiceMessage:NO groupMetaMessage:TSGroupMetaMessageUnspecified quotedMessage:nil contactShare:nil linkPreview:nil];
|
|
|
|
|
|
|
|
message.skipSave = YES;
|
|
|
|
SignalRecipient *recipient = [[SignalRecipient alloc] initWithUniqueId:hexEncodedPublicKey];
|
|
|
|
SignalRecipient *recipient = [[SignalRecipient alloc] initWithUniqueId:hexEncodedPublicKey];
|
|
|
|
NSString *userHexEncodedPublicKey = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey;
|
|
|
|
NSString *userHexEncodedPublicKey = OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey;
|
|
|
|
return [[OWSMessageSend alloc] initWithMessage:message thread:thread recipient:recipient senderCertificate:nil udAccess:nil localNumber:userHexEncodedPublicKey success:^{ } failure:^(NSError *error) { }];
|
|
|
|
return [[OWSMessageSend alloc] initWithMessage:message thread:thread recipient:recipient senderCertificate:nil udAccess:nil localNumber:userHexEncodedPublicKey success:^{ } failure:^(NSError *error) { }];
|
|
|
@ -1247,27 +1248,31 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
uint64_t ttl = ((NSNumber *)signalMessageInfo[@"ttl"]).unsignedIntegerValue;
|
|
|
|
uint64_t ttl = ((NSNumber *)signalMessageInfo[@"ttl"]).unsignedIntegerValue;
|
|
|
|
BOOL isPing = ((NSNumber *)signalMessageInfo[@"isPing"]).boolValue;
|
|
|
|
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];
|
|
|
|
LKSignalMessage *signalMessage = [[LKSignalMessage alloc] initWithType:type timestamp:timestamp senderID:senderID senderDeviceID:senderDeviceID content:content recipientID:recipientID ttl:ttl isPing:isPing];
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
if (!message.skipSave) {
|
|
|
|
// Update the PoW calculation status
|
|
|
|
|
|
|
|
[message saveIsCalculatingProofOfWork:YES withTransaction:transaction];
|
|
|
|
|
|
|
|
// Update the message and thread if needed
|
|
|
|
|
|
|
|
if (signalMessage.type == TSFriendRequestMessageType) {
|
|
|
|
|
|
|
|
[message.thread saveFriendRequestStatus:LKThreadFriendRequestStatusRequestSending withTransaction:transaction];
|
|
|
|
|
|
|
|
[message saveFriendRequestStatus:LKMessageFriendRequestStatusSendingOrFailed withTransaction:transaction];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
// Convenience
|
|
|
|
|
|
|
|
void (^onP2PSuccess)() = ^() { message.isP2P = YES; };
|
|
|
|
|
|
|
|
void (^handleError)(NSError *error) = ^(NSError *error) {
|
|
|
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
|
|
|
// Update the PoW calculation status
|
|
|
|
|
|
|
|
[message saveIsCalculatingProofOfWork:YES withTransaction:transaction];
|
|
|
|
// Update the message and thread if needed
|
|
|
|
// Update the message and thread if needed
|
|
|
|
if (signalMessage.type == TSFriendRequestMessageType) {
|
|
|
|
if (signalMessage.type == TSFriendRequestMessageType) {
|
|
|
|
[message.thread saveFriendRequestStatus:LKThreadFriendRequestStatusNone withTransaction:transaction];
|
|
|
|
[message.thread saveFriendRequestStatus:LKThreadFriendRequestStatusRequestSending withTransaction:transaction];
|
|
|
|
[message saveFriendRequestStatus:LKMessageFriendRequestStatusSendingOrFailed withTransaction:transaction];
|
|
|
|
[message saveFriendRequestStatus:LKMessageFriendRequestStatusSendingOrFailed withTransaction:transaction];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Update the PoW calculation status
|
|
|
|
|
|
|
|
[message saveIsCalculatingProofOfWork:NO withTransaction:transaction];
|
|
|
|
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convenience
|
|
|
|
|
|
|
|
void (^onP2PSuccess)() = ^() { message.isP2P = YES; };
|
|
|
|
|
|
|
|
void (^handleError)(NSError *error) = ^(NSError *error) {
|
|
|
|
|
|
|
|
if (!message.skipSave) {
|
|
|
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
|
|
|
// Update the message and thread if needed
|
|
|
|
|
|
|
|
if (signalMessage.type == TSFriendRequestMessageType) {
|
|
|
|
|
|
|
|
[message.thread saveFriendRequestStatus:LKThreadFriendRequestStatusNone withTransaction:transaction];
|
|
|
|
|
|
|
|
[message saveFriendRequestStatus:LKMessageFriendRequestStatusSendingOrFailed withTransaction:transaction];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the PoW calculation status
|
|
|
|
|
|
|
|
[message saveIsCalculatingProofOfWork:NO withTransaction:transaction];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
}
|
|
|
|
// Handle the error
|
|
|
|
// Handle the error
|
|
|
|
failedMessageSend(error);
|
|
|
|
failedMessageSend(error);
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -1285,16 +1290,18 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|
|
|
[LKAnalytics.shared track:@"Sent Message Using Swarm API"];
|
|
|
|
[LKAnalytics.shared track:@"Sent Message Using Swarm API"];
|
|
|
|
isSuccess = YES;
|
|
|
|
isSuccess = YES;
|
|
|
|
if (signalMessage.type == TSFriendRequestMessageType) {
|
|
|
|
if (signalMessage.type == TSFriendRequestMessageType) {
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
if (!message.skipSave) {
|
|
|
|
// Update the thread
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[message.thread saveFriendRequestStatus:LKThreadFriendRequestStatusRequestSent withTransaction:transaction];
|
|
|
|
// Update the thread
|
|
|
|
[message.thread removeOldOutgoingFriendRequestMessagesIfNeededWithTransaction:transaction];
|
|
|
|
[message.thread saveFriendRequestStatus:LKThreadFriendRequestStatusRequestSent withTransaction:transaction];
|
|
|
|
// Update the message
|
|
|
|
[message.thread removeOldOutgoingFriendRequestMessagesIfNeededWithTransaction:transaction];
|
|
|
|
[message saveFriendRequestStatus:LKMessageFriendRequestStatusPending withTransaction:transaction];
|
|
|
|
// Update the message
|
|
|
|
NSTimeInterval expirationInterval = 72 * kHourInterval;
|
|
|
|
[message saveFriendRequestStatus:LKMessageFriendRequestStatusPending withTransaction:transaction];
|
|
|
|
NSDate *expirationDate = [[NSDate new] dateByAddingTimeInterval:expirationInterval];
|
|
|
|
NSTimeInterval expirationInterval = 72 * kHourInterval;
|
|
|
|
[message saveFriendRequestExpiresAt:[NSDate ows_millisecondsSince1970ForDate:expirationDate] withTransaction:transaction];
|
|
|
|
NSDate *expirationDate = [[NSDate new] dateByAddingTimeInterval:expirationInterval];
|
|
|
|
}];
|
|
|
|
[message saveFriendRequestExpiresAt:[NSDate ows_millisecondsSince1970ForDate:expirationDate] withTransaction:transaction];
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Invoke the completion handler
|
|
|
|
// Invoke the completion handler
|
|
|
|
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:false wasSentByWebsocket:false];
|
|
|
|
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:false wasSentByWebsocket:false];
|
|
|
|