1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Prevent last emission - causes duplicate message

Discussão em 'Angular' iniciado por DRNR, Maio 27, 2025.

  1. DRNR

    DRNR Guest

    I need the LAST emission to call signals.onResponse(), thus the tap, so that my deep chat ui completes and re-enables the submit button after last message. I have to hack deep chat and use the addMessage as multiple messages can be emitted (deep chat does not support this out of the box), that is what the streamPending$ observable is for, it emits false when all messages have been received and that is when I need to call signals.onResponse(). Working with angular, rxjs and deep chat. This is my current code relevant to question. (messages()) is an input in angular, not a function)

    combineLatest([this.service.streamPending$.pipe(skip(1)), this.messages()]).pipe(
    tap(([bool, message]) => {
    console.log('bool')
    if (bool) {
    signals.onResponse({ text: message } as MessageContent);
    signals.onClose();
    }
    }),
    takeWhile(([bool]) => !bool)
    ).subscribe(([bool, message]) => {
    if (!bool) {
    (this.chatElementRef()?.nativeElement as any).addMessage({
    text: message,
    role: 'ai'
    });
    }
    });


    console.log('bool'); is printed twice on the second message (if exists), which obviously shows the second message twice in my UI. I understand why, but don't know how to fix it. Help appreciated!

    Continue reading...

Compartilhe esta Página