From 3568c5d6b32d8d71c09fe489307673a59d477080 Mon Sep 17 00:00:00 2001 From: STDquantum <405720329@qq.com> Date: Fri, 22 Dec 2023 14:19:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=BB=9A=E5=8A=A8=E4=B8=8A=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=8C=E7=8E=B0=E5=9C=A8=E5=8F=AF=E4=BB=A5=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E4=B8=80=E7=9B=B4=E4=B8=8B=E6=8B=89=E5=88=B0=E5=BA=95=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E5=BD=93=E7=84=B6=E9=80=9A=E8=BF=87=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E5=99=A8=E5=88=86=E9=A1=B5=E4=B9=9F=E6=98=AF=E5=8F=AF=E9=80=89?= =?UTF-8?q?=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/output_pc.py | 43 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/app/DataBase/output_pc.py b/app/DataBase/output_pc.py index 3a9d967..7229915 100644 --- a/app/DataBase/output_pc.py +++ b/app/DataBase/output_pc.py @@ -1080,11 +1080,16 @@ html_end = ''' const itemsPerPage = 100; // 每页显示的元素个数 let currentPage = 1; // 当前页 -var reachedBottom = false; // 到达底部的标记 + var reachedBottom = false; // 到达底部的标记 + var lastScrollTop = 0; function renderPage(page) { - reachedBottom = false; const container = document.getElementById('chat-container'); - container.innerHTML = ''; // 清空容器 + if (!reachedBottom) { + container.innerHTML = ''; // 清空容器 + lastScrollTop = 0; + } else { + reachedBottom = false; + } // 计算当前页应该显示的元素范围 const startIndex = (page - 1) * itemsPerPage; @@ -1141,7 +1146,7 @@ var reachedBottom = false; // 到达底部的标记 return messageAudioTag; } - // 从数据列表中取出对应范围的元素并添加到容器中 + // 从数据列表中取出对应范围的元素并添加到容器中 for (let i = startIndex; i < endIndex && i < chatMessages.length; i++) { const message = chatMessages[i]; if (i == startIndex) { // 判断一下在页面顶部多加一个时间 @@ -1249,7 +1254,7 @@ var reachedBottom = false; // 到达底部的标记 } chatContainer.appendChild(messageElement); } - document.querySelector("#chat-container").scrollTop = 0; + document.querySelector("#chat-container").scrollTop = lastScrollTop; updatePaginationInfo(); refreshMediaListener(); } @@ -1287,22 +1292,22 @@ var reachedBottom = false; // 到达底部的标记 } - function checkScroll() { - var chatContainer = document.getElementById("chat-container"); + function checkScroll() { + var chatContainer = document.getElementById("chat-container"); - // 检查滚动条是否滑到底部 - if (chatContainer.scrollHeight - chatContainer.scrollTop === chatContainer.clientHeight) { - // 如果滚动条在底部 - if (!reachedBottom) { - // 设置标记并返回 - reachedBottom = true; - return; - } - else{ - nextPage(); - } + // 检查滚动条是否滑到底部 + if (chatContainer.scrollHeight - chatContainer.scrollTop - 10 <= chatContainer.clientHeight) { + // 如果滚动条在底部 + if (!reachedBottom) { + // 设置标记并返回 + reachedBottom = true; + lastScrollTop = chatContainer.scrollTop; + } + if (reachedBottom) { + nextPage(); + } + } } - } // 初始化页面 renderPage(currentPage); From 3a7049d08f72ed7798aa7b1c7d09c85313894210 Mon Sep 17 00:00:00 2001 From: STDquantum <405720329@qq.com> Date: Fri, 22 Dec 2023 18:39:30 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=B7=B2?= =?UTF-8?q?=E9=80=80=E7=BE=A4=E7=9A=84=E4=BA=BA=E6=98=B5=E7=A7=B0=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=89=BE=E5=88=B0=E5=AF=BC=E8=87=B4=E7=9A=84=E9=97=AA?= =?UTF-8?q?=E9=80=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/output_pc.py | 1 + app/DataBase/package_msg.py | 15 ++++++++++----- app/person.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/app/DataBase/output_pc.py b/app/DataBase/output_pc.py index 7229915..c34e8aa 100644 --- a/app/DataBase/output_pc.py +++ b/app/DataBase/output_pc.py @@ -549,6 +549,7 @@ class ChildThread(QThread): if not os.path.exists(chatroom_avatar_path): message[12].avatar.save(chatroom_avatar_path) except: + print(message) pass else: self.contact.avatar.save(os.path.join(f"{origin_docx_path}/avatar/{self.contact.wxid}.png")) diff --git a/app/DataBase/package_msg.py b/app/DataBase/package_msg.py index 1560063..138bb7d 100644 --- a/app/DataBase/package_msg.py +++ b/app/DataBase/package_msg.py @@ -3,7 +3,7 @@ import threading from app.DataBase import msg_db, micro_msg_db, misc_db from app.util.protocbuf.msg_pb2 import MessageBytesExtra from app.util.protocbuf.roomdata_pb2 import ChatRoomData -from app.person import ContactPC, MePC +from app.person import ContactPC, MePC, ContactDefault lock = threading.Lock() @@ -107,12 +107,11 @@ class PackageMsg: a[9]: msgSvrId, a[10]: BytesExtra, a[11]: CompressContent, - a[12]: msg_sender, (ContactPC类型,这个才是群聊里的信息发送人,不是群聊或者自己是发送者没有这个字段) + a[12]: msg_sender, (ContactPC 或 ContactDefault 类型,这个才是群聊里的信息发送人,不是群聊或者自己是发送者没有这个字段) ''' updated_messages = [] # 用于存储修改后的消息列表 messages = msg_db.get_messages(chatroom_wxid) - for row in messages: message = list(row) if message[4] == 1: # 自己发送的就没必要解析了 @@ -120,6 +119,7 @@ class PackageMsg: updated_messages.append(message) continue if message[10] is None: # BytesExtra是空的跳过 + message.append(ContactDefault(wxid)) updated_messages.append(message) continue msgbytes = MessageBytesExtra() @@ -130,9 +130,14 @@ class PackageMsg: continue wxid = tmp.field2 if wxid == "": # 系统消息里面 wxid 不存在 + message.append(ContactDefault(wxid)) updated_messages.append(message) continue contact_info_list = micro_msg_db.get_contact_by_username(wxid) + if contact_info_list is None: # 群聊中已退群的联系人不会保存在数据库里 + message.append(ContactDefault(wxid)) + updated_messages.append(message) + continue contact_info = { 'UserName': contact_info_list[0], 'Alias': contact_info_list[1], @@ -145,7 +150,7 @@ class PackageMsg: contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid) contact.set_avatar(contact.smallHeadImgBLOG) message.append(contact) - updated_messages.append(tuple(message)) + updated_messages.append(message) return updated_messages def get_chatroom_member_list(self, strtalker): @@ -175,4 +180,4 @@ class PackageMsg: if __name__ == "__main__": p = PackageMsg() - print(p.get_package_message_by_wxid("44326600419@chatroom")) + print(p.get_package_message_by_wxid("48615079469@chatroom")) diff --git a/app/person.py b/app/person.py index e1a49d2..dcd64a5 100644 --- a/app/person.py +++ b/app/person.py @@ -89,6 +89,40 @@ class ContactPC: self.avatar.save(save_path) print('保存头像', save_path) +class ContactDefault: + def __init__(self, wxid=""): + self.avatar = QPixmap(Icon.Default_avatar_path) + self.avatar_path = ':/icons/icons/default_avatar.svg' + self.wxid = wxid + self.remark = wxid + self.alias = wxid + self.nickName = wxid + self.smallHeadImgUrl = "" + self.smallHeadImgBLOG = b'' + self.is_chatroom = False + + def set_avatar(self, img_bytes): + if not img_bytes: + self.avatar.load(Icon.Default_avatar_path) + return + if img_bytes[:4] == b'\x89PNG': + self.avatar.loadFromData(img_bytes, format='PNG') + else: + self.avatar.loadFromData(img_bytes, format='jfif') + self.avatar.scaled(60, 60, Qt.IgnoreAspectRatio, Qt.SmoothTransformation) + + def save_avatar(self, path=None): + if not self.avatar: + return + if path: + save_path = path + else: + os.makedirs('./data/avatar', exist_ok=True) + save_path = os.path.join(f'data/avatar/', self.wxid + '.png') + self.avatar_path = save_path + self.avatar.save(save_path) + print('保存头像', save_path) + if __name__ == '__main__': p1 = MePC() From 206dbc88f818d1da28658f4a2ed372dddb58e3b7 Mon Sep 17 00:00:00 2001 From: STDquantum <405720329@qq.com> Date: Fri, 22 Dec 2023 19:22:30 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A4=84=E7=90=86404=20emoji?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/output_pc.py | 6 +----- app/util/emoji.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/DataBase/output_pc.py b/app/DataBase/output_pc.py index c34e8aa..d322546 100644 --- a/app/DataBase/output_pc.py +++ b/app/DataBase/output_pc.py @@ -336,11 +336,7 @@ class ChildThread(QThread): displayname = escape_js_and_html(displayname) if self.output_type == Output.HTML: emoji_path = get_emoji(str_content, thumb=True, output_path=origin_docx_path + '/emoji') - if emoji_path == "": - # todo 改为网络404图片 - emoji_path = "./emoji/404.png" - else: - emoji_path = './emoji/' + os.path.basename(emoji_path) + emoji_path = './emoji/' + os.path.basename(emoji_path) if self.is_5_min(timestamp): doc.write( f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:'',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},''' diff --git a/app/util/emoji.py b/app/util/emoji.py index 31b63ba..ddafc5f 100644 --- a/app/util/emoji.py +++ b/app/util/emoji.py @@ -13,7 +13,7 @@ import traceback import xml.etree.ElementTree as ET import sqlite3 import threading - +from PyQt5.QtGui import QPixmap import requests from app.log import log, logger @@ -144,8 +144,6 @@ class Emotion: @log def download(url, output_dir, name, thumb=False): - if not url: - return ':/icons/icons/404.png' resp = requests.get(url) byte = resp.content image_format = get_image_format(byte[:8]) @@ -221,10 +219,16 @@ def get_emoji(xml_string, thumb=True, output_path=root_path) -> str: return output_path else: print("!!!未知表情包数据,信息:", xml_string, emoji_info, url) - return "" + output_path = os.path.join(output_path, '404.png') + if not os.path.exists(output_path): + QPixmap(':/icons/icons/404.png').save(output_path) + return output_path except: logger.error(traceback.format_exc()) - return "" + output_path = os.path.join(output_path, "404.png") + if not os.path.exists(output_path): + QPixmap(':/icons/icons/404.png').save(output_path) + return output_path if __name__ == '__main__':