Integrate transaction handling utility part 3
This commit is contained in:
parent
a42b6afce8
commit
4f3544c1fc
|
@ -1254,10 +1254,9 @@ static NSTimeInterval launchStartedAt;
|
|||
if ([self.tsAccountManager isRegistered]) {
|
||||
OWSLogInfo(@"localNumber: %@", [self.tsAccountManager localNumber]);
|
||||
|
||||
[self.primaryStorage.newDatabaseConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[ExperienceUpgradeFinder.sharedManager markAllAsSeenWithTransaction:transaction];
|
||||
}];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[ExperienceUpgradeFinder.sharedManager markAllAsSeenWithTransaction:transaction];
|
||||
} error:nil];
|
||||
|
||||
// Start running the disappearing messages job in case the newly registered user
|
||||
// enables this feature
|
||||
|
@ -1424,10 +1423,10 @@ static NSTimeInterval launchStartedAt;
|
|||
BOOL isChatSetUp = [NSUserDefaults.standardUserDefaults boolForKey:userDefaultsKey];
|
||||
if (!isChatSetUp || !chat.isDeletable) {
|
||||
[LKPublicChatManager.shared addChatWithServer:chat.server channel:chat.channel name:chat.displayName];
|
||||
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
TSGroupThread *thread = [TSGroupThread threadWithGroupId:[LKGroupUtilities getEncodedOpenGroupIDAsData:chat.id] transaction:transaction];
|
||||
if (thread != nil) { [OWSProfileManager.sharedManager addThreadToProfileWhitelist:thread]; }
|
||||
}];
|
||||
} error:nil];
|
||||
[NSUserDefaults.standardUserDefaults setBool:YES forKey:userDefaultsKey];
|
||||
}
|
||||
}
|
||||
|
@ -1466,9 +1465,9 @@ static NSTimeInterval launchStartedAt;
|
|||
if (!isFeedSetUp || !feed.isDeletable) {
|
||||
TSGroupModel *group = [[TSGroupModel alloc] initWithTitle:feed.displayName memberIds:@[ userHexEncodedPublicKey, feed.server ] image:nil groupId:[LKGroupUtilities getEncodedRSSFeedIDAsData:feed.id] groupType:rssFeed adminIds:@[ userHexEncodedPublicKey, feed.server ]];
|
||||
__block TSGroupThread *thread;
|
||||
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
thread = [TSGroupThread getOrCreateThreadWithGroupModel:group transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
[OWSProfileManager.sharedManager addThreadToProfileWhitelist:thread];
|
||||
[NSUserDefaults.standardUserDefaults setBool:YES forKey:userDefaultsKey];
|
||||
}
|
||||
|
|
|
@ -1255,9 +1255,9 @@ typedef enum : NSUInteger {
|
|||
|
||||
- (void)restoreSession {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[OWSPrimaryStorage.sharedManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKSessionManagementProtocol startSessionResetInThread:self.thread using:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1926,10 +1926,9 @@ typedef enum : NSUInteger {
|
|||
accessibilityIdentifier:ACCESSIBILITY_IDENTIFIER_WITH_NAME(self, @"send_again")
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction *action) {
|
||||
[self.editingDatabaseConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
}];
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
}];
|
||||
}];
|
||||
|
||||
[actionSheet addAction:resendMessageAction];
|
||||
|
@ -1980,10 +1979,9 @@ typedef enum : NSUInteger {
|
|||
return;
|
||||
}
|
||||
TSContactThread *contactThread = (TSContactThread *)self.thread;
|
||||
[self.editingDatabaseConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.sessionResetJobQueue addContactThread:contactThread transaction:transaction];
|
||||
}];
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.sessionResetJobQueue addContactThread:contactThread transaction:transaction];
|
||||
}];
|
||||
}];
|
||||
[alert addAction:resetSessionAction];
|
||||
|
||||
|
@ -2358,12 +2356,11 @@ typedef enum : NSUInteger {
|
|||
OWSLogInfo(@"Blocking an unknown user.");
|
||||
[self.blockingManager addBlockedPhoneNumber:interaction.recipientId];
|
||||
// Delete the offers.
|
||||
[self.editingDatabaseConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
contactThread.hasDismissedOffers = YES;
|
||||
[contactThread saveWithTransaction:transaction];
|
||||
[interaction removeWithTransaction:transaction];
|
||||
}];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
contactThread.hasDismissedOffers = YES;
|
||||
[contactThread saveWithTransaction:transaction];
|
||||
[interaction removeWithTransaction:transaction];
|
||||
} error:nil];
|
||||
}];
|
||||
[actionSheet addAction:blockAction];
|
||||
|
||||
|
@ -2387,11 +2384,11 @@ typedef enum : NSUInteger {
|
|||
editImmediately:YES];
|
||||
|
||||
// Delete the offers.
|
||||
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
contactThread.hasDismissedOffers = YES;
|
||||
[contactThread saveWithTransaction:transaction];
|
||||
[interaction removeWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)tappedAddToProfileWhitelistOfferMessage:(OWSContactOffersInteraction *)interaction
|
||||
|
@ -2405,11 +2402,11 @@ typedef enum : NSUInteger {
|
|||
|
||||
[self presentAddThreadToProfileWhitelistWithSuccess:^() {
|
||||
// Delete the offers.
|
||||
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
contactThread.hasDismissedOffers = YES;
|
||||
[contactThread saveWithTransaction:transaction];
|
||||
[interaction removeWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
|
@ -2583,18 +2580,16 @@ typedef enum : NSUInteger {
|
|||
success:^(NSArray<TSAttachmentStream *> *attachmentStreams) {
|
||||
OWSAssertDebug(attachmentStreams.count == 1);
|
||||
TSAttachmentStream *attachmentStream = attachmentStreams.firstObject;
|
||||
[self.editingDatabaseConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *postSuccessTransaction) {
|
||||
[message setQuotedMessageThumbnailAttachmentStream:attachmentStream];
|
||||
[message saveWithTransaction:postSuccessTransaction];
|
||||
}];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *postSuccessTransaction) {
|
||||
[message setQuotedMessageThumbnailAttachmentStream:attachmentStream];
|
||||
[message saveWithTransaction:postSuccessTransaction];
|
||||
} error:nil];
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
OWSLogWarn(@"Failed to redownload thumbnail with error: %@", error);
|
||||
[self.editingDatabaseConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *postSuccessTransaction) {
|
||||
[message touchWithTransaction:postSuccessTransaction];
|
||||
}];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *postSuccessTransaction) {
|
||||
[message touchWithTransaction:postSuccessTransaction];
|
||||
} error:nil];
|
||||
}];
|
||||
}];
|
||||
}
|
||||
|
@ -2899,9 +2894,9 @@ typedef enum : NSUInteger {
|
|||
if ([self.thread isKindOfClass:TSContactThread.class] && [message isKindOfClass:LKFriendRequestMessage.class]) {
|
||||
NSString *recipientID = self.thread.contactIdentifier;
|
||||
OWSAssertIsOnMainThread();
|
||||
[OWSPrimaryStorage.sharedManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKFriendRequestProtocol setFriendRequestStatusToSendingIfNeededForHexEncodedPublicKey:recipientID transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3716,7 +3711,7 @@ typedef enum : NSUInteger {
|
|||
__block TSGroupThread *groupThread;
|
||||
__block TSOutgoingMessage *message;
|
||||
|
||||
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
groupThread = [TSGroupThread getOrCreateThreadWithGroupModel:newGroupModel transaction:transaction];
|
||||
|
||||
NSString *updateGroupInfo =
|
||||
|
@ -3730,7 +3725,7 @@ typedef enum : NSUInteger {
|
|||
groupMetaMessage:TSGroupMetaMessageUpdate
|
||||
expiresInSeconds:expiresInSeconds];
|
||||
[message updateWithCustomMessage:updateGroupInfo transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
[groupThread fireAvatarChangedNotification];
|
||||
|
||||
|
@ -3800,7 +3795,7 @@ typedef enum : NSUInteger {
|
|||
__block TSThread *thread = _thread;
|
||||
__block NSString *currentDraft = [self.inputToolbar messageText];
|
||||
|
||||
[self.editingDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[thread setDraft:currentDraft transaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
@ -4501,17 +4496,17 @@ typedef enum : NSUInteger {
|
|||
- (void)acceptFriendRequest:(TSIncomingMessage *)friendRequest
|
||||
{
|
||||
if (self.thread.isGroupThread || self.thread.contactIdentifier == nil) { return; }
|
||||
[OWSPrimaryStorage.sharedManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKFriendRequestProtocol acceptFriendRequestFromHexEncodedPublicKey:self.thread.contactIdentifier using:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)declineFriendRequest:(TSIncomingMessage *)friendRequest
|
||||
{
|
||||
if (self.thread.isGroupThread || self.thread.contactIdentifier == nil) { return; }
|
||||
[OWSPrimaryStorage.sharedManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKFriendRequestProtocol declineFriendRequestFromHexEncodedPublicKey:self.thread.contactIdentifier using:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
#pragma mark - ConversationViewLayoutDelegate
|
||||
|
@ -4610,7 +4605,7 @@ typedef enum : NSUInteger {
|
|||
[BenchManager completeEventWithEventId:@"fromSendUntil_toggleDefaultKeyboard"];
|
||||
});
|
||||
|
||||
[self.editingDatabaseConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self.thread setDraft:@"" transaction:transaction];
|
||||
}];
|
||||
|
||||
|
@ -5452,13 +5447,13 @@ typedef enum : NSUInteger {
|
|||
}
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
__block TSInteraction *targetInteraction;
|
||||
[OWSPrimaryStorage.sharedManager.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self.thread enumerateInteractionsWithTransaction:transaction usingBlock:^(TSInteraction *interaction, YapDatabaseReadTransaction *t) {
|
||||
if (interaction.timestamp == timestamp.unsignedLongLongValue) {
|
||||
targetInteraction = interaction;
|
||||
}
|
||||
}];
|
||||
}];
|
||||
} error:nil];
|
||||
if (targetInteraction == nil || targetInteraction.interactionType != OWSInteractionType_OutgoingMessage) { return; }
|
||||
NSString *hexEncodedPublicKey = targetInteraction.thread.contactIdentifier;
|
||||
if (hexEncodedPublicKey == nil) { return; }
|
||||
|
|
|
@ -550,10 +550,9 @@ static const int kYapDatabaseRangeMaxLength = 25000;
|
|||
if (oldIndicatorItem) {
|
||||
// TODO ideally this would be happening within the *same* transaction that caused the unreadMessageIndicator
|
||||
// to be cleared.
|
||||
[self.editingDatabaseConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[oldIndicatorItem.interaction touchWithTransaction:transaction];
|
||||
}];
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[oldIndicatorItem.interaction touchWithTransaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
||||
if (self.hasClearedUnreadMessagesIndicator) {
|
||||
|
|
|
@ -1426,7 +1426,7 @@ typedef NS_ENUM(NSInteger, HomeViewControllerSection) {
|
|||
|
||||
- (void)deleteThread:(TSThread *)thread
|
||||
{
|
||||
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
/* Loki: Orignal Code
|
||||
=====================
|
||||
if ([thread isKindOfClass:[TSGroupThread class]]) {
|
||||
|
@ -1440,7 +1440,7 @@ typedef NS_ENUM(NSInteger, HomeViewControllerSection) {
|
|||
|
||||
// Loki: For now hard delete all groups
|
||||
[thread removeWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
// Loki: Post notification
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification.threadDeleted object:nil userInfo:@{ @"threadId": thread.uniqueId }];
|
||||
|
@ -1457,7 +1457,7 @@ typedef NS_ENUM(NSInteger, HomeViewControllerSection) {
|
|||
|
||||
TSThread *thread = [self threadForIndexPath:indexPath];
|
||||
|
||||
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
switch (self.homeViewMode) {
|
||||
case HomeViewMode_Inbox:
|
||||
[thread archiveThreadWithTransaction:transaction];
|
||||
|
@ -1466,7 +1466,7 @@ typedef NS_ENUM(NSInteger, HomeViewControllerSection) {
|
|||
[thread unarchiveThreadWithTransaction:transaction];
|
||||
break;
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
[self updateViewState];
|
||||
}
|
||||
|
||||
|
|
|
@ -461,10 +461,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
TSGroupModel *model = [self makeGroup];
|
||||
|
||||
__block TSGroupThread *thread;
|
||||
[OWSPrimaryStorage.dbReadWriteConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
thread = [TSGroupThread getOrCreateThreadWithGroupModel:model transaction:transaction];
|
||||
}];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
thread = [TSGroupThread getOrCreateThreadWithGroupModel:model transaction:transaction];
|
||||
} error:nil];
|
||||
OWSAssertDebug(thread);
|
||||
|
||||
[OWSProfileManager.sharedManager addThreadToProfileWhitelist:thread];
|
||||
|
|
|
@ -519,20 +519,19 @@ typedef void (^CustomLayoutBlock)(void);
|
|||
- (void)verifyUnverifyButtonTapped:(UIGestureRecognizer *)gestureRecognizer
|
||||
{
|
||||
if (gestureRecognizer.state == UIGestureRecognizerStateRecognized) {
|
||||
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
BOOL isVerified = [[OWSIdentityManager sharedManager] verificationStateForRecipientId:self.recipientId
|
||||
transaction:transaction]
|
||||
== OWSVerificationStateVerified;
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
BOOL isVerified = [[OWSIdentityManager sharedManager] verificationStateForRecipientId:self.recipientId
|
||||
transaction:transaction]
|
||||
== OWSVerificationStateVerified;
|
||||
|
||||
OWSVerificationState newVerificationState
|
||||
= (isVerified ? OWSVerificationStateDefault : OWSVerificationStateVerified);
|
||||
[[OWSIdentityManager sharedManager] setVerificationState:newVerificationState
|
||||
identityKey:self.identityKey
|
||||
recipientId:self.recipientId
|
||||
isUserInitiatedChange:YES
|
||||
transaction:transaction];
|
||||
}];
|
||||
OWSVerificationState newVerificationState
|
||||
= (isVerified ? OWSVerificationStateDefault : OWSVerificationStateVerified);
|
||||
[[OWSIdentityManager sharedManager] setVerificationState:newVerificationState
|
||||
identityKey:self.identityKey
|
||||
recipientId:self.recipientId
|
||||
isUserInitiatedChange:YES
|
||||
transaction:transaction];
|
||||
} error:nil];
|
||||
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
|
|
@ -1036,7 +1036,7 @@ const CGFloat kIconViewLength = 24;
|
|||
}
|
||||
|
||||
if (self.disappearingMessagesConfiguration.dictionaryValueDidChange) {
|
||||
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.disappearingMessagesConfiguration saveWithTransaction:transaction];
|
||||
// MJK TODO - should be safe to remove this senderTimestamp
|
||||
OWSDisappearingConfigurationUpdateInfoMessage *infoMessage =
|
||||
|
@ -1053,7 +1053,7 @@ const CGFloat kIconViewLength = 24;
|
|||
thread:self.thread];
|
||||
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1170,10 +1170,10 @@ const CGFloat kIconViewLength = 24;
|
|||
TSOutgoingMessage *message =
|
||||
[TSOutgoingMessage outgoingMessageInThread:gThread groupMetaMessage:TSGroupMetaMessageQuit expiresInSeconds:0];
|
||||
|
||||
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
[gThread leaveGroupWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
|
@ -1389,9 +1389,9 @@ const CGFloat kIconViewLength = 24;
|
|||
|
||||
- (void)setThreadMutedUntilDate:(nullable NSDate *)value
|
||||
{
|
||||
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction * _Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction * _Nonnull transaction) {
|
||||
[self.thread updateWithMutedUntilDate:value transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
[self updateTableContents];
|
||||
}
|
||||
|
@ -1456,9 +1456,9 @@ const CGFloat kIconViewLength = 24;
|
|||
didPickConversationColor:(OWSConversationColor *_Nonnull)conversationColor
|
||||
{
|
||||
OWSLogDebug(@"picked color: %@", conversationColor.name);
|
||||
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.thread updateConversationColorName:conversationColor.name transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
[self.contactsManager.avatarCache removeAllImages];
|
||||
[self updateTableContents];
|
||||
|
|
|
@ -62,10 +62,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
animated:(BOOL)isAnimated
|
||||
{
|
||||
__block TSThread *thread = nil;
|
||||
[OWSPrimaryStorage.dbReadWriteConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
thread = [TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction];
|
||||
}];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
thread = [TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction];
|
||||
} error:nil];
|
||||
[self presentConversationForThread:thread action:action animated:(BOOL)isAnimated];
|
||||
}
|
||||
|
||||
|
|
|
@ -867,10 +867,10 @@ NSError *OWSBackupErrorWithDescription(NSString *description)
|
|||
return [AnyPromise promiseWithValue:error];
|
||||
}
|
||||
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
// This should overwrite the attachment pointer with an attachment stream.
|
||||
[stream saveWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
return [AnyPromise promiseWithValue:@(1)];
|
||||
}
|
||||
|
|
|
@ -864,9 +864,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
backupFragment.relativeFilePath = attachmentExport.relativeFilePath;
|
||||
backupFragment.attachmentId = attachmentExport.attachmentId;
|
||||
backupFragment.uncompressedDataLength = exportItem.uncompressedDataLength;
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[backupFragment saveWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
OWSLogVerbose(@"saved attachment: %@ as %@",
|
||||
attachmentExport.attachmentFilePath,
|
||||
|
@ -1102,7 +1102,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// After every successful backup export, we can (and should) cull metadata
|
||||
// for any backup fragment (i.e. CloudKit record) that wasn't involved in
|
||||
// the latest backup export.
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
NSArray<NSString *> *allRecordNames = [transaction allKeysInCollection:[OWSBackupFragment collection]];
|
||||
|
||||
NSMutableSet<NSString *> *obsoleteRecordNames = [NSMutableSet new];
|
||||
|
@ -1110,7 +1110,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[obsoleteRecordNames minusSet:activeRecordNames];
|
||||
|
||||
[transaction removeObjectsForKeys:obsoleteRecordNames.allObjects inCollection:[OWSBackupFragment collection]];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (AnyPromise *)cleanUpCloudWithActiveRecordNames:(NSSet<NSString *> *)activeRecordNames
|
||||
|
|
|
@ -157,11 +157,11 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
|
|||
[allItems addObjectsFromArray:self.attachmentsItems];
|
||||
|
||||
// Record metadata for all items, so that we can re-use them in incremental backups after the restore.
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (OWSBackupFragment *item in allItems) {
|
||||
[item saveWithTransaction:transaction];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
return [self downloadFilesFromCloud:blockingItems]
|
||||
.thenInBackground(^{
|
||||
|
@ -390,7 +390,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
|
|||
}
|
||||
|
||||
__block NSUInteger count = 0;
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (OWSBackupFragment *item in self.attachmentsItems) {
|
||||
if (self.isComplete) {
|
||||
return;
|
||||
|
@ -428,7 +428,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
|
|||
@"Indicates that the backup import data is being restored.")
|
||||
progress:@(count / (CGFloat)self.attachmentsItems.count)];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
OWSLogError(@"enqueued lazy restore of %zd files.", count);
|
||||
|
||||
|
@ -456,7 +456,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
|
|||
NSMutableDictionary<NSString *, NSNumber *> *restoredEntityCounts = [NSMutableDictionary new];
|
||||
__block unsigned long long copiedEntities = 0;
|
||||
__block BOOL aborted = NO;
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (NSString *collection in collectionsToRestore) {
|
||||
if ([collection isEqualToString:[OWSDatabaseMigration collection]]) {
|
||||
// It's okay if there are existing migrations; we'll clear those
|
||||
|
@ -585,7 +585,7 @@ NSString *const kOWSBackup_ImportDatabaseKeySpec = @"kOWSBackup_ImportDatabaseKe
|
|||
}
|
||||
}
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
if (aborted) {
|
||||
return [AnyPromise promiseWithValue:OWSBackupErrorWithDescription(@"Backup import failed.")];
|
||||
|
|
|
@ -525,14 +525,14 @@ typedef void (^OrphanDataBlock)(OWSOrphanData *);
|
|||
success:^{
|
||||
OWSLogInfo(@"Completed orphan data cleanup.");
|
||||
|
||||
[databaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[transaction setObject:AppVersion.sharedInstance.currentAppVersion
|
||||
forKey:OWSOrphanDataCleaner_LastCleaningVersionKey
|
||||
inCollection:OWSOrphanDataCleaner_Collection];
|
||||
[transaction setDate:[NSDate new]
|
||||
forKey:OWSOrphanDataCleaner_LastCleaningDateKey
|
||||
inCollection:OWSOrphanDataCleaner_Collection];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
if (completion) {
|
||||
completion();
|
||||
|
@ -613,7 +613,7 @@ typedef void (^OrphanDataBlock)(OWSOrphanData *);
|
|||
NSDate *appLaunchTime = CurrentAppContext().appLaunchTime;
|
||||
NSTimeInterval thresholdTimestamp = appLaunchTime.timeIntervalSince1970 - kMinimumOrphanAgeSeconds;
|
||||
NSDate *thresholdDate = [NSDate dateWithTimeIntervalSince1970:thresholdTimestamp];
|
||||
[databaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
NSUInteger interactionsRemoved = 0;
|
||||
for (NSString *interactionId in orphanData.interactionIds) {
|
||||
if (!self.isMainAppAndActive) {
|
||||
|
@ -674,7 +674,7 @@ typedef void (^OrphanDataBlock)(OWSOrphanData *);
|
|||
[attachmentStream removeWithTransaction:transaction];
|
||||
}
|
||||
OWSLogInfo(@"Deleted orphan attachments: %zu", attachmentsRemoved);
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
if (shouldAbort) {
|
||||
return nil;
|
||||
|
|
|
@ -596,16 +596,16 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
|
|||
|
||||
DispatchMainThreadSafe(^{
|
||||
__block TSThread *thread = nil;
|
||||
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
thread = [TSContactThread getOrCreateThreadWithContactId:recipientId transaction:transaction];
|
||||
}];
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
} error:nil];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[ThreadUtil enqueueMessageWithText:url.absoluteString
|
||||
inThread:thread
|
||||
quotedReplyModel:nil
|
||||
linkPreviewDraft:nil
|
||||
transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
});
|
||||
|
||||
// Also copy to pasteboard.
|
||||
|
@ -624,13 +624,13 @@ typedef void (^DebugLogUploadFailure)(DebugLogUploader *uploader, NSError *error
|
|||
}];
|
||||
DispatchMainThreadSafe(^{
|
||||
if (thread) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[ThreadUtil enqueueMessageWithText:url.absoluteString
|
||||
inThread:thread
|
||||
quotedReplyModel:nil
|
||||
linkPreviewDraft:nil
|
||||
transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
} else {
|
||||
[Pastelog showFailureAlertWithMessage:@"Could not find last thread."];
|
||||
}
|
||||
|
|
|
@ -341,9 +341,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
}
|
||||
|
||||
__block TSThread *thread = nil;
|
||||
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
thread = [TSContactThread getOrCreateThreadWithContactId:signalAccount.recipientId transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
OWSAssertDebug(thread);
|
||||
|
||||
[self.selectThreadViewDelegate threadWasSelected:thread];
|
||||
|
|
|
@ -375,6 +375,9 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion);
|
|||
OWSAssertIsOnMainThread();
|
||||
// TODO - in line with QuotedReply and other message attachments, saving should happen as part of sending
|
||||
// preparation rather than duplicated here and in the SAE
|
||||
|
||||
// TODO: <--------
|
||||
|
||||
[self.dbReadWriteConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
if (contactShare.avatarImage) {
|
||||
|
@ -552,7 +555,7 @@ typedef void (^SendMessageBlock)(SendCompletionBlock completion);
|
|||
|
||||
OWSLogDebug(@"Confirming identity for recipient: %@", recipientId);
|
||||
|
||||
[self.dbReadWriteConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
OWSVerificationState verificationState =
|
||||
[[OWSIdentityManager sharedManager] verificationStateForRecipientId:recipientId transaction:transaction];
|
||||
switch (verificationState) {
|
||||
|
|
|
@ -340,7 +340,7 @@ NSString *const OWSContactsManagerKeyNextFullIntersectionDate = @"OWSContactsMan
|
|||
OWSAssertDebug(recipientIdsForIntersection.count > 0);
|
||||
|
||||
dispatch_async(self.serialQueue, ^{
|
||||
[self.dbReadConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[transaction setObject:recipientIdsForIntersection
|
||||
forKey:OWSContactsManagerKeyLastKnownContactPhoneNumbers
|
||||
inCollection:OWSContactsManagerCollection];
|
||||
|
@ -354,7 +354,7 @@ NSString *const OWSContactsManagerKeyNextFullIntersectionDate = @"OWSContactsMan
|
|||
forKey:OWSContactsManagerKeyNextFullIntersectionDate
|
||||
inCollection:OWSContactsManagerCollection];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -522,7 +522,7 @@ NSString *const OWSContactsManagerKeyNextFullIntersectionDate = @"OWSContactsMan
|
|||
}
|
||||
|
||||
// Update cached SignalAccounts on disk
|
||||
[self.dbWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
OWSLogInfo(@"Saving %lu SignalAccounts", (unsigned long)accountsToSave.count);
|
||||
for (SignalAccount *signalAccount in accountsToSave) {
|
||||
OWSLogVerbose(@"Saving SignalAccount: %@", signalAccount);
|
||||
|
@ -553,7 +553,7 @@ NSString *const OWSContactsManagerKeyNextFullIntersectionDate = @"OWSContactsMan
|
|||
[signalAccounts sortUsingComparator:self.signalAccountComparator];
|
||||
}
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self updateSignalAccounts:signalAccounts];
|
||||
|
|
|
@ -252,9 +252,9 @@ NSString *const kSyncManagerLastContactSyncKey = @"kTSStorageManagerOWSSyncManag
|
|||
showTypingIndicators:showTypingIndicators
|
||||
sendLinkPreviews:sendLinkPreviews];
|
||||
|
||||
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.messageSenderJobQueue addMessage:syncConfigurationMessage transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
#pragma mark - Local Sync
|
||||
|
|
|
@ -292,9 +292,9 @@ NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlob
|
|||
|
||||
- (void)setGlobalNotificationSound:(OWSSound)sound
|
||||
{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self setGlobalNotificationSound:sound transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
+ (void)setGlobalNotificationSound:(OWSSound)sound transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
|
|
|
@ -156,10 +156,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
NSError *deleteError;
|
||||
if ([fm removeItemAtPath:bloomFilterPath error:&deleteError]) {
|
||||
OWSLogInfo(@"Successfully removed bloom filter cache.");
|
||||
[OWSPrimaryStorage.dbReadWriteConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[transaction removeAllObjectsInCollection:@"TSRecipient"];
|
||||
}];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[transaction removeAllObjectsInCollection:@"TSRecipient"];
|
||||
} error:nil];
|
||||
OWSLogInfo(@"Removed all TSRecipient records - will be replaced by SignalRecipients at next address sync.");
|
||||
} else {
|
||||
OWSLogError(@"Failed to remove bloom filter cache with error: %@", deleteError.localizedDescription);
|
||||
|
@ -174,7 +173,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// Versions less than or equal to 1.2.0 didn't store public chat mappings
|
||||
+ (void)updatePublicChatMapping
|
||||
{
|
||||
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction * _Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction * _Nonnull transaction) {
|
||||
for (LKPublicChat *chat in LKPublicChatAPI.defaultChats) {
|
||||
TSGroupThread *thread = [TSGroupThread threadWithGroupId:[LKGroupUtilities getEncodedOpenGroupIDAsData:chat.id] transaction:transaction];
|
||||
if (thread != nil) {
|
||||
|
@ -203,7 +202,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[thread saveWithTransaction:transaction];
|
||||
}
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#import "OWSDatabaseMigration.h"
|
||||
#import <SessionServiceKit/OWSPrimaryStorage.h>
|
||||
#import <SessionServiceKit/SSKEnvironment.h>
|
||||
#import <SessionServiceKit/SessionServiceKit-Swift.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
@ -70,8 +71,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
OWSDatabaseConnection *dbConnection = (OWSDatabaseConnection *)self.primaryStorage.newDatabaseConnection;
|
||||
|
||||
[dbConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self runUpWithTransaction:transaction];
|
||||
}
|
||||
completionBlock:^{
|
||||
|
|
|
@ -78,7 +78,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[knownMigrationIds addObject:migration.uniqueId];
|
||||
}
|
||||
|
||||
[self.primaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
NSArray<NSString *> *savedMigrationIds = [transaction allKeysInCollection:OWSDatabaseMigration.collection];
|
||||
|
||||
NSMutableSet<NSString *> *unknownMigrationIds = [NSMutableSet new];
|
||||
|
@ -89,7 +89,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSLogInfo(@"Culling unknown migration: %@", unknownMigrationId);
|
||||
[transaction removeObjectForKey:unknownMigrationId inCollection:OWSDatabaseMigration.collection];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
// Run migrations serially to:
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#import "OWSResaveCollectionDBMigration.h"
|
||||
#import <YapDatabase/YapDatabaseConnection.h>
|
||||
#import <YapDatabase/YapDatabaseTransaction.h>
|
||||
#import <SessionServiceKit/SessionServiceKit-Swift.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
@ -20,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
OWSAssertDebug(completion);
|
||||
|
||||
NSMutableArray<NSString *> *recordIds = [NSMutableArray new];
|
||||
[dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[recordIds addObjectsFromArray:[transaction allKeysInCollection:collection]];
|
||||
OWSLogInfo(@"Migrating %lu records from: %@.", (unsigned long)recordIds.count, collection);
|
||||
}
|
||||
|
@ -52,7 +53,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return;
|
||||
}
|
||||
|
||||
[dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
const int kBatchSize = 1000;
|
||||
for (int i = 0; i < kBatchSize && recordIds.count > 0; i++) {
|
||||
NSString *messageId = [recordIds lastObject];
|
||||
|
|
|
@ -695,7 +695,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
// Remove blocked users and groups from profile whitelist.
|
||||
//
|
||||
// This will always succeed.
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[transaction removeObjectsForKeys:intersectingRecipientIds.allObjects
|
||||
inCollection:kOWSProfileManager_UserWhitelistCollection];
|
||||
for (NSData *groupId in intersectingGroupIds) {
|
||||
|
@ -703,7 +703,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
[transaction removeObjectForKey:groupIdKey
|
||||
inCollection:kOWSProfileManager_GroupWhitelistCollection];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
return @(1);
|
||||
});
|
||||
|
||||
|
@ -750,7 +750,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
{
|
||||
OWSLogWarn(@"Clearing the profile whitelist.");
|
||||
|
||||
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[transaction removeAllObjectsInCollection:kOWSProfileManager_UserWhitelistCollection];
|
||||
[transaction removeAllObjectsInCollection:kOWSProfileManager_GroupWhitelistCollection];
|
||||
OWSAssertDebug(0 == [transaction numberOfKeysInCollection:kOWSProfileManager_UserWhitelistCollection]);
|
||||
|
@ -795,7 +795,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
OWSAssertDebug(recipientIds);
|
||||
|
||||
NSMutableSet<NSString *> *newRecipientIds = [NSMutableSet new];
|
||||
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (NSString *recipientId in recipientIds) {
|
||||
NSNumber *_Nullable oldValue =
|
||||
[transaction objectForKey:recipientId inCollection:kOWSProfileManager_UserWhitelistCollection];
|
||||
|
@ -849,7 +849,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
NSString *groupIdKey = [self groupKeyForGroupId:groupId];
|
||||
|
||||
__block BOOL didChange = NO;
|
||||
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
NSNumber *_Nullable oldValue =
|
||||
[transaction objectForKey:groupIdKey inCollection:kOWSProfileManager_GroupWhitelistCollection];
|
||||
if (oldValue && oldValue.boolValue) {
|
||||
|
@ -1451,9 +1451,9 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
[[OWSProfileKeyMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] inThread:thread];
|
||||
[OWSProfileManager.sharedManager addThreadToProfileWhitelist:thread];
|
||||
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
#pragma mark - Notifications
|
||||
|
|
|
@ -55,9 +55,9 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
{
|
||||
__block OWSUserProfile *userProfile;
|
||||
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
userProfile = [OWSUserProfile getOrBuildUserProfileForRecipientId:recipientId transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
return userProfile;
|
||||
}
|
||||
|
||||
|
@ -187,9 +187,9 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion
|
||||
{
|
||||
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self applyChanges:changeBlock functionName:functionName transaction:transaction completion:completion];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)applyChanges:(void (^)(id))changeBlock
|
||||
|
@ -369,9 +369,9 @@ NSString *const kLocalProfileUniqueId = @"kLocalProfileUniqueId";
|
|||
dbConnection:(YapDatabaseConnection *)dbConnection
|
||||
completion:(nullable OWSUserProfileCompletion)completion
|
||||
{
|
||||
[dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self updateWithProfileKey:profileKey transaction:transaction completion:completion];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)updateWithProfileKey:(OWSAES256Key *)profileKey
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#import <SessionServiceKit/TSStorageHeaders.h>
|
||||
#import <SessionServiceKit/YapDatabaseConnection+OWS.h>
|
||||
#import <SessionServiceKit/YapDatabaseTransaction+OWS.h>
|
||||
#import <SessionServiceKit/SessionServiceKit-Swift.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
@ -87,9 +88,9 @@ NSString *const OWSPreferencesKeySystemCallLogEnabled = @"OWSPreferencesKeySyste
|
|||
|
||||
- (void)setValueForKey:(NSString *)key toValue:(nullable id)value
|
||||
{
|
||||
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self setValueForKey:key toValue:value transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)setValueForKey:(NSString *)key
|
||||
|
|
|
@ -87,7 +87,7 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess
|
|||
|
||||
+ (void)enqueueDeviceLinkMessage:(LKDeviceLinkMessage *)message
|
||||
{
|
||||
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
@ -203,6 +203,9 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess
|
|||
block:^(void (^benchmarkCompletion)(void)) {
|
||||
// To avoid blocking the send flow, we dispatch an async write from within this read
|
||||
// transaction
|
||||
|
||||
// TODO: <-------
|
||||
|
||||
[self.dbConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull writeTransaction) {
|
||||
[message saveWithTransaction:writeTransaction];
|
||||
|
@ -251,7 +254,7 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess
|
|||
contactShare:contactShare
|
||||
linkPreview:nil];
|
||||
|
||||
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[message saveWithTransaction:transaction];
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
}];
|
||||
|
@ -266,7 +269,7 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess
|
|||
TSOutgoingMessage *message =
|
||||
[TSOutgoingMessage outgoingMessageInThread:thread groupMetaMessage:TSGroupMetaMessageQuit expiresInSeconds:0];
|
||||
|
||||
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
}];
|
||||
}
|
||||
|
@ -701,25 +704,24 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess
|
|||
{
|
||||
OWSLogInfo(@"");
|
||||
|
||||
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self removeAllObjectsInCollection:[TSThread collection]
|
||||
class:[TSThread class]
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self removeAllObjectsInCollection:[TSThread collection]
|
||||
class:[TSThread class]
|
||||
transaction:transaction];
|
||||
[self removeAllObjectsInCollection:[TSInteraction collection]
|
||||
class:[TSInteraction class]
|
||||
transaction:transaction];
|
||||
[self removeAllObjectsInCollection:[TSAttachment collection]
|
||||
class:[TSAttachment class]
|
||||
transaction:transaction];
|
||||
@try {
|
||||
[self removeAllObjectsInCollection:[SignalRecipient collection]
|
||||
class:[SignalRecipient class]
|
||||
transaction:transaction];
|
||||
[self removeAllObjectsInCollection:[TSInteraction collection]
|
||||
class:[TSInteraction class]
|
||||
transaction:transaction];
|
||||
[self removeAllObjectsInCollection:[TSAttachment collection]
|
||||
class:[TSAttachment class]
|
||||
transaction:transaction];
|
||||
@try {
|
||||
[self removeAllObjectsInCollection:[SignalRecipient collection]
|
||||
class:[SignalRecipient class]
|
||||
transaction:transaction];
|
||||
} @catch (NSException *exception) {
|
||||
// Do nothing
|
||||
}
|
||||
}];
|
||||
} @catch (NSException *exception) {
|
||||
// Do nothing
|
||||
}
|
||||
}];
|
||||
[TSAttachmentStream deleteAttachments];
|
||||
}
|
||||
|
||||
|
|
|
@ -251,9 +251,9 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
- (uint32_t)getOrGenerateRegistrationId
|
||||
{
|
||||
__block uint32_t result;
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
result = [self getOrGenerateRegistrationId:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -523,11 +523,11 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
|
||||
- (void)storeServerAuthToken:(NSString *)authToken
|
||||
{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[transaction setObject:authToken
|
||||
forKey:TSAccountManager_ServerAuthToken
|
||||
inCollection:TSAccountManager_UserAccountCollection];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
+ (void)unregisterTextSecureWithSuccess:(void (^)(void))success failure:(void (^)(NSError *error))failureBlock
|
||||
|
@ -599,7 +599,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
self.cachedIsDeregistered = @(isDeregistered);
|
||||
}
|
||||
|
||||
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[transaction setObject:@(isDeregistered)
|
||||
forKey:TSAccountManager_IsDeregisteredKey
|
||||
inCollection:TSAccountManager_UserAccountCollection];
|
||||
|
@ -623,7 +623,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
_cachedLocalNumber = nil;
|
||||
_phoneNumberAwaitingVerification = nil;
|
||||
_cachedIsDeregistered = nil;
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[transaction removeAllObjectsInCollection:TSAccountManager_UserAccountCollection];
|
||||
|
||||
[[OWSPrimaryStorage sharedManager] resetSessionStore:transaction];
|
||||
|
@ -631,7 +631,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
[transaction setObject:localNumber
|
||||
forKey:TSAccountManager_ReregisteringPhoneNumberKey
|
||||
inCollection:TSAccountManager_UserAccountCollection];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
[self postRegistrationStateDidChangeNotification];
|
||||
|
||||
|
@ -723,7 +723,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
}
|
||||
AnyPromise *promise = [self performUpdateAccountAttributes];
|
||||
promise = promise.then(^(id value) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
// Clear the update request unless a new update has been requested
|
||||
// while this update was in flight.
|
||||
NSDate *_Nullable latestUpdateRequestDate =
|
||||
|
@ -733,7 +733,7 @@ NSString *const TSAccountManager_NeedsAccountAttributesUpdateKey = @"TSAccountMa
|
|||
[transaction removeObjectForKey:TSAccountManager_NeedsAccountAttributesUpdateKey
|
||||
inCollection:TSAccountManager_UserAccountCollection];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
NSSet<NSString *> *registeredRecipientIds = operation.registeredRecipientIds;
|
||||
|
||||
NSMutableSet<SignalRecipient *> *recipients = [NSMutableSet new];
|
||||
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (NSString *recipientId in recipientIdsToLookup) {
|
||||
if ([registeredRecipientIds containsObject:recipientId]) {
|
||||
SignalRecipient *recipient =
|
||||
|
@ -106,7 +106,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
[SignalRecipient markRecipientAsUnregistered:recipientId transaction:transaction];
|
||||
}
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
success([recipients copy]);
|
||||
|
|
|
@ -53,9 +53,9 @@ NSString *const TSContactThreadPrefix = @"c";
|
|||
OWSAssertDebug(contactId.length > 0);
|
||||
|
||||
__block TSContactThread *thread;
|
||||
[[self dbReadWriteConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
thread = [self getOrCreateThreadWithContactId:contactId transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
|
|
@ -89,9 +89,9 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
|
|||
OWSAssertDebug(groupId.length > 0);
|
||||
|
||||
__block TSGroupThread *thread;
|
||||
[[self dbReadWriteConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
thread = [self getOrCreateThreadWithGroupId:groupId groupType:groupType transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
return thread;
|
||||
}
|
||||
|
||||
|
@ -117,9 +117,9 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
|
|||
OWSAssertDebug(groupModel.groupId.length > 0);
|
||||
|
||||
__block TSGroupThread *thread;
|
||||
[[self dbReadWriteConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
thread = [self getOrCreateThreadWithGroupModel:groupModel transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
return thread;
|
||||
}
|
||||
|
||||
|
@ -242,9 +242,9 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
|
|||
|
||||
- (void)leaveGroupWithSneakyTransaction
|
||||
{
|
||||
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self leaveGroupWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)leaveGroupWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
|
@ -272,9 +272,9 @@ NSString *const TSGroupThread_NotificationKey_UniqueId = @"TSGroupThread_Notific
|
|||
|
||||
- (void)updateAvatarWithAttachmentStream:(TSAttachmentStream *)attachmentStream
|
||||
{
|
||||
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self updateAvatarWithAttachmentStream:attachmentStream transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)updateAvatarWithAttachmentStream:(TSAttachmentStream *)attachmentStream
|
||||
|
|
|
@ -66,23 +66,21 @@ NSString *const kOWSPrimaryStorage_MayHaveLinkedDevices = @"kTSStorageManager_Ma
|
|||
- (void)clearMayHaveLinkedDevices
|
||||
{
|
||||
// Note that we write async to avoid opening transactions within transactions.
|
||||
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[transaction setObject:@(NO)
|
||||
forKey:kOWSPrimaryStorage_MayHaveLinkedDevices
|
||||
inCollection:kOWSPrimaryStorage_OWSDeviceCollection];
|
||||
}];
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[transaction setObject:@(NO)
|
||||
forKey:kOWSPrimaryStorage_MayHaveLinkedDevices
|
||||
inCollection:kOWSPrimaryStorage_OWSDeviceCollection];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setMayHaveLinkedDevices
|
||||
{
|
||||
// Note that we write async to avoid opening transactions within transactions.
|
||||
[OWSPrimaryStorage.sharedManager.newDatabaseConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[transaction setObject:@(YES)
|
||||
forKey:kOWSPrimaryStorage_MayHaveLinkedDevices
|
||||
inCollection:kOWSPrimaryStorage_OWSDeviceCollection];
|
||||
}];
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[transaction setObject:@(YES)
|
||||
forKey:kOWSPrimaryStorage_MayHaveLinkedDevices
|
||||
inCollection:kOWSPrimaryStorage_OWSDeviceCollection];
|
||||
}];
|
||||
}
|
||||
|
||||
- (BOOL)hasReceivedSyncMessageInLastSeconds:(NSTimeInterval)intervalSeconds
|
||||
|
|
|
@ -130,14 +130,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
success:^(NSArray<TSAttachmentStream *> *attachmentStreams) {
|
||||
OWSAssertDebug(attachmentStreams.count == 1);
|
||||
TSAttachmentStream *attachmentStream = attachmentStreams.firstObject;
|
||||
[self.primaryStorage.newDatabaseConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[outgoingMessage setQuotedMessageThumbnailAttachmentStream:attachmentStream];
|
||||
[outgoingMessage saveWithTransaction:transaction];
|
||||
if (serverID != 0) {
|
||||
[OWSPrimaryStorage.sharedManager setIDForMessageWithServerID:serverID to:outgoingMessage.uniqueId in:transaction];
|
||||
}
|
||||
}];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[outgoingMessage setQuotedMessageThumbnailAttachmentStream:attachmentStream];
|
||||
[outgoingMessage saveWithTransaction:transaction];
|
||||
if (serverID != 0) {
|
||||
[OWSPrimaryStorage.sharedManager setIDForMessageWithServerID:serverID to:outgoingMessage.uniqueId in:transaction];
|
||||
}
|
||||
} error:nil];
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
OWSLogWarn(@"failed to fetch thumbnail for transcript: %lu with error: %@",
|
||||
|
|
|
@ -287,27 +287,26 @@ typedef void (^AttachmentDownloadFailure)(NSError *error);
|
|||
self.downloadingJobMap[job.attachmentPointer.uniqueId] = job;
|
||||
}
|
||||
|
||||
[self.primaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
job.attachmentPointer.state = TSAttachmentPointerStateDownloading;
|
||||
[job.attachmentPointer saveWithTransaction:transaction];
|
||||
|
||||
if (job.message) {
|
||||
[job.message touchWithTransaction:transaction];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
[self retrieveAttachmentForJob:job
|
||||
success:^(TSAttachmentStream *attachmentStream) {
|
||||
OWSLogVerbose(@"Attachment download succeeded.");
|
||||
|
||||
[self.primaryStorage.dbReadWriteConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[attachmentStream saveWithTransaction:transaction];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[attachmentStream saveWithTransaction:transaction];
|
||||
|
||||
if (job.message) {
|
||||
[job.message touchWithTransaction:transaction];
|
||||
}
|
||||
}];
|
||||
if (job.message) {
|
||||
[job.message touchWithTransaction:transaction];
|
||||
}
|
||||
} error:nil];
|
||||
|
||||
job.success(attachmentStream);
|
||||
|
||||
|
@ -320,16 +319,15 @@ typedef void (^AttachmentDownloadFailure)(NSError *error);
|
|||
failure:^(NSError *error) {
|
||||
OWSLogError(@"Attachment download failed with error: %@", error);
|
||||
|
||||
[self.primaryStorage.dbReadWriteConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
job.attachmentPointer.mostRecentFailureLocalizedText = error.localizedDescription;
|
||||
job.attachmentPointer.state = TSAttachmentPointerStateFailed;
|
||||
[job.attachmentPointer saveWithTransaction:transaction];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
job.attachmentPointer.mostRecentFailureLocalizedText = error.localizedDescription;
|
||||
job.attachmentPointer.state = TSAttachmentPointerStateFailed;
|
||||
[job.attachmentPointer saveWithTransaction:transaction];
|
||||
|
||||
if (job.message) {
|
||||
[job.message touchWithTransaction:transaction];
|
||||
}
|
||||
}];
|
||||
if (job.message) {
|
||||
[job.message touchWithTransaction:transaction];
|
||||
}
|
||||
} error:nil];
|
||||
|
||||
@synchronized(self) {
|
||||
[self.downloadingJobMap removeObjectForKey:job.attachmentPointer.uniqueId];
|
||||
|
|
|
@ -545,7 +545,7 @@ typedef void (^OWSLoadedThumbnailSuccess)(OWSLoadedThumbnail *loadedThumbnail);
|
|||
{
|
||||
OWSAssertDebug(changeBlock);
|
||||
|
||||
[self.dbReadWriteConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
NSString *collection = [TSAttachmentStream collection];
|
||||
TSAttachmentStream *latestInstance = [transaction objectForKey:self.uniqueId inCollection:collection];
|
||||
if (!latestInstance) {
|
||||
|
|
|
@ -389,7 +389,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
|
|||
if (attachmentIds.count < 1) {
|
||||
return;
|
||||
}
|
||||
[self.dbReadWriteConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (NSString *attachmentId in attachmentIds) {
|
||||
// We need to fetch each attachment, since [TSAttachment removeWithTransaction:] does important work.
|
||||
TSAttachment *_Nullable attachment =
|
||||
|
@ -672,9 +672,9 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
|
|||
|
||||
- (void)updateWithCustomMessage:(NSString *)customMessage
|
||||
{
|
||||
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self updateWithCustomMessage:customMessage transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)saveIsCalculatingProofOfWork:(BOOL)isCalculatingPoW withTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
|
|
|
@ -168,9 +168,9 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
|
|||
|
||||
- (void)removeJobsWithIds:(NSArray<NSString *> *)uniqueIds
|
||||
{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[transaction removeObjectsForKeys:uniqueIds inCollection:[OWSMessageContentJob collection]];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
+ (YapDatabaseView *)databaseExtension
|
||||
|
@ -418,7 +418,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
|
|||
AssertOnDispatchQueue(self.serialQueue);
|
||||
|
||||
NSMutableArray<OWSMessageContentJob *> *processedJobs = [NSMutableArray new];
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (OWSMessageContentJob *job in jobs) {
|
||||
|
||||
void (^reportFailure)(YapDatabaseReadWriteTransaction *transaction) = ^(
|
||||
|
@ -453,7 +453,7 @@ NSString *const OWSMessageContentJobFinderExtensionGroup = @"OWSMessageContentJo
|
|||
break;
|
||||
}
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
return processedJobs;
|
||||
}
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ void AssertIsOnDisappearingMessagesQueue()
|
|||
OWSBackgroundTask *_Nullable backgroundTask = [OWSBackgroundTask backgroundTaskWithLabelStr:__PRETTY_FUNCTION__];
|
||||
|
||||
__block NSUInteger expirationCount = 0;
|
||||
[self.databaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.disappearingMessagesFinder enumerateExpiredMessagesWithBlock:^(TSMessage *message) {
|
||||
// sanity check
|
||||
if (message.expiresAt > now) {
|
||||
|
@ -139,7 +139,7 @@ void AssertIsOnDisappearingMessagesQueue()
|
|||
expirationCount++;
|
||||
}
|
||||
transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
OWSLogDebug(@"Removed %lu expired messages", (unsigned long)expirationCount);
|
||||
|
||||
|
@ -266,9 +266,9 @@ void AssertIsOnDisappearingMessagesQueue()
|
|||
dispatch_async(OWSDisappearingMessagesJob.serialQueue, ^{
|
||||
// Theoretically this shouldn't be necessary, but there was a race condition when receiving a backlog
|
||||
// of messages across timer changes which could cause a disappearing message's timer to never be started.
|
||||
[self.databaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self cleanupMessagesWhichFailedToStartExpiringWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
[self runLoop];
|
||||
});
|
||||
|
|
|
@ -77,18 +77,17 @@ static NSString *const OWSFailedAttachmentDownloadsJobAttachmentStateIndex = @"i
|
|||
- (void)run
|
||||
{
|
||||
__block uint count = 0;
|
||||
[[self.primaryStorage newDatabaseConnection]
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self enumerateAttemptingOutAttachmentsWithBlock:^(TSAttachmentPointer *attachment) {
|
||||
// sanity check
|
||||
if (attachment.state != TSAttachmentPointerStateFailed) {
|
||||
attachment.state = TSAttachmentPointerStateFailed;
|
||||
[attachment saveWithTransaction:transaction];
|
||||
count++;
|
||||
}
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self enumerateAttemptingOutAttachmentsWithBlock:^(TSAttachmentPointer *attachment) {
|
||||
// sanity check
|
||||
if (attachment.state != TSAttachmentPointerStateFailed) {
|
||||
attachment.state = TSAttachmentPointerStateFailed;
|
||||
[attachment saveWithTransaction:transaction];
|
||||
count++;
|
||||
}
|
||||
transaction:transaction];
|
||||
}];
|
||||
}
|
||||
transaction:transaction];
|
||||
} error:nil];
|
||||
|
||||
OWSLogDebug(@"Marked %u attachments as unsent", count);
|
||||
}
|
||||
|
|
|
@ -79,24 +79,23 @@ static NSString *const OWSFailedMessagesJobMessageStateIndex = @"index_outoing_m
|
|||
{
|
||||
__block uint count = 0;
|
||||
|
||||
[[self.primaryStorage newDatabaseConnection]
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self enumerateAttemptingOutMessagesWithBlock:^(TSOutgoingMessage *message) {
|
||||
// sanity check
|
||||
OWSAssertDebug(message.messageState == TSOutgoingMessageStateSending);
|
||||
if (message.messageState != TSOutgoingMessageStateSending) {
|
||||
OWSLogError(@"Refusing to mark as unsent message with state: %d", (int)message.messageState);
|
||||
return;
|
||||
}
|
||||
|
||||
OWSLogDebug(@"marking message as unsent: %@", message.uniqueId);
|
||||
[message updateWithAllSendingRecipientsMarkedAsFailedWithTansaction:transaction];
|
||||
OWSAssertDebug(message.messageState == TSOutgoingMessageStateFailed);
|
||||
|
||||
count++;
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self enumerateAttemptingOutMessagesWithBlock:^(TSOutgoingMessage *message) {
|
||||
// sanity check
|
||||
OWSAssertDebug(message.messageState == TSOutgoingMessageStateSending);
|
||||
if (message.messageState != TSOutgoingMessageStateSending) {
|
||||
OWSLogError(@"Refusing to mark as unsent message with state: %d", (int)message.messageState);
|
||||
return;
|
||||
}
|
||||
transaction:transaction];
|
||||
}];
|
||||
|
||||
OWSLogDebug(@"marking message as unsent: %@", message.uniqueId);
|
||||
[message updateWithAllSendingRecipientsMarkedAsFailedWithTansaction:transaction];
|
||||
OWSAssertDebug(message.messageState == TSOutgoingMessageStateFailed);
|
||||
|
||||
count++;
|
||||
}
|
||||
transaction:transaction];
|
||||
} error:nil];
|
||||
|
||||
OWSLogDebug(@"Marked %u messages as unsent", count);
|
||||
}
|
||||
|
|
|
@ -206,9 +206,9 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|||
OWSAssertDebug(recipientId.length > 0);
|
||||
|
||||
__block BOOL result;
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
result = [self saveRemoteIdentity:identityKey recipientId:recipientId protocolContext:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -294,13 +294,13 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|||
OWSAssertDebug(identityKey.length == kStoredIdentityKeyLength);
|
||||
OWSAssertDebug(recipientId.length > 0);
|
||||
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self setVerificationState:verificationState
|
||||
identityKey:identityKey
|
||||
recipientId:recipientId
|
||||
isUserInitiatedChange:isUserInitiatedChange
|
||||
transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)setVerificationState:(OWSVerificationState)verificationState
|
||||
|
@ -663,10 +663,10 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|||
OWSLogInfo(@"Successfully sent verification state sync message");
|
||||
|
||||
// Record that this verification state was successfully synced.
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self clearSyncMessageForRecipientId:message.verificationForRecipientId
|
||||
transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
OWSLogError(@"Failed to send verification state sync message with error: %@", error);
|
||||
|
@ -678,9 +678,9 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
|
|||
OWSLogInfo(@"Removing retries for syncing verification state, since user is no longer registered: %@",
|
||||
message.verificationForRecipientId);
|
||||
// Otherwise this will fail forever.
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self clearSyncMessageForRecipientId:message.verificationForRecipientId transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ static NSString *const OWSIncompleteCallsJobCallTypeIndex = @"index_calls_on_cal
|
|||
OWSAssertDebug(CurrentAppContext().appLaunchTime);
|
||||
uint64_t cutoffTimestamp = [NSDate ows_millisecondsSince1970ForDate:CurrentAppContext().appLaunchTime];
|
||||
|
||||
[[self.primaryStorage newDatabaseConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self
|
||||
enumerateIncompleteCallsWithBlock:^(TSCall *call) {
|
||||
if (call.timestamp <= cutoffTimestamp) {
|
||||
|
@ -106,7 +106,7 @@ static NSString *const OWSIncompleteCallsJobCallTypeIndex = @"index_calls_on_cal
|
|||
count++;
|
||||
}
|
||||
transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
OWSLogInfo(@"Marked %u calls as missed", count);
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
|
|||
|
||||
switch (envelope.type) {
|
||||
case SSKProtoEnvelopeTypeFriendRequest: {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self decryptFriendRequestMessage:envelope
|
||||
envelopeData:envelopeData
|
||||
successBlock:^(OWSMessageDecryptResult *result) {
|
||||
|
@ -229,7 +229,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
|
|||
error);
|
||||
failureBlock();
|
||||
}];
|
||||
}];
|
||||
} error:nil];
|
||||
// Return to avoid double-acknowledging
|
||||
return;
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
|
|||
case SSKProtoEnvelopeTypeReceipt:
|
||||
case SSKProtoEnvelopeTypeKeyExchange:
|
||||
case SSKProtoEnvelopeTypeUnknown: {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
OWSMessageDecryptResult *result =
|
||||
[OWSMessageDecryptResult resultWithEnvelopeData:envelopeData
|
||||
plaintextData:nil
|
||||
|
@ -279,7 +279,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
|
|||
sourceDevice:envelope.sourceDevice
|
||||
isUDMessage:NO];
|
||||
successBlock(result, transaction);
|
||||
}];
|
||||
} error:nil];
|
||||
// Return to avoid double-acknowledging.
|
||||
return;
|
||||
}
|
||||
|
@ -307,12 +307,11 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
|
|||
OWSFailDebug(@"Received an invalid envelope: %@.", exception.debugDescription);
|
||||
OWSProdFail([OWSAnalyticsEvents messageManagerErrorInvalidProtocolMessage]);
|
||||
|
||||
[[self.primaryStorage newDatabaseConnection]
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
TSErrorMessage *errorMessage = [TSErrorMessage corruptedMessageInUnknownThread];
|
||||
[SSKEnvironment.shared.notificationsManager notifyUserForThreadlessErrorMessage:errorMessage
|
||||
transaction:transaction];
|
||||
}];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
TSErrorMessage *errorMessage = [TSErrorMessage corruptedMessageInUnknownThread];
|
||||
[SSKEnvironment.shared.notificationsManager notifyUserForThreadlessErrorMessage:errorMessage
|
||||
transaction:transaction];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
failureBlock();
|
||||
|
@ -422,43 +421,42 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
|
|||
return failureBlock(error);
|
||||
}
|
||||
|
||||
[self.dbConnection
|
||||
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
@try {
|
||||
id<CipherMessage> cipherMessage = cipherMessageBlock(encryptedData);
|
||||
LKSessionCipher *cipher = [[LKSessionCipher alloc]
|
||||
initWithSessionResetImplementation:self.sessionResetImplementation
|
||||
sessionStore:self.primaryStorage
|
||||
preKeyStore:self.primaryStorage
|
||||
signedPreKeyStore:self.primaryStorage
|
||||
identityKeyStore:self.identityManager
|
||||
recipientID:recipientId
|
||||
deviceID:deviceId];
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
@try {
|
||||
id<CipherMessage> cipherMessage = cipherMessageBlock(encryptedData);
|
||||
LKSessionCipher *cipher = [[LKSessionCipher alloc]
|
||||
initWithSessionResetImplementation:self.sessionResetImplementation
|
||||
sessionStore:self.primaryStorage
|
||||
preKeyStore:self.primaryStorage
|
||||
signedPreKeyStore:self.primaryStorage
|
||||
identityKeyStore:self.identityManager
|
||||
recipientID:recipientId
|
||||
deviceID:deviceId];
|
||||
|
||||
// plaintextData may be nil for some envelope types.
|
||||
NSError *error = nil;
|
||||
NSData *_Nullable decryptedData = [cipher decrypt:cipherMessage protocolContext:transaction error:&error];
|
||||
// Throw if we got an error
|
||||
SCKRaiseIfExceptionWrapperError(error);
|
||||
NSData *_Nullable plaintextData = decryptedData != nil ? [decryptedData removePadding] : nil;
|
||||
|
||||
OWSMessageDecryptResult *result = [OWSMessageDecryptResult resultWithEnvelopeData:envelopeData
|
||||
plaintextData:plaintextData
|
||||
source:envelope.source
|
||||
sourceDevice:envelope.sourceDevice
|
||||
isUDMessage:NO];
|
||||
successBlock(result, transaction);
|
||||
} @catch (NSException *exception) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[self processException:exception envelope:envelope];
|
||||
NSString *errorDescription = [NSString
|
||||
stringWithFormat:@"Exception while decrypting %@: %@.", cipherTypeName, exception.description];
|
||||
OWSLogError(@"%@", errorDescription);
|
||||
NSError *error = OWSErrorWithCodeDescription(OWSErrorCodeFailedToDecryptMessage, errorDescription);
|
||||
failureBlock(error);
|
||||
});
|
||||
}
|
||||
}];
|
||||
// plaintextData may be nil for some envelope types.
|
||||
NSError *error = nil;
|
||||
NSData *_Nullable decryptedData = [cipher decrypt:cipherMessage protocolContext:transaction error:&error];
|
||||
// Throw if we got an error
|
||||
SCKRaiseIfExceptionWrapperError(error);
|
||||
NSData *_Nullable plaintextData = decryptedData != nil ? [decryptedData removePadding] : nil;
|
||||
|
||||
OWSMessageDecryptResult *result = [OWSMessageDecryptResult resultWithEnvelopeData:envelopeData
|
||||
plaintextData:plaintextData
|
||||
source:envelope.source
|
||||
sourceDevice:envelope.sourceDevice
|
||||
isUDMessage:NO];
|
||||
successBlock(result, transaction);
|
||||
} @catch (NSException *exception) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[self processException:exception envelope:envelope];
|
||||
NSString *errorDescription = [NSString
|
||||
stringWithFormat:@"Exception while decrypting %@: %@.", cipherTypeName, exception.description];
|
||||
OWSLogError(@"%@", errorDescription);
|
||||
NSError *error = OWSErrorWithCodeDescription(OWSErrorCodeFailedToDecryptMessage, errorDescription);
|
||||
failureBlock(error);
|
||||
});
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)decryptUnidentifiedSender:(SSKProtoEnvelope *)envelope
|
||||
|
@ -486,7 +484,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
|
|||
NSString *localRecipientId = self.tsAccountManager.localNumber;
|
||||
uint32_t localDeviceId = OWSDevicePrimaryDeviceId;
|
||||
|
||||
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
NSError *cipherError;
|
||||
SMKSecretSessionCipher *_Nullable cipher =
|
||||
[[SMKSecretSessionCipher alloc] initWithSessionResetImplementation:self.sessionResetImplementation
|
||||
|
@ -635,7 +633,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
|
|||
OWSLogError(
|
||||
@"Got exception: %@ of type: %@ with reason: %@", exception.description, exception.name, exception.reason);
|
||||
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
TSErrorMessage *errorMessage;
|
||||
|
||||
if (envelope.source.length == 0) {
|
||||
|
@ -676,7 +674,7 @@ NSError *EnsureDecryptError(NSError *_Nullable error, NSString *fallbackErrorDes
|
|||
[LKSessionManagementProtocol handleDecryptionError:errorMessage.errorType forHexEncodedPublicKey:envelope.source using:transaction];
|
||||
[self notifyUserForErrorMessage:errorMessage envelope:envelope transaction:transaction];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)notifyUserForErrorMessage:(TSErrorMessage *)errorMessage
|
||||
|
|
|
@ -938,7 +938,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
attachmentHandler:^(NSArray<TSAttachmentStream *> *attachmentStreams) {
|
||||
OWSAssertDebug(attachmentStreams.count == 1);
|
||||
TSAttachmentStream *attachmentStream = attachmentStreams.firstObject;
|
||||
[self.dbConnection readWriteWithBlock:^(
|
||||
[LKStorage writeSyncWithBlock:^(
|
||||
YapDatabaseReadWriteTransaction *transaction) {
|
||||
TSGroupThread *_Nullable groupThread =
|
||||
[TSGroupThread threadWithGroupId:dataMessage.group.id
|
||||
|
@ -950,7 +950,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
[groupThread updateAvatarWithAttachmentStream:attachmentStream
|
||||
transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
transaction:transaction
|
||||
];
|
||||
|
@ -1636,7 +1636,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// * Failures don't interfere with successes.
|
||||
[self.attachmentDownloads downloadAttachmentPointer:attachmentPointer
|
||||
success:^(NSArray<TSAttachmentStream *> *attachmentStreams) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
TSAttachmentStream *_Nullable attachmentStream = attachmentStreams.firstObject;
|
||||
OWSAssertDebug(attachmentStream);
|
||||
if (attachmentStream && incomingMessage.quotedMessage.thumbnailAttachmentPointerId.length > 0 &&
|
||||
|
@ -1649,7 +1649,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
// since the attachment might be a contact avatar, etc.
|
||||
[incomingMessage touchWithTransaction:transaction];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
failure:^(NSError *error) {
|
||||
OWSLogWarn(@"Failed to download attachment for message: %lu with error: %@.",
|
||||
|
|
|
@ -136,17 +136,17 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
|
|||
|
||||
- (void)addJobForEnvelopeData:(NSData *)envelopeData
|
||||
{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
OWSMessageDecryptJob *job = [[OWSMessageDecryptJob alloc] initWithEnvelopeData:envelopeData];
|
||||
[job saveWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)removeJobWithId:(NSString *)uniqueId
|
||||
{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[transaction removeObjectForKey:uniqueId inCollection:[OWSMessageDecryptJob collection]];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
+ (YapDatabaseView *)databaseExtension
|
||||
|
@ -375,11 +375,11 @@ NSString *const OWSMessageDecryptJobFinderExtensionGroup = @"OWSMessageProcessin
|
|||
if (!envelope) {
|
||||
OWSFailDebug(@"Couldn't parse proto.");
|
||||
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
TSErrorMessage *errorMessage = [TSErrorMessage corruptedMessageInUnknownThread];
|
||||
[SSKEnvironment.shared.notificationsManager notifyUserForThreadlessErrorMessage:errorMessage
|
||||
transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
dispatch_async(self.serialQueue, ^{
|
||||
completion(NO);
|
||||
|
|
|
@ -366,11 +366,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
}
|
||||
|
||||
if ([LKFriendRequestProtocol shouldUpdateFriendRequestStatusFromMessage:message]) {
|
||||
[self.primaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
// Loki: Optimistically update friend request status when we can. This is used for
|
||||
// e.g. preventing AFRs from being sent twice on a contact sync.
|
||||
[LKFriendRequestProtocol setFriendRequestStatusToSendingIfNeededForHexEncodedPublicKey:message.thread.contactIdentifier transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
|
@ -388,10 +388,10 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
//
|
||||
// So we're using YDB behavior to ensure this invariant, which is a bit
|
||||
// unorthodox.
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[allAttachmentIds
|
||||
addObjectsFromArray:[OutgoingMessagePreparer prepareMessageForSending:message transaction:transaction]];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
NSOperationQueue *sendingQueue = [self sendingQueueForMessage:message];
|
||||
OWSSendMessageOperation *sendMessageOperation =
|
||||
|
@ -610,11 +610,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
}];
|
||||
|
||||
if ([LKMultiDeviceProtocol isMultiDeviceRequiredForMessage:message]) { // Avoid the write transaction if possible
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.primaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKMultiDeviceProtocol sendMessageToDestinationAndLinkedDevices:messageSend in:transaction];
|
||||
}];
|
||||
});
|
||||
[self.primaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
||||
[LKMultiDeviceProtocol sendMessageToDestinationAndLinkedDevices:messageSend in:transaction];
|
||||
}];
|
||||
} else {
|
||||
[self sendMessage:messageSend];
|
||||
}
|
||||
|
@ -717,12 +715,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
NSMutableSet<NSString *> *obsoleteRecipientIds = [NSMutableSet setWithArray:message.sendingRecipientIds];
|
||||
[obsoleteRecipientIds minusSet:[NSSet setWithArray:recipientIds]];
|
||||
if (obsoleteRecipientIds.count > 0) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (NSString *recipientId in obsoleteRecipientIds) {
|
||||
// Mark this recipient as "skipped".
|
||||
[message updateWithSkippedRecipient:recipientId transaction:transaction];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
if (recipientIds.count < 1) {
|
||||
|
@ -806,7 +804,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
message:(TSOutgoingMessage *)message
|
||||
thread:(TSThread *)thread
|
||||
{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
if (thread.isGroupThread) {
|
||||
// Mark as "skipped" group members who no longer have signal accounts.
|
||||
[message updateWithSkippedRecipient:recipient.recipientId transaction:transaction];
|
||||
|
@ -824,7 +822,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
// TODO: Should we deleteAllSessionsForContact here?
|
||||
// If so, we'll need to avoid doing a prekey fetch every
|
||||
// time we try to send a message to an unregistered user.
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (nullable NSArray<NSDictionary *> *)deviceMessagesForMessageSend:(OWSMessageSend *)messageSend
|
||||
|
@ -1053,9 +1051,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
|
||||
dispatch_async([OWSDispatch sendingQueue], ^{
|
||||
// This emulates the completion logic of an actual successful send (see below).
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[message updateWithSkippedRecipient:messageSend.localNumber transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
messageSend.success();
|
||||
});
|
||||
|
||||
|
@ -1170,10 +1168,10 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
message.actualSenderHexEncodedPublicKey = userHexEncodedPublicKey;
|
||||
[[LKPublicChatAPI sendMessage:groupMessage toGroup:publicChat.channel onServer:publicChat.server]
|
||||
.thenOn(OWSDispatch.sendingQueue, ^(LKGroupMessage *groupMessage) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[message saveOpenGroupServerMessageID:groupMessage.serverID in:transaction];
|
||||
[self.primaryStorage setIDForMessageWithServerID:groupMessage.serverID to:message.uniqueId in:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:messageSend.isUDSend wasSentByWebsocket:false];
|
||||
})
|
||||
.catchOn(OWSDispatch.sendingQueue, ^(NSError *error) {
|
||||
|
@ -1204,7 +1202,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
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 shouldUpdateFriendRequestStatus = [LKFriendRequestProtocol shouldUpdateFriendRequestStatusFromMessage:message];
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
if (!message.skipSave) {
|
||||
// Update the PoW calculation status
|
||||
[message saveIsCalculatingProofOfWork:YES withTransaction:transaction];
|
||||
|
@ -1212,11 +1210,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
if (shouldUpdateFriendRequestStatus) {
|
||||
[LKFriendRequestProtocol setFriendRequestStatusToSendingIfNeededForHexEncodedPublicKey:recipientID transaction:transaction];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
// Convenience
|
||||
void (^onP2PSuccess)() = ^() { message.isP2P = YES; };
|
||||
void (^handleError)(NSError *error) = ^(NSError *error) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
if (!message.skipSave) {
|
||||
// Update the PoW calculation status
|
||||
[message saveIsCalculatingProofOfWork:NO withTransaction:transaction];
|
||||
|
@ -1224,7 +1222,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
if (shouldUpdateFriendRequestStatus) {
|
||||
[LKFriendRequestProtocol setFriendRequestStatusToFailedIfNeededForHexEncodedPublicKey:recipientID transaction:transaction];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
// Handle the error
|
||||
failedMessageSend(error);
|
||||
};
|
||||
|
@ -1242,7 +1240,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.messageSent object:[[NSNumber alloc] initWithUnsignedLongLong:signalMessage.timestamp]];
|
||||
isSuccess = YES;
|
||||
if (shouldUpdateFriendRequestStatus) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
if (!message.skipSave) {
|
||||
// Update the message
|
||||
NSTimeInterval expirationInterval = 72 * kHourInterval;
|
||||
|
@ -1250,7 +1248,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
[message saveFriendRequestExpiresAt:[NSDate ows_millisecondsSince1970ForDate:expirationDate] withTransaction:transaction];
|
||||
}
|
||||
[LKFriendRequestProtocol setFriendRequestStatusToSentIfNeededForHexEncodedPublicKey:recipientID transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
// Invoke the completion handler
|
||||
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:messageSend.isUDSend wasSentByWebsocket:false];
|
||||
|
@ -1295,7 +1293,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
}
|
||||
|
||||
dispatch_async([OWSDispatch sendingQueue], ^{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[messageSend.message updateWithSentRecipient:messageSend.recipient.uniqueId
|
||||
wasSentByUD:wasSentByUD
|
||||
transaction:transaction];
|
||||
|
@ -1303,7 +1301,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
// If we've just delivered a message to a user, we know they
|
||||
// have a valid Signal account.
|
||||
[SignalRecipient markRecipientAsRegisteredAndGet:recipient.recipientId transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
messageSend.success();
|
||||
});
|
||||
|
@ -1465,29 +1463,28 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
}
|
||||
}
|
||||
|
||||
[self.dbConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
if (extraDevices.count < 1 && missingDevices.count < 1) {
|
||||
OWSProdFail([OWSAnalyticsEvents messageSenderErrorNoMissingOrExtraDevices]);
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
if (extraDevices.count < 1 && missingDevices.count < 1) {
|
||||
OWSProdFail([OWSAnalyticsEvents messageSenderErrorNoMissingOrExtraDevices]);
|
||||
}
|
||||
|
||||
[recipient updateRegisteredRecipientWithDevicesToAdd:missingDevices
|
||||
devicesToRemove:extraDevices
|
||||
transaction:transaction];
|
||||
|
||||
if (extraDevices && extraDevices.count > 0) {
|
||||
OWSLogInfo(@"Deleting sessions for extra devices: %@", extraDevices);
|
||||
for (NSNumber *extraDeviceId in extraDevices) {
|
||||
[self.primaryStorage deleteSessionForContact:recipient.uniqueId
|
||||
deviceId:extraDeviceId.intValue
|
||||
protocolContext:transaction];
|
||||
}
|
||||
}
|
||||
|
||||
[recipient updateRegisteredRecipientWithDevicesToAdd:missingDevices
|
||||
devicesToRemove:extraDevices
|
||||
transaction:transaction];
|
||||
|
||||
if (extraDevices && extraDevices.count > 0) {
|
||||
OWSLogInfo(@"Deleting sessions for extra devices: %@", extraDevices);
|
||||
for (NSNumber *extraDeviceId in extraDevices) {
|
||||
[self.primaryStorage deleteSessionForContact:recipient.uniqueId
|
||||
deviceId:extraDeviceId.intValue
|
||||
protocolContext:transaction];
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
completionHandler();
|
||||
});
|
||||
}];
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
completionHandler();
|
||||
});
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)handleMessageSentLocally:(TSOutgoingMessage *)message
|
||||
|
@ -1499,21 +1496,21 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
// Loki: Take into account multi device
|
||||
BOOL isNoteToSelf = [LKSessionMetaProtocol isThreadNoteToSelf:message.thread];
|
||||
if (isNoteToSelf && !([message isKindOfClass:LKDeviceLinkMessage.class])) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (NSString *recipientId in message.sendingRecipientIds) {
|
||||
[message updateWithReadRecipientId:recipientId readTimestamp:message.timestamp transaction:transaction];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
successParam();
|
||||
};
|
||||
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[[OWSDisappearingMessagesJob sharedJob] startAnyExpirationForMessage:message
|
||||
expirationStartedAt:[NSDate ows_millisecondTimeStamp]
|
||||
transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
if (!message.shouldSyncTranscript) {
|
||||
return success();
|
||||
|
@ -1529,9 +1526,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
sendSyncTranscriptForMessage:message
|
||||
isRecipientUpdate:isRecipientUpdate
|
||||
success:^{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[message updateWithHasSyncedTranscript:YES transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
success();
|
||||
}
|
||||
|
@ -1563,9 +1560,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
|
||||
NSString *recipientId = otherDevice ?: currentDevice;
|
||||
__block SignalRecipient *recipient;
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
recipient = [SignalRecipient markRecipientAsRegisteredAndGet:recipientId transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
SMKSenderCertificate *senderCertificate = [self.udManager getSenderCertificate];
|
||||
OWSUDAccess *recipientUDAccess = nil;
|
||||
|
@ -1636,17 +1633,16 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
|
||||
__block NSDictionary *_Nullable messageDict;
|
||||
__block NSException *encryptionException;
|
||||
[self.dbConnection
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
@try {
|
||||
messageDict = [self throws_encryptedMessageForMessageSend:messageSend
|
||||
recipientID:recipientID
|
||||
plainText:plainText
|
||||
transaction:transaction];
|
||||
} @catch (NSException *exception) {
|
||||
encryptionException = exception;
|
||||
}
|
||||
}];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
@try {
|
||||
messageDict = [self throws_encryptedMessageForMessageSend:messageSend
|
||||
recipientID:recipientID
|
||||
plainText:plainText
|
||||
transaction:transaction];
|
||||
} @catch (NSException *exception) {
|
||||
encryptionException = exception;
|
||||
}
|
||||
} error:nil];
|
||||
|
||||
if (encryptionException) {
|
||||
OWSLogInfo(@"Exception during encryption: %@.", encryptionException);
|
||||
|
@ -1660,11 +1656,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
}
|
||||
} @catch (NSException *exception) {
|
||||
if ([exception.name isEqualToString:OWSMessageSenderInvalidDeviceException]) {
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[recipient updateRegisteredRecipientWithDevicesToAdd:nil
|
||||
devicesToRemove:@[ @(OWSDevicePrimaryDeviceId) ]
|
||||
transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
} else {
|
||||
@throw exception;
|
||||
}
|
||||
|
@ -1684,9 +1680,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
OWSAssertDebug(recipientID.length > 0);
|
||||
|
||||
__block BOOL hasSession;
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
hasSession = [storage containsSession:recipientID deviceId:[deviceId intValue] protocolContext:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
if (hasSession) {
|
||||
return YES;
|
||||
}
|
||||
|
@ -1747,7 +1743,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
identityKeyStore:self.identityManager
|
||||
recipientId:recipientID
|
||||
deviceId:[deviceId intValue]];
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
@try {
|
||||
[builder throws_processPrekeyBundle:bundle protocolContext:transaction];
|
||||
|
||||
|
@ -1756,7 +1752,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
} @catch (NSException *caughtException) {
|
||||
exception = caughtException;
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
if (exception) {
|
||||
if ([exception.name isEqualToString:UntrustedIdentityKeyException]) {
|
||||
OWSRaiseExceptionWithUserInfo(UntrustedIdentityKeyException,
|
||||
|
@ -2009,7 +2005,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
return;
|
||||
}
|
||||
|
||||
[self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (NSUInteger i = 0; i < [devices count]; i++) {
|
||||
int deviceNumber = [devices[i] intValue];
|
||||
[[OWSPrimaryStorage sharedManager] deleteSessionForContact:identifier
|
||||
|
@ -2115,7 +2111,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
[attachmentStreams addObject:attachmentStream];
|
||||
}
|
||||
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
for (TSAttachmentStream *attachmentStream in attachmentStreams) {
|
||||
[outgoingMessage.attachmentIds addObject:attachmentStream.uniqueId];
|
||||
if (attachmentStream.sourceFilename) {
|
||||
|
@ -2126,7 +2122,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
|
|||
for (TSAttachmentStream *attachmentStream in attachmentStreams) {
|
||||
[attachmentStream saveWithTransaction:transaction];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
completionHandler(nil);
|
||||
});
|
||||
|
|
|
@ -249,14 +249,14 @@ NSString *const kOutgoingReadReceiptManagerCollection = @"kOutgoingReadReceiptMa
|
|||
return;
|
||||
}
|
||||
dispatch_async(self.serialQueue, ^{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
NSSet<NSNumber *> *_Nullable oldTimestamps = [transaction objectForKey:recipientId inCollection:collection];
|
||||
NSMutableSet<NSNumber *> *newTimestamps
|
||||
= (oldTimestamps ? [oldTimestamps mutableCopy] : [NSMutableSet new]);
|
||||
[newTimestamps addObject:@(timestamp)];
|
||||
|
||||
[transaction setObject:newTimestamps forKey:recipientId inCollection:collection];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
[self process];
|
||||
});
|
||||
|
@ -276,7 +276,7 @@ NSString *const kOutgoingReadReceiptManagerCollection = @"kOutgoingReadReceiptMa
|
|||
return;
|
||||
}
|
||||
dispatch_async(self.serialQueue, ^{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
NSSet<NSNumber *> *_Nullable oldTimestamps = [transaction objectForKey:recipientId inCollection:collection];
|
||||
NSMutableSet<NSNumber *> *newTimestamps
|
||||
= (oldTimestamps ? [oldTimestamps mutableCopy] : [NSMutableSet new]);
|
||||
|
@ -287,7 +287,7 @@ NSString *const kOutgoingReadReceiptManagerCollection = @"kOutgoingReadReceiptMa
|
|||
} else {
|
||||
[transaction removeObjectForKey:recipientId inCollection:collection];
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -217,9 +217,9 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|||
OWSReadReceiptsForLinkedDevicesMessage *message =
|
||||
[[OWSReadReceiptsForLinkedDevicesMessage alloc] initWithReadReceipts:readReceiptsForLinkedDevices];
|
||||
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self.messageSenderJobQueue addMessage:message transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
BOOL didWork = readReceiptsForLinkedDevices.count > 0;
|
||||
|
@ -250,13 +250,13 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|||
OWSAssertDebug(thread);
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self markAsReadBeforeSortId:sortId
|
||||
thread:thread
|
||||
readTimestamp:[NSDate ows_millisecondTimeStamp]
|
||||
wasLocal:YES
|
||||
transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|||
}
|
||||
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
for (NSNumber *nsSentTimestamp in sentTimestamps) {
|
||||
UInt64 sentTimestamp = [nsSentTimestamp unsignedLongLongValue];
|
||||
|
||||
|
@ -343,7 +343,7 @@ NSString *const OWSReadReceiptManagerAreReadReceiptsEnabled = @"areReadReceiptsE
|
|||
transaction:transaction];
|
||||
}
|
||||
}
|
||||
}];
|
||||
} error:nil];
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#import "TSContactThread.h"
|
||||
#import <YapDatabase/YapDatabaseConnection.h>
|
||||
#import <YapDatabase/YapDatabaseTransaction.h>
|
||||
#import <SessionServiceKit/SessionServiceKit-Swift.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
@ -152,9 +153,9 @@ NSUInteger TSCallCurrentSchemaVersion = 1;
|
|||
|
||||
- (void)updateCallType:(RPRecentCallType)callType
|
||||
{
|
||||
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self updateCallType:callType transaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)updateCallType:(RPRecentCallType)callType transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
|
|
|
@ -795,12 +795,11 @@ NSString *const kNSNotification_OWSWebSocketStateDidChange = @"kNSNotification_O
|
|||
}
|
||||
|
||||
if (!success) {
|
||||
[[self.primaryStorage newDatabaseConnection]
|
||||
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
TSErrorMessage *errorMessage = [TSErrorMessage corruptedMessageInUnknownThread];
|
||||
[self.notificationsManager notifyUserForThreadlessErrorMessage:errorMessage
|
||||
transaction:transaction];
|
||||
}];
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
TSErrorMessage *errorMessage = [TSErrorMessage corruptedMessageInUnknownThread];
|
||||
[self.notificationsManager notifyUserForThreadlessErrorMessage:errorMessage
|
||||
transaction:transaction];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
|
|
@ -149,7 +149,7 @@ SSKProtoVerified *_Nullable BuildVerifiedProtoWithRecipientId(NSString *destinat
|
|||
{
|
||||
changeBlock(self);
|
||||
|
||||
[[self class].dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
OWSRecipientIdentity *latest = [[self class] fetchObjectWithUniqueID:self.uniqueId transaction:transaction];
|
||||
if (latest == nil) {
|
||||
[self saveWithTransaction:transaction];
|
||||
|
@ -158,7 +158,7 @@ SSKProtoVerified *_Nullable BuildVerifiedProtoWithRecipientId(NSString *destinat
|
|||
|
||||
changeBlock(latest);
|
||||
[latest saveWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
#pragma mark - debug
|
||||
|
|
|
@ -452,7 +452,7 @@ void VerifyRegistrationsForPrimaryStorage(OWSStorage *storage)
|
|||
// made in another process (e.g. the SAE) from showing up in other processes.
|
||||
// There's a simple workaround: a trivial write to the database flushes changes
|
||||
// made from other processes.
|
||||
[self.dbReadWriteConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[transaction setObject:[NSUUID UUID].UUIDString forKey:@"conversation_view_noop_mod" inCollection:@"temp"];
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -45,13 +45,14 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (void)save
|
||||
{
|
||||
[[self dbReadWriteConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self saveWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)saveAsyncWithCompletionBlock:(void (^_Nullable)(void))completionBlock
|
||||
{
|
||||
// TODO: <--------
|
||||
[[self dbReadWriteConnection] asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
||||
[self saveWithTransaction:transaction];
|
||||
}
|
||||
|
@ -65,9 +66,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (void)touch
|
||||
{
|
||||
[[self dbReadWriteConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self touchWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (void)removeWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
|
@ -77,9 +78,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
- (void)remove
|
||||
{
|
||||
[[self dbReadWriteConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self removeWithTransaction:transaction];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
- (YapDatabaseConnection *)dbReadConnection
|
||||
|
@ -181,9 +182,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
+ (void)removeAllObjectsInCollection
|
||||
{
|
||||
[[self dbReadWriteConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[transaction removeAllObjectsInCollection:[self collection]];
|
||||
}];
|
||||
} error:nil];
|
||||
}
|
||||
|
||||
+ (nullable instancetype)fetchObjectWithUniqueID:(NSString *)uniqueID
|
||||
|
|
|
@ -187,10 +187,10 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
|
|||
dispatch_async(self.serialQueue, ^{
|
||||
self.hasRequestInFlight = NO;
|
||||
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
// Remove from queue.
|
||||
[transaction removeObjectForKey:eventKey inCollection:kOWSAnalytics_EventsCollection];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
// Wait a second between network requests / retries.
|
||||
dispatch_after(
|
||||
|
@ -323,7 +323,7 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
|
|||
[self sendEvent:eventDictionary eventKey:eventKey isCritical:YES];
|
||||
} else {
|
||||
// Add to queue.
|
||||
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
const int kMaxQueuedEvents = 5000;
|
||||
if ([transaction numberOfKeysInCollection:kOWSAnalytics_EventsCollection] > kMaxQueuedEvents) {
|
||||
OWSLogError(@"Event queue overflow.");
|
||||
|
@ -331,7 +331,7 @@ NSString *NSStringForOWSAnalyticsSeverity(OWSAnalyticsSeverity severity)
|
|||
}
|
||||
|
||||
[transaction setObject:eventDictionary forKey:eventKey inCollection:kOWSAnalytics_EventsCollection];
|
||||
}];
|
||||
} error:nil];
|
||||
|
||||
[self tryToSyncEvents];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue