mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-26 00:50:56 -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 Embed from "./embed/Embed";
|
||||||
import EmbedInvite from "./embed/EmbedInvite";
|
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 {
|
interface Props {
|
||||||
attachContext?: boolean;
|
attachContext?: boolean;
|
||||||
queued?: QueuedMessage;
|
queued?: QueuedMessage;
|
||||||
|
@ -37,7 +45,6 @@ interface Props {
|
||||||
hideReply?: boolean;
|
hideReply?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Message = observer(
|
const Message = observer(
|
||||||
({
|
({
|
||||||
highlight,
|
highlight,
|
||||||
|
@ -145,15 +152,21 @@ const Message = observer(
|
||||||
)}
|
)}
|
||||||
{replacement ?? <Markdown content={content} />}
|
{replacement ?? <Markdown content={content} />}
|
||||||
{(() => {
|
{(() => {
|
||||||
if (content.includes(".revolt.chat/invite/") || content.includes("rvlt.gg/")) {
|
let isInvite = false;
|
||||||
const inviteRegex = /(?:(?:app|nightly)\.revolt\.chat\/invite|rvlt.gg)\/([A-Za-z0-9]*)/g;
|
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)) {
|
if (inviteRegex.test(content)) {
|
||||||
let results = [];
|
let results: string[] = [];
|
||||||
let match;
|
let match: RegExpExecArray | null;
|
||||||
inviteRegex.lastIndex = 0;
|
inviteRegex.lastIndex = 0;
|
||||||
while ((match = inviteRegex.exec(content)) !== null) {
|
while ((match = inviteRegex.exec(content)) !== null) {
|
||||||
if (!results.includes(match[1])) {
|
if (!results.includes(match[match.length - 1])) {
|
||||||
results.push(match[1]);
|
results.push(match[match.length - 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results.map(code => <EmbedInvite code={code} />);
|
return results.map(code => <EmbedInvite code={code} />);
|
||||||
|
|
|
@ -2,6 +2,7 @@ import styled from "styled-components";
|
||||||
|
|
||||||
import { autorun } from "mobx";
|
import { autorun } from "mobx";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
|
import { RetrievedInvite } from "revolt-api/types/Invites";
|
||||||
|
|
||||||
import { useContext, useEffect, useState } from "preact/hooks";
|
import { useContext, useEffect, useState } from "preact/hooks";
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ const EmbedInviteBase = styled.div`
|
||||||
width: 400px;
|
width: 400px;
|
||||||
height: 80px;
|
height: 80px;
|
||||||
background-color: var(--secondary-background);
|
background-color: var(--secondary-background);
|
||||||
border-radius: 6px;
|
border-radius: var(--border-radius);
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 0 12px;
|
padding: 0 12px;
|
||||||
|
@ -45,8 +46,11 @@ const EmbedInviteMemberCount = styled.div`
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
code: string
|
||||||
|
}
|
||||||
|
|
||||||
export default function EmbedInvite(props) {
|
export default function EmbedInvite(props: Props) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const client = useContext(AppContext);
|
const client = useContext(AppContext);
|
||||||
const status = useContext(StatusContext);
|
const status = useContext(StatusContext);
|
||||||
|
|
Loading…
Reference in a new issue