feat: add disable / delete funct; bump revolt-api

This commit is contained in:
Paul Makles 2022-06-10 14:32:21 +01:00
parent e0ca1681bd
commit 6be0807433
8 changed files with 47 additions and 26 deletions

View file

@ -145,7 +145,7 @@
"react-router-dom": "^5.2.0", "react-router-dom": "^5.2.0",
"react-scroll": "^1.8.2", "react-scroll": "^1.8.2",
"react-virtuoso": "^2.12.0", "react-virtuoso": "^2.12.0",
"revolt.js": "6.0.2", "revolt.js": "6.0.3",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"sass": "^1.35.1", "sass": "^1.35.1",
"shade-blend-color": "^1.0.0", "shade-blend-color": "^1.0.0",

View file

@ -177,7 +177,7 @@ export function SpecialInputModal(props: SpecialProps) {
question={"Add Friend"} question={"Add Friend"}
callback={(username) => callback={(username) =>
client.api client.api
.put(`/users/${username as ""}/friend`) .post(`/users/friend`, { username })
.then(undefined) .then(undefined)
} }
/> />

View file

@ -3,7 +3,7 @@ import { observer } from "mobx-react-lite";
import { Client } from "revolt.js"; import { Client } from "revolt.js";
import { createContext } from "preact"; import { createContext } from "preact";
import { useContext, useEffect, useState } from "preact/hooks"; import { useCallback, useContext, useEffect, useState } from "preact/hooks";
import { Preloader } from "@revoltchat/ui"; import { Preloader } from "@revoltchat/ui";
@ -29,7 +29,7 @@ export interface ClientOperations {
export const AppContext = createContext<Client>(null!); export const AppContext = createContext<Client>(null!);
export const StatusContext = createContext<ClientStatus>(null!); export const StatusContext = createContext<ClientStatus>(null!);
export const LogOutContext = createContext(() => {}); export const LogOutContext = createContext((avoidReq?: boolean) => {});
type Props = { type Props = {
children: Children; children: Children;
@ -42,10 +42,10 @@ export default observer(({ children }: Props) => {
const [status, setStatus] = useState(ClientStatus.LOADING); const [status, setStatus] = useState(ClientStatus.LOADING);
const [loaded, setLoaded] = useState(false); const [loaded, setLoaded] = useState(false);
function logout() { const logout = useCallback((avoidReq?: boolean) => {
setLoaded(false); setLoaded(false);
client.logout(false); client.logout(avoidReq);
} }, []);
useEffect(() => { useEffect(() => {
if (navigator.onLine) { if (navigator.onLine) {

View file

@ -58,7 +58,7 @@ export interface LegacySyncOptions {
export interface LegacyAuthState { export interface LegacyAuthState {
accounts: { accounts: {
[key: string]: { [key: string]: {
session: API.Session; session: Session;
}; };
}; };
active?: string; active?: string;

View file

@ -8,7 +8,7 @@ import Persistent from "../interfaces/Persistent";
import Store from "../interfaces/Store"; import Store from "../interfaces/Store";
interface Account { interface Account {
session: API.Session; session: Session;
} }
export interface Data { export interface Data {
@ -82,7 +82,7 @@ export default class Auth implements Store, Persistent<Data> {
* Add a new session to the auth manager. * Add a new session to the auth manager.
* @param session Session * @param session Session
*/ */
@action setSession(session: API.Session) { @action setSession(session: Session) {
this.sessions.set(session.user_id, { session }); this.sessions.set(session.user_id, { session });
this.current = session.user_id; this.current = session.user_id;
} }

View file

@ -21,6 +21,7 @@ import { stopPropagation } from "../../../lib/stopPropagation";
import { useIntermediate } from "../../../context/intermediate/Intermediate"; import { useIntermediate } from "../../../context/intermediate/Intermediate";
import { import {
ClientStatus, ClientStatus,
LogOutContext,
StatusContext, StatusContext,
useClient, useClient,
} from "../../../context/revoltjs/RevoltClient"; } from "../../../context/revoltjs/RevoltClient";
@ -30,6 +31,7 @@ import UserIcon from "../../../components/common/user/UserIcon";
export const Account = observer(() => { export const Account = observer(() => {
const { openScreen, writeClipboard } = useIntermediate(); const { openScreen, writeClipboard } = useIntermediate();
const logOut = useContext(LogOutContext);
const status = useContext(StatusContext); const status = useContext(StatusContext);
const client = useClient(); const client = useClient();
@ -207,9 +209,15 @@ export const Account = observer(() => {
"Disable your account. You won't be able to access it unless you contact support." "Disable your account. You won't be able to access it unless you contact support."
} }
action="chevron" action="chevron"
onClick={() => { onClick={() =>
// client.api
}}> .post("/auth/account/disable", undefined, {
headers: {
"X-MFA-Ticket": "TICKET",
},
})
.then(() => logOut(true))
}>
<Text id="app.settings.pages.account.manage.disable" /> <Text id="app.settings.pages.account.manage.disable" />
</CategoryButton> </CategoryButton>
<CategoryButton <CategoryButton
@ -218,9 +226,15 @@ export const Account = observer(() => {
"Your account will be queued for deletion, a confirmation email will be sent." "Your account will be queued for deletion, a confirmation email will be sent."
} }
action="chevron" action="chevron"
onClick={() => { onClick={() =>
// client.api
}}> .post("/auth/account/delete", undefined, {
headers: {
"X-MFA-Ticket": "TICKET",
},
})
.then(() => logOut(true))
}>
<Text id="app.settings.pages.account.manage.delete" /> <Text id="app.settings.pages.account.manage.delete" />
</CategoryButton> </CategoryButton>
<Tip> <Tip>

7
src/types/revolt-api.d.ts vendored Normal file
View file

@ -0,0 +1,7 @@
// TODO: re-export from revolt-api in some way
declare type Session = {
_id: string;
token: string;
name: string;
user_id: string;
};

View file

@ -3578,7 +3578,7 @@ __metadata:
react-router-dom: ^5.2.0 react-router-dom: ^5.2.0
react-scroll: ^1.8.2 react-scroll: ^1.8.2
react-virtuoso: ^2.12.0 react-virtuoso: ^2.12.0
revolt.js: 6.0.2 revolt.js: 6.0.3
rimraf: ^3.0.2 rimraf: ^3.0.2
sass: ^1.35.1 sass: ^1.35.1
shade-blend-color: ^1.0.0 shade-blend-color: ^1.0.0
@ -6858,20 +6858,20 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"revolt-api@npm:0.5.3-5-patch.4": "revolt-api@npm:0.5.3-7":
version: 0.5.3-5-patch.4 version: 0.5.3-7
resolution: "revolt-api@npm:0.5.3-5-patch.4" resolution: "revolt-api@npm:0.5.3-7"
dependencies: dependencies:
"@insertish/oapi": 0.1.16 "@insertish/oapi": 0.1.16
axios: ^0.26.1 axios: ^0.26.1
lodash.defaultsdeep: ^4.6.1 lodash.defaultsdeep: ^4.6.1
checksum: 4f01c43bff96c4030d13ab0bb5dc83614445763602cfdd8b3ff1dbf61620446a22513ca259bbfc9c490f6b9b19c79d610921a252b667d25adf4040b4222d98cf checksum: acc2f412d1be90f0cfa8a24ba715d8257813762c56ba0e48c649efff349674517036a8fa5939eda61ce31fd64a37f0c54af3d8fae56edf4596f05b10304e090e
languageName: node languageName: node
linkType: hard linkType: hard
"revolt.js@npm:6.0.2": "revolt.js@npm:6.0.3":
version: 6.0.2 version: 6.0.3
resolution: "revolt.js@npm:6.0.2" resolution: "revolt.js@npm:6.0.3"
dependencies: dependencies:
"@insertish/exponential-backoff": 3.1.0-patch.2 "@insertish/exponential-backoff": 3.1.0-patch.2
"@insertish/isomorphic-ws": ^4.0.1 "@insertish/isomorphic-ws": ^4.0.1
@ -6882,10 +6882,10 @@ __metadata:
lodash.isequal: ^4.5.0 lodash.isequal: ^4.5.0
long: ^5.2.0 long: ^5.2.0
mobx: ^6.3.2 mobx: ^6.3.2
revolt-api: 0.5.3-5-patch.4 revolt-api: 0.5.3-7
ulid: ^2.3.0 ulid: ^2.3.0
ws: ^8.2.2 ws: ^8.2.2
checksum: 1b0c6ce0ceae5d20aec373f24432a5e804677c455fbc39edadaeb6ae0427a0b4fe2ea2b950df92262cd56a43e3f8759d80887b65d66111882b6ecb82e813ff38 checksum: cfecbde7a9b795da75bfac3cec05f2aed5fd02cd14fcac1b2fad26285de1b887cf7ccb339e8a63a019f1e83058b041305927e029d7b5eedcc00823582d9a842a
languageName: node languageName: node
linkType: hard linkType: hard