forked from abner/for-legacy-web
feat: switch to revolt.js@6.0.0 + new revolt-api
This commit is contained in:
@@ -149,9 +149,9 @@ const TextChannel = observer(({ channel }: { channel: ChannelI }) => {
|
||||
// Mark channel as read.
|
||||
useEffect(() => {
|
||||
setLastId(
|
||||
channel.unread
|
||||
(channel.unread
|
||||
? channel.client.unreads?.getUnread(channel._id)?.last_id
|
||||
: undefined ?? undefined,
|
||||
: undefined) ?? undefined,
|
||||
);
|
||||
|
||||
const checkUnread = () =>
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
import { X } from "@styled-icons/boxicons-regular";
|
||||
import isEqual from "lodash.isequal";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { Masquerade } from "revolt-api/types/Channels";
|
||||
import { RelationshipStatus } from "revolt-api/types/Users";
|
||||
import { API } from "revolt.js";
|
||||
import { Message as MessageI } from "revolt.js/dist/maps/Messages";
|
||||
import { Nullable } from "revolt.js/dist/util/null";
|
||||
import styled from "styled-components/macro";
|
||||
@@ -99,10 +98,10 @@ export default observer(({ last_id, renderer, highlight }: Props) => {
|
||||
function compare(
|
||||
current: string,
|
||||
curAuthor: string,
|
||||
currentMasq: Nullable<Masquerade>,
|
||||
currentMasq: Nullable<API.Masquerade>,
|
||||
previous: string,
|
||||
prevAuthor: string,
|
||||
previousMasq: Nullable<Masquerade>,
|
||||
previousMasq: Nullable<API.Masquerade>,
|
||||
) {
|
||||
head = false;
|
||||
const atime = decodeTime(current),
|
||||
@@ -172,9 +171,7 @@ export default observer(({ last_id, renderer, highlight }: Props) => {
|
||||
highlight={highlight === message._id}
|
||||
/>,
|
||||
);
|
||||
} else if (
|
||||
message.author?.relationship === RelationshipStatus.Blocked
|
||||
) {
|
||||
} else if (message.author?.relationship === "Blocked") {
|
||||
blocked++;
|
||||
} else {
|
||||
if (blocked > 0) pushBlocked();
|
||||
|
||||
@@ -2,7 +2,6 @@ import { X, Plus } from "@styled-icons/boxicons-regular";
|
||||
import { PhoneCall, Envelope, UserX } from "@styled-icons/boxicons-solid";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import { RelationshipStatus } from "revolt-api/types/Users";
|
||||
import { User } from "revolt.js/dist/maps/Users";
|
||||
|
||||
import styles from "./Friend.module.scss";
|
||||
@@ -33,7 +32,7 @@ export const Friend = observer(({ user }: Props) => {
|
||||
const actions: Children[] = [];
|
||||
let subtext: Children = null;
|
||||
|
||||
if (user.relationship === RelationshipStatus.Friend) {
|
||||
if (user.relationship === "Friend") {
|
||||
subtext = <UserStatus user={user} />;
|
||||
actions.push(
|
||||
<>
|
||||
@@ -70,7 +69,7 @@ export const Friend = observer(({ user }: Props) => {
|
||||
);
|
||||
}
|
||||
|
||||
if (user.relationship === RelationshipStatus.Incoming) {
|
||||
if (user.relationship === "Incoming") {
|
||||
actions.push(
|
||||
<IconButton
|
||||
type="circle"
|
||||
@@ -83,14 +82,14 @@ export const Friend = observer(({ user }: Props) => {
|
||||
subtext = <Text id="app.special.friends.incoming" />;
|
||||
}
|
||||
|
||||
if (user.relationship === RelationshipStatus.Outgoing) {
|
||||
if (user.relationship === "Outgoing") {
|
||||
subtext = <Text id="app.special.friends.outgoing" />;
|
||||
}
|
||||
|
||||
if (
|
||||
user.relationship === RelationshipStatus.Friend ||
|
||||
user.relationship === RelationshipStatus.Outgoing ||
|
||||
user.relationship === RelationshipStatus.Incoming
|
||||
user.relationship === "Friend" ||
|
||||
user.relationship === "Outgoing" ||
|
||||
user.relationship === "Incoming"
|
||||
) {
|
||||
actions.push(
|
||||
<IconButton
|
||||
@@ -103,7 +102,7 @@ export const Friend = observer(({ user }: Props) => {
|
||||
onClick={(ev) =>
|
||||
stopPropagation(
|
||||
ev,
|
||||
user.relationship === RelationshipStatus.Friend
|
||||
user.relationship === "Friend"
|
||||
? openScreen({
|
||||
id: "special_prompt",
|
||||
type: "unfriend_user",
|
||||
@@ -117,7 +116,7 @@ export const Friend = observer(({ user }: Props) => {
|
||||
);
|
||||
}
|
||||
|
||||
if (user.relationship === RelationshipStatus.Blocked) {
|
||||
if (user.relationship === "Blocked") {
|
||||
actions.push(
|
||||
<IconButton
|
||||
type="circle"
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { ChevronRight } from "@styled-icons/boxicons-regular";
|
||||
import { UserDetail, MessageAdd, UserPlus } from "@styled-icons/boxicons-solid";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { RelationshipStatus, Presence } from "revolt-api/types/Users";
|
||||
import { User } from "revolt.js/dist/maps/Users";
|
||||
import styled, { css } from "styled-components/macro";
|
||||
|
||||
import styles from "./Friend.module.scss";
|
||||
import classNames from "classnames";
|
||||
@@ -31,37 +29,32 @@ export default observer(() => {
|
||||
const users = [...client.users.values()];
|
||||
users.sort((a, b) => a.username.localeCompare(b.username));
|
||||
|
||||
const friends = users.filter(
|
||||
(x) => x.relationship === RelationshipStatus.Friend,
|
||||
);
|
||||
const friends = users.filter((x) => x.relationship === "Friend");
|
||||
|
||||
const lists = [
|
||||
[
|
||||
"",
|
||||
users.filter((x) => x.relationship === RelationshipStatus.Incoming),
|
||||
],
|
||||
["", users.filter((x) => x.relationship === "Incoming")],
|
||||
[
|
||||
"app.special.friends.sent",
|
||||
users.filter((x) => x.relationship === RelationshipStatus.Outgoing),
|
||||
users.filter((x) => x.relationship === "Outgoing"),
|
||||
"outgoing",
|
||||
],
|
||||
[
|
||||
"app.status.online",
|
||||
friends.filter(
|
||||
(x) => x.online && x.status?.presence !== Presence.Invisible,
|
||||
(x) => x.online && x.status?.presence !== "Invisible",
|
||||
),
|
||||
"online",
|
||||
],
|
||||
[
|
||||
"app.status.offline",
|
||||
friends.filter(
|
||||
(x) => !x.online || x.status?.presence === Presence.Invisible,
|
||||
(x) => !x.online || x.status?.presence === "Invisible",
|
||||
),
|
||||
"offline",
|
||||
],
|
||||
[
|
||||
"app.special.friends.blocked",
|
||||
users.filter((x) => x.relationship === RelationshipStatus.Blocked),
|
||||
users.filter((x) => x.relationship === "Blocked"),
|
||||
"blocked",
|
||||
],
|
||||
] as [string, User[], string][];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ArrowBack } from "@styled-icons/boxicons-regular";
|
||||
import { autorun } from "mobx";
|
||||
import { Redirect, useHistory, useParams } from "react-router-dom";
|
||||
import { RetrievedInvite } from "revolt-api/types/Invites";
|
||||
import { API } from "revolt.js";
|
||||
|
||||
import styles from "./Invite.module.scss";
|
||||
import { Text } from "preact-i18n";
|
||||
@@ -36,7 +36,7 @@ export default function Invite() {
|
||||
const { code } = useParams<{ code: string }>();
|
||||
const [processing, setProcessing] = useState(false);
|
||||
const [error, setError] = useState<string | undefined>(undefined);
|
||||
const [invite, setInvite] = useState<RetrievedInvite | undefined>(
|
||||
const [invite, setInvite] = useState<API.InviteResponse | undefined>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
@@ -92,6 +92,8 @@ export default function Invite() {
|
||||
);
|
||||
}
|
||||
|
||||
if (invite.type === "Group") return <h1>unimplemented</h1>;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={styles.invite}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useParams } from "react-router-dom";
|
||||
import { Permission } from "revolt.js";
|
||||
import { Route } from "revolt.js/dist/api/routes";
|
||||
import { API, Permission } from "revolt.js";
|
||||
import styled from "styled-components/macro";
|
||||
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
@@ -37,8 +36,7 @@ const Option = styled.div`
|
||||
export default function InviteBot() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const client = useClient();
|
||||
const [data, setData] =
|
||||
useState<Route<"GET", "/bots/id/invite">["response"]>();
|
||||
const [data, setData] = useState<API.PublicBot>();
|
||||
|
||||
useEffect(() => {
|
||||
client.bots.fetchPublic(id).then(setData);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { detect } from "detect-browser";
|
||||
import { Session } from "revolt-api/types/Auth";
|
||||
import { Client } from "revolt.js";
|
||||
import { API } from "revolt.js";
|
||||
|
||||
import { useApplicationState } from "../../../mobx/State";
|
||||
|
||||
@@ -44,25 +43,26 @@ export function FormLogin() {
|
||||
// This should be replaced in the future.
|
||||
const client = state.config.createClient();
|
||||
await client.fetchConfiguration();
|
||||
const session = (await client.req(
|
||||
"POST",
|
||||
"/auth/session/login",
|
||||
{ ...data, friendly_name },
|
||||
)) as unknown as Session;
|
||||
const session = await client.api.post("/auth/session/login", {
|
||||
...data,
|
||||
friendly_name,
|
||||
});
|
||||
|
||||
client.session = session;
|
||||
(client as any).Axios.defaults.headers = {
|
||||
"x-session-token": session?.token,
|
||||
};
|
||||
|
||||
async function login() {
|
||||
state.auth.setSession(session);
|
||||
if (session.result !== "Success") {
|
||||
alert("unsupported!");
|
||||
return;
|
||||
}
|
||||
|
||||
const { onboarding } = await client.req(
|
||||
"GET",
|
||||
"/onboard/hello",
|
||||
);
|
||||
const s = session;
|
||||
|
||||
client.session = session;
|
||||
(client as any).$updateHeaders();
|
||||
|
||||
async function login() {
|
||||
state.auth.setSession(s);
|
||||
}
|
||||
|
||||
const { onboarding } = await client.api.get("/onboard/hello");
|
||||
|
||||
if (onboarding) {
|
||||
openScreen({
|
||||
|
||||
@@ -16,7 +16,7 @@ export function FormSendReset() {
|
||||
<Form
|
||||
page="send_reset"
|
||||
callback={async (data) => {
|
||||
await client.req("POST", "/auth/account/reset_password", data);
|
||||
await client.api.post("/auth/account/reset_password", data);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
@@ -32,7 +32,7 @@ export function FormReset() {
|
||||
<Form
|
||||
page="reset"
|
||||
callback={async (data) => {
|
||||
await client.req("PATCH", "/auth/account/reset_password", {
|
||||
await client.api.patch("/auth/account/reset_password", {
|
||||
token,
|
||||
...data,
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ export function FormResend() {
|
||||
<Form
|
||||
page="resend"
|
||||
callback={async (data) => {
|
||||
await client.req("POST", "/auth/account/reverify", data);
|
||||
await client.api.post("/auth/account/reverify", data);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
@@ -34,11 +34,8 @@ export function FormVerify() {
|
||||
const history = useHistory();
|
||||
|
||||
useEffect(() => {
|
||||
client
|
||||
.req(
|
||||
"POST",
|
||||
`/auth/account/verify/${token}` as "/auth/account/verify/:code",
|
||||
)
|
||||
client.api
|
||||
.post(`/auth/account/verify/${token as ""}`)
|
||||
.then(() => history.push("/login"))
|
||||
.catch((err) => setError(takeError(err)));
|
||||
// eslint-disable-next-line
|
||||
|
||||
@@ -337,7 +337,9 @@ export default observer(() => {
|
||||
<Trash
|
||||
size={24}
|
||||
onClick={() =>
|
||||
client.users.edit({ remove: "StatusText" })
|
||||
client.users.edit({
|
||||
remove: ["StatusText"],
|
||||
})
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -69,7 +69,7 @@ export default observer(({ channel }: Props) => {
|
||||
{ max_side: 256 },
|
||||
true,
|
||||
)}
|
||||
remove={() => channel.edit({ remove: "Icon" })}
|
||||
remove={() => channel.edit({ remove: ["Icon"] })}
|
||||
defaultPreview={
|
||||
channel.channel_type === "Group"
|
||||
? "/assets/group.png"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import isEqual from "lodash.isequal";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { OverrideField } from "revolt-api/types/_common";
|
||||
import { Channel } from "revolt.js/dist/maps/Channels";
|
||||
import { Channel, API } from "revolt.js";
|
||||
|
||||
import { useLayoutEffect, useState } from "preact/hooks";
|
||||
|
||||
@@ -42,7 +41,7 @@ export default observer(({ channel }: Props) => {
|
||||
|
||||
// Keep track of whatever role we're editing right now.
|
||||
const [selected, setSelected] = useState("default");
|
||||
const [value, setValue] = useState<OverrideField | number | undefined>(
|
||||
const [value, setValue] = useState<API.OverrideField | number | undefined>(
|
||||
undefined,
|
||||
);
|
||||
const currentPermission = currentRoles.find(
|
||||
@@ -64,10 +63,10 @@ export default observer(({ channel }: Props) => {
|
||||
selected,
|
||||
typeof currentValue === "number"
|
||||
? currentValue
|
||||
: {
|
||||
: ({
|
||||
allow: currentValue.a,
|
||||
deny: currentValue.d,
|
||||
},
|
||||
} as any),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { At, Key, Block, ListOl } from "@styled-icons/boxicons-regular";
|
||||
import { At, Key, Block } from "@styled-icons/boxicons-regular";
|
||||
import {
|
||||
Envelope,
|
||||
HelpCircle,
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
} from "@styled-icons/boxicons-solid";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import { Profile } from "revolt-api/types/Users";
|
||||
import { API } from "revolt.js";
|
||||
|
||||
import styles from "./Panes.module.scss";
|
||||
import { Text } from "preact-i18n";
|
||||
@@ -37,7 +37,9 @@ export const Account = observer(() => {
|
||||
|
||||
const [email, setEmail] = useState("...");
|
||||
const [revealEmail, setRevealEmail] = useState(false);
|
||||
const [profile, setProfile] = useState<undefined | Profile>(undefined);
|
||||
const [profile, setProfile] = useState<undefined | API.UserProfile>(
|
||||
undefined,
|
||||
);
|
||||
const history = useHistory();
|
||||
|
||||
function switchPage(to: string) {
|
||||
@@ -46,8 +48,8 @@ export const Account = observer(() => {
|
||||
|
||||
useEffect(() => {
|
||||
if (email === "..." && status === ClientStatus.ONLINE) {
|
||||
client
|
||||
.req("GET", "/auth/account")
|
||||
client.api
|
||||
.get("/auth/account/")
|
||||
.then((account) => setEmail(account.email));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// ! FIXME: this code is garbage, need to replace
|
||||
import { Key, Clipboard, Globe, Plus } from "@styled-icons/boxicons-regular";
|
||||
import { LockAlt, HelpCircle } from "@styled-icons/boxicons-solid";
|
||||
import type { AxiosError } from "axios";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { Bot } from "revolt-api/types/Bots";
|
||||
import { Profile as ProfileI } from "revolt-api/types/Users";
|
||||
import { API } from "revolt.js";
|
||||
import { User } from "revolt.js/dist/maps/Users";
|
||||
import styled from "styled-components/macro";
|
||||
|
||||
@@ -43,7 +43,7 @@ interface Changes {
|
||||
name?: string;
|
||||
public?: boolean;
|
||||
interactions_url?: string;
|
||||
remove?: "InteractionsURL";
|
||||
remove?: "InteractionsURL"[];
|
||||
}
|
||||
|
||||
const BotBadge = styled.div`
|
||||
@@ -62,7 +62,7 @@ const BotBadge = styled.div`
|
||||
`;
|
||||
|
||||
interface Props {
|
||||
bot: Bot;
|
||||
bot: API.Bot;
|
||||
onDelete(): void;
|
||||
onUpdate(changes: Changes): void;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||
_id: bot._id,
|
||||
username: user.username,
|
||||
public: bot.public,
|
||||
interactions_url: bot.interactions_url,
|
||||
interactions_url: bot.interactions_url as any,
|
||||
});
|
||||
const [error, setError] = useState<string | JSX.Element>("");
|
||||
const [saving, setSaving] = useState(false);
|
||||
@@ -87,23 +87,21 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||
useState<HTMLInputElement | null>(null);
|
||||
const { writeClipboard, openScreen } = useIntermediate();
|
||||
|
||||
const [profile, setProfile] = useState<undefined | ProfileI>(undefined);
|
||||
const [profile, setProfile] = useState<undefined | API.UserProfile>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
const refreshProfile = useCallback(() => {
|
||||
client
|
||||
.request(
|
||||
"GET",
|
||||
`/users/${bot._id}/profile` as "/users/id/profile",
|
||||
{
|
||||
headers: { "x-bot-token": bot.token },
|
||||
transformRequest: (data, headers) => {
|
||||
// Remove user headers for this request
|
||||
delete headers["x-user-id"];
|
||||
delete headers["x-session-token"];
|
||||
return data;
|
||||
},
|
||||
client.api
|
||||
.get(`/users/${bot._id as ""}/profile`, undefined, {
|
||||
headers: { "x-bot-token": bot.token },
|
||||
transformRequest: (data, headers) => {
|
||||
// Remove user headers for this request
|
||||
delete headers?.["x-user-id"];
|
||||
delete headers?.["x-session-token"];
|
||||
return data;
|
||||
},
|
||||
)
|
||||
})
|
||||
.then((profile) => setProfile(profile ?? {}));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [user, setProfile]);
|
||||
@@ -122,14 +120,14 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||
const changes: Changes = {};
|
||||
if (data.username !== user!.username) changes.name = data.username;
|
||||
if (data.public !== bot.public) changes.public = data.public;
|
||||
if (data.interactions_url === "") changes.remove = "InteractionsURL";
|
||||
if (data.interactions_url === "") changes.remove = ["InteractionsURL"];
|
||||
else if (data.interactions_url !== bot.interactions_url)
|
||||
changes.interactions_url = data.interactions_url;
|
||||
setSaving(true);
|
||||
setError("");
|
||||
try {
|
||||
await client.bots.edit(bot._id, changes);
|
||||
if (changed) await editBotContent(profile?.content);
|
||||
if (changed) await editBotContent(profile?.content ?? undefined);
|
||||
onUpdate(changes);
|
||||
setChanged(false);
|
||||
setEditMode(false);
|
||||
@@ -152,19 +150,22 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||
async function editBotAvatar(avatar?: string) {
|
||||
setSaving(true);
|
||||
setError("");
|
||||
await client.request("PATCH", "/users/id", {
|
||||
headers: { "x-bot-token": bot.token },
|
||||
transformRequest: (data, headers) => {
|
||||
// Remove user headers for this request
|
||||
delete headers["x-user-id"];
|
||||
delete headers["x-session-token"];
|
||||
return data;
|
||||
await client.api.patch(
|
||||
"/users/@me",
|
||||
avatar ? { avatar } : { remove: ["Avatar"] },
|
||||
{
|
||||
headers: { "x-bot-token": bot.token },
|
||||
transformRequest: (data, headers) => {
|
||||
// Remove user headers for this request
|
||||
delete headers?.["x-user-id"];
|
||||
delete headers?.["x-session-token"];
|
||||
return data;
|
||||
},
|
||||
},
|
||||
data: JSON.stringify(avatar ? { avatar } : { remove: "Avatar" }),
|
||||
});
|
||||
);
|
||||
|
||||
const res = await client.bots.fetch(bot._id);
|
||||
if (!avatar) res.user.update({}, "Avatar");
|
||||
if (!avatar) res.user.update({}, ["Avatar"]);
|
||||
setUser(res.user);
|
||||
setSaving(false);
|
||||
}
|
||||
@@ -172,20 +173,21 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||
async function editBotBackground(background?: string) {
|
||||
setSaving(true);
|
||||
setError("");
|
||||
await client.request("PATCH", "/users/id", {
|
||||
headers: { "x-bot-token": bot.token },
|
||||
transformRequest: (data, headers) => {
|
||||
// Remove user headers for this request
|
||||
delete headers["x-user-id"];
|
||||
delete headers["x-session-token"];
|
||||
return data;
|
||||
await client.api.patch(
|
||||
"/users/@me",
|
||||
background
|
||||
? { profile: { background } }
|
||||
: { remove: ["ProfileBackground"] },
|
||||
{
|
||||
headers: { "x-bot-token": bot.token },
|
||||
transformRequest: (data, headers) => {
|
||||
// Remove user headers for this request
|
||||
delete headers?.["x-user-id"];
|
||||
delete headers?.["x-session-token"];
|
||||
return data;
|
||||
},
|
||||
},
|
||||
data: JSON.stringify(
|
||||
background
|
||||
? { profile: { background } }
|
||||
: { remove: "ProfileBackground" },
|
||||
),
|
||||
});
|
||||
);
|
||||
|
||||
if (!background) setProfile({ ...profile, background: undefined });
|
||||
else refreshProfile();
|
||||
@@ -195,20 +197,19 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||
async function editBotContent(content?: string) {
|
||||
setSaving(true);
|
||||
setError("");
|
||||
await client.request("PATCH", "/users/id", {
|
||||
headers: { "x-bot-token": bot.token },
|
||||
transformRequest: (data, headers) => {
|
||||
// Remove user headers for this request
|
||||
delete headers["x-user-id"];
|
||||
delete headers["x-session-token"];
|
||||
return data;
|
||||
await client.api.patch(
|
||||
"/users/@me",
|
||||
content ? { profile: { content } } : { remove: ["ProfileContent"] },
|
||||
{
|
||||
headers: { "x-bot-token": bot.token },
|
||||
transformRequest: (data, headers) => {
|
||||
// Remove user headers for this request
|
||||
delete headers?.["x-user-id"];
|
||||
delete headers?.["x-session-token"];
|
||||
return data;
|
||||
},
|
||||
},
|
||||
data: JSON.stringify(
|
||||
content
|
||||
? { profile: { content } }
|
||||
: { remove: "ProfileContent" },
|
||||
),
|
||||
});
|
||||
);
|
||||
|
||||
if (!content) setProfile({ ...profile, content: undefined });
|
||||
else refreshProfile();
|
||||
@@ -333,7 +334,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||
_id: bot._id,
|
||||
username: user!.username,
|
||||
public: bot.public,
|
||||
interactions_url: bot.interactions_url,
|
||||
interactions_url: bot.interactions_url as any,
|
||||
});
|
||||
usernameRef!.value = user!.username;
|
||||
interactionsRef!.value = bot.interactions_url || "";
|
||||
@@ -521,7 +522,7 @@ function BotCard({ bot, onDelete, onUpdate }: Props) {
|
||||
|
||||
export const MyBots = observer(() => {
|
||||
const client = useClient();
|
||||
const [bots, setBots] = useState<Bot[] | undefined>(undefined);
|
||||
const [bots, setBots] = useState<API.Bot[] | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
client.bots.fetchOwned().then(({ bots }) => setBots(bots));
|
||||
@@ -582,7 +583,7 @@ export const MyBots = observer(() => {
|
||||
changes.interactions_url;
|
||||
if (
|
||||
changes.remove ===
|
||||
"InteractionsURL"
|
||||
["InteractionsURL"]
|
||||
)
|
||||
x.interactions_url = undefined;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ export const Notifications = observer(() => {
|
||||
// tell the server we just subscribed
|
||||
const json = sub.toJSON();
|
||||
if (json.keys) {
|
||||
client.req("POST", "/push/subscribe", {
|
||||
client.api.post("/push/subscribe", {
|
||||
endpoint: sub.endpoint,
|
||||
...(json.keys as {
|
||||
p256dh: string;
|
||||
@@ -96,7 +96,7 @@ export const Notifications = observer(() => {
|
||||
sub?.unsubscribe();
|
||||
setPushEnabled(false);
|
||||
|
||||
client.req("POST", "/push/unsubscribe");
|
||||
client.api.post("/push/unsubscribe");
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Markdown } from "@styled-icons/boxicons-logos";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import { Profile as ProfileI } from "revolt-api/types/Users";
|
||||
import { API } from "revolt.js";
|
||||
|
||||
import styles from "./Panes.module.scss";
|
||||
import { Text } from "preact-i18n";
|
||||
@@ -30,7 +30,9 @@ export const Profile = observer(() => {
|
||||
const client = useClient();
|
||||
const history = useHistory();
|
||||
|
||||
const [profile, setProfile] = useState<undefined | ProfileI>(undefined);
|
||||
const [profile, setProfile] = useState<undefined | API.UserProfile>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
// ! FIXME: temporary solution
|
||||
// ! we should just announce profile changes through WS
|
||||
@@ -103,7 +105,7 @@ export const Profile = observer(() => {
|
||||
behaviour="upload"
|
||||
maxFileSize={4_000_000}
|
||||
onUpload={(avatar) => client.users.edit({ avatar })}
|
||||
remove={() => client.users.edit({ remove: "Avatar" })}
|
||||
remove={() => client.users.edit({ remove: ["Avatar"] })}
|
||||
defaultPreview={client.user!.generateAvatarURL(
|
||||
{ max_side: 256 },
|
||||
true,
|
||||
@@ -132,7 +134,7 @@ export const Profile = observer(() => {
|
||||
}}
|
||||
remove={async () => {
|
||||
await client.users.edit({
|
||||
remove: "ProfileBackground",
|
||||
remove: ["ProfileBackground"],
|
||||
});
|
||||
setProfile({ ...profile, background: undefined });
|
||||
}}
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
} from "@styled-icons/simple-icons";
|
||||
import relativeTime from "dayjs/plugin/relativeTime";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import { SessionInfo } from "revolt-api/types/Auth";
|
||||
import { API } from "revolt.js";
|
||||
import { decodeTime } from "ulid";
|
||||
|
||||
import styles from "./Panes.module.scss";
|
||||
@@ -33,7 +33,7 @@ export function Sessions() {
|
||||
const deviceId =
|
||||
typeof client.session === "object" ? client.session._id : undefined;
|
||||
|
||||
const [sessions, setSessions] = useState<SessionInfo[] | undefined>(
|
||||
const [sessions, setSessions] = useState<API.SessionInfo[] | undefined>(
|
||||
undefined,
|
||||
);
|
||||
const [attemptingDelete, setDelete] = useState<string[]>([]);
|
||||
@@ -44,7 +44,7 @@ export function Sessions() {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
client.req("GET", "/auth/session/all").then((data) => {
|
||||
client.api.get("/auth/session/all").then((data) => {
|
||||
data.sort(
|
||||
(a, b) =>
|
||||
(b._id === deviceId ? 1 : 0) - (a._id === deviceId ? 1 : 0),
|
||||
@@ -61,7 +61,7 @@ export function Sessions() {
|
||||
);
|
||||
}
|
||||
|
||||
function getIcon(session: SessionInfo) {
|
||||
function getIcon(session: API.SessionInfo) {
|
||||
const name = session.name;
|
||||
switch (true) {
|
||||
case /firefox/i.test(name):
|
||||
@@ -83,7 +83,7 @@ export function Sessions() {
|
||||
}
|
||||
}
|
||||
|
||||
function getSystemIcon(session: SessionInfo) {
|
||||
function getSystemIcon(session: API.SessionInfo) {
|
||||
const name = session.name;
|
||||
switch (true) {
|
||||
case /linux/i.test(name):
|
||||
@@ -187,9 +187,10 @@ export function Sessions() {
|
||||
...attemptingDelete,
|
||||
session._id,
|
||||
]);
|
||||
await client.req(
|
||||
"DELETE",
|
||||
`/auth/session/${session._id}` as "/auth/session/id",
|
||||
await client.api.delete(
|
||||
`/auth/session/${
|
||||
session._id as ""
|
||||
}`,
|
||||
);
|
||||
setSessions(
|
||||
sessions?.filter(
|
||||
@@ -222,10 +223,7 @@ export function Sessions() {
|
||||
setDelete(del);
|
||||
|
||||
for (const id of del) {
|
||||
await client.req(
|
||||
"DELETE",
|
||||
`/auth/session/${id}` as "/auth/session/id",
|
||||
);
|
||||
await client.api.delete(`/auth/session/${id as ""}`);
|
||||
}
|
||||
|
||||
setSessions(sessions.filter((x) => x._id === deviceId));
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { XCircle } from "@styled-icons/boxicons-regular";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { Virtuoso } from "react-virtuoso";
|
||||
import { Ban } from "revolt-api/types/Servers";
|
||||
import { User } from "revolt-api/types/Users";
|
||||
import { Route } from "revolt.js/dist/api/routes";
|
||||
import { API } from "revolt.js";
|
||||
import { Server } from "revolt.js/dist/maps/Servers";
|
||||
|
||||
import styles from "./Panes.module.scss";
|
||||
@@ -15,8 +13,8 @@ import IconButton from "../../../components/ui/IconButton";
|
||||
import Preloader from "../../../components/ui/Preloader";
|
||||
|
||||
interface InnerProps {
|
||||
ban: Ban;
|
||||
users: Pick<User, "username" | "avatar" | "_id">[];
|
||||
ban: API.ServerBan;
|
||||
users: Pick<API.User, "username" | "avatar" | "_id">[];
|
||||
server: Server;
|
||||
removeSelf: () => void;
|
||||
}
|
||||
@@ -53,9 +51,7 @@ interface Props {
|
||||
}
|
||||
|
||||
export const Bans = observer(({ server }: Props) => {
|
||||
const [data, setData] = useState<
|
||||
Route<"GET", "/servers/id/bans">["response"] | undefined
|
||||
>(undefined);
|
||||
const [data, setData] = useState<API.BanListResult | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
server.fetchBans().then(setData);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { Plus, X } from "@styled-icons/boxicons-regular";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { DragDropContext } from "react-beautiful-dnd";
|
||||
import { TextChannel, VoiceChannel } from "revolt-api/types/Channels";
|
||||
import { Category } from "revolt-api/types/Servers";
|
||||
import { Server } from "revolt.js/dist/maps/Servers";
|
||||
import { Channel, Server, API } from "revolt.js";
|
||||
import styled, { css } from "styled-components/macro";
|
||||
import { ulid } from "ulid";
|
||||
|
||||
@@ -135,7 +133,7 @@ interface Props {
|
||||
|
||||
export const Categories = observer(({ server }: Props) => {
|
||||
const [status, setStatus] = useState<EditStatus>("saved");
|
||||
const [categories, setCategories] = useState<Category[]>(
|
||||
const [categories, setCategories] = useState<API.Category[]>(
|
||||
server.categories ?? [],
|
||||
);
|
||||
|
||||
@@ -327,12 +325,14 @@ function ListElement({
|
||||
addChannel,
|
||||
draggable,
|
||||
}: {
|
||||
category: Category;
|
||||
category: API.Category;
|
||||
server: Server;
|
||||
index: number;
|
||||
setTitle?: (title: string) => void;
|
||||
deleteSelf?: () => void;
|
||||
addChannel: (channel: TextChannel | VoiceChannel) => void;
|
||||
addChannel: (
|
||||
channel: Channel & { channel_type: "TextChannel" | "VoiceChannel" },
|
||||
) => void;
|
||||
draggable?: boolean;
|
||||
}) {
|
||||
const { openScreen } = useIntermediate();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { XCircle } from "@styled-icons/boxicons-regular";
|
||||
import { observer } from "mobx-react-lite";
|
||||
import { Virtuoso } from "react-virtuoso";
|
||||
import { Invite, ServerInvite } from "revolt-api/types/Invites";
|
||||
import { Server } from "revolt.js/dist/maps/Servers";
|
||||
import { API, Server } from "revolt.js";
|
||||
|
||||
import styles from "./Panes.module.scss";
|
||||
import { Text } from "preact-i18n";
|
||||
@@ -16,7 +15,7 @@ import IconButton from "../../../components/ui/IconButton";
|
||||
import Preloader from "../../../components/ui/Preloader";
|
||||
|
||||
interface InnerProps {
|
||||
invite: Invite;
|
||||
invite: API.Invite;
|
||||
server: Server;
|
||||
removeSelf: () => void;
|
||||
}
|
||||
@@ -52,12 +51,10 @@ interface Props {
|
||||
}
|
||||
|
||||
export const Invites = ({ server }: Props) => {
|
||||
const [invites, setInvites] = useState<ServerInvite[] | undefined>(
|
||||
undefined,
|
||||
);
|
||||
const [invites, setInvites] = useState<API.Invite[] | undefined>(undefined);
|
||||
|
||||
useEffect(() => {
|
||||
server.fetchInvites().then(setInvites);
|
||||
server.fetchInvites().then((v) => setInvites(v));
|
||||
}, [server, setInvites]);
|
||||
|
||||
return (
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Text } from "preact-i18n";
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
import TextAreaAutoSize from "../../../lib/TextAreaAutoSize";
|
||||
import { noop } from "../../../lib/js";
|
||||
|
||||
import { FileUploader } from "../../../context/revoltjs/FileUploads";
|
||||
import { getChannelName } from "../../../context/revoltjs/util";
|
||||
@@ -60,9 +61,9 @@ export const Overview = observer(({ server }: Props) => {
|
||||
fileType="icons"
|
||||
behaviour="upload"
|
||||
maxFileSize={2_500_000}
|
||||
onUpload={(icon) => server.edit({ icon })}
|
||||
onUpload={(icon) => server.edit({ icon }).then(noop)}
|
||||
previewURL={server.generateIconURL({ max_side: 256 }, true)}
|
||||
remove={() => server.edit({ remove: "Icon" })}
|
||||
remove={() => server.edit({ remove: ["Icon"] }).then(noop)}
|
||||
/>
|
||||
<div className={styles.name}>
|
||||
<h3>
|
||||
@@ -117,9 +118,9 @@ export const Overview = observer(({ server }: Props) => {
|
||||
fileType="banners"
|
||||
behaviour="upload"
|
||||
maxFileSize={6_000_000}
|
||||
onUpload={(banner) => server.edit({ banner })}
|
||||
onUpload={(banner) => server.edit({ banner }).then(noop)}
|
||||
previewURL={server.generateBannerURL({ width: 1000 }, true)}
|
||||
remove={() => server.edit({ remove: "Banner" })}
|
||||
remove={() => server.edit({ remove: ["Banner"] }).then(noop)}
|
||||
/>
|
||||
<hr />
|
||||
<h3>
|
||||
|
||||
Reference in New Issue
Block a user