mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-26 17:10:57 -05:00
chore(mobx): write jsdoc for auth / mqueue
This commit is contained in:
parent
faca4ac32b
commit
fef2c5997f
2 changed files with 31 additions and 2 deletions
|
@ -2,8 +2,6 @@ import { action, computed, makeAutoObservable, ObservableMap } from "mobx";
|
||||||
import { Session } from "revolt-api/types/Auth";
|
import { Session } from "revolt-api/types/Auth";
|
||||||
import { Nullable } from "revolt.js/dist/util/null";
|
import { Nullable } from "revolt.js/dist/util/null";
|
||||||
|
|
||||||
import { mapToRecord } from "../../lib/conversion";
|
|
||||||
|
|
||||||
import Persistent from "../interfaces/Persistent";
|
import Persistent from "../interfaces/Persistent";
|
||||||
import Store from "../interfaces/Store";
|
import Store from "../interfaces/Store";
|
||||||
|
|
||||||
|
@ -85,10 +83,17 @@ export default class Auth implements Store, Persistent<Data> {
|
||||||
this.sessions.delete(user_id);
|
this.sessions.delete(user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove current session.
|
||||||
|
*/
|
||||||
@action logout() {
|
@action logout() {
|
||||||
this.current && this.removeSession(this.current);
|
this.current && this.removeSession(this.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current session.
|
||||||
|
* @returns Current session
|
||||||
|
*/
|
||||||
@computed getSession() {
|
@computed getSession() {
|
||||||
if (!this.current) return;
|
if (!this.current) return;
|
||||||
return this.sessions.get(this.current)!.session;
|
return this.sessions.get(this.current)!.session;
|
||||||
|
|
|
@ -53,6 +53,12 @@ export default class MessageQueue implements Store {
|
||||||
return "queue";
|
return "queue";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a message to the queue.
|
||||||
|
* @param id Nonce value
|
||||||
|
* @param channel Channel ID
|
||||||
|
* @param data Message data
|
||||||
|
*/
|
||||||
@action add(id: string, channel: string, data: QueuedMessageData) {
|
@action add(id: string, channel: string, data: QueuedMessageData) {
|
||||||
this.messages.push({
|
this.messages.push({
|
||||||
id,
|
id,
|
||||||
|
@ -62,22 +68,40 @@ export default class MessageQueue implements Store {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fail a queued message.
|
||||||
|
* @param id Nonce value
|
||||||
|
* @param error Error string
|
||||||
|
*/
|
||||||
@action fail(id: string, error: string) {
|
@action fail(id: string, error: string) {
|
||||||
const entry = this.messages.find((x) => x.id === id)!;
|
const entry = this.messages.find((x) => x.id === id)!;
|
||||||
entry.status = QueueStatus.ERRORED;
|
entry.status = QueueStatus.ERRORED;
|
||||||
entry.error = error;
|
entry.error = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark a queued message as sending.
|
||||||
|
* @param id Nonce value
|
||||||
|
*/
|
||||||
@action start(id: string) {
|
@action start(id: string) {
|
||||||
const entry = this.messages.find((x) => x.id === id)!;
|
const entry = this.messages.find((x) => x.id === id)!;
|
||||||
entry.status = QueueStatus.SENDING;
|
entry.status = QueueStatus.SENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a queued message.
|
||||||
|
* @param id Nonce value
|
||||||
|
*/
|
||||||
@action remove(id: string) {
|
@action remove(id: string) {
|
||||||
const entry = this.messages.find((x) => x.id === id)!;
|
const entry = this.messages.find((x) => x.id === id)!;
|
||||||
this.messages.remove(entry);
|
this.messages.remove(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all queued messages for a channel.
|
||||||
|
* @param channel Channel ID
|
||||||
|
* @returns Array of queued messages
|
||||||
|
*/
|
||||||
@computed get(channel: string) {
|
@computed get(channel: string) {
|
||||||
return this.messages.filter((x) => x.channel === channel);
|
return this.messages.filter((x) => x.channel === channel);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue