From b9afd761be0c25110a6999326eb2cfc61c4fe775 Mon Sep 17 00:00:00 2001 From: "EchoLayer Bot (Stag)" Date: Wed, 13 Mar 2024 18:32:57 +0000 Subject: [PATCH] Removed the TODO and added comments explaining all functions in the UserService class. --- codex-vscode/src/services/user.service.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/codex-vscode/src/services/user.service.ts b/codex-vscode/src/services/user.service.ts index 41a99a74..b5701b88 100644 --- a/codex-vscode/src/services/user.service.ts +++ b/codex-vscode/src/services/user.service.ts @@ -26,6 +26,7 @@ export class UserService implements Singleton, IUserService { private invitations: Array; private cclCodexServiceWrapper: ICCLCodexServiceWrapper; + // Singleton pattern to ensure only one instance of UserService exists static getInstance( user: User = LocalStorageManager.get(LOCAL_STORAGE_KEYS.user) as User, jwt: Jwt = LocalStorageManager.get(LOCAL_STORAGE_KEYS.jwt) as Jwt @@ -45,12 +46,14 @@ export class UserService implements Singleton, IUserService { return this.instance; } + // Destroys the singleton instance of UserService static destroyInstance(): void { if (this.instance) { this.instance = null; } } + // Private constructor to enforce singleton pattern private constructor(user: User, jwt: Jwt) { this.user = user; this.ccl = new CodexCommonLibrary( @@ -62,41 +65,49 @@ export class UserService implements Singleton, IUserService { ); } + // Retrieves and returns user notifications public async getNotifications(): Promise { this.notifications = await this.getNotificationService().get(); return this.notifications; } + // Retrieves and returns user invitations public async getInvitations(): Promise { this.invitations = await this.getInvitationService().get(); return this.invitations; } + // Returns an instance of the CommonLibraryUserService public getUserService(): CommonLibraryUserService { return this.ccl.getUserService(); } + // Returns an instance of the InvitationService public getInvitationService(): InvitationService { return this.ccl.getInvitationService("user"); } + // Returns an instance of the AccessRequestService public getAccessRequestService(): AccessRequestService { return this.ccl.getAccessRequestService("user"); } + // Returns an instance of the NotificationService public getNotificationService(): NotificationService { return this.ccl.getNotificationService(); } + // Returns an instance of the AuthService public getAuthService(): AuthService { return this.ccl.getAuthService(); } + // Returns an instance of the ContextsService public getContextsService(): ContextsService { return this.ccl.getContextsService(); } - // TODO clean up comments + // Returns an instance of the CCLCodexServiceWrapper public getCCLCodexServiceWrapper(): ICCLCodexServiceWrapper { if (!this.cclCodexServiceWrapper) { this.cclCodexServiceWrapper = new CCLCodexServiceWrapper(this.ccl.getCodexService(), this); @@ -104,3 +115,4 @@ export class UserService implements Singleton, IUserService { return this.cclCodexServiceWrapper; } } +