重构数据库管理逻辑,新增旧数据库清理功能,优化数据库初始化流程,更新联系人管理和消息处理逻辑,提升代码可读性和用户体验。

This commit is contained in:
超级老白兔
2025-10-24 16:14:13 +08:00
parent e1d4f678ab
commit 28cbcea4f9
13 changed files with 278 additions and 561 deletions

View File

@@ -18,7 +18,8 @@ import {
getFriendInjectConfig,
} from "@/pages/pc/ckbox/api";
import { ChatRecord, ContractData, weChatGroup } from "@/pages/pc/ckbox/data";
import { weChatGroupService, contractService } from "@/utils/db";
import { ContactManager } from "@/utils/dbAction";
import { useUserStore } from "@/store/module/user";
import {
addChatSession,
updateChatSession,
@@ -323,21 +324,21 @@ export const useWeChatStore = create<WeChatState>()(
pinChatSessionToTop(getMessageId);
} else {
// 如果会话不存在,创建新会话
if (isWechatGroup) {
const [group] = await weChatGroupService.findByIds(getMessageId);
if (group) {
addChatSession({
...group,
config: { unreadCount: 1 },
});
// 新创建的会话会自动添加到列表顶部,无需额外置顶
}
} else {
const [user] = await contractService.findByIds(getMessageId);
const currentUserId = useUserStore.getState().user?.id || 0;
const contactType = isWechatGroup ? "group" : "friend";
// 从统一联系人表查询
const contacts =
await ContactManager.getUserContacts(currentUserId);
const contact = contacts.find(
c => c.id === getMessageId[0] && c.type === contactType,
);
if (contact) {
addChatSession({
...user,
...contact,
config: { unreadCount: 1 },
});
} as any);
// 新创建的会话会自动添加到列表顶部,无需额外置顶
}
}