@@ -73,6 +73,7 @@ import {
7373} from '../automation/index.js'
7474import type { CitationConfig , MessageContext } from '../events/context.js'
7575import { createDownloadFn } from '../events/decoders/_media-download.js'
76+ import { ephemeralExpirationOf } from '../events/decoders/messages.js'
7677import type { CallPayload , MediaDownloadResult , MediaKind } from '../events/types.js'
7778import {
7879 formatConnectionStatus ,
@@ -614,7 +615,7 @@ export class Client extends TypedEventEmitter<ClientEventMap> {
614615 resolveQuoted : ( id , remoteJid ) => this . lookupQuoted ( id , remoteJid ) ,
615616 resolveLidToPn : ( ) => Promise . resolve ( null ) ,
616617 sendReply : async ( target , content , opts , quoted ) =>
617- await this . send ( target ) . text ( content , opts ) . reply ( quoted ) ,
618+ await this . replyWithSameLifetime ( target , content , opts , quoted ) ,
618619 react : ( key , emoji ) => this . react ( key , emoji ) ,
619620 ignoreMe : this . ignoreMe ,
620621 } )
@@ -805,6 +806,19 @@ export class Client extends TypedEventEmitter<ClientEventMap> {
805806 } )
806807 }
807808
809+ /** Replies inherit the quoted message's disappearing timer, so an answer never outlives its thread. */
810+ private async replyWithSameLifetime (
811+ target : string ,
812+ content : string ,
813+ opts : TextOptions | undefined ,
814+ quoted : WAMessage ,
815+ ) : Promise < WAMessageKey > {
816+ const builder = this . send ( target ) . text ( content , opts )
817+ const expiration = ephemeralExpirationOf ( quoted )
818+ const withLifetime = expiration !== undefined ? builder . disappearing ( expiration ) : builder
819+ return withLifetime . reply ( quoted )
820+ }
821+
808822 /** Admin lookup for the `admin` guard. Never throws — an unreachable group means "not an admin". */
809823 private async isGroupAdmin ( groupJid : string , senderJid : string ) : Promise < boolean > {
810824 try {
@@ -835,7 +849,7 @@ export class Client extends TypedEventEmitter<ClientEventMap> {
835849 json : resolved . json ,
836850 reply : async ( content : string , opts ?: TextOptions ) : Promise < WAMessageKey > => {
837851 const target = msg . message ( ) . key . remoteJid ?? msg . roomId ?? msg . senderId
838- const key = await this . send ( target ) . text ( content , opts ) . reply ( msg . message ( ) )
852+ const key = await this . replyWithSameLifetime ( target , content , opts , msg . message ( ) )
839853 lastSentKey = key
840854 return key
841855 } ,
@@ -1141,7 +1155,7 @@ export class Client extends TypedEventEmitter<ClientEventMap> {
11411155 resolveQuoted : ( id , remoteJid ) => this . lookupQuoted ( id , remoteJid ) ,
11421156 resolveLidToPn : ( lid ) => this . lidToPn ( lid ) ,
11431157 sendReply : async ( target , content , opts , quoted ) =>
1144- await this . send ( target ) . text ( content , opts ) . reply ( quoted ) ,
1158+ await this . replyWithSameLifetime ( target , content , opts , quoted ) ,
11451159 react : ( key , emoji ) => this . react ( key , emoji ) ,
11461160 ignoreMe : this . ignoreMe ,
11471161 } )
0 commit comments