diff --git a/src/components/common/messaging/Message.tsx b/src/components/common/messaging/Message.tsx index 7c008cb6..62e758b5 100644 --- a/src/components/common/messaging/Message.tsx +++ b/src/components/common/messaging/Message.tsx @@ -26,6 +26,14 @@ 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" +] + interface Props { attachContext?: boolean; queued?: QueuedMessage; @@ -37,7 +45,6 @@ interface Props { hideReply?: boolean; } - const Message = observer( ({ highlight, @@ -145,15 +152,21 @@ const Message = observer( )} {replacement ?? } {(() => { - if (content.includes(".revolt.chat/invite/") || content.includes("rvlt.gg/")) { - const inviteRegex = /(?:(?:app|nightly)\.revolt\.chat\/invite|rvlt.gg)\/([A-Za-z0-9]*)/g; + 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 = []; - let match; + let results: string[] = []; + let match: RegExpExecArray | null; inviteRegex.lastIndex = 0; while ((match = inviteRegex.exec(content)) !== null) { - if (!results.includes(match[1])) { - results.push(match[1]); + if (!results.includes(match[match.length - 1])) { + results.push(match[match.length - 1]); } } return results.map(code => ); diff --git a/src/components/common/messaging/embed/EmbedInvite.tsx b/src/components/common/messaging/embed/EmbedInvite.tsx index 48bc59c2..2bb1fc78 100644 --- a/src/components/common/messaging/embed/EmbedInvite.tsx +++ b/src/components/common/messaging/embed/EmbedInvite.tsx @@ -2,6 +2,7 @@ import styled from "styled-components"; import { autorun } from "mobx"; import { useHistory } from "react-router-dom"; +import { RetrievedInvite } from "revolt-api/types/Invites"; import { useContext, useEffect, useState } from "preact/hooks"; @@ -28,7 +29,7 @@ const EmbedInviteBase = styled.div` width: 400px; height: 80px; background-color: var(--secondary-background); - border-radius: 6px; + border-radius: var(--border-radius); display: flex; align-items: center; padding: 0 12px; @@ -45,8 +46,11 @@ const EmbedInviteMemberCount = styled.div` font-size: 0.8em; `; +type Props = { + code: string +} -export default function EmbedInvite(props) { +export default function EmbedInvite(props: Props) { const history = useHistory(); const client = useContext(AppContext); const status = useContext(StatusContext);