mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-25 23:22:06 -05:00
Handle additional side effects from events.
This commit is contained in:
parent
b0681dfc99
commit
6531486636
2 changed files with 57 additions and 11 deletions
|
@ -321,7 +321,7 @@ export class DataStore {
|
|||
}
|
||||
|
||||
@action
|
||||
packet(packet: ClientboundNotification) {
|
||||
async packet(packet: ClientboundNotification) {
|
||||
switch (packet.type) {
|
||||
case "Ready": {
|
||||
for (let user of packet.users) {
|
||||
|
@ -352,6 +352,12 @@ export class DataStore {
|
|||
}
|
||||
case "ChannelGroupJoin": {
|
||||
this.channels.get(packet.id)?.groupJoin(packet.user);
|
||||
|
||||
if (!this.users.has(packet.user)) {
|
||||
let user = await this.client.users.fetch(packet.user);
|
||||
this.users.set(packet.user, new User(user));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "ChannelGroupLeave": {
|
||||
|
@ -375,6 +381,13 @@ export class DataStore {
|
|||
break;
|
||||
}
|
||||
case "ServerDelete": {
|
||||
let server = this.servers.get(packet.id);
|
||||
if (server) {
|
||||
for (let channel of server.channels) {
|
||||
this.channels.delete(channel);
|
||||
}
|
||||
}
|
||||
|
||||
this.servers.delete(packet.id);
|
||||
break;
|
||||
}
|
||||
|
@ -385,10 +398,32 @@ export class DataStore {
|
|||
case "ServerMemberJoin": {
|
||||
const _id = { server: packet.id, user: packet.user };
|
||||
this.members.set(_id, new Member({ _id }));
|
||||
|
||||
if (!this.servers.has(packet.id)) {
|
||||
let server = await this.client.servers.fetch(packet.id);
|
||||
this.servers.set(packet.id, new Server(server));
|
||||
|
||||
for (let id of server.channels) {
|
||||
let channel = this.client.channels.get(id);
|
||||
if (channel) {
|
||||
this.channels.set(id, new Channel(channel));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.users.has(packet.user)) {
|
||||
let user = await this.client.users.fetch(packet.user);
|
||||
this.users.set(packet.user, new User(user));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case "ServerMemberLeave": {
|
||||
this.members.delete({ server: packet.id, user: packet.user });
|
||||
if (packet.user === this.client.user!._id) {
|
||||
await this.packet({ type: "ServerDelete", id: packet.id });
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
import { ArrowBack } from "@styled-icons/boxicons-regular";
|
||||
import { autorun } from "mobx";
|
||||
import { useStore } from "react-redux";
|
||||
import { useHistory, useParams } from "react-router-dom";
|
||||
import { Invites } from "revolt.js/dist/api/objects";
|
||||
import { Invites, Servers } from "revolt.js/dist/api/objects";
|
||||
|
||||
import styles from "./Invite.module.scss";
|
||||
import { useContext, useEffect, useState } from "preact/hooks";
|
||||
|
||||
import { defer } from "../../lib/defer";
|
||||
|
||||
import { useData } from "../../mobx/State";
|
||||
|
||||
import RequiresOnline from "../../context/revoltjs/RequiresOnline";
|
||||
import {
|
||||
AppContext,
|
||||
|
@ -22,6 +26,7 @@ import Overline from "../../components/ui/Overline";
|
|||
import Preloader from "../../components/ui/Preloader";
|
||||
|
||||
export default function Invite() {
|
||||
const store = useData();
|
||||
const history = useHistory();
|
||||
const client = useContext(AppContext);
|
||||
const status = useContext(StatusContext);
|
||||
|
@ -115,19 +120,25 @@ export default function Invite() {
|
|||
`/server/${invite.server_id}/channel/${invite.channel_id}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const result = await client.joinInvite(
|
||||
code,
|
||||
const dispose = autorun(() => {
|
||||
let server = store.servers.get(
|
||||
invite.server_id,
|
||||
);
|
||||
|
||||
if (result.type === "Server") {
|
||||
defer(() => {
|
||||
if (server) {
|
||||
history.push(
|
||||
`/server/${result.server._id}/channel/${result.channel._id}`,
|
||||
`/server/${server._id}/channel/${invite.channel_id}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
dispose();
|
||||
});
|
||||
}
|
||||
|
||||
await client.joinInvite(code);
|
||||
} catch (err) {
|
||||
setError(takeError(err));
|
||||
setProcessing(false);
|
||||
|
|
Loading…
Reference in a new issue