html群聊导出支持头像和昵称;修复了一些其他问题

This commit is contained in:
STDquantum
2023-12-17 18:33:06 +08:00
parent 053b1a114a
commit ef7bea7f9c
5 changed files with 424 additions and 96 deletions

View File

@@ -1,8 +1,9 @@
import threading
from app.DataBase import msg_db, micro_msg_db
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
lock = threading.Lock()
@@ -76,6 +77,63 @@ class PackageMsg:
row_list.append(sender)
updated_messages.append(tuple(row_list))
return updated_messages
def get_package_message_by_wxid(self, chatroom_wxid):
'''
获取一个群聊的聊天记录
return list
a[0]: localId,
a[1]: talkerId, 和strtalker对应的不是群聊信息发送人
a[2]: type,
a[3]: subType,
a[4]: is_sender,
a[5]: timestamp,
a[6]: status, (没啥用)
a[7]: str_content,
a[8]: str_time, (格式化的时间)
a[9]: msgSvrId,
a[10]: BytesExtra,
a[11]: CompressContent,
a[12]: msg_sender, ContactPC类型这个才是群聊里的信息发送人不是群聊或者自己是发送者没有这个字段
'''
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是空的跳过
updated_messages.append(message)
continue
msgbytes = MessageBytesExtra()
msgbytes.ParseFromString(message[10])
wxid = ''
for tmp in msgbytes.message2:
if tmp.field1 != 1:
continue
wxid = tmp.field2
if wxid == "": # 系统消息里面 wxid 不存在
updated_messages.append(message)
continue
contact_info_list = micro_msg_db.get_contact_by_username(wxid)
contact_info = {
'UserName': contact_info_list[0],
'Alias': contact_info_list[1],
'Type': contact_info_list[2],
'Remark': contact_info_list[3],
'NickName': contact_info_list[4],
'smallHeadImgUrl': contact_info_list[7]
}
contact = ContactPC(contact_info)
contact.smallHeadImgBLOG = misc_db.get_avatar_buffer(contact.wxid)
contact.set_avatar(contact.smallHeadImgBLOG)
message.append(contact)
updated_messages.append(tuple(message))
return updated_messages
def get_chatroom_member_list(self, strtalker):
membermap = {}
@@ -101,3 +159,7 @@ class PackageMsg:
finally:
lock.release()
return membermap
if __name__ == "__main__":
p = PackageMsg()
print(p.get_package_message_by_wxid("44326600419@chatroom"))