Skip to content

Commit d955225

Browse files
committed
fix #1436 -- chat search for author name
1 parent 1352bcf commit d955225

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/packages/frontend/chat/filter-messages.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { ChatMessages, ChatMessageTyped, MessageHistory } from "./types";
1010
import { search_match, search_split } from "@cocalc/util/misc";
1111
import { List } from "immutable";
1212
import type { TypedMap } from "@cocalc/frontend/app-framework";
13+
import { redux } from "@cocalc/frontend/app-framework";
1314
import { webapp_client } from "@cocalc/frontend/webapp-client";
1415
import LRU from "lru-cache";
1516

@@ -74,15 +75,24 @@ export function filterMessages({
7475
return matchingThreads;
7576
}
7677

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 {
8279
const first = message.get("history", List()).first() as
8380
| TypedMap<MessageHistory>
8481
| 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;
8696
}
8797

8898
// Make a map
@@ -102,6 +112,7 @@ function getSearchData(messages): SearchData {
102112
return cache.get(messages)!;
103113
}
104114
const data: SearchData = {};
115+
const userMap = redux.getStore("users").get("user_map");
105116
for (const [time, message] of messages) {
106117
let rootTime: string;
107118
if (message.get("reply_to")) {
@@ -112,7 +123,7 @@ function getSearchData(messages): SearchData {
112123
rootTime = time;
113124
}
114125
const messageTime = parseFloat(time);
115-
const content = getContent(message);
126+
const content = getContent(message, userMap);
116127
if (data[rootTime] == null) {
117128
data[rootTime] = {
118129
content,

src/packages/frontend/chat/message.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ export default function Message(props: Readonly<Props>) {
806806
? `Reply to ${modelToName(
807807
isLLMThread,
808808
)}, sending the entire thread as context.`
809-
: "Reply in this thread."
809+
: "Reply to this thread."
810810
}
811811
>
812812
<Button

0 commit comments

Comments
 (0)