From a9406a7914ab1140062da6bb86b7f048eea19b8e Mon Sep 17 00:00:00 2001 From: ayumi-signal <143036029+ayumi-signal@users.noreply.github.com> Date: Mon, 23 Sep 2024 10:51:16 -0700 Subject: [PATCH] Fix link preview for received call link previews without title --- ts/components/conversation/Message.tsx | 22 ++++++++++++++-------- ts/models/messages.ts | 20 ++++++++++---------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index ae47cecf8..e9c7c837c 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -1188,6 +1188,16 @@ export class Message extends React.PureComponent { const isFullSizeImage = shouldUseFullSizeLinkPreviewImage(first); const linkPreviewDate = first.date || null; + const title = + first.title || + (first.isCallLink + ? i18n('icu:calling__call-link-default-title') + : undefined); + const description = + first.description || + (first.isCallLink + ? i18n('icu:message--call-link-description') + : undefined); const isClickable = this.areLinksEnabled(); @@ -1266,9 +1276,7 @@ export class Message extends React.PureComponent { isMe={false} sharedGroupNames={[]} size={64} - title={ - first.title ?? i18n('icu:calling__call-link-default-title') - } + title={title ?? i18n('icu:calling__call-link-default-title')} /> )} @@ -1280,12 +1288,10 @@ export class Message extends React.PureComponent { : null )} > -
- {first.title} -
- {first.description && ( +
{title}
+ {description && (
- {unescape(first.description)} + {unescape(description)}
)}
diff --git a/ts/models/messages.ts b/ts/models/messages.ts index 7dbfb4c22..18e517a8c 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -1820,7 +1820,15 @@ export class MessageModel extends window.Backbone.Model { const incomingPreview = dataMessage.preview || []; const preview = incomingPreview .map((item: LinkPreviewType) => { - if (!item.image && !item.title) { + if (LinkPreview.isCallLink(item.url)) { + return { + ...item, + isCallLink: true, + callLinkRoomId: getRoomIdFromCallLink(item.url), + }; + } + + if (!item.image || !item.title) { return null; } // Story link previews don't have to correspond to links in the @@ -1835,21 +1843,13 @@ export class MessageModel extends window.Backbone.Model { return undefined; } - if (LinkPreview.isCallLink(item.url)) { - return { - ...item, - isCallLink: true, - callLinkRoomId: getRoomIdFromCallLink(item.url), - }; - } - return item; }) .filter(isNotNil); if (preview.length < incomingPreview.length) { log.info( `${message.idForLogging()}: Eliminated ${ - preview.length - incomingPreview.length + incomingPreview.length - preview.length } previews with invalid urls'` ); }