feat: lots of updates
This commit is contained in:
@@ -2,7 +2,8 @@ import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
const initialState = {
|
||||
user: null,
|
||||
usersVersion: 0,
|
||||
usersVersion: null,
|
||||
afterMid: null,
|
||||
token: null,
|
||||
refreshToken: null,
|
||||
};
|
||||
@@ -21,16 +22,25 @@ const authDataSlice = createSlice({
|
||||
state.user = null;
|
||||
state.token = null;
|
||||
state.refreshToken = null;
|
||||
// 清掉本地缓存auth data
|
||||
// localStorage.removeItem("AUTH_DATA");
|
||||
// state.afterMid = null;
|
||||
// state.usersVersion = null;
|
||||
},
|
||||
setUsersVersion(state, action) {
|
||||
const { version } = action.payload;
|
||||
state.usersVersion = version;
|
||||
},
|
||||
setAfterMid(state, action) {
|
||||
const { mid } = action.payload;
|
||||
state.afterMid = mid;
|
||||
},
|
||||
},
|
||||
});
|
||||
export const {
|
||||
setAuthData,
|
||||
clearAuthData,
|
||||
setUsersVersion,
|
||||
setAfterMid,
|
||||
} = authDataSlice.actions;
|
||||
export default authDataSlice.reducer;
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
const initialState = {};
|
||||
const channelsSlice = createSlice({
|
||||
name: "channels",
|
||||
name: `channels`,
|
||||
initialState,
|
||||
reducers: {
|
||||
setChannels(state, action) {
|
||||
// console.log("set channels store", action);
|
||||
const chs = action.payload;
|
||||
chs.forEach((c) => {
|
||||
const { gid, ...rest } = c;
|
||||
console.log("wtf", gid, rest);
|
||||
state[gid] = rest;
|
||||
});
|
||||
console.log("set channels store", state);
|
||||
const chs = action.payload || [];
|
||||
return Object.fromEntries(
|
||||
chs.map((c) => {
|
||||
const { gid, ...rest } = c;
|
||||
return [gid, rest];
|
||||
})
|
||||
);
|
||||
},
|
||||
addChannel(state, action) {
|
||||
// console.log("set channels store", action);
|
||||
|
||||
@@ -5,6 +5,7 @@ const initialState = {
|
||||
// accessLogs: {},
|
||||
pendingMsgs: [],
|
||||
};
|
||||
|
||||
const channelMsgSlice = createSlice({
|
||||
name: "channelMessage",
|
||||
initialState,
|
||||
@@ -16,9 +17,10 @@ const channelMsgSlice = createSlice({
|
||||
created_at,
|
||||
mid,
|
||||
from_uid,
|
||||
content_type,
|
||||
unread = true,
|
||||
} = action.payload;
|
||||
const newMsg = { content, created_at, from_uid, unread };
|
||||
const newMsg = { content, content_type, created_at, from_uid, unread };
|
||||
if (state[id]) {
|
||||
let replaceMsg = state[id][mid];
|
||||
// 如果存在,并且新消息和缓存消息不一样,则替换掉,并且改为已读(可能有问题)
|
||||
|
||||
@@ -10,12 +10,13 @@ const userMsgSlice = createSlice({
|
||||
const {
|
||||
id,
|
||||
content,
|
||||
content_type,
|
||||
created_at,
|
||||
mid,
|
||||
from_uid,
|
||||
unread = true,
|
||||
} = action.payload;
|
||||
const newMsg = { content, created_at, from_uid, unread };
|
||||
const newMsg = { content, content_type, created_at, from_uid, unread };
|
||||
if (state[id]) {
|
||||
let replaceMsg = state[id][mid];
|
||||
// 如果存在,并且新消息和缓存消息不一样,则替换掉
|
||||
|
||||
Reference in New Issue
Block a user