Skip to content

Commit 30117ad

Browse files
committed
add name option to sendChat.
1 parent dbca134 commit 30117ad

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/packages/frontend/chat/actions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export class ChatActions extends Actions<ChatState> {
169169
noNotification,
170170
submitMentionsRef,
171171
extraInput,
172+
name,
172173
}: {
173174
input?: string;
174175
sender_id?: string;
@@ -177,6 +178,8 @@ export class ChatActions extends Actions<ChatState> {
177178
noNotification?: boolean;
178179
submitMentionsRef?;
179180
extraInput?: string;
181+
// if name is given, rename thread to have that name
182+
name?: string;
180183
}): string => {
181184
if (this.syncdb == null || this.store == null) {
182185
console.warn("attempt to sendChat before chat actions initialized");
@@ -196,6 +199,7 @@ export class ChatActions extends Actions<ChatState> {
196199
// do not send when there is nothing to send.
197200
return "";
198201
}
202+
const trimmedName = name?.trim();
199203
const message: ChatMessage = {
200204
sender_id,
201205
event: "chat",
@@ -210,6 +214,9 @@ export class ChatActions extends Actions<ChatState> {
210214
reply_to: reply_to?.toISOString(),
211215
editing: {},
212216
};
217+
if (trimmedName && !reply_to) {
218+
(message as any).name = trimmedName;
219+
}
213220
this.syncdb.set(message);
214221
const messagesState = this.store.get("messages");
215222
let selectedThreadKey: string;
@@ -242,6 +249,9 @@ export class ChatActions extends Actions<ChatState> {
242249
if (selectedThreadKey != "0") {
243250
this.setSelectedThread(selectedThreadKey);
244251
}
252+
if (trimmedName && reply_to) {
253+
this.renameThread(selectedThreadKey, trimmedName);
254+
}
245255

246256
const project_id = this.store?.get("project_id");
247257
const path = this.store?.get("path");

0 commit comments

Comments
 (0)