|
|
|
@ -1166,8 +1166,7 @@ static const int kYapDatabaseRangeMinLength = 0;
|
|
|
|
|
[self ensureConversationProfileState];
|
|
|
|
|
|
|
|
|
|
__block BOOL hasError = NO;
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
id<ConversationViewItem> (^tryToAddViewItem)(TSInteraction *) = ^(TSInteraction *interaction) {
|
|
|
|
|
id<ConversationViewItem> (^tryToAddViewItem)(TSInteraction *, YapDatabaseReadTransaction *) = ^(TSInteraction *interaction, YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
OWSAssertDebug(interaction.uniqueId.length > 0);
|
|
|
|
|
|
|
|
|
|
id<ConversationViewItem> _Nullable viewItem = self.viewItemCache[interaction.uniqueId];
|
|
|
|
@ -1183,6 +1182,7 @@ static const int kYapDatabaseRangeMinLength = 0;
|
|
|
|
|
return viewItem;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
NSMutableArray<TSInteraction *> *interactions = [NSMutableArray new];
|
|
|
|
|
NSMutableSet<NSString *> *interactionIds = [NSMutableSet new];
|
|
|
|
|
|
|
|
|
@ -1217,7 +1217,7 @@ static const int kYapDatabaseRangeMinLength = 0;
|
|
|
|
|
loadedInteractions:interactions
|
|
|
|
|
canLoadMoreItems:canLoadMoreItems];
|
|
|
|
|
if (offers && [interactionIds containsObject:offers.beforeInteractionId]) {
|
|
|
|
|
id<ConversationViewItem> offersItem = tryToAddViewItem(offers);
|
|
|
|
|
id<ConversationViewItem> offersItem = tryToAddViewItem(offers, transaction);
|
|
|
|
|
if ([offersItem.interaction isKindOfClass:[OWSContactOffersInteraction class]]) {
|
|
|
|
|
OWSContactOffersInteraction *oldOffers = (OWSContactOffersInteraction *)offersItem.interaction;
|
|
|
|
|
BOOL didChange = (oldOffers.hasBlockOffer != offers.hasBlockOffer
|
|
|
|
@ -1232,25 +1232,27 @@ static const int kYapDatabaseRangeMinLength = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (TSInteraction *interaction in interactions) {
|
|
|
|
|
tryToAddViewItem(interaction);
|
|
|
|
|
tryToAddViewItem(interaction, transaction);
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
// This will usually be redundant, but this will resolve one of the symptoms
|
|
|
|
|
// of the "corrupt YDB view" issue caused by multi-process writes.
|
|
|
|
|
[viewItems sortUsingComparator:^NSComparisonResult(id<ConversationViewItem> left, id<ConversationViewItem> right) {
|
|
|
|
|
return [left.interaction compareForSorting:right.interaction];
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
if (self.typingIndicatorsSender) {
|
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
|
id<ConversationViewItem> _Nullable lastViewItem = viewItems.lastObject;
|
|
|
|
|
uint64_t typingIndicatorTimestamp = (lastViewItem ? lastViewItem.interaction.timestamp + 1 : 1);
|
|
|
|
|
TSInteraction *interaction =
|
|
|
|
|
[[OWSTypingIndicatorInteraction alloc] initWithThread:self.thread
|
|
|
|
|
timestamp:typingIndicatorTimestamp
|
|
|
|
|
recipientId:self.typingIndicatorsSender];
|
|
|
|
|
tryToAddViewItem(interaction);
|
|
|
|
|
}
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
// This will usually be redundant, but this will resolve one of the symptoms
|
|
|
|
|
// of the "corrupt YDB view" issue caused by multi-process writes.
|
|
|
|
|
[viewItems sortUsingComparator:^NSComparisonResult(id<ConversationViewItem> left, id<ConversationViewItem> right) {
|
|
|
|
|
return [left.interaction compareForSorting:right.interaction];
|
|
|
|
|
tryToAddViewItem(interaction, transaction);
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Flag to ensure that we only increment once per launch.
|
|
|
|
|
if (hasError) {
|
|
|
|
|