From 5853b778f2b62d4132207ea8e8a08ef401792314 Mon Sep 17 00:00:00 2001 From: devlikepro Date: Tue, 23 Sep 2025 12:02:53 +0700 Subject: [PATCH] [core] GOWS - fix "typing" after message fix #1364 --- src/core/engines/gows/session.gows.core.ts | 51 +++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/core/engines/gows/session.gows.core.ts b/src/core/engines/gows/session.gows.core.ts index ead704d5..8de8053d 100644 --- a/src/core/engines/gows/session.gows.core.ts +++ b/src/core/engines/gows/session.gows.core.ts @@ -142,6 +142,7 @@ import { retry, share, } from 'rxjs'; +import { Subject } from 'rxjs'; import { map } from 'rxjs/operators'; import { promisify } from 'util'; @@ -212,6 +213,8 @@ export class WhatsappSessionGoWSCore extends WhatsappSession { public session: messages.Session; protected presences: any; + private local$ = new Subject(); + public constructor(config) { super(config); this.qr = new QR(); @@ -298,7 +301,11 @@ export class WhatsappSessionGoWSCore extends WhatsappSession { ); // Retry on error with delay - this.all$ = this.stream$.pipe(retry({ delay: 2_000 }), share()); + // Accept locally re-issued events as well + this.all$ = merge(this.stream$, this.local$).pipe( + retry({ delay: 2_000 }), + share(), + ); } subscribeEvents() { @@ -384,6 +391,48 @@ export class WhatsappSessionGoWSCore extends WhatsappSession { // add new value this.presences.set(Chat, [...filtered, event]); }); + + // + // Fix for "typing" after sending a message + // Re-issue a synthetic ChatPresence(PAUSED) to cancel COMPOSING state + // Works for both DM and Group chats + // + events.on(WhatsMeowEvent.MESSAGE, (message: any) => { + const chat = message?.Info?.Chat; + if (!this.jids.include(chat)) { + return; + } + if (message?.Info?.IsFromMe) { + return; + } + const sender = message?.Info?.Sender || chat; + if (!chat || !sender) { + return; + } + const stored: Array = + this.presences.get(chat) || []; + const composing = stored.find( + (presence: any) => + (presence?.Sender === sender || presence?.From === sender) && + presence?.State === gows.ChatPresenceState.COMPOSING, + ) as gows.ChatPresence | undefined; + if (!composing) { + return; + } + const presence: gows.ChatPresence = { + Chat: chat, + Sender: sender, + IsFromMe: false, + IsGroup: !!isJidGroup(chat), + State: gows.ChatPresenceState.PAUSED, + Media: (composing as any)?.Media ?? gows.ChatPresenceMedia.TEXT, + } as any; + this.local$.next({ + event: WhatsMeowEvent.CHAT_PRESENCE, + data: presence, + } as any); + }); + events.start(); }