@@ -18,6 +18,8 @@ import DiffStreamer from "../../lib/diff-streamer";
1818import SmoothStreamer from " ../../lib/smooth-streamer" ;
1919import AiIndicatorWave from " ../ai-indicator-wave" ;
2020
21+ const CHANNEL = " /discourse-ai/ai-helper/stream_composer_suggestion" ;
22+
2123export default class ModalDiffModal extends Component {
2224 @service currentUser;
2325 @service messageBus;
@@ -49,12 +51,9 @@ export default class ModalDiffModal extends Component {
4951 }
5052
5153 get isStreaming () {
52- // diffStreamer stops "streaming" when it is finished with a chunk
53- return (
54- this .diffStreamer .isStreaming ||
55- ! this .diffStreamer .isDone ||
56- this .smoothStreamer .isStreaming
57- );
54+ // diffStreamer stops Streaming when it is finished with a chunk, looking at isDone is safe
55+ // it starts off not done
56+ return ! this .diffStreamer .isDone || this .smoothStreamer .isStreaming ;
5857 }
5958
6059 get primaryBtnLabel () {
@@ -69,25 +68,23 @@ export default class ModalDiffModal extends Component {
6968
7069 @bind
7170 subscribe () {
72- const channel = " /discourse-ai/ai-helper/stream_composer_suggestion" ;
73- this .messageBus .subscribe (channel, this .updateResult );
71+ this .messageBus .subscribe (CHANNEL , this .updateResult );
7472 }
7573
7674 @bind
77- unsubscribe () {
78- const channel = " /discourse-ai/ai-helper/stream_composer_suggestion" ;
79- this .messageBus .unsubscribe (channel, this .updateResult );
75+ cleanup () {
76+ // stop all callbacks so it does not end up streaming pointlessly
77+ this .smoothStreamer .resetStreaming ();
78+ this .diffStreamer .reset ();
79+ this .messageBus .unsubscribe (CHANNEL , this .updateResult );
8080 }
8181
8282 @action
83- async updateResult (result ) {
83+ updateResult (result ) {
8484 this .loading = false ;
8585
8686 if (result .done ) {
8787 this .finalResult = result .result ;
88- }
89-
90- if (result .done ) {
9188 this .loading = false ;
9289 }
9390
@@ -154,7 +151,7 @@ export default class ModalDiffModal extends Component {
154151 <: body >
155152 <div
156153 {{didInsert this . subscribe}}
157- {{willDestroy this . unsubscribe }}
154+ {{willDestroy this . cleanup }}
158155 class =" text-preview"
159156 >
160157 {{#if this . loading }}
0 commit comments