feat: lots updates

This commit is contained in:
zerosoul
2022-03-22 16:10:49 +08:00
parent eef55e5cb3
commit a23800b042
40 changed files with 504 additions and 415 deletions
+10
View File
@@ -1,6 +1,7 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import { nanoid } from "@reduxjs/toolkit";
import baseQuery from "./base.query";
import { updateToken, resetAuthData } from "../slices/auth.data";
import BASE_URL, { KEY_DEVICE_KEY } from "../config";
const getDeviceId = () => {
let d = localStorage.getItem(KEY_DEVICE_KEY);
@@ -43,6 +44,15 @@ export const authApi = createApi({
refresh_token: refreshToken,
},
}),
async onQueryStarted(params, { dispatch, queryFulfilled }) {
try {
const { data } = await queryFulfilled;
dispatch(updateToken(data));
} catch {
dispatch(resetAuthData());
console.log("remove channel error");
}
},
}),
// 获取openid
getOpenid: builder.mutation({
+9 -1
View File
@@ -78,7 +78,7 @@ export const channelApi = createApi({
query: ({ id, content, type = "text", properties = "" }) => ({
headers: {
"content-type": ContentTypes[type],
"X-Properties": properties,
"X-Properties": properties ? btoa(JSON.stringify(properties)) : "",
},
url: `group/${id}/send`,
method: "POST",
@@ -95,6 +95,13 @@ export const channelApi = createApi({
body: members,
}),
}),
removeMembers: builder.mutation({
query: ({ id, members }) => ({
url: `group/${id}/members/remove`,
method: "POST",
body: members,
}),
}),
}),
});
@@ -106,4 +113,5 @@ export const {
useCreateChannelMutation,
useSendChannelMsgMutation,
useAddMembersMutation,
useRemoveMembersMutation,
} = channelApi;
+1 -2
View File
@@ -32,7 +32,6 @@ export const contactApi = createApi({
// 用户已注销或被禁用
console.log("no matched user, redirect to login");
dispatch(resetAuthData());
// navigate("/login");
} else {
const markedContacts = contacts.map((u) => {
return u.uid == matchedUser.uid ? { ...u, online: true } : u;
@@ -76,7 +75,7 @@ export const contactApi = createApi({
query: ({ id, content, type = "text", properties = "" }) => ({
headers: {
"content-type": ContentTypes[type],
"X-Properties": properties,
"X-Properties": properties ? btoa(JSON.stringify(properties)) : "",
},
url: `user/${id}/send`,
method: "POST",
+10 -2
View File
@@ -5,16 +5,24 @@ import { addChannelMsg, removeChannelMsg } from "../slices/message.channel";
import { addUserMsg, removeUserMsg } from "../slices/message.user";
import { addMessage, removeMessage } from "../slices/message";
export const onMessageSendStarted = async (
{ id, content, type = "text", from_uid, reply_mid = null },
{
id,
content,
type = "text",
from_uid,
reply_mid = null,
properties = { local_id: new Date().getTime() },
},
{ dispatch, queryFulfilled },
from = "channel"
) => {
// id: who send to ,from_uid: who sent
const ts = new Date().getTime();
const ts = properties.local_id || new Date().getTime();
const tmpMsg = {
content: type == "image" ? URL.createObjectURL(content) : content,
content_type: ContentTypes[type],
created_at: ts,
properties,
from_uid,
reply_mid,
// 已读