From 4eff75af64019ce0fef5b2574dda626e96cb32da Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Mon, 27 Feb 2023 20:50:10 +0800 Subject: [PATCH] fix: sort mids in session --- src/routes/chat/SessionList/index.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/routes/chat/SessionList/index.tsx b/src/routes/chat/SessionList/index.tsx index 19fcee08..969008b0 100644 --- a/src/routes/chat/SessionList/index.tsx +++ b/src/routes/chat/SessionList/index.tsx @@ -34,10 +34,13 @@ const SessionList: FC = ({ tempSession }) => { useEffect(() => { const cSessions = channelIDs.map((id) => { const mids = channelMessage[id]; + // console.log("midssss", mids); + if (!mids || mids.length == 0) { return { key: `channel_${id}`, unreads: 0, id, type: "channel" }; } - const mid = [...mids].sort().pop(); + // 先转换成数字,再排序 + const mid = [...mids].map(mid => +mid).sort().pop(); return { key: `channel_${id}`, id, mid, type: "channel" }; }); const uSessions = DMs.map((id) => { @@ -45,7 +48,8 @@ const SessionList: FC = ({ tempSession }) => { if (!mids || mids.length == 0) { return { key: `user_${id}`, unreads: 0, id, type: "user" }; } - const mid = [...mids].sort().pop(); + // 先转换成数字,再排序 + const mid = [...mids].map(mid => +mid).sort().pop(); return { key: `user_${id}`, type: "user", id, mid }; }); const tmps = [...(cSessions as ChatSession[]), ...(uSessions as ChatSession[])].sort((a, b) => {