mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 09:25:27 +00:00
chore: deprecate RevoltClient context
This commit is contained in:
@@ -47,8 +47,6 @@ export default class State {
|
||||
private persistent: [string, Persistent<unknown>][] = [];
|
||||
private disabled: Set<string> = new Set();
|
||||
|
||||
client?: Client;
|
||||
|
||||
/**
|
||||
* Construct new State.
|
||||
*/
|
||||
@@ -67,14 +65,10 @@ export default class State {
|
||||
this.plugins = new Plugins(this);
|
||||
this.ordering = new Ordering(this);
|
||||
|
||||
makeAutoObservable(this, {
|
||||
client: false,
|
||||
});
|
||||
makeAutoObservable(this);
|
||||
|
||||
this.register();
|
||||
this.setDisabled = this.setDisabled.bind(this);
|
||||
|
||||
this.client = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,11 +132,11 @@ export default class State {
|
||||
registerListeners(client?: Client) {
|
||||
// If a client is present currently, expose it and provide it to plugins.
|
||||
if (client) {
|
||||
this.client = client;
|
||||
// this.client = client;
|
||||
this.plugins.onClient(client);
|
||||
|
||||
// Register message listener for clearing queue.
|
||||
this.client.addListener("message", this.queue.onMessage);
|
||||
// this.client.addListener("message", this.queue.onMessage);
|
||||
}
|
||||
|
||||
// Register all the listeners required for saving and syncing state.
|
||||
@@ -228,13 +222,13 @@ export default class State {
|
||||
});
|
||||
|
||||
return () => {
|
||||
// Remove any listeners attached to client.
|
||||
/*// Remove any listeners attached to client.
|
||||
if (client) {
|
||||
client.removeListener("message", this.queue.onMessage);
|
||||
}
|
||||
|
||||
// Stop exposing the client.
|
||||
this.client = undefined;
|
||||
this.client = undefined;*/
|
||||
|
||||
// Wipe all listeners.
|
||||
listeners.forEach((x) => x());
|
||||
|
||||
@@ -2,6 +2,7 @@ import { action, computed, makeAutoObservable } from "mobx";
|
||||
|
||||
import { reorder } from "@revoltchat/ui";
|
||||
|
||||
import { clientController } from "../../controllers/client/ClientController";
|
||||
import State from "../State";
|
||||
import Persistent from "../interfaces/Persistent";
|
||||
import Store from "../interfaces/Store";
|
||||
@@ -63,18 +64,19 @@ export default class Ordering implements Store, Persistent<Data>, Syncable {
|
||||
* All known servers with ordering applied
|
||||
*/
|
||||
@computed get orderedServers() {
|
||||
const known = new Set(this.state.client?.servers.keys() ?? []);
|
||||
const client = clientController.getReadyClient();
|
||||
const known = new Set(client?.servers.keys() ?? []);
|
||||
const ordered = [...this.servers];
|
||||
|
||||
const out = [];
|
||||
for (const id of ordered) {
|
||||
if (known.delete(id)) {
|
||||
out.push(this.state.client!.servers.get(id)!);
|
||||
out.push(client!.servers.get(id)!);
|
||||
}
|
||||
}
|
||||
|
||||
for (const id of known) {
|
||||
out.push(this.state.client!.servers.get(id)!);
|
||||
out.push(client!.servers.get(id)!);
|
||||
}
|
||||
|
||||
return out;
|
||||
|
||||
@@ -59,7 +59,7 @@ type Plugin = {
|
||||
|
||||
type Instance = {
|
||||
format: 1;
|
||||
onClient?: (client: Client) => {};
|
||||
onClient?: (client: Client) => void;
|
||||
onUnload?: () => void;
|
||||
};
|
||||
|
||||
@@ -124,7 +124,7 @@ export default class Plugins implements Store, Persistent<Data> {
|
||||
* @param id Plugin Id
|
||||
*/
|
||||
@computed get(namespace: string, id: string) {
|
||||
return this.plugins.get(`${namespace }/${ id}`);
|
||||
return this.plugins.get(`${namespace}/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +133,7 @@ export default class Plugins implements Store, Persistent<Data> {
|
||||
* @returns Plugin Instance
|
||||
*/
|
||||
private getInstance(plugin: Pick<Plugin, "namespace" | "id">) {
|
||||
return this.instances.get(`${plugin.namespace }/${ plugin.id}`);
|
||||
return this.instances.get(`${plugin.namespace}/${plugin.id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +159,7 @@ export default class Plugins implements Store, Persistent<Data> {
|
||||
this.unload(plugin.namespace, plugin.id);
|
||||
}
|
||||
|
||||
this.plugins.set(`${plugin.namespace }/${ plugin.id}`, plugin);
|
||||
this.plugins.set(`${plugin.namespace}/${plugin.id}`, plugin);
|
||||
|
||||
if (typeof plugin.enabled === "undefined" || plugin) {
|
||||
this.load(plugin.namespace, plugin.id);
|
||||
@@ -173,7 +173,7 @@ export default class Plugins implements Store, Persistent<Data> {
|
||||
*/
|
||||
remove(namespace: string, id: string) {
|
||||
this.unload(namespace, id);
|
||||
this.plugins.delete(`${namespace }/${ id}`);
|
||||
this.plugins.delete(`${namespace}/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,7 +186,7 @@ export default class Plugins implements Store, Persistent<Data> {
|
||||
if (!plugin) throw "Unknown plugin!";
|
||||
|
||||
try {
|
||||
const ns = `${plugin.namespace }/${ plugin.id}`;
|
||||
const ns = `${plugin.namespace}/${plugin.id}`;
|
||||
|
||||
const instance: Instance = eval(plugin.entrypoint)();
|
||||
this.instances.set(ns, {
|
||||
@@ -198,10 +198,6 @@ export default class Plugins implements Store, Persistent<Data> {
|
||||
...plugin,
|
||||
enabled: true,
|
||||
});
|
||||
|
||||
if (this.state.client) {
|
||||
instance.onClient?.(this.state.client);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Failed to load ${namespace}/${id}!`);
|
||||
console.error(error);
|
||||
@@ -217,7 +213,7 @@ export default class Plugins implements Store, Persistent<Data> {
|
||||
const plugin = this.get(namespace, id);
|
||||
if (!plugin) throw "Unknown plugin!";
|
||||
|
||||
const ns = `${plugin.namespace }/${ plugin.id}`;
|
||||
const ns = `${plugin.namespace}/${plugin.id}`;
|
||||
const loaded = this.getInstance(plugin);
|
||||
if (loaded) {
|
||||
loaded.onUnload?.();
|
||||
|
||||
Reference in New Issue
Block a user