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