add profile caching
parent
e8a53541e8
commit
d3d66ded45
|
@ -1,4 +1,4 @@
|
||||||
import { MethodCall, TCJSONResponse, TCResponse, TCResponseRaw } from "./types";
|
import { MethodCall, TCJSONResponse, TCProfile, TCResponse, TCResponseRaw } from "./types";
|
||||||
import { AskModule } from "./ask";
|
import { AskModule } from "./ask";
|
||||||
import { MessagesModule } from "./messages";
|
import { MessagesModule } from "./messages";
|
||||||
import { ForumModule } from "./forum";
|
import { ForumModule } from "./forum";
|
||||||
|
@ -31,6 +31,8 @@ export class Client {
|
||||||
/** @internal */
|
/** @internal */
|
||||||
public _cache: { [key: string]: any; } = { };
|
public _cache: { [key: string]: any; } = { };
|
||||||
|
|
||||||
|
public profileCache: { [key: string]: TCProfile } = { };
|
||||||
|
|
||||||
public auth?: string;
|
public auth?: string;
|
||||||
|
|
||||||
public agent: string = "pecans";
|
public agent: string = "pecans";
|
||||||
|
@ -121,6 +123,10 @@ export class Client {
|
||||||
profiles: res?.profiles,
|
profiles: res?.profiles,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
res?.profiles?.forEach((profile) => {
|
||||||
|
this.profileCache[profile.id] = profile;
|
||||||
|
});
|
||||||
|
|
||||||
resolve(new creator(rawResponse));
|
resolve(new creator(rawResponse));
|
||||||
})
|
})
|
||||||
.catch((reason) => reject(reason));
|
.catch((reason) => reject(reason));
|
||||||
|
@ -165,6 +171,10 @@ export class Client {
|
||||||
profiles: res?.profiles,
|
profiles: res?.profiles,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
res?.profiles?.forEach((profile) => {
|
||||||
|
this.profileCache[profile.id] = profile;
|
||||||
|
});
|
||||||
|
|
||||||
c.resolve(new c.creator(individualResponse));
|
c.resolve(new c.creator(individualResponse));
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
@ -27,6 +27,10 @@ export class TCResponse {
|
||||||
this.error = response.error;
|
this.error = response.error;
|
||||||
this.profiles = response.profiles;
|
this.profiles = response.profiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public toObject(): {[key: string]: any} {
|
||||||
|
return { ...this };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TCResponseConstructor {
|
export interface TCResponseConstructor {
|
||||||
|
@ -45,5 +49,9 @@ export interface TCProfile {
|
||||||
readonly name: string;
|
readonly name: string;
|
||||||
readonly online: number;
|
readonly online: number;
|
||||||
readonly avatar: string;
|
readonly avatar: string;
|
||||||
|
readonly subs: {
|
||||||
|
readonly in: number;
|
||||||
|
readonly out: number;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue