|
|
@ -516,8 +516,6 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- (void)generateLinkPreviewIfNeededFromURL:(NSString *)url {
|
|
|
|
- (void)generateLinkPreviewIfNeededFromURL:(NSString *)url {
|
|
|
|
// If we already have a link preview or attachment then don't bother
|
|
|
|
|
|
|
|
if (self.linkPreview != nil || self.hasAttachments) { return; }
|
|
|
|
|
|
|
|
[OWSLinkPreview tryToBuildPreviewInfoObjcWithPreviewUrl:url]
|
|
|
|
[OWSLinkPreview tryToBuildPreviewInfoObjcWithPreviewUrl:url]
|
|
|
|
.thenOn(dispatch_get_main_queue(), ^(OWSLinkPreviewDraft *linkPreviewDraft) {
|
|
|
|
.thenOn(dispatch_get_main_queue(), ^(OWSLinkPreviewDraft *linkPreviewDraft) {
|
|
|
|
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
@ -531,29 +529,26 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
|
|
|
|
if ([OWSLinkPreview isInvalidContentError:error]) {
|
|
|
|
if ([OWSLinkPreview isInvalidContentError:error]) {
|
|
|
|
__block AnyPromise *promise;
|
|
|
|
__block AnyPromise *promise;
|
|
|
|
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
promise = [OWSLinkPreview getImagePreviewFromUrl:url transaction:transaction];
|
|
|
|
promise = [OWSLinkPreview getImagePreviewWithURL:url transaction:transaction]
|
|
|
|
}];
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return [AnyPromise promiseWithValue:error];
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.thenOn(dispatch_get_main_queue(), ^(OWSLinkPreview *linkPreview) {
|
|
|
|
.thenOn(dispatch_get_main_queue(), ^(OWSLinkPreview *linkPreview) {
|
|
|
|
// If we managed to get a direct image preview then render it
|
|
|
|
// If we managed to get a direct image preview then render it
|
|
|
|
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[self.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
if (linkPreview.isDirectAttachment) {
|
|
|
|
if (linkPreview.isDirectAttachment) {
|
|
|
|
if (!self.hasAttachments) {
|
|
|
|
|
|
|
|
[self addAttachmentWithID:linkPreview.imageAttachmentId in:transaction];
|
|
|
|
[self addAttachmentWithID:linkPreview.imageAttachmentId in:transaction];
|
|
|
|
TSAttachmentStream *linkPreviewAttachment = [TSAttachmentStream fetchObjectWithUniqueID:linkPreview.imageAttachmentId transaction:transaction];
|
|
|
|
TSAttachmentStream *attachment = [TSAttachmentStream fetchObjectWithUniqueID:linkPreview.imageAttachmentId transaction:transaction];
|
|
|
|
linkPreviewAttachment.albumMessageId = self.uniqueId;
|
|
|
|
attachment.albumMessageId = self.uniqueId;
|
|
|
|
linkPreviewAttachment.isUploaded = true;
|
|
|
|
attachment.isUploaded = true;
|
|
|
|
[linkPreviewAttachment saveWithTransaction:transaction];
|
|
|
|
[attachment saveWithTransaction:transaction];
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
self.linkPreview = linkPreview;
|
|
|
|
// Do nothing
|
|
|
|
[self saveWithTransaction:transaction];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@throw error;
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
@end
|
|
|
|