@@ -8,34 +8,31 @@ Render all the messages in the chat.
8
8
*/
9
9
10
10
import { Alert } from "antd" ;
11
- import { List , Set as immutableSet } from "immutable" ;
11
+ import { Set as immutableSet } from "immutable" ;
12
12
import { MutableRefObject , useEffect , useMemo , useRef } from "react" ;
13
13
import { Virtuoso , VirtuosoHandle } from "react-virtuoso" ;
14
14
import { chatBotName , isChatBot } from "@cocalc/frontend/account/chatbot" ;
15
15
import {
16
- TypedMap ,
17
16
useActions ,
18
17
useRedux ,
19
18
useTypedRedux ,
20
19
} from "@cocalc/frontend/app-framework" ;
21
20
import { VisibleMDLG } from "@cocalc/frontend/components" ;
22
21
import useVirtuosoScrollHook from "@cocalc/frontend/components/virtuoso-scroll-hook" ;
23
22
import { HashtagBar } from "@cocalc/frontend/editors/task-editor/hashtag-bar" ;
24
- import { webapp_client } from "@cocalc/frontend/webapp-client" ;
25
23
import {
26
24
cmp ,
27
25
hoursToTimeIntervalHuman ,
28
26
parse_hashtags ,
29
27
plural ,
30
- search_match ,
31
- search_split ,
32
28
} from "@cocalc/util/misc" ;
33
29
import { ChatActions , getRootMessage } from "./actions" ;
34
30
import Composing from "./composing" ;
35
31
import Message from "./message" ;
36
- import { ChatMessageTyped , ChatMessages , MessageHistory , Mode } from "./types" ;
32
+ import type { ChatMessageTyped , ChatMessages , Mode } from "./types" ;
37
33
import { getSelectedHashtagsSearch , newest_content } from "./utils" ;
38
34
import { DivTempHeight } from "@cocalc/frontend/jupyter/cell-list" ;
35
+ import { filterMessages } from "./filter-messages" ;
39
36
40
37
interface Props {
41
38
project_id : string ; // used to render links more effectively
@@ -231,20 +228,11 @@ function isPrevMessageSender(
231
228
) ;
232
229
}
233
230
234
- // NOTE: I removed search including send name, since that would
235
- // be slower and of questionable value.
236
- function searchMatches ( message : ChatMessageTyped , searchTerms ) : boolean {
237
- const first = message . get ( "history" , List ( ) ) . first ( ) as
238
- | TypedMap < MessageHistory >
239
- | undefined ;
240
- if ( first == null ) return false ;
241
- return search_match ( first . get ( "content" , "" ) , searchTerms ) ;
242
- }
243
-
244
231
function isThread ( messages : ChatMessages , message : ChatMessageTyped ) {
245
232
if ( message . get ( "reply_to" ) != null ) {
246
233
return true ;
247
234
}
235
+
248
236
// TODO/WARNING!!! This is a linear search
249
237
// through all messages to decide if a message is the root of a thread.
250
238
// This is VERY BAD and must to be redone at some point, since we call isThread
@@ -253,9 +241,8 @@ function isThread(messages: ChatMessages, message: ChatMessageTyped) {
253
241
// use a proper data structure (or even a cache) to track this once
254
242
// and for all. It's more complicated but everything needs to be at
255
243
// most O(n).
256
- return messages . some (
257
- ( m ) => m . get ( "reply_to" ) === message . get ( "date" ) . toISOString ( ) ,
258
- ) ;
244
+ const s = message . get ( "date" ) . toISOString ( ) ;
245
+ return messages . some ( ( m ) => m . get ( "reply_to" ) === s ) ;
259
246
}
260
247
261
248
function isFolded (
@@ -282,21 +269,11 @@ export function getSortedDates(
282
269
) : { dates : string [ ] ; numFolded : number } {
283
270
let numFolded = 0 ;
284
271
let m = messages ;
285
- if ( m == null ) return { dates : [ ] , numFolded : 0 } ;
286
-
287
- if ( search ) {
288
- const searchTerms = search_split ( search ) ;
289
- m = m . filter ( ( message ) => searchMatches ( message , searchTerms ) ) ;
272
+ if ( m == null ) {
273
+ return { dates : [ ] , numFolded : 0 } ;
290
274
}
291
275
292
- if ( typeof filterRecentH === "number" && filterRecentH > 0 ) {
293
- const now = webapp_client . server_time ( ) . getTime ( ) ;
294
- const cutoff = now - filterRecentH * 1000 * 60 * 60 ;
295
- m = m . filter ( ( msg ) => {
296
- const date = msg . get ( "date" ) . getTime ( ) ;
297
- return date >= cutoff ;
298
- } ) ;
299
- }
276
+ m = filterMessages ( { messages : m , filter : search , filterRecentH } ) ;
300
277
301
278
const v : [ date : number , reply_to : number | undefined ] [ ] = [ ] ;
302
279
for ( const [ date , message ] of m ) {
@@ -383,7 +360,7 @@ function NotShowing({ num, search, filterRecentH }: NotShowingProps) {
383
360
key = "not_showing"
384
361
message = {
385
362
< b >
386
- WARNING: Hiding { num } { plural ( num , "message " ) }
363
+ WARNING: Hiding { num } { plural ( num , "messages " ) }
387
364
{ search . trim ( )
388
365
? ` that ${
389
366
num != 1 ? "do" : "does"
@@ -406,7 +383,6 @@ export function MessageList({
406
383
account_id,
407
384
virtuosoRef,
408
385
sortedDates,
409
- search,
410
386
user_map,
411
387
project_id,
412
388
path,
@@ -461,10 +437,7 @@ export function MessageList({
461
437
}
462
438
463
439
const is_thread = isThread ( messages , message ) ;
464
- // if we search for a message, we treat all threads as unfolded
465
- const force_unfold = ! ! search ;
466
- const is_folded =
467
- ! force_unfold && isFolded ( messages , message , account_id ) ;
440
+ const is_folded = isFolded ( messages , message , account_id ) ;
468
441
const is_thread_body = message . get ( "reply_to" ) != null ;
469
442
const h = virtuosoHeightsRef . current [ index ] ;
470
443
@@ -484,7 +457,6 @@ export function MessageList({
484
457
actions = { actions }
485
458
is_thread = { is_thread }
486
459
is_folded = { is_folded }
487
- force_unfold = { force_unfold }
488
460
is_thread_body = { is_thread_body }
489
461
is_prev_sender = { isPrevMessageSender (
490
462
index ,
0 commit comments