From 5c86c2fbf28e80af3d2ce22fc2797b1a8aa551be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B6=85=E7=BA=A7=E8=80=81=E7=99=BD=E5=85=94?= Date: Thu, 23 Oct 2025 17:14:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B6=88=E6=81=AF=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E9=80=BB=E8=BE=91=EF=BC=8C=E8=B0=83=E6=95=B4=E7=BD=AE?= =?UTF-8?q?=E9=A1=B6=E5=92=8C=E6=97=B6=E9=97=B4=E6=88=B3=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BB=A5=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E7=BD=AE=E9=A1=B6=E6=B6=88=E6=81=AF=E4=BC=98=E5=85=88=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=EF=BC=8C=E6=8F=90=E5=8D=87=E6=B6=88=E6=81=AF=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BD=93=E9=AA=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/SidebarMenu/MessageList/index.tsx | 2 +- Touchkebao/src/utils/dbAction/message.ts | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/MessageList/index.tsx b/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/MessageList/index.tsx index cb2083bf..dec222c6 100644 --- a/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/MessageList/index.tsx +++ b/Touchkebao/src/pages/pc/ckbox/weChat/components/SidebarMenu/MessageList/index.tsx @@ -437,7 +437,7 @@ const MessageList: React.FC = () => { const newSessions = [...prev]; newSessions[existingIndex] = updatedSession; - // 按sortKey降序重新排序(最新的在前面) + // 按sortKey降序重新排序(置顶在前,最新的在前) return newSessions.sort((a, b) => { const aKey = MessageManager["generateSortKey"](a); const bKey = MessageManager["generateSortKey"](b); diff --git a/Touchkebao/src/utils/dbAction/message.ts b/Touchkebao/src/utils/dbAction/message.ts index d741c75a..bd5f7f97 100644 --- a/Touchkebao/src/utils/dbAction/message.ts +++ b/Touchkebao/src/utils/dbAction/message.ts @@ -52,21 +52,18 @@ export class MessageManager { * @returns 排序键 */ private static generateSortKey(session: any): string { - const isTop = session.config?.top ? 0 : 1; - // 时间戳转换:使用9e15减去时间戳,这样最新的时间sortKey最小 - // 9e15 是一个足够大的数字,确保结果为正数 + const isTop = session.config?.top ? 1 : 0; + // 时间戳:使用正序时间戳,最新的时间值最大 const timestamp = new Date(session.lastUpdateTime || new Date()).getTime(); - const time = 9e15 - timestamp; const displayName = ( session.conRemark || session.nickname || "" ).toLowerCase(); - // 格式:置顶标识|时间反转值(补齐15位)|显示名称 - // sortKey越小,排序越靠前 - // 最新的消息time值最小,所以排在最前面 - const timeStr = String(Math.floor(time)).padStart(16, "0"); + // 格式:置顶标识|时间戳(补齐15位)|显示名称 + // 降序排序:置顶(1)在前,时间大的在前(即最新的在前),名称小的在前 + const timeStr = String(timestamp).padStart(16, "0"); return `${isTop}|${timeStr}|${displayName}`; } @@ -144,7 +141,7 @@ export class MessageManager { */ static async getUserSessions(userId: number): Promise { try { - // 按sortKey降序排序查询(最新的在前面) + // 按sortKey降序排序查询(置顶在前,最新的在前) const sessions = await db.chatSessions .where("userId") .equals(userId)