分开个人好友和群好友

This commit is contained in:
liuwei
2025-05-26 16:43:31 +08:00
parent da0d95d635
commit 6adef5277b
2 changed files with 20 additions and 14 deletions

View File

@@ -20,7 +20,7 @@ class ContactManager:
_head_images: Dict[str, str] = {} # 头像信息
_initialized = False
_logger = logger
_friends: List[Dict] = []
_friends: List[str] = []
_group_contacts_friends: Dict[str, Dict[str, str]] = {}
# 定义公共好友列表
_PUBLIC_FRIENDS = {
@@ -51,7 +51,7 @@ class ContactManager:
cls._instance = ContactManager()
return cls._instance
def set_contacts(self, contacts: Dict[str, str], head_imgs: Dict[str, str]) -> None:
def set_contacts(self, contacts: Dict[str, str], friends: List[str], head_imgs: Dict[str, str]) -> None:
"""设置联系人字典
Args:
@@ -68,7 +68,7 @@ class ContactManager:
"gender": gender}
"""
self._contacts = contacts
self._friends = contacts
self._friends = friends
self._head_images = head_imgs
self._logger.info(f"联系人信息已更新,共 {len(contacts)} 个联系人")
# 分类联系人
@@ -92,7 +92,9 @@ class ContactManager:
elif wxid.endswith('@chatroom'):
self._group_contacts[wxid] = nickname
else:
self._personal_contacts[wxid] = nickname
# 判断 frinds 在contacts 里面,将在里面的用户分在
if wxid in self._friends:
self._personal_contacts[wxid] = nickname
self._logger.info(f"联系人分类完成: {len(self._group_contacts)} 个群组, "
f"{len(self._personal_contacts)} 个个人联系人, "
f"{len(self._public_contacts)} 个公共好友, "
@@ -208,19 +210,20 @@ class ContactManager:
# 需要获取群成员昵称信息; 从数据库里面提取。
# self._group_contacts_friends[wxid] = {}
else:
self._personal_contacts[wxid] = nickname
if wxid in self._friends:
self._personal_contacts[wxid] = nickname
self._logger.debug(f"已更新联系人: {wxid} -> {nickname}")
def refresh_contacts(self, new_contacts: Dict[str, str]) -> None:
def refresh_contacts(self, new_contacts: Dict[str, str], friends: List[str]) -> None:
"""刷新联系人信息
Args:
new_contacts: 新的联系人字典
head_imgs: 联系人头像字典,格式为 {"wxid": "http://xxxxx"}
wcf :wcf
friends: 联系人信息,格式为 ["wxid","wxid2"]
"""
self._contacts = new_contacts
self._friends = friends
# friends: 好友清单 contact = {
# "wxid": cnt.get("wxid", ""),
# "code": cnt.get("code", ""),