feat: read index

This commit is contained in:
zerosoul
2022-03-20 17:41:09 +08:00
parent 8366be7182
commit b60160cd50
16 changed files with 179 additions and 138 deletions
+2 -1
View File
@@ -75,9 +75,10 @@ export const channelApi = createApi({
},
}),
sendChannelMsg: builder.mutation({
query: ({ id, content, type = "text" }) => ({
query: ({ id, content, type = "text", properties = "" }) => ({
headers: {
"content-type": ContentTypes[type],
"X-Properties": properties,
},
url: `group/${id}/send`,
method: "POST",
+2 -1
View File
@@ -73,9 +73,10 @@ export const contactApi = createApi({
}),
}),
sendMsg: builder.mutation({
query: ({ id, content, type = "text" }) => ({
query: ({ id, content, type = "text", properties = "" }) => ({
headers: {
"content-type": ContentTypes[type],
"X-Properties": properties,
},
url: `user/${id}/send`,
method: "POST",
+21 -17
View File
@@ -1,5 +1,5 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import { batch } from "react-redux";
// import { batch } from "react-redux";
import { ContentTypes } from "../config";
import { updateReadChannels, updateReadUsers } from "../slices/footprint";
@@ -57,27 +57,31 @@ export const messageApi = createApi({
method: "POST",
body: data,
}),
async onQueryStarted(data, { dispatch, getState, queryFulfilled }) {
const { users = [], groups = [] } = data;
const { readUsers, readChannels } = getState().footprint.readUsers;
const prevUsers = users.map(({ uid }) => {
return { uid, mid: readUsers[uid] };
});
const prevChannels = users.map(({ gid }) => {
return { gid, mid: readChannels[gid] };
});
batch(() => {
dispatch(updateReadChannels(groups));
async onQueryStarted(data, { dispatch, queryFulfilled }) {
const { users = null, groups = null } = data;
// const { readUsers, readChannels } = getState().footprint;
// const prevUsers = users.map(({ uid }) => {
// return { uid, mid: readUsers[uid] };
// });
// const prevChannels = users.map(({ gid }) => {
// return { gid, mid: readChannels[gid] };
// });
// batch(() => {
if (users) {
dispatch(updateReadUsers(users));
});
}
if (groups) {
dispatch(updateReadChannels(groups));
}
// });
try {
await queryFulfilled;
} catch {
// todo
batch(() => {
dispatch(updateReadChannels(prevChannels));
dispatch(updateReadUsers(prevUsers));
});
// batch(() => {
// dispatch(updateReadChannels(prevChannels));
// dispatch(updateReadUsers(prevUsers));
// });
}
},
}),