Skip to content

Commit caa4782

Browse files
committed
chat: properly embed fragment in mention
- this code is definitely painful and hard to follow. sorry...
1 parent 7ed8e5d commit caa4782

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

src/packages/frontend/chat/actions.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,28 +162,37 @@ export class ChatActions extends Actions<ChatState> {
162162
reply_to,
163163
tag,
164164
noNotification,
165+
submitMentionsRef,
165166
}: {
166167
input?: string;
167168
sender_id?: string;
168169
reply_to?: Date;
169170
tag?: string;
170171
noNotification?: boolean;
172+
submitMentionsRef?;
171173
}): string => {
172174
if (this.syncdb == null || this.store == null) {
173175
console.warn("attempt to sendChat before chat actions initialized");
174176
// WARNING: give an error or try again later?
175177
return "";
176178
}
179+
if (this.store.get("is_uploading")) {
180+
// do not send while uploading, since would be mangled.
181+
return "";
182+
}
183+
const time_stamp: Date = webapp_client.server_time();
184+
const time_stamp_str = time_stamp.toISOString();
185+
if (submitMentionsRef?.current != null) {
186+
input = submitMentionsRef.current?.({ chat: `${time_stamp.valueOf()}` });
187+
}
177188
if (input == null) {
178189
input = this.store.get("input");
179190
}
180191
input = input.trim();
181-
if (input.length == 0 || this.store.get("is_uploading")) {
182-
// do not send while uploading or there is nothing to send.
192+
if (input.length == 0) {
193+
// do not send when there is nothing to send.
183194
return "";
184195
}
185-
const time_stamp: Date = webapp_client.server_time();
186-
const time_stamp_str = time_stamp.toISOString();
187196
const message: ChatMessage = {
188197
sender_id,
189198
event: "chat",
@@ -345,12 +354,14 @@ export class ChatActions extends Actions<ChatState> {
345354
from,
346355
noNotification,
347356
reply_to,
357+
submitMentionsRef,
348358
}: {
349359
message: ChatMessage;
350-
reply: string;
360+
reply?: string;
351361
from?: string;
352362
noNotification?: boolean;
353363
reply_to?: Date;
364+
submitMentionsRef?;
354365
}): string => {
355366
const store = this.store;
356367
if (store == null) {
@@ -369,6 +380,7 @@ export class ChatActions extends Actions<ChatState> {
369380
});
370381
const time_stamp_str = this.sendChat({
371382
input: reply,
383+
submitMentionsRef,
372384
sender_id: from ?? this.redux.getStore("account").get_account_id(),
373385
reply_to: new Date(reply_to_value),
374386
noNotification,

src/packages/frontend/chat/chatroom.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,8 @@ export function ChatRoom({
267267
}
268268

269269
function on_send(): void {
270-
const input = submitMentionsRef.current?.();
271270
scrollToBottomRef.current?.(true);
272-
actions.sendChat({ input });
271+
actions.sendChat({ submitMentionsRef });
273272
setTimeout(() => {
274273
scrollToBottomRef.current?.(true);
275274
}, 100);

src/packages/frontend/chat/message.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,9 @@ export default function Message(props: Readonly<Props>) {
653653

654654
function saveEditedMessage(): void {
655655
if (props.actions == null) return;
656-
const mesg = submitMentionsRef.current?.() ?? edited_message_ref.current;
656+
const mesg =
657+
submitMentionsRef.current?.({ chat: `${date}` }) ??
658+
edited_message_ref.current;
657659
const value = newest_content(message);
658660
if (mesg !== value) {
659661
set_edited_message(mesg);
@@ -717,10 +719,14 @@ export default function Message(props: Readonly<Props>) {
717719
function sendReply(reply?: string) {
718720
if (props.actions == null) return;
719721
setReplying(false);
720-
if (!reply) {
721-
reply = replyMentionsRef.current?.() ?? replyMessageRef.current;
722+
if (!reply && !replyMentionsRef.current?.(undefined, true)) {
723+
reply = replyMessageRef.current;
722724
}
723-
props.actions.sendReply({ message: message.toJS(), reply });
725+
props.actions.sendReply({
726+
message: message.toJS(),
727+
reply,
728+
submitMentionsRef: replyMentionsRef,
729+
});
724730
props.actions.scrollToIndex(props.index);
725731
}
726732

src/packages/frontend/chat/side-chat.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ export default function SideChat({
7575

7676
const sendChat = useCallback(
7777
(options?) => {
78-
const input = submitMentionsRef.current?.();
79-
actions.sendChat({ input, ...options });
78+
actions.sendChat({ submitMentionsRef, ...options });
8079
actions.deleteDraft(0);
8180
scrollToBottomRef.current?.(true);
8281
setTimeout(() => {

0 commit comments

Comments
 (0)