chore: sort first when insert new user message

This commit is contained in:
Tristan Yang
2023-03-09 20:39:33 +08:00
parent 8000c83a60
commit 928db8f1fa
+3 -1
View File
@@ -28,7 +28,9 @@ const userMsgSlice = createSlice({
const midExisted = state.byId[id].findIndex((id: number) => id == mid) > -1; const midExisted = state.byId[id].findIndex((id: number) => id == mid) > -1;
const localMsgExisted = state.byId[id].findIndex((id: number) => id == local_id) > -1; const localMsgExisted = state.byId[id].findIndex((id: number) => id == local_id) > -1;
if (midExisted || localMsgExisted) return; if (midExisted || localMsgExisted) return;
state.byId[id].push(+mid); // 每次入库,都排序
const newArr = [...state.byId[id], +mid].sort((a, b) => a - b);
state.byId[id] = newArr;
// 只要有新消息,就检查下 // 只要有新消息,就检查下
if (state.ids.findIndex((uid) => uid == id) == -1) { if (state.ids.findIndex((uid) => uid == id) == -1) {
state.ids.push(+id); state.ids.push(+id);