加入头像显示功能
This commit is contained in:
@@ -16,6 +16,7 @@ class ContactManager:
|
||||
_personal_contacts: Dict[str, str] = {} # 个人联系人
|
||||
_public_contacts: Dict[str, str] = {} # 公共好友
|
||||
_official_accounts: Dict[str, str] = {} # 公众号
|
||||
_head_images: Dict[str, str] = {} # 头像信息
|
||||
_initialized = False
|
||||
_logger = logging.getLogger("ContactManager")
|
||||
_friends: List[Dict] = []
|
||||
@@ -49,11 +50,12 @@ class ContactManager:
|
||||
cls._instance = ContactManager()
|
||||
return cls._instance
|
||||
|
||||
def set_contacts(self, contacts: Dict[str, str], wcf: Wcf) -> None:
|
||||
def set_contacts(self, contacts: Dict[str, str], head_imgs: Dict[str, str], wcf: Wcf) -> None:
|
||||
"""设置联系人字典
|
||||
|
||||
Args:
|
||||
contacts: 联系人字典,格式为 {"wxid": "NickName"}
|
||||
head_imgs: 联系人头像字典,格式为 {"wxid": "http://xxxxx"}
|
||||
friends: 好友清单 contact = {
|
||||
"wxid": cnt.get("wxid", ""),
|
||||
"code": cnt.get("code", ""),
|
||||
@@ -66,6 +68,7 @@ class ContactManager:
|
||||
"""
|
||||
self._contacts = contacts
|
||||
self._friends = wcf.get_friends()
|
||||
self._head_images = head_imgs
|
||||
self._logger.info(f"联系人信息已更新,共 {len(contacts)} 个联系人")
|
||||
# 分类联系人
|
||||
self._classify_contacts(wcf)
|
||||
@@ -153,6 +156,25 @@ class ContactManager:
|
||||
"""
|
||||
return self._contacts.get(wxid, wxid)
|
||||
|
||||
def get_all_head_images(self) -> Dict[str, str]:
|
||||
"""返回所有的头像信息
|
||||
|
||||
Returns:
|
||||
头像 {"wxid": "http://xxxxx"}
|
||||
"""
|
||||
return self._head_images
|
||||
|
||||
def get_head_image(self, wxid: str) -> str:
|
||||
"""根据微信ID获取头像
|
||||
|
||||
Args:
|
||||
wxid: 微信ID
|
||||
|
||||
Returns:
|
||||
对应的头像,如果不存在这返回""
|
||||
"""
|
||||
return self._head_images.get(wxid, "")
|
||||
|
||||
def get_group_name(self, roomid: str, wxid: str) -> str:
|
||||
"""
|
||||
Args:
|
||||
@@ -194,11 +216,12 @@ class ContactManager:
|
||||
self._personal_contacts[wxid] = nickname
|
||||
self._logger.debug(f"已更新联系人: {wxid} -> {nickname}")
|
||||
|
||||
def refresh_contacts(self, new_contacts: Dict[str, str], wcf: Wcf) -> None:
|
||||
def refresh_contacts(self, new_contacts: Dict[str, str], head_imgs: Dict[str, str], wcf: Wcf) -> None:
|
||||
"""刷新联系人信息
|
||||
|
||||
Args:
|
||||
new_contacts: 新的联系人字典
|
||||
head_imgs: 联系人头像字典,格式为 {"wxid": "http://xxxxx"}
|
||||
wcf :wcf
|
||||
|
||||
"""
|
||||
@@ -213,6 +236,7 @@ class ContactManager:
|
||||
# "city": cnt.get("city", ""),
|
||||
# "gender": gender}
|
||||
self._friends = wcf.get_friends()
|
||||
self._head_images = head_imgs
|
||||
self._logger.info(f"联系人信息已刷新,共 {len(new_contacts)} 个联系人")
|
||||
# 重新分类联系人
|
||||
self._classify_contacts(wcf)
|
||||
|
||||
Reference in New Issue
Block a user