mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-25 07:02:10 -05:00
invite embeds 2: electric boogaloo
This commit is contained in:
parent
2e9a76519e
commit
0b0d1186eb
2 changed files with 26 additions and 9 deletions
|
@ -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 ?? <Markdown content={content} />}
|
||||
{(() => {
|
||||
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 => <EmbedInvite code={code} />);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue