fix: optimistic channel insert on create to recover from buffered SSE; bump version to 0.9.95

This commit is contained in:
haorwen
2026-06-27 10:57:06 +08:00
parent fec64393c6
commit 48c79656b3
2 changed files with 35 additions and 3 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "vocechat-web",
"version": "0.9.94",
"version": "0.9.95",
"homepage": "https://voce.chat",
"dependencies": {
"@metamask/onboarding": "^1.0.1",
+34 -2
View File
@@ -4,7 +4,7 @@ import { Channel, ChannelDTO, CreateChannelDTO } from "@/types/channel";
import { ContentTypeKey } from "@/types/message";
import { encodeBase64, transformInviteLink } from "@/utils";
import BASE_URL, { ContentTypes } from "../config";
import { removeChannel, updateChannel } from "../slices/channels";
import { addChannel, removeChannel, updateChannel } from "../slices/channels";
import { removeMessage } from "../slices/message";
import { removeChannelSession } from "../slices/message.channel";
import { removeReactionMessage } from "../slices/message.reaction";
@@ -42,7 +42,39 @@ export const channelApi = createApi({
url: "/group",
method: "POST",
body: data
})
}),
async onQueryStarted(arg, { dispatch, queryFulfilled, getState }) {
try {
const { data } = await queryFulfilled;
const gid = typeof data === "object" ? data.gid : data;
if (!gid) return;
const state = getState() as RootState;
if (state.channels.byId[gid]) return;
const loginUid = state.authData.user?.uid ?? 0;
const members = arg.is_public
? []
: Array.from(new Set([...(arg.members ?? []), loginUid].filter(Boolean)));
dispatch(
addChannel({
gid,
owner: loginUid,
name: arg.name,
description: arg.description ?? "",
members,
is_public: arg.is_public,
avatar_updated_at: 0,
pinned_messages: [],
show_email: false,
dm_to_member: false,
add_friend: false,
only_owner_can_send_msg: false,
ext_setting: null
})
);
} catch {
console.error("create channel failed");
}
}
}
),
changeChannelType: builder.mutation<