mirror of
https://github.com/LC044/WeChatMsg
synced 2025-02-22 19:02:17 +08:00
Merge pull request #214 from STDquantum/master
修复了页面滚动上的问题,现在可以直接一直下拉到底了,当然通过分页器分页也是可选的
This commit is contained in:
commit
23d191c193
@ -336,11 +336,7 @@ class ChildThread(QThread):
|
|||||||
displayname = escape_js_and_html(displayname)
|
displayname = escape_js_and_html(displayname)
|
||||||
if self.output_type == Output.HTML:
|
if self.output_type == Output.HTML:
|
||||||
emoji_path = get_emoji(str_content, thumb=True, output_path=origin_docx_path + '/emoji')
|
emoji_path = get_emoji(str_content, thumb=True, output_path=origin_docx_path + '/emoji')
|
||||||
if emoji_path == "":
|
emoji_path = './emoji/' + os.path.basename(emoji_path)
|
||||||
# todo 改为网络404图片
|
|
||||||
emoji_path = "./emoji/404.png"
|
|
||||||
else:
|
|
||||||
emoji_path = './emoji/' + os.path.basename(emoji_path)
|
|
||||||
if self.is_5_min(timestamp):
|
if self.is_5_min(timestamp):
|
||||||
doc.write(
|
doc.write(
|
||||||
f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:'',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
|
f'''{{ type:0, text: '{str_time}',is_send:0,avatar_path:'',timestamp:{timestamp},is_chatroom:{is_chatroom},displayname:'{displayname}'}},'''
|
||||||
@ -549,6 +545,7 @@ class ChildThread(QThread):
|
|||||||
if not os.path.exists(chatroom_avatar_path):
|
if not os.path.exists(chatroom_avatar_path):
|
||||||
message[12].avatar.save(chatroom_avatar_path)
|
message[12].avatar.save(chatroom_avatar_path)
|
||||||
except:
|
except:
|
||||||
|
print(message)
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.contact.avatar.save(os.path.join(f"{origin_docx_path}/avatar/{self.contact.wxid}.png"))
|
self.contact.avatar.save(os.path.join(f"{origin_docx_path}/avatar/{self.contact.wxid}.png"))
|
||||||
@ -1080,11 +1077,16 @@ html_end = '''
|
|||||||
|
|
||||||
const itemsPerPage = 100; // 每页显示的元素个数
|
const itemsPerPage = 100; // 每页显示的元素个数
|
||||||
let currentPage = 1; // 当前页
|
let currentPage = 1; // 当前页
|
||||||
var reachedBottom = false; // 到达底部的标记
|
var reachedBottom = false; // 到达底部的标记
|
||||||
|
var lastScrollTop = 0;
|
||||||
function renderPage(page) {
|
function renderPage(page) {
|
||||||
reachedBottom = false;
|
|
||||||
const container = document.getElementById('chat-container');
|
const container = document.getElementById('chat-container');
|
||||||
container.innerHTML = ''; // 清空容器
|
if (!reachedBottom) {
|
||||||
|
container.innerHTML = ''; // 清空容器
|
||||||
|
lastScrollTop = 0;
|
||||||
|
} else {
|
||||||
|
reachedBottom = false;
|
||||||
|
}
|
||||||
|
|
||||||
// 计算当前页应该显示的元素范围
|
// 计算当前页应该显示的元素范围
|
||||||
const startIndex = (page - 1) * itemsPerPage;
|
const startIndex = (page - 1) * itemsPerPage;
|
||||||
@ -1141,7 +1143,7 @@ var reachedBottom = false; // 到达底部的标记
|
|||||||
return messageAudioTag;
|
return messageAudioTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从数据列表中取出对应范围的元素并添加到容器中
|
// 从数据列表中取出对应范围的元素并添加到容器中
|
||||||
for (let i = startIndex; i < endIndex && i < chatMessages.length; i++) {
|
for (let i = startIndex; i < endIndex && i < chatMessages.length; i++) {
|
||||||
const message = chatMessages[i];
|
const message = chatMessages[i];
|
||||||
if (i == startIndex) { // 判断一下在页面顶部多加一个时间
|
if (i == startIndex) { // 判断一下在页面顶部多加一个时间
|
||||||
@ -1249,7 +1251,7 @@ var reachedBottom = false; // 到达底部的标记
|
|||||||
}
|
}
|
||||||
chatContainer.appendChild(messageElement);
|
chatContainer.appendChild(messageElement);
|
||||||
}
|
}
|
||||||
document.querySelector("#chat-container").scrollTop = 0;
|
document.querySelector("#chat-container").scrollTop = lastScrollTop;
|
||||||
updatePaginationInfo();
|
updatePaginationInfo();
|
||||||
refreshMediaListener();
|
refreshMediaListener();
|
||||||
}
|
}
|
||||||
@ -1287,22 +1289,22 @@ var reachedBottom = false; // 到达底部的标记
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function checkScroll() {
|
function checkScroll() {
|
||||||
var chatContainer = document.getElementById("chat-container");
|
var chatContainer = document.getElementById("chat-container");
|
||||||
|
|
||||||
// 检查滚动条是否滑到底部
|
// 检查滚动条是否滑到底部
|
||||||
if (chatContainer.scrollHeight - chatContainer.scrollTop === chatContainer.clientHeight) {
|
if (chatContainer.scrollHeight - chatContainer.scrollTop - 10 <= chatContainer.clientHeight) {
|
||||||
// 如果滚动条在底部
|
// 如果滚动条在底部
|
||||||
if (!reachedBottom) {
|
if (!reachedBottom) {
|
||||||
// 设置标记并返回
|
// 设置标记并返回
|
||||||
reachedBottom = true;
|
reachedBottom = true;
|
||||||
return;
|
lastScrollTop = chatContainer.scrollTop;
|
||||||
}
|
}
|
||||||
else{
|
if (reachedBottom) {
|
||||||
nextPage();
|
nextPage();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// 初始化页面
|
// 初始化页面
|
||||||
renderPage(currentPage);
|
renderPage(currentPage);
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import threading
|
|||||||
from app.DataBase import msg_db, micro_msg_db, misc_db
|
from app.DataBase import msg_db, micro_msg_db, misc_db
|
||||||
from app.util.protocbuf.msg_pb2 import MessageBytesExtra
|
from app.util.protocbuf.msg_pb2 import MessageBytesExtra
|
||||||
from app.util.protocbuf.roomdata_pb2 import ChatRoomData
|
from app.util.protocbuf.roomdata_pb2 import ChatRoomData
|
||||||
from app.person import ContactPC, MePC
|
from app.person import ContactPC, MePC, ContactDefault
|
||||||
|
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
|
|
||||||
@ -107,12 +107,11 @@ class PackageMsg:
|
|||||||
a[9]: msgSvrId,
|
a[9]: msgSvrId,
|
||||||
a[10]: BytesExtra,
|
a[10]: BytesExtra,
|
||||||
a[11]: CompressContent,
|
a[11]: CompressContent,
|
||||||
a[12]: msg_sender, (ContactPC类型,这个才是群聊里的信息发送人,不是群聊或者自己是发送者没有这个字段)
|
a[12]: msg_sender, (ContactPC 或 ContactDefault 类型,这个才是群聊里的信息发送人,不是群聊或者自己是发送者没有这个字段)
|
||||||
'''
|
'''
|
||||||
updated_messages = [] # 用于存储修改后的消息列表
|
updated_messages = [] # 用于存储修改后的消息列表
|
||||||
|
|
||||||
messages = msg_db.get_messages(chatroom_wxid)
|
messages = msg_db.get_messages(chatroom_wxid)
|
||||||
|
|
||||||
for row in messages:
|
for row in messages:
|
||||||
message = list(row)
|
message = list(row)
|
||||||
if message[4] == 1: # 自己发送的就没必要解析了
|
if message[4] == 1: # 自己发送的就没必要解析了
|
||||||
@ -120,6 +119,7 @@ class PackageMsg:
|
|||||||
updated_messages.append(message)
|
updated_messages.append(message)
|
||||||
continue
|
continue
|
||||||
if message[10] is None: # BytesExtra是空的跳过
|
if message[10] is None: # BytesExtra是空的跳过
|
||||||
|
message.append(ContactDefault(wxid))
|
||||||
updated_messages.append(message)
|
updated_messages.append(message)
|
||||||
continue
|
continue
|
||||||
msgbytes = MessageBytesExtra()
|
msgbytes = MessageBytesExtra()
|
||||||
@ -130,9 +130,14 @@ class PackageMsg:
|
|||||||
continue
|
continue
|
||||||
wxid = tmp.field2
|
wxid = tmp.field2
|
||||||
if wxid == "": # 系统消息里面 wxid 不存在
|
if wxid == "": # 系统消息里面 wxid 不存在
|
||||||
|
message.append(ContactDefault(wxid))
|
||||||
updated_messages.append(message)
|
updated_messages.append(message)
|
||||||
continue
|
continue
|
||||||
contact_info_list = micro_msg_db.get_contact_by_username(wxid)
|
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 = {
|
contact_info = {
|
||||||
'UserName': contact_info_list[0],
|
'UserName': contact_info_list[0],
|
||||||
'Alias': contact_info_list[1],
|
'Alias': contact_info_list[1],
|
||||||
@ -145,7 +150,7 @@ class PackageMsg:
|
|||||||
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
|
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
|
||||||
contact.set_avatar(contact.smallHeadImgBLOG)
|
contact.set_avatar(contact.smallHeadImgBLOG)
|
||||||
message.append(contact)
|
message.append(contact)
|
||||||
updated_messages.append(tuple(message))
|
updated_messages.append(message)
|
||||||
return updated_messages
|
return updated_messages
|
||||||
|
|
||||||
def get_chatroom_member_list(self, strtalker):
|
def get_chatroom_member_list(self, strtalker):
|
||||||
@ -175,4 +180,4 @@ class PackageMsg:
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
p = PackageMsg()
|
p = PackageMsg()
|
||||||
print(p.get_package_message_by_wxid("44326600419@chatroom"))
|
print(p.get_package_message_by_wxid("48615079469@chatroom"))
|
||||||
|
@ -89,6 +89,40 @@ class ContactPC:
|
|||||||
self.avatar.save(save_path)
|
self.avatar.save(save_path)
|
||||||
print('保存头像', 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__':
|
if __name__ == '__main__':
|
||||||
p1 = MePC()
|
p1 = MePC()
|
||||||
|
@ -13,7 +13,7 @@ import traceback
|
|||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import threading
|
import threading
|
||||||
|
from PyQt5.QtGui import QPixmap
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from app.log import log, logger
|
from app.log import log, logger
|
||||||
@ -144,8 +144,6 @@ class Emotion:
|
|||||||
|
|
||||||
@log
|
@log
|
||||||
def download(url, output_dir, name, thumb=False):
|
def download(url, output_dir, name, thumb=False):
|
||||||
if not url:
|
|
||||||
return ':/icons/icons/404.png'
|
|
||||||
resp = requests.get(url)
|
resp = requests.get(url)
|
||||||
byte = resp.content
|
byte = resp.content
|
||||||
image_format = get_image_format(byte[:8])
|
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
|
return output_path
|
||||||
else:
|
else:
|
||||||
print("!!!未知表情包数据,信息:", xml_string, emoji_info, url)
|
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:
|
except:
|
||||||
logger.error(traceback.format_exc())
|
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__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user