DEV: Remove unnecessary chat hashtag/mention transform JS (#23054)

Not sure when we added this but it is no longer necessary,
hashtags are cooked appropriately when sending chat messages
and the mention transform was not used anywhere.
This commit is contained in:
Martin Brennan 2023-08-10 17:31:41 +10:00 committed by GitHub
parent f32c95c1b9
commit 2ecc8291e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 48 deletions

View File

@ -1,43 +0,0 @@
import getURL from "discourse-common/lib/get-url";
const domParser = new DOMParser();
export default function transform(cooked, categories) {
let html = domParser.parseFromString(cooked, "text/html");
transformMentions(html);
transformCategoryTagHashes(html, categories);
return html.body.innerHTML;
}
function transformMentions(html) {
(html.querySelectorAll("span.mention") || []).forEach((mentionSpan) => {
let mentionLink = document.createElement("a");
let mentionText = document.createTextNode(mentionSpan.innerText);
mentionLink.classList.add("mention");
mentionLink.appendChild(mentionText);
mentionLink.href = getURL(`/u/${mentionSpan.innerText.substring(1)}`);
mentionSpan.parentNode.replaceChild(mentionLink, mentionSpan);
});
}
function transformCategoryTagHashes(html, categories) {
(html.querySelectorAll("span.hashtag") || []).forEach((hashSpan) => {
const categoryTagName = hashSpan.innerText.substring(1);
const matchingCategory = categories.find(
(category) =>
category.name.toLowerCase() === categoryTagName.toLowerCase()
);
const href = getURL(
matchingCategory
? `/c/${matchingCategory.name}/${matchingCategory.id}`
: `/tag/${categoryTagName}`
);
let hashLink = document.createElement("a");
let hashText = document.createTextNode(hashSpan.innerText);
hashLink.classList.add("hashtag");
hashLink.appendChild(hashText);
hashLink.href = href;
hashSpan.parentNode.replaceChild(hashLink, hashSpan);
});
}

View File

@ -5,7 +5,6 @@ import ChatMessageReaction from "discourse/plugins/chat/discourse/models/chat-me
import Bookmark from "discourse/models/bookmark";
import I18n from "I18n";
import { generateCookFunction } from "discourse/lib/text";
import simpleCategoryHashMentionTransform from "discourse/plugins/chat/discourse/lib/simple-category-hash-mention-transform";
import { getOwner } from "discourse-common/lib/get-owner";
import discourseLater from "discourse-common/lib/later";
@ -192,10 +191,7 @@ export default class ChatMessage {
} else {
const cookFunction = await generateCookFunction(markdownOptions);
ChatMessage.cookFunction = (raw) => {
return simpleCategoryHashMentionTransform(
cookFunction(raw),
site.categories
);
return cookFunction(raw);
};
this.cooked = ChatMessage.cookFunction(this.message);