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