Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chow #334

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Chow #334

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/DataBase/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/DataBase/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
38 changes: 27 additions & 11 deletions app/ui/chat/chat_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -81,25 +82,20 @@ 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:
if self.contact.is_chatroom:
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
Expand All @@ -111,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]
Expand Down Expand Up @@ -157,6 +153,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('<revokemsg>').rstrip('</revokemsg>')
message = Notice(str_content)
Expand Down
8 changes: 8 additions & 0 deletions app/util/compress_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down