Skip to content

Commit

Permalink
Widen types for message rendering helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Jun 18, 2024
1 parent 3039968 commit d251cfc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
18 changes: 6 additions & 12 deletions apps/meteor/app/emoji/client/emojiParser.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import { isIE11 } from '../../../client/lib/utils/isIE11';
import { emoji } from './lib';

/*
/**
* emojiParser is a function that will replace emojis
* @param {Object} message - The message object
* @param {{ html: string }} message - The message object
* @return {{ html: string }}
*/

const emojiParser = (message) => {
if (!message.html?.trim()) {
return message;
}

let html = message.html.trim();
export const emojiParser = ({ html }) => {
html = html.trim();

// ' to apostrophe (') for emojis such as :')
html = html.replace(/'/g, "'");
Expand Down Expand Up @@ -64,7 +60,5 @@ const emojiParser = (message) => {
// line breaks ' <br> ' back to '<br>'
html = html.replace(/ <br> /g, '<br>');

return { ...message, html };
return { html };
};

export { emojiParser };
2 changes: 2 additions & 0 deletions apps/meteor/app/markdown/lib/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ class MarkdownClass {
return code(...args);
}

/** @param {string} message */
filterMarkdownFromMessage(message) {
return parsers.filtered(message);
}
}

export const Markdown = new MarkdownClass();

/** @param {string} message */
export const filterMarkdown = (message) => Markdown.filterMarkdownFromMessage(message);

export const createMarkdownMessageRenderer = ({ ...options }) => {
Expand Down
5 changes: 3 additions & 2 deletions apps/meteor/app/markdown/lib/parser/filtered/filtered.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
/**
* Filter markdown tags in message
* Use case: notifications
* Use case: notifications
* @param {string} message
*/
export const filtered = (
message,
Expand Down
6 changes: 2 additions & 4 deletions apps/meteor/client/lib/utils/renderMessageEmoji.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { IMessage } from '@rocket.chat/core-typings';
import { emojiParser } from '../../../app/emoji/client/emojiParser';

import { emojiParser } from '../../../app/emoji/client/emojiParser.js';

export const renderMessageEmoji = <T extends Partial<IMessage> & { html?: string }>(message: T): string => emojiParser(message)?.html;
export const renderMessageEmoji = ({ html }: { html: string }): string => emojiParser({ html }).html;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type ThreadTitleProps = {
};

const ThreadTitle = ({ mainMessage }: ThreadTitleProps) => {
const innerHTML = useMemo(() => ({ __html: normalizeThreadTitle(mainMessage) }), [mainMessage]);
const innerHTML = useMemo(() => ({ __html: normalizeThreadTitle(mainMessage) ?? '' }), [mainMessage]);
return <ContextualbarTitle dangerouslySetInnerHTML={innerHTML} />;
};

Expand Down

0 comments on commit d251cfc

Please sign in to comment.