@@ -10,6 +10,7 @@ import type { ChatMessages, ChatMessageTyped, MessageHistory } from "./types";
10
10
import { search_match , search_split } from "@cocalc/util/misc" ;
11
11
import { List } from "immutable" ;
12
12
import type { TypedMap } from "@cocalc/frontend/app-framework" ;
13
+ import { redux } from "@cocalc/frontend/app-framework" ;
13
14
import { webapp_client } from "@cocalc/frontend/webapp-client" ;
14
15
import LRU from "lru-cache" ;
15
16
@@ -74,15 +75,24 @@ export function filterMessages({
74
75
return matchingThreads ;
75
76
}
76
77
77
- // NOTE: I removed search including send name, since that would
78
- // be slower and of questionable value. Maybe we want to add it back?
79
- // A dropdown listing people might be better though, similar to the
80
- // time filter.
81
- function getContent ( message : ChatMessageTyped ) : string {
78
+ function getContent ( message : ChatMessageTyped , userMap ) : string {
82
79
const first = message . get ( "history" , List ( ) ) . first ( ) as
83
80
| TypedMap < MessageHistory >
84
81
| undefined ;
85
- return first ?. get ( "content" ) ?? "" ;
82
+ if ( ! first ) {
83
+ return "" ;
84
+ }
85
+ let content = first . get ( "content" ) ?? "" ;
86
+
87
+ // add in name of most recent author of message. We do this using userMap, which
88
+ // might not be complete in general, but is VERY FAST.... which is fine
89
+ // for a search filter.
90
+ const author_id = first . get ( "author_id" ) ;
91
+ const user = userMap ?. get ( author_id ) ;
92
+ if ( user != null ) {
93
+ content += " " + user . get ( "first_name" ) + " " + user . get ( "last_name" ) ;
94
+ }
95
+ return content ;
86
96
}
87
97
88
98
// Make a map
@@ -102,6 +112,7 @@ function getSearchData(messages): SearchData {
102
112
return cache . get ( messages ) ! ;
103
113
}
104
114
const data : SearchData = { } ;
115
+ const userMap = redux . getStore ( "users" ) . get ( "user_map" ) ;
105
116
for ( const [ time , message ] of messages ) {
106
117
let rootTime : string ;
107
118
if ( message . get ( "reply_to" ) ) {
@@ -112,7 +123,7 @@ function getSearchData(messages): SearchData {
112
123
rootTime = time ;
113
124
}
114
125
const messageTime = parseFloat ( time ) ;
115
- const content = getContent ( message ) ;
126
+ const content = getContent ( message , userMap ) ;
116
127
if ( data [ rootTime ] == null ) {
117
128
data [ rootTime ] = {
118
129
content,
0 commit comments