feat: lots of updates

This commit is contained in:
zerosoul
2022-02-10 23:35:25 +08:00
parent e8b6c2b0f1
commit d05c5ff8f2
33 changed files with 1072 additions and 331 deletions
+11 -1
View File
@@ -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;
+9 -9
View File
@@ -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);
+3 -1
View File
@@ -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];
// 如果存在,并且新消息和缓存消息不一样,则替换掉,并且改为已读(可能有问题)
+2 -1
View File
@@ -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];
// 如果存在,并且新消息和缓存消息不一样,则替换掉