feat: lots updates

This commit is contained in:
zerosoul
2022-03-10 10:30:38 +08:00
parent e6f5b6e428
commit d497e7df4f
22 changed files with 415 additions and 174 deletions
+4 -36
View File
@@ -1,13 +1,9 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import toast from "react-hot-toast";
// import toast from "react-hot-toast";
import baseQuery from "./base.query";
import { ContentTypes } from "../config";
import { addChannelMsg } from "../slices/message.channel";
import { updateChannel } from "../slices/channels";
import {
addPendingMessage,
removePendingMessage,
} from "../slices/message.pending";
import { onMessageSendStarted } from "./handlers";
export const channelApi = createApi({
reducerPath: "channel",
baseQuery,
@@ -61,36 +57,8 @@ export const channelApi = createApi({
method: "POST",
body: content,
}),
async onQueryStarted(
{ id, content, type, from_uid },
{ dispatch, queryFulfilled }
) {
// id: who send to ,from_uid: who sent
const mid = new Date().getTime();
const tmpMsg = {
id,
content,
content_type: ContentTypes[type],
created_at: new Date().getTime(),
mid,
from_uid,
unread: false,
};
dispatch(addPendingMessage({ type: "channel", msg: tmpMsg }));
try {
const { data: server_mid } = await queryFulfilled;
console.log("channel server mid", server_mid);
// 此处的id,是指给谁发的
dispatch(
addChannelMsg({ ...tmpMsg, mid: server_mid, unread: false })
);
dispatch(removePendingMessage({ id, mid, type: "channel" }));
} catch {
console.log("channel message send failed");
toast.error("Send Message Failed");
dispatch(removePendingMessage({ id, mid, type: "channel" }));
// patchResult.undo();
}
async onQueryStarted(param1, param2) {
await onMessageSendStarted.call(this, param1, param2, "channel");
},
}),
}),