Fix issue with dates on inbound link previews
This commit is contained in:
parent
5e0412042a
commit
bd32a55c15
2 changed files with 28 additions and 13 deletions
|
@ -778,7 +778,6 @@
|
|||
isStickerPack: window.Signal.LinkPreviews.isStickerPack(preview.url),
|
||||
domain: window.Signal.LinkPreviews.getDomain(preview.url),
|
||||
image: preview.image ? this.getPropsForAttachment(preview.image) : null,
|
||||
date: preview.date ? preview.date.toNumber() : null,
|
||||
}));
|
||||
},
|
||||
getPropsForQuote() {
|
||||
|
|
|
@ -1701,6 +1701,29 @@ class MessageReceiverInner extends EventTarget {
|
|||
digest: attachment.digest ? attachment.digest.toString('base64') : null,
|
||||
};
|
||||
}
|
||||
private isLinkPreviewDateValid(value: unknown): value is number {
|
||||
return (
|
||||
typeof value === 'number' &&
|
||||
!Number.isNaN(value) &&
|
||||
Number.isFinite(value) &&
|
||||
value > 0
|
||||
);
|
||||
}
|
||||
private cleanLinkPreviewDate(value: unknown): number | null {
|
||||
if (this.isLinkPreviewDateValid(value)) {
|
||||
return value;
|
||||
}
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
let result: unknown;
|
||||
try {
|
||||
result = (value as any).toNumber();
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
return this.isLinkPreviewDateValid(result) ? result : null;
|
||||
}
|
||||
async downloadAttachment(
|
||||
attachment: AttachmentPointerClass
|
||||
): Promise<DownloadAttachmentType> {
|
||||
|
@ -1856,18 +1879,11 @@ class MessageReceiverInner extends EventTarget {
|
|||
decrypted.attachments = (decrypted.attachments || []).map(
|
||||
this.cleanAttachment.bind(this)
|
||||
);
|
||||
decrypted.preview = (decrypted.preview || []).map(item => {
|
||||
const { image } = item;
|
||||
|
||||
if (!image) {
|
||||
return item;
|
||||
}
|
||||
|
||||
return {
|
||||
...item,
|
||||
image: this.cleanAttachment(image),
|
||||
};
|
||||
});
|
||||
decrypted.preview = (decrypted.preview || []).map(item => ({
|
||||
...item,
|
||||
date: this.cleanLinkPreviewDate(item.date),
|
||||
...(item.image ? this.cleanAttachment(item.image) : {}),
|
||||
}));
|
||||
decrypted.contact = (decrypted.contact || []).map(item => {
|
||||
const { avatar } = item;
|
||||
|
||||
|
|
Loading…
Reference in a new issue