Added caching and implemented UserService

This commit is contained in:
2026-04-07 11:19:38 +02:00
parent aa451e4786
commit 4f96b1d687
11 changed files with 488 additions and 3 deletions

View File

@@ -53,6 +53,9 @@ export class DMService {
async get(from: number = 0): Promise<Message[]> {
try {
const resp = await this.client.get<Message[]>(`chat/dm/messages?chatid=${this.chatid}&userid=${this.userid}&from=${from}`);
if (from == 0) {
this.database.set("messages", this.chatid, JSON.stringify(resp.data))
}
return resp.data
} catch (e) {
if (isAxiosError<GenericErrorBody>(e)) {
@@ -62,6 +65,15 @@ export class DMService {
}
}
getQuick(): Message[] {
const messages = this.database.get("messages", this.chatid)
if (messages) {
return JSON.parse(messages)
} else {
throw new Error("No messages in database")
}
}
/**
* Fetches the position of the specified message which can be used in get() to fetch an old message with it's surrounding messages
* @param messageId