[core] Make getSessionMeInfo sync

This commit is contained in:
devlikepro committed 2024-06-24 18:41:42 +07:00
1 parent e15ca41d6e
commit 610aef2f14
7 files changed
+15 -17

No files matched your search

+2 -2
View File
@@ -63,7 +63,7 @@ class SessionsController {
}
@Get('/')
async list(@Query() query: ListSessionsQuery): Promise<SessionInfo[]> {
list(@Query() query: ListSessionsQuery): Promise<SessionInfo[]> {
const all = parseBool(query.all);
return this.manager.getSessions(all);
}
@@ -87,7 +87,7 @@ class SessionController {
@Get('me')
@SessionApiParam
@ApiOperation({ summary: 'Get information about the authenticated account' })
getMe(@SessionParam session: WhatsappSession): Promise<MeInfo | null> {
getMe(@SessionParam session: WhatsappSession): MeInfo | null {
return session.getSessionMeInfo();
}
}
+3 -2
View File
@@ -8,6 +8,7 @@ import { EventEmitter } from 'events';
import { WAHAEngine, WAHAEvents } from '../../structures/enums.dto';
import {
MeInfo,
SessionDTO,
SessionInfo,
SessionLogoutRequest,
@@ -49,8 +50,8 @@ export abstract class SessionManager implements BeforeApplicationShutdown {
abstract getSessions(all: boolean): Promise<SessionInfo[]>;
handleSessionEvent(event: WAHAEvents, session: WhatsappSession) {
return async (payload: any) => {
const me = await session.getSessionMeInfo().catch((err) => null);
return (payload: any) => {
const me = session.getSessionMeInfo();
const data: WAHAWebhook = {
event: event,
session: session.name,
+2 -2
View File
@@ -219,8 +219,8 @@ export abstract class WhatsappSession {
abstract getScreenshot(): Promise<Buffer>;
public getSessionMeInfo(): Promise<MeInfo | null> {
throw new NotImplementedByEngineError();
public getSessionMeInfo(): MeInfo | null {
return null;
}
public getCaptcha(): Promise<QR> {
+2 -4
View File
@@ -1,5 +1,4 @@
import makeWASocket, {
areJidsSameUser,
Browsers,
Contact,
DisconnectReason,
@@ -424,17 +423,16 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
this.store?.close();
}
async getSessionMeInfo(): Promise<MeInfo | null> {
getSessionMeInfo(): MeInfo | null {
const me = this.sock.authState?.creds?.me;
if (!me) {
return null;
}
const meId = jidNormalizedUser(me.id);
const meInfo: MeInfo = {
return {
id: toCusFormat(meId),
pushName: me.name,
};
return meInfo;
}
/**
+4 -5
View File
@@ -220,17 +220,16 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
}
}
async getSessionMeInfo(): Promise<MeInfo | null> {
getSessionMeInfo(): MeInfo | null {
const clientInfo = this.whatsapp?.info;
if (!clientInfo) {
return null;
}
const wid = clientInfo.wid;
const meInfo: MeInfo = {
id: wid._serialized,
pushName: clientInfo.pushname,
return {
id: wid?._serialized,
pushName: clientInfo?.pushname,
};
return meInfo;
}
protected listenEngineEventsInDebugMode() {
+1 -1
View File
@@ -245,7 +245,7 @@ export class SessionManagerCore extends SessionManager {
},
];
}
const me = await this.session.getSessionMeInfo().catch((err) => null);
const me = this.session.getSessionMeInfo();
const engine = {
engine: this.session?.engine,
...(await this.session?.getEngineInfo().catch((err) => ({}))),
+1 -1
View File
@@ -127,7 +127,7 @@ export class WebhookConductorCore implements WebhookConductor {
data: any,
sender: WebhookSender,
) {
const me = await session.getSessionMeInfo().catch((err) => null);
const me = session.getSessionMeInfo();
const json: WAHAWebhook = {
event: event,
session: session.name,