fix: append messages locally on send, don't rely solely on WS
This commit is contained in:
@@ -135,12 +135,14 @@ export const useConversationStore = create<ConversationState>((set, get) => ({
|
||||
},
|
||||
|
||||
sendMessage: async (conversationId, content) => {
|
||||
// don't append here — WS MESSAGE_CREATE broadcast is the single source of truth.
|
||||
// Appending in both places caused double messages when the WS event arrived before the HTTP response.
|
||||
// Add locally so the message appears immediately even if WS lags.
|
||||
// addMessage dedupes, so a late WS event won't double it.
|
||||
const message = await api.post<ConversationMessage>(
|
||||
`/conversations/${conversationId}/messages`,
|
||||
{ content },
|
||||
);
|
||||
// ponytail: local append as fallback for WS MESSAGE_CREATE; remove if WS reliability improves
|
||||
get().addMessage(message);
|
||||
return message;
|
||||
},
|
||||
|
||||
|
||||
@@ -169,12 +169,14 @@ export const useMessageStore = create<MessageState>((set, get) => ({
|
||||
sendMessage: async (channelId, content, replyTo) => {
|
||||
const body: { content: string; reply_to?: string } = { content };
|
||||
if (replyTo) body.reply_to = replyTo;
|
||||
// ponytail: don't append here — WS MESSAGE_CREATE broadcast is the single source of truth.
|
||||
// Appending in both places caused double messages when the WS event arrived before the HTTP response.
|
||||
// Add locally so the message appears immediately even if WS lags.
|
||||
// addMessage dedupes, so a late WS event won't double it.
|
||||
const message = await api.post<Message>(
|
||||
`/channels/${channelId}/messages`,
|
||||
body,
|
||||
);
|
||||
// ponytail: local append as fallback for WS MESSAGE_CREATE; remove if WS reliability improves
|
||||
get().addMessage(message);
|
||||
return message;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user