fix: stop double-posting messages (WS + HTTP both appended)

This commit is contained in:
2026-07-01 15:59:31 -04:00
parent 48a99d58ee
commit 33dc63b94c
+2 -9
View File
@@ -92,19 +92,12 @@ export const useMessageStore = create<MessageState>((set) => ({
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.
// Appending in both places caused double messages when the WS event arrived before the HTTP response.
const message = await api.post<Message>( const message = await api.post<Message>(
`/channels/${channelId}/messages`, `/channels/${channelId}/messages`,
body, body,
); );
set((state) => {
const list = state.messagesByChannel[channelId] || [];
return {
messagesByChannel: {
...state.messagesByChannel,
[channelId]: [...list, message],
},
};
});
return message; return message;
}, },