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