From a8045930d699228db389a20947d09a8899352a86 Mon Sep 17 00:00:00 2001 From: zhiyu Date: Mon, 22 Jan 2024 10:02:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B8=A6=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/msg.py | 2 +- app/ui/chat/chat_info.py | 21 +++++++++++++++++++++ app/util/compress_content.py | 8 ++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/DataBase/msg.py b/app/DataBase/msg.py index 1d9b8076..b1cfa059 100644 --- a/app/DataBase/msg.py +++ b/app/DataBase/msg.py @@ -45,7 +45,7 @@ def parser_chatroom_message(messages): message.append(Me()) updated_messages.append(tuple(message)) continue - if message[10] is None: # BytesExtra是空的跳过 + if message[10] is None and not (message[2] == 49 and message[3] == 57): # BytesExtra是空且不是带引用的消息的跳过 message.append(ContactDefault(wxid)) updated_messages.append(tuple(message)) continue diff --git a/app/ui/chat/chat_info.py b/app/ui/chat/chat_info.py index 64738468..f6084842 100644 --- a/app/ui/chat/chat_info.py +++ b/app/ui/chat/chat_info.py @@ -8,6 +8,7 @@ from app.person import Me from app.util import get_abs_path from app.util.emoji import get_emoji +from app.util.compress_content import parser_reply class ChatInfo(QWidget): @@ -157,6 +158,26 @@ def add_message(self, message): is_send ) self.chat_window.add_message_item(bubble_message, 0) + elif type_ == 49 and message[3] == 57: + # return + if self.is_5_min(timestamp): + time_message = Notice(self.last_str_time) + self.last_str_time = str_time + self.chat_window.add_message_item(time_message, 0) + content = parser_reply(message[11]) + refer_msg = content.get('refer') + if refer_msg is None: + str_content = content.get('title') + else: + str_content = f"「{refer_msg.get('displayname')}: {refer_msg.get('content')}」\n—————————\n{content.get('title')}" + bubble_message = BubbleMessage( + str_content, + avatar, + 1, + is_send, + display_name=display_name + ) + self.chat_window.add_message_item(bubble_message, 0) elif type_ == 10000: str_content = str_content.lstrip('').rstrip('') message = Notice(str_content) diff --git a/app/util/compress_content.py b/app/util/compress_content.py index f21af90a..1e6d4899 100644 --- a/app/util/compress_content.py +++ b/app/util/compress_content.py @@ -70,6 +70,14 @@ def parser_reply(data: bytes): title = appmsg.find("title").text refermsg_content = appmsg.find("refermsg").find("content").text refermsg_type = int(appmsg.find("refermsg").find("type").text) + # 处理引用的消息是个带有引用的消息 + if refermsg_type == 49: + refer_root = ET.XML(refermsg_content) + refer_appmsg = refer_root.find('appmsg') + refer_msg_type = int(refer_appmsg.find('type').text) + if refer_msg_type == 57: + refermsg_type = 1 + refermsg_content = refer_appmsg.find('title').text refermsg_displayname = appmsg.find("refermsg").find("displayname").text return { "type": msg_type, From 7184fd2c8ac0d4c782e1e40afae801a1ec08d879 Mon Sep 17 00:00:00 2001 From: zhiyu Date: Mon, 22 Jan 2024 10:14:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=94=A8-1=E4=BB=A3=E6=9B=BF=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E4=B8=80=E4=B8=AA=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/output.py | 6 +++--- app/ui/chat/chat_info.py | 17 ++++++----------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/app/DataBase/output.py b/app/DataBase/output.py index 763ff0f1..c4941b70 100644 --- a/app/DataBase/output.py +++ b/app/DataBase/output.py @@ -124,12 +124,12 @@ def is_5_min(self, timestamp) -> bool: def get_avatar_path(self, is_send, message, is_absolute_path=False) -> str: if is_absolute_path: if self.contact.is_chatroom: - avatar = message[13].avatar_path + avatar = message[-1].avatar_path else: avatar = Me().avatar_path if is_send else self.contact.avatar_path else: if self.contact.is_chatroom: - avatar = message[13].smallHeadImgUrl + avatar = message[-1].smallHeadImgUrl else: avatar = Me().smallHeadImgUrl if is_send else self.contact.smallHeadImgUrl return avatar @@ -139,7 +139,7 @@ def get_display_name(self, is_send, message) -> str: if is_send: display_name = Me().name else: - display_name = message[13].remark + display_name = message[-1].remark else: display_name = Me().name if is_send else self.contact.remark return escape_js_and_html(display_name) diff --git a/app/ui/chat/chat_info.py b/app/ui/chat/chat_info.py index f6084842..696464d0 100644 --- a/app/ui/chat/chat_info.py +++ b/app/ui/chat/chat_info.py @@ -82,17 +82,12 @@ def is_5_min(self, timestamp): return True return False - def get_avatar_path(self, is_send, message, is_absolute_path=False) -> str: + def get_avatar(self, is_send, message) -> str: if self.contact.is_chatroom: - avatar = message[13].smallHeadImgUrl + # message[-1].save_avatar() + avatar = message[-1].avatar else: - avatar = Me().smallHeadImgUrl if is_send else self.contact.smallHeadImgUrl - if is_absolute_path: - if self.contact.is_chatroom: - # message[13].save_avatar() - avatar = message[13].avatar - else: - avatar = Me().avatar if is_send else self.contact.avatar + avatar = Me().avatar if is_send else self.contact.avatar return avatar def get_display_name(self, is_send, message) -> str: @@ -100,7 +95,7 @@ def get_display_name(self, is_send, message) -> str: if is_send: display_name = Me().name else: - display_name = message[13].remark + display_name = message[-1].remark else: display_name = None return display_name @@ -112,7 +107,7 @@ def add_message(self, message): str_time = message[8] # print(type_, type(type_)) is_send = message[4] - avatar = self.get_avatar_path(is_send, message,True) + avatar = self.get_avatar(is_send, message) display_name = self.get_display_name(is_send, message) timestamp = message[5] BytesExtra = message[10]