feat: lots updates
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
// 已读
|
||||
|
||||
Reference in New Issue
Block a user