Make storage async
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@chatenium/chatenium-sdk",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.5",
|
||||
"description": "A library for interacting with the Chatenium API",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
||||
@@ -7,12 +7,12 @@ export class KeyringMock implements KeyringAPI {
|
||||
this.ring[key] = value;
|
||||
}
|
||||
|
||||
get(key: string): string {
|
||||
return this.ring[key];
|
||||
get(key: string): Promise<string> {
|
||||
return Promise.resolve(this.ring[key]);
|
||||
}
|
||||
|
||||
getAll(): string[] {
|
||||
return Object.keys(this.ring);
|
||||
getAll(): Promise<string[]> {
|
||||
return Promise.resolve(Object.keys(this.ring));
|
||||
}
|
||||
|
||||
delete(key: string) {
|
||||
|
||||
@@ -58,8 +58,8 @@ export class ChatService {
|
||||
}
|
||||
}
|
||||
|
||||
getQuick(): Message[] {
|
||||
const chats = this.database.get("chats", this.userid)
|
||||
async getQuick(): Promise<Message[]> {
|
||||
const chats = await this.database.get("chats", this.userid)
|
||||
if (chats) {
|
||||
return JSON.parse(chats)
|
||||
} else {
|
||||
|
||||
@@ -65,8 +65,8 @@ export class DMService {
|
||||
}
|
||||
}
|
||||
|
||||
getQuick(): Message[] {
|
||||
const messages = this.database.get("messages", this.chatid)
|
||||
async getQuick(): Promise<Message[]> {
|
||||
const messages = await this.database.get("messages", this.chatid)
|
||||
if (messages) {
|
||||
return JSON.parse(messages)
|
||||
} else {
|
||||
|
||||
@@ -108,8 +108,8 @@ export class NetworkService {
|
||||
}
|
||||
}
|
||||
|
||||
getQuick(): Message[] {
|
||||
const networks = this.database.get("networks", this.userid)
|
||||
async getQuick(): Promise<Message[]> {
|
||||
const networks = await this.database.get("networks", this.userid)
|
||||
if (networks) {
|
||||
return JSON.parse(networks)
|
||||
} else {
|
||||
|
||||
@@ -54,8 +54,8 @@ export class PictureService {
|
||||
}
|
||||
}
|
||||
|
||||
getQuick(): Message[] {
|
||||
const pictures = this.database.get("pictures", this.uploaderId)
|
||||
async getQuick(): Promise<Message[]> {
|
||||
const pictures = await this.database.get("pictures", this.uploaderId)
|
||||
if (pictures) {
|
||||
return JSON.parse(pictures)
|
||||
} else {
|
||||
|
||||
@@ -33,18 +33,18 @@ export class SessionManager {
|
||||
/**
|
||||
* Loads all saved sessions
|
||||
*/
|
||||
loadSessions(): Session[] {
|
||||
const tokens = this.keyring.getAll()
|
||||
async loadSessions(): Promise<Session[]> {
|
||||
const tokens = await this.keyring.getAll()
|
||||
const sessions: Session[] = []
|
||||
tokens.forEach(token => {
|
||||
const userData = this.database.get("sessions", token.split(".")[0])
|
||||
for (const token of tokens) {
|
||||
const userData = await this.database.get("sessions", token.split(".")[0])
|
||||
if (userData) {
|
||||
sessions.push({
|
||||
token: token,
|
||||
userData: JSON.parse(userData)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return sessions
|
||||
}
|
||||
@@ -52,8 +52,8 @@ export class SessionManager {
|
||||
/**
|
||||
* Gets the preferred user set by the client
|
||||
*/
|
||||
getPreferredUser(): string {
|
||||
return this.KeyValue.get("preferredUser") ?? ""
|
||||
async getPreferredUser(): Promise<string> {
|
||||
return await this.KeyValue.get("preferredUser") ?? ""
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,9 +67,9 @@ export class SessionManager {
|
||||
/**
|
||||
* Loads the preferred session by the client
|
||||
*/
|
||||
loadPreferredSession() {
|
||||
const sessions = this.loadSessions()
|
||||
let preferredUser = this.getPreferredUser()
|
||||
async loadPreferredSession() {
|
||||
const sessions = await this.loadSessions()
|
||||
let preferredUser = await this.getPreferredUser()
|
||||
if (preferredUser == "") {
|
||||
preferredUser = sessions[0].userData.userid
|
||||
this.setPreferredUser(sessions[0].userData.userid)
|
||||
|
||||
@@ -71,8 +71,8 @@ export class TextChannelServiceService {
|
||||
}
|
||||
}
|
||||
|
||||
getQuick(): Message[] {
|
||||
const messages = this.database.get("networkmessages", this.channelId)
|
||||
async getQuick(): Promise<Message[]> {
|
||||
const messages = await this.database.get("networkmessages", this.channelId)
|
||||
if (messages) {
|
||||
return JSON.parse(messages)
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export interface DatabaseAPI {
|
||||
set(collection: string, key: string, value: any): void;
|
||||
get(collection: string, key: string): string;
|
||||
get(collection: string, key: string): Promise<string>;
|
||||
delete(collection: string, key: string): void;
|
||||
flush(): void;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
export interface KeyringAPI {
|
||||
set(key: string, value: any): void;
|
||||
get(key: string): string;
|
||||
getAll(): string[];
|
||||
get(key: string): Promise<string>;
|
||||
getAll(): Promise<string[]>;
|
||||
delete(key: string): void;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
export interface KeyValueAPI {
|
||||
set(key: string, value: any): void;
|
||||
get(key: string): string;
|
||||
get(key: string): Promise<string>;
|
||||
delete(key: string): void;
|
||||
flush(): void;
|
||||
}
|
||||
Reference in New Issue
Block a user