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

修复了页面滚动上的问题,现在可以直接一直下拉到底了,当然通过分页器分页也是可选的 #214

Merged
merged 3 commits into from
Dec 22, 2023
Merged
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
52 changes: 27 additions & 25 deletions app/DataBase/output_pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,7 @@ def emoji(self, doc, message):
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}'}},'''
Expand Down Expand Up @@ -549,6 +545,7 @@ def to_html_(self):
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"))
Expand Down Expand Up @@ -1080,11 +1077,16 @@ def cancel(self):

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;
Expand Down Expand Up @@ -1141,7 +1143,7 @@ def cancel(self):
return messageAudioTag;
}

// 从数据列表中取出对应范围的元素并添加到容器中
// 从数据列表中取出对应范围的元素并添加到容器中
for (let i = startIndex; i < endIndex && i < chatMessages.length; i++) {
const message = chatMessages[i];
if (i == startIndex) { // 判断一下在页面顶部多加一个时间
Expand Down Expand Up @@ -1249,7 +1251,7 @@ def cancel(self):
}
chatContainer.appendChild(messageElement);
}
document.querySelector("#chat-container").scrollTop = 0;
document.querySelector("#chat-container").scrollTop = lastScrollTop;
updatePaginationInfo();
refreshMediaListener();
}
Expand Down Expand Up @@ -1287,22 +1289,22 @@ def cancel(self):
}


function checkScroll() {
var chatContainer = document.getElementById("chat-container");

// 检查滚动条是否滑到底部
if (chatContainer.scrollHeight - chatContainer.scrollTop === chatContainer.clientHeight) {
// 如果滚动条在底部
if (!reachedBottom) {
// 设置标记并返回
reachedBottom = true;
return;
}
else{
nextPage();
}
function checkScroll() {
var chatContainer = document.getElementById("chat-container");

// 检查滚动条是否滑到底部
if (chatContainer.scrollHeight - chatContainer.scrollTop - 10 <= chatContainer.clientHeight) {
// 如果滚动条在底部
if (!reachedBottom) {
// 设置标记并返回
reachedBottom = true;
lastScrollTop = chatContainer.scrollTop;
}
if (reachedBottom) {
nextPage();
}
}
}
}
// 初始化页面
renderPage(currentPage);

Expand Down
15 changes: 10 additions & 5 deletions app/DataBase/package_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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()

Expand Down Expand Up @@ -107,19 +107,19 @@ def get_package_message_by_wxid(self, chatroom_wxid):
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: # 自己发送的就没必要解析了
message.append(MePC())
updated_messages.append(message)
continue
if message[10] is None: # BytesExtra是空的跳过
message.append(ContactDefault(wxid))
updated_messages.append(message)
continue
msgbytes = MessageBytesExtra()
Expand All @@ -130,9 +130,14 @@ def get_package_message_by_wxid(self, chatroom_wxid):
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],
Expand All @@ -145,7 +150,7 @@ def get_package_message_by_wxid(self, chatroom_wxid):
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):
Expand Down Expand Up @@ -175,4 +180,4 @@ def get_chatroom_member_list(self, strtalker):

if __name__ == "__main__":
p = PackageMsg()
print(p.get_package_message_by_wxid("44326600419@chatroom"))
print(p.get_package_message_by_wxid("48615079469@chatroom"))
34 changes: 34 additions & 0 deletions app/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,40 @@ def save_avatar(self, path=None):
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()
Expand Down
14 changes: 9 additions & 5 deletions app/util/emoji.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import xml.etree.ElementTree as ET
import sqlite3
import threading

from PyQt5.QtGui import QPixmap
import requests

from app.log import log, logger
Expand Down Expand Up @@ -144,8 +144,6 @@ def __del__(self):

@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])
Expand Down Expand Up @@ -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__':
Expand Down