|
|
|
@ -66,97 +66,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
#pragma mark - Durable Message Enqueue
|
|
|
|
|
|
|
|
|
|
// TODO: Move this elsewhere.
|
|
|
|
|
+ (void)ensureLinkPreviewForMessage:(TSOutgoingMessage *)message completion:(dispatch_block_t)completion
|
|
|
|
|
{
|
|
|
|
|
OWSAssert(message);
|
|
|
|
|
OWSAssert(completion);
|
|
|
|
|
|
|
|
|
|
if (message.linkPreview != nil) {
|
|
|
|
|
// Message already has link preview.
|
|
|
|
|
completion();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[OWSLinkPreview
|
|
|
|
|
tryToBuildPreviewInfoForMessageBodyText:message.body
|
|
|
|
|
completion:^(OWSLinkPreviewInfo *_Nullable linkPreviewInfo) {
|
|
|
|
|
if (!linkPreviewInfo) {
|
|
|
|
|
completion();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[self.dbConnection
|
|
|
|
|
asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
|
NSError *linkPreviewError;
|
|
|
|
|
OWSLinkPreview *_Nullable linkPreview = [OWSLinkPreview
|
|
|
|
|
buildValidatedLinkPreviewFromInfo:linkPreviewInfo
|
|
|
|
|
transaction:transaction
|
|
|
|
|
error:&linkPreviewError];
|
|
|
|
|
if (linkPreviewError
|
|
|
|
|
&& ![OWSLinkPreview isNoPreviewError:linkPreviewError]) {
|
|
|
|
|
OWSFailDebug(@"linkPreviewError: %@", linkPreviewError);
|
|
|
|
|
completion();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!linkPreview) {
|
|
|
|
|
OWSFailDebug(@"Missing linkPreview.");
|
|
|
|
|
completion();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[message updateWithLinkPreview:linkPreview transaction:transaction];
|
|
|
|
|
completion();
|
|
|
|
|
}];
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//+ (TSOutgoingMessage *)enqueueMessageWithText:(NSString *)text
|
|
|
|
|
// inThread:(TSThread *)thread
|
|
|
|
|
// quotedReplyModel:(nullable OWSQuotedReplyModel *)quotedReplyModel
|
|
|
|
|
// linkPreview:(nullable OWSLinkPreview *)linkPreview
|
|
|
|
|
// transaction:(YapDatabaseReadTransaction *)transaction
|
|
|
|
|
//{
|
|
|
|
|
// OWSDisappearingMessagesConfiguration *configuration =
|
|
|
|
|
// [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId transaction:transaction];
|
|
|
|
|
//
|
|
|
|
|
// uint32_t expiresInSeconds = (configuration.isEnabled ? configuration.durationSeconds : 0);
|
|
|
|
|
//
|
|
|
|
|
// TSOutgoingMessage *message =
|
|
|
|
|
// [TSOutgoingMessage outgoingMessageInThread:thread
|
|
|
|
|
// messageBody:text
|
|
|
|
|
// attachmentId:nil
|
|
|
|
|
// expiresInSeconds:expiresInSeconds
|
|
|
|
|
// quotedMessage:[quotedReplyModel buildQuotedMessageForSending]
|
|
|
|
|
// linkPreview:linkPreview];
|
|
|
|
|
//
|
|
|
|
|
// [BenchManager benchAsyncWithTitle:@"Saving outgoing message" block:^(void (^benchmarkCompletion)(void)) {
|
|
|
|
|
// // To avoid blocking the send flow, we dispatch an async write from within this read transaction
|
|
|
|
|
// AnyPromise *promise = [[AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
|
|
|
|
|
// [self.dbConnection asyncReadWriteWithBlock:^(YapDatabaseReadWriteTransaction *writeTransaction) {
|
|
|
|
|
// [message saveWithTransaction:writeTransaction];
|
|
|
|
|
// }
|
|
|
|
|
// completionBlock:^{
|
|
|
|
|
// resolve(@(1));
|
|
|
|
|
// }];
|
|
|
|
|
// }].thenInBackground(^{
|
|
|
|
|
// return [AnyPromise promiseWithResolverBlock:^(PMKResolver resolve) {
|
|
|
|
|
// [ThreadUtil ensureLinkPreviewForMessage:message
|
|
|
|
|
// completion:^{
|
|
|
|
|
// resolve(@(1));
|
|
|
|
|
// }];
|
|
|
|
|
// }];
|
|
|
|
|
// }].thenInBackground(^{
|
|
|
|
|
// [self.messageSenderJobQueue addMessage:message
|
|
|
|
|
// transaction:writeTransaction];
|
|
|
|
|
// }].thenInBackground(^{
|
|
|
|
|
// benchmarkCompletion();
|
|
|
|
|
// }) retainUntilComplete];
|
|
|
|
|
// }];
|
|
|
|
|
//
|
|
|
|
|
// return message;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
+ (TSOutgoingMessage *)enqueueMessageWithText:(NSString *)text
|
|
|
|
|
inThread:(TSThread *)thread
|
|
|
|
|
quotedReplyModel:(nullable OWSQuotedReplyModel *)quotedReplyModel
|
|
|
|
|