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

@@ -12,6 +12,7 @@ import {
StartNewReq,
ToggleChatMuteReq
} from "../domain/chatService.schema";
import {Message} from "../domain/dmService.schema";
/**
* ChatService is an exception because it's one instance for all chats because it's unnecessary to create a new instance for each chat
@@ -47,9 +48,9 @@ export class ChatService {
async get(): Promise<Chat[]> {
try {
const resp = await this.client.get<Chat[]>(`chat/get?userid=${this.userid}`);
this.database.set("chats", this.userid, JSON.stringify(resp.data))
return resp.data
} catch (e) {
console.log(e)
if (isAxiosError<GenericErrorBody>(e)) {
throw e;
}
@@ -57,6 +58,15 @@ export class ChatService {
}
}
getQuick(): Message[] {
const chats = this.database.get("chats", this.userid)
if (chats) {
return JSON.parse(chats)
} else {
throw new Error("No chats in database")
}
}
/**
* Gets the availability of the specified user
* @param userid