Added caching and implemented UserService
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user