Change invite rendering logic.

Handle link warnings on embeds.
Remove "EDIT!!" 🙏🙏🙏
This commit is contained in:
Paul
2021-09-03 13:04:37 +01:00
parent 571b30243c
commit 2ccc0b7b5e
7 changed files with 219 additions and 179 deletions

View File

@@ -24,15 +24,7 @@ import MessageBase, {
import Attachment from "./attachments/Attachment";
import { MessageReply } from "./attachments/MessageReply";
import Embed from "./embed/Embed";
import EmbedInvite from "./embed/EmbedInvite";
const INVITE_PATHS = [
location.hostname + "/invite",
"app.revolt.chat/invite",
"nightly.revolt.chat/invite",
"local.revolt.chat/invite",
"rvlt.gg"
]
import InviteList from "./embed/EmbedInvite";
interface Props {
attachContext?: boolean;
@@ -151,28 +143,7 @@ const Message = observer(
</span>
)}
{replacement ?? <Markdown content={content} />}
{(() => {
let isInvite = false;
INVITE_PATHS.forEach(path => {
if (content.includes(path)) {
isInvite = true;
}
})
if (isInvite) {
const inviteRegex = new RegExp("(?:" + INVITE_PATHS.map((path, index) => path.split(".").join("\\.") + (index !== INVITE_PATHS.length - 1 ? "|" : "")).join("") + ")/([A-Za-z0-9]*)", "g");
if (inviteRegex.test(content)) {
let results: string[] = [];
let match: RegExpExecArray | null;
inviteRegex.lastIndex = 0;
while ((match = inviteRegex.exec(content)) !== null) {
if (!results.includes(match[match.length - 1])) {
results.push(match[match.length - 1]);
}
}
return results.map(code => <EmbedInvite code={code} />);
}
}
})()}
{!queued && <InviteList message={message} />}
{queued?.error && (
<Overline type="error" error={queued.error} />
)}