Allow send with edited link preview
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
parent
29f0b96aaa
commit
bfbe5fb2e3
3 changed files with 31 additions and 0 deletions
|
@ -51,6 +51,7 @@ import type {
|
||||||
} from '../state/ducks/conversations';
|
} from '../state/ducks/conversations';
|
||||||
import type { EmojiPickDataType } from './emoji/EmojiPicker';
|
import type { EmojiPickDataType } from './emoji/EmojiPicker';
|
||||||
import type { LinkPreviewType } from '../types/message/LinkPreviews';
|
import type { LinkPreviewType } from '../types/message/LinkPreviews';
|
||||||
|
import { isSameLinkPreview } from '../types/message/LinkPreviews';
|
||||||
|
|
||||||
import { MandatoryProfileSharingActions } from './conversation/MandatoryProfileSharingActions';
|
import { MandatoryProfileSharingActions } from './conversation/MandatoryProfileSharingActions';
|
||||||
import { MediaQualitySelector } from './MediaQualitySelector';
|
import { MediaQualitySelector } from './MediaQualitySelector';
|
||||||
|
@ -366,6 +367,9 @@ export const CompositionArea = memo(function CompositionArea({
|
||||||
(draftEditMessage != null &&
|
(draftEditMessage != null &&
|
||||||
dropNull(draftEditMessage.quote?.messageId) !==
|
dropNull(draftEditMessage.quote?.messageId) !==
|
||||||
dropNull(quotedMessageId)) ||
|
dropNull(quotedMessageId)) ||
|
||||||
|
// Link preview of edited message changed
|
||||||
|
(draftEditMessage != null &&
|
||||||
|
!isSameLinkPreview(linkPreviewResult, draftEditMessage?.preview)) ||
|
||||||
// Not edit message, but has attachments
|
// Not edit message, but has attachments
|
||||||
(draftEditMessage == null && draftAttachments.length !== 0);
|
(draftEditMessage == null && draftAttachments.length !== 0);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import * as Errors from '../types/errors';
|
||||||
import type { StickerPackType as StickerPackDBType } from '../sql/Interface';
|
import type { StickerPackType as StickerPackDBType } from '../sql/Interface';
|
||||||
import type { MIMEType } from '../types/MIME';
|
import type { MIMEType } from '../types/MIME';
|
||||||
import * as Bytes from '../Bytes';
|
import * as Bytes from '../Bytes';
|
||||||
|
import { sha256 } from '../Crypto';
|
||||||
import * as LinkPreview from '../types/LinkPreview';
|
import * as LinkPreview from '../types/LinkPreview';
|
||||||
import * as Stickers from '../types/Stickers';
|
import * as Stickers from '../types/Stickers';
|
||||||
import * as VisualAttachment from '../types/VisualAttachment';
|
import * as VisualAttachment from '../types/VisualAttachment';
|
||||||
|
@ -364,6 +365,7 @@ async function getPreview(
|
||||||
data,
|
data,
|
||||||
size: data.byteLength,
|
size: data.byteLength,
|
||||||
...dimensions,
|
...dimensions,
|
||||||
|
plaintextHash: Bytes.toHex(sha256(data)),
|
||||||
contentType: stringToMIMEType(withBlob.file.type),
|
contentType: stringToMIMEType(withBlob.file.type),
|
||||||
blurHash,
|
blurHash,
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,3 +17,28 @@ type GenericLinkPreviewType<Image> = {
|
||||||
export type LinkPreviewType = GenericLinkPreviewType<AttachmentType>;
|
export type LinkPreviewType = GenericLinkPreviewType<AttachmentType>;
|
||||||
export type LinkPreviewWithHydratedData =
|
export type LinkPreviewWithHydratedData =
|
||||||
GenericLinkPreviewType<AttachmentWithHydratedData>;
|
GenericLinkPreviewType<AttachmentWithHydratedData>;
|
||||||
|
|
||||||
|
export function isSameLinkPreview(
|
||||||
|
prev: LinkPreviewType | undefined | null,
|
||||||
|
next: LinkPreviewType | undefined | null
|
||||||
|
): boolean {
|
||||||
|
// Both has to be absent or present
|
||||||
|
if (prev == null || next == null) {
|
||||||
|
return prev == null && next == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prev.url !== next.url) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (prev.title !== next.title) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (prev.description !== next.description) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (prev.image?.plaintextHash !== next.image?.plaintextHash) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue