fix: stop double-posting messages (WS + HTTP both appended)
This commit is contained in:
@@ -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;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user