[core] Remove apps by session

This commit is contained in:
devlikepro committed 2025-12-05 00:15:49 -08:00
1 parent 41b6b3459e
commit 07b1e50534
5 files changed
+20

No files matched your search

@@ -37,6 +37,10 @@ export class AppsDisabledService implements IAppsService {
throw new AppsIsDisabledError();
}
async removeBySession(manager: SessionManager, session: string) {
return;
}
migrate(knex: Knex<any, any[]>): Promise<void> {
return;
}
@@ -156,6 +156,12 @@ export class AppsEnabledService implements IAppsService {
return;
}
async removeBySession(manager: SessionManager, session: string) {
const knex = manager.store.getWAHADatabase();
const repo = new AppRepository(knex);
await repo.deleteBySession(session);
}
async beforeSessionStart(session: WhatsappSession, store: DataStore) {
const knex = store.getWAHADatabase();
const repo = new AppRepository(knex);
@@ -15,6 +15,8 @@ export interface IAppsService {
delete(manager: SessionManager, appId: string): Promise<void>;
removeBySession(manager: SessionManager, session: string): Promise<void>;
beforeSessionStart(session: WhatsappSession, store: DataStore): Promise<void>;
afterSessionStart(session: WhatsappSession, store: DataStore): Promise<void>;
@@ -123,4 +123,11 @@ export class AppRepository {
async delete(id: string): Promise<void> {
await this.knex(this.tableName).where('id', id).delete();
}
/**
* Deletes all apps for a session
*/
async deleteBySession(session: string): Promise<void> {
await this.knex(this.tableName).where('session', session).delete();
}
}
+1
View File
@@ -295,6 +295,7 @@ export class SessionManagerCore extends SessionManager implements OnModuleInit {
async delete(name: string): Promise<void> {
this.onlyDefault(name);
await this.appsService.removeBySession(this, name);
this.session = DefaultSessionStatus.REMOVED;
this.updateSession();
this.sessionConfig = undefined;