Skip to content

Commit b9d0f6d

Browse files
committed
Properly render mentions when using Markdown.
1 parent 103ff7f commit b9d0f6d

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

ts/components/conversation/message/message-content/MessageBody.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,24 @@ export const MessageBody = (props: Props) => {
201201
}
202202

203203
if (window.getSettingValue('message-formatting')) {
204+
/* Resolve mentioned ids to user names and mark them up in bold */
205+
const mention = new RegExp(`@${PubKey.regexForPubkeys}`, 'g');
206+
const textWithMentions = text.trim().replace(mention,
207+
(_match, capture) => {
208+
if (isUsAnySogsFromCache(capture)) {
209+
/* It's me. Italicise also. */
210+
return `***@${window.i18n('you')}***`;
211+
}
212+
213+
/* It's someone else. */
214+
return `**@${getConversationController().get(capture)?.getContactProfileNameOrShortenedPubKey() || PubKey.shorten(capture)}**`;
215+
}
216+
);
217+
204218
/* tslint:disable:react-no-dangerous-html */
205219
return (
206220
<div className="text-selectable"
207-
dangerouslySetInnerHTML={{__html: `<span style="font-size: 1.1em;">${markdown.render(text).trim()}</span>`}}
221+
dangerouslySetInnerHTML={{__html: `<span style="font-size: 1.1em;">${markdown.render(textWithMentions)}</span>`}}
208222
/>
209223
);
210224
}

0 commit comments

Comments
 (0)