fix: optimistic channel insert on create to recover from buffered SSE; bump version to 0.9.95
This commit is contained in:
+1
-1
@@ -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",
|
||||
|
||||
@@ -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<
|
||||
|
||||
Reference in New Issue
Block a user