mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-19 17:13:31 -04:00
feat: add User.statusMessage and User.presence
This commit is contained in:
+6
-3
@@ -1,4 +1,4 @@
|
||||
import { Accessor, Setter, createSignal } from "solid-js";
|
||||
import { Accessor, Setter, batch, createSignal } from "solid-js";
|
||||
|
||||
import EventEmitter from "eventemitter3";
|
||||
import { API, Role } from "revolt-api";
|
||||
@@ -231,8 +231,11 @@ export class Client extends EventEmitter<Events> {
|
||||
this.events.on("state", (state) => {
|
||||
switch (state) {
|
||||
case ConnectionState.Connected:
|
||||
this.#setConnectionFailureCount(0);
|
||||
this.emit("connected");
|
||||
batch(() => {
|
||||
this.servers.forEach((server) => server.resetSyncStatus());
|
||||
this.#setConnectionFailureCount(0);
|
||||
this.emit("connected");
|
||||
});
|
||||
break;
|
||||
case ConnectionState.Connecting:
|
||||
this.emit("connecting");
|
||||
|
||||
@@ -537,11 +537,15 @@ export class Server {
|
||||
);
|
||||
}
|
||||
|
||||
#synced: undefined | "partial" | "full";
|
||||
|
||||
/**
|
||||
* Optimised member fetch route
|
||||
* @param excludeOffline
|
||||
*/
|
||||
async syncMembers(excludeOffline?: boolean) {
|
||||
if (this.#synced && (this.#synced === "full" || excludeOffline)) return;
|
||||
|
||||
const data = await this.#collection.client.api.get(
|
||||
`/servers/${this.id as ""}/members`,
|
||||
{ exclude_offline: excludeOffline }
|
||||
@@ -574,6 +578,13 @@ export class Server {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset member sync status
|
||||
*/
|
||||
resetSyncStatus() {
|
||||
this.#synced = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a server's members
|
||||
* @returns List of the server's members and their user objects
|
||||
|
||||
+20
-1
@@ -1,4 +1,4 @@
|
||||
import { DataEditUser } from "revolt-api";
|
||||
import { DataEditUser, Presence } from "revolt-api";
|
||||
import { decodeTime } from "ulid";
|
||||
|
||||
import { UserCollection } from "../collections";
|
||||
@@ -127,6 +127,25 @@ export class User {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Presence
|
||||
*/
|
||||
get presence() {
|
||||
return this.status?.presence ?? (this.online ? "Online" : "Invisible");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate status message
|
||||
* @param translate Translation function
|
||||
* @returns Status message
|
||||
*/
|
||||
statusMessage(translate: (presence: Presence) => string = (a) => a) {
|
||||
return (
|
||||
this.status?.text ??
|
||||
(this.presence === "Focus" ? translate("Focus") : undefined)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Permissions against this user
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user