From 6713c4f475408198aa7c6be301195e3c04cdd764 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期三, 27 十一月 2024 14:05:34 +0800
Subject: [PATCH] bug 修复

---
 src/stores/chatRoom.ts |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/src/stores/chatRoom.ts b/src/stores/chatRoom.ts
index 8d85350..21b2af3 100644
--- a/src/stores/chatRoom.ts
+++ b/src/stores/chatRoom.ts
@@ -125,6 +125,7 @@
 			getSelectListSample(selectSample, userTemplateList);
 		})
 		.catch((err) => {});
+	getHistoryChatRooms();
 };
 
 //#endregion
@@ -195,3 +196,45 @@
 		return !this.get()?.web_login;
 	},
 };
+
+let getHistoryChatRoomsPromise: Promise<any>;
+//鍘嗗彶瀵硅瘽
+const getHistoryChatRooms = async () => {
+	getHistoryChatRoomsPromise = new Promise(async (resolve, reject) => {
+		if (isSharePage.value) return resolve(null);
+		const res = await GetHistoryGroups();
+		const resData = (res?.groups || []) as any[];
+		// 鎸夋渶鏅氭椂闂村埌鏈�鏃╂椂闂�
+		chatRoomList.value = resData
+			?.toSorted((a, b) => {
+				return b.create_time.localeCompare(a.create_time);
+			})
+			.map((item) => {
+				return {
+					id: item.group_id,
+					title: item.group_title,
+					createTime: item.create_time,
+					isInitial: Number(item.chat_count) === 0,
+				};
+			});
+
+		resolve(chatRoomList.value);
+	});
+};
+
+const roomClick = (room: ChatRoomItem) => {
+	activeRoomId.value = room.id;
+
+	gotoAnswerPage(room);
+};
+
+export const selectFirstRoom = () => {
+	getHistoryChatRoomsPromise.then(() => {
+		if (!chatRoomList.value || chatRoomList.value.length === 0) {
+			newChatRoomClick();
+		} else {
+			const toClickRoom = activeChatRoom.value ?? chatRoomList.value[0];
+			roomClick(toClickRoom);
+		}
+	});
+};

--
Gitblit v1.9.3