@@ -39,7 +39,7 @@ import {
39
39
toOllamaModel ,
40
40
type LanguageModel ,
41
41
} from "@cocalc/util/db-schema/llm-utils" ;
42
- import { cmp , isValidUUID , parse_hashtags , uuid } from "@cocalc/util/misc" ;
42
+ import { cmp , isValidUUID , uuid } from "@cocalc/util/misc" ;
43
43
import { reuseInFlight } from "@cocalc/util/reuse-in-flight" ;
44
44
import { getSortedDates , getUserName } from "./chat-log" ;
45
45
import { message_to_markdown } from "./message" ;
@@ -51,7 +51,6 @@ import {
51
51
Feedback ,
52
52
MessageHistory ,
53
53
} from "./types" ;
54
- import { getSelectedHashtagsSearch } from "./utils" ;
55
54
import { history_path } from "@cocalc/util/misc" ;
56
55
57
56
const MAX_CHATSTREAM = 10 ;
@@ -193,7 +192,7 @@ export class ChatActions extends Actions<ChatState> {
193
192
} ) ;
194
193
}
195
194
196
- public foldThread ( reply_to : Date , msgIndex : number ) {
195
+ public foldThread ( reply_to : Date , messageIndex ? : number ) {
197
196
if ( this . syncdb == null ) return ;
198
197
const account_id = this . redux . getStore ( "account" ) . get_account_id ( ) ;
199
198
const cur = this . syncdb . get_one ( { event : "chat" , date : reply_to } ) ;
@@ -210,8 +209,8 @@ export class ChatActions extends Actions<ChatState> {
210
209
211
210
this . syncdb . commit ( ) ;
212
211
213
- if ( folded && msgIndex != null ) {
214
- this . scrollToBottom ( msgIndex ) ;
212
+ if ( folded && messageIndex != null ) {
213
+ this . scrollToBottom ( messageIndex ) ;
215
214
}
216
215
}
217
216
@@ -294,40 +293,44 @@ export class ChatActions extends Actions<ChatState> {
294
293
// For replies search find full threads not individual messages.
295
294
this . setState ( {
296
295
input : "" ,
297
- search : "" ,
298
296
} ) ;
297
+ this . clearAllFilters ( ) ;
299
298
} else {
300
- // TODO: but until we improve search to be by thread (instead of by message), do this:
301
- this . setState ( {
302
- search : "" ,
303
- } ) ;
304
- }
305
- this . ensureDraftStartsWithHashtags ( false ) ;
306
-
307
- if ( this . store != null ) {
308
- const project_id = this . store ?. get ( "project_id" ) ;
309
- const path = this . store ?. get ( "path" ) ;
310
- // set notification saying that we sent an actual chat
311
- let action ;
299
+ // when replying we make sure that the thread is expanded, since otherwise
300
+ // our reply won't be visible
301
+ const messages = this . store . get ( "messages" ) ;
312
302
if (
313
- noNotification ||
314
- mentionsLanguageModel ( input ) ||
315
- this . isLanguageModelThread ( reply_to )
303
+ messages
304
+ ?. getIn ( [ ` ${ reply_to . valueOf ( ) } ` , "folding" ] )
305
+ ?. includes ( sender_id )
316
306
) {
317
- // Note: don't mark it is a chat if it is with chatgpt,
318
- // since no point in notifying all collabs of this.
319
- action = "edit" ;
320
- } else {
321
- action = "chat" ;
307
+ this . foldThread ( reply_to ) ;
322
308
}
323
- webapp_client . mark_file ( {
324
- project_id,
325
- path,
326
- action,
327
- ttl : 10000 ,
328
- } ) ;
329
- track ( "send_chat" , { project_id, path } ) ;
330
309
}
310
+
311
+ const project_id = this . store ?. get ( "project_id" ) ;
312
+ const path = this . store ?. get ( "path" ) ;
313
+ // set notification saying that we sent an actual chat
314
+ let action ;
315
+ if (
316
+ noNotification ||
317
+ mentionsLanguageModel ( input ) ||
318
+ this . isLanguageModelThread ( reply_to )
319
+ ) {
320
+ // Note: don't mark it is a chat if it is with chatgpt,
321
+ // since no point in notifying all collabs of this.
322
+ action = "edit" ;
323
+ } else {
324
+ action = "chat" ;
325
+ }
326
+ webapp_client . mark_file ( {
327
+ project_id,
328
+ path,
329
+ action,
330
+ ttl : 10000 ,
331
+ } ) ;
332
+ track ( "send_chat" , { project_id, path } ) ;
333
+
331
334
this . save_to_disk ( ) ;
332
335
( async ( ) => {
333
336
await this . processLLM ( {
@@ -621,38 +624,6 @@ export class ChatActions extends Actions<ChatState> {
621
624
? selectedHashtags . delete ( tag )
622
625
: selectedHashtags . set ( tag , state ) ;
623
626
this . setState ( { selectedHashtags } ) ;
624
- this . ensureDraftStartsWithHashtags ( true ) ;
625
- }
626
-
627
- private ensureDraftStartsWithHashtags ( commit : boolean = false ) : void {
628
- if ( this . syncdb == null || this . store == null ) return ;
629
- // set draft input to match selected hashtags, if any.
630
- const hashtags = this . store . get ( "selectedHashtags" ) ;
631
- if ( hashtags == null ) return ;
632
- const { selectedHashtagsSearch } = getSelectedHashtagsSearch ( hashtags ) ;
633
- let input = this . store . get ( "input" ) ;
634
- const prefix = selectedHashtagsSearch . trim ( ) + " " ;
635
- if ( input . startsWith ( prefix ) ) {
636
- return ;
637
- }
638
- const v = parse_hashtags ( input ) ;
639
- if ( v . length > 0 ) {
640
- input = input . slice ( v [ v . length - 1 ] [ 1 ] ) ;
641
- }
642
-
643
- input = prefix + input ;
644
- this . setState ( { input } ) ;
645
- const sender_id = this . redux . getStore ( "account" ) . get_account_id ( ) ;
646
- this . syncdb . set ( {
647
- event : "draft" ,
648
- active : Date . now ( ) ,
649
- sender_id,
650
- input,
651
- date : 0 ,
652
- } ) ;
653
- if ( commit ) {
654
- this . syncdb . commit ( ) ;
655
- }
656
627
}
657
628
658
629
public help ( ) {
@@ -1131,6 +1102,14 @@ export class ChatActions extends Actions<ChatState> {
1131
1102
foreground_project : true ,
1132
1103
} ) ;
1133
1104
} ;
1105
+
1106
+ clearAllFilters = ( ) => {
1107
+ this . setState ( {
1108
+ search : "" ,
1109
+ selectedHashtags : immutableMap ( ) ,
1110
+ filterRecentH : 0 ,
1111
+ } ) ;
1112
+ } ;
1134
1113
}
1135
1114
1136
1115
export function getRootMessage (
0 commit comments