diff --git a/src/app/slices/message.user.ts b/src/app/slices/message.user.ts index ffed745f..d5531950 100644 --- a/src/app/slices/message.user.ts +++ b/src/app/slices/message.user.ts @@ -28,7 +28,9 @@ const userMsgSlice = createSlice({ const midExisted = state.byId[id].findIndex((id: number) => id == mid) > -1; const localMsgExisted = state.byId[id].findIndex((id: number) => id == local_id) > -1; 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) { state.ids.push(+id);