Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion codex-vscode/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class UserService implements Singleton, IUserService {
private invitations: Array<Invitation>;
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
Expand All @@ -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(
Expand All @@ -62,45 +65,54 @@ export class UserService implements Singleton, IUserService {
);
}

// Retrieves and returns user notifications
public async getNotifications(): Promise<Notification[]> {
this.notifications = await this.getNotificationService().get();
return this.notifications;
}

// Retrieves and returns user invitations
public async getInvitations(): Promise<Invitation[]> {
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);
}
return this.cclCodexServiceWrapper;
}
}