Remove unnessesary comments

This commit is contained in:
Ajay Bura 2022-08-05 10:34:01 +05:30
parent 7abd8aebe0
commit 5ad03dad5f

View file

@ -109,17 +109,12 @@ function bindReplyToContent(roomId, reply, content) {
return newContent; return newContent;
} }
// Apply formatting to a plain text message
//
// This includes inserting any custom emoji that might be relevant, and (only if the
// user has enabled it in their settings) formatting the message using markdown.
function formatAndEmojifyText(mx, roomList, roomId, text) { function formatAndEmojifyText(mx, roomList, roomId, text) {
const room = mx.getRoom(roomId); const room = mx.getRoom(roomId);
const parentIds = roomList.getAllParentSpaces(roomId); const parentIds = roomList.getAllParentSpaces(roomId);
const parentRooms = [...parentIds].map((id) => mx.getRoom(id)); const parentRooms = [...parentIds].map((id) => mx.getRoom(id));
const allEmoji = getShortcodeToEmoji(mx, [room, ...parentRooms]); const allEmoji = getShortcodeToEmoji(mx, [room, ...parentRooms]);
// Start by applying markdown formatting (if relevant)
let formattedText; let formattedText;
if (settings.isMarkdown) { if (settings.isMarkdown) {
formattedText = getFormattedBody(text); formattedText = getFormattedBody(text);
@ -127,17 +122,14 @@ function formatAndEmojifyText(mx, roomList, roomId, text) {
formattedText = text; formattedText = text;
} }
// Check to see if there are any :shortcode-style-tags: in the message const SHORTCODE_REGEX = /\B:([\w-]+):\B/g;
Array.from(formattedText.matchAll(/\B:([\w-]+):\B/g)) Array.from(formattedText.matchAll(SHORTCODE_REGEX))
// Then filter to only the ones corresponding to a valid emoji .filter((shortcodeMatch) => allEmoji.has(shortcodeMatch[1]))
.filter((match) => allEmoji.has(match[1])) .reverse() /* Reversing the array ensures that indices are preserved as we start replacing */
// Reversing the array ensures that indices are preserved as we start replacing
.reverse()
// Replace each :shortcode: with an <img/> tag
.forEach((shortcodeMatch) => { .forEach((shortcodeMatch) => {
const emoji = allEmoji.get(shortcodeMatch[1]); const emoji = allEmoji.get(shortcodeMatch[1]);
console.log(shortcodeMatch);
// Render the tag that will replace the shortcode
let tag; let tag;
if (emoji.mxc) { if (emoji.mxc) {
tag = `<img data-mx-emoticon="" src="${ tag = `<img data-mx-emoticon="" src="${
@ -151,7 +143,6 @@ function formatAndEmojifyText(mx, roomList, roomId, text) {
tag = emoji.unicode; tag = emoji.unicode;
} }
// Splice the tag into the text
formattedText = formattedText.substr(0, shortcodeMatch.index) formattedText = formattedText.substr(0, shortcodeMatch.index)
+ tag + tag
+ formattedText.substr(shortcodeMatch.index + shortcodeMatch[0].length); + formattedText.substr(shortcodeMatch.index + shortcodeMatch[0].length);