mirror of
https://github.com/LC044/WeChatMsg
synced 2024-11-14 22:01:54 +08:00
Merge pull request #125 from STDquantum/master
修复引用refertype的bug,美化引用元素,修复引用显示跨页问题
This commit is contained in:
commit
03967fe26f
@ -73,7 +73,7 @@ class MediaMsg:
|
||||
root = ET.fromstring(content)
|
||||
transtext = root.find(".//voicetrans").get("transtext")
|
||||
return transtext
|
||||
except ET.ParseError:
|
||||
except:
|
||||
return ""
|
||||
|
||||
|
||||
|
@ -20,10 +20,13 @@ def merge_MediaMSG_databases(source_paths, target_path):
|
||||
cursor.execute(sql)
|
||||
result = cursor.fetchall()
|
||||
# 附加源数据库
|
||||
try:
|
||||
target_cursor.executemany(
|
||||
"INSERT INTO Media (Key,Reserved0,Buf,Reserved1,Reserved2)"
|
||||
"VALUES(?,?,?,?,?)",
|
||||
result)
|
||||
except sqlite3.IntegrityError:
|
||||
print("有重复key", "跳过")
|
||||
cursor.close()
|
||||
db.close()
|
||||
# 提交事务
|
||||
|
@ -63,6 +63,7 @@ class Msg:
|
||||
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent
|
||||
from MSG
|
||||
where StrTalker=?
|
||||
group by MsgSvrID
|
||||
order by CreateTime
|
||||
'''
|
||||
try:
|
||||
@ -78,6 +79,7 @@ class Msg:
|
||||
sql = '''
|
||||
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,StrTalker,Reserved1,CompressContent
|
||||
from MSG
|
||||
group by MsgSvrID
|
||||
order by CreateTime
|
||||
'''
|
||||
if not self.open_flag:
|
||||
@ -94,6 +96,7 @@ class Msg:
|
||||
def get_messages_length(self):
|
||||
sql = '''
|
||||
select count(*)
|
||||
group by MsgSvrID
|
||||
from MSG
|
||||
'''
|
||||
if not self.open_flag:
|
||||
@ -113,6 +116,7 @@ class Msg:
|
||||
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent
|
||||
from MSG
|
||||
where StrTalker = ? and localId < ?
|
||||
group by MsgSvrID
|
||||
order by CreateTime desc
|
||||
limit 20
|
||||
'''
|
||||
@ -138,6 +142,7 @@ class Msg:
|
||||
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent
|
||||
from MSG
|
||||
where StrTalker=? and Type=? and strftime('%Y',CreateTime,'unixepoch','localtime') = ?
|
||||
group by MsgSvrID
|
||||
order by CreateTime
|
||||
'''
|
||||
else:
|
||||
@ -145,6 +150,7 @@ class Msg:
|
||||
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra,CompressContent
|
||||
from MSG
|
||||
where StrTalker=? and Type=?
|
||||
group by MsgSvrID
|
||||
order by CreateTime
|
||||
'''
|
||||
try:
|
||||
@ -165,6 +171,7 @@ class Msg:
|
||||
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID,BytesExtra
|
||||
from MSG
|
||||
where StrTalker=? and Type=1 and LENGTH(StrContent)<? and StrContent like ?
|
||||
group by MsgSvrID
|
||||
order by CreateTime desc
|
||||
'''
|
||||
temp = []
|
||||
@ -185,6 +192,7 @@ class Msg:
|
||||
select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime,MsgSvrID
|
||||
from MSG
|
||||
where localId > ? and StrTalker=? and Type=1 and IsSender=?
|
||||
group by MsgSvrID
|
||||
limit 1
|
||||
'''
|
||||
self.cursor.execute(sql, [local_id, username_, 1 - is_send])
|
||||
@ -205,15 +213,23 @@ class Msg:
|
||||
if is_Annual_report_:
|
||||
sql = '''
|
||||
SELECT strftime('%Y-%m-%d',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID)
|
||||
from MSG
|
||||
where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ?
|
||||
from (
|
||||
SELECT MsgSvrID, CreateTime
|
||||
FROM MSG
|
||||
WHERE StrTalker = ? AND strftime('%Y', CreateTime, 'unixepoch', 'localtime') = ?
|
||||
GROUP BY MsgSvrID
|
||||
)
|
||||
group by days
|
||||
'''
|
||||
else:
|
||||
sql = '''
|
||||
SELECT strftime('%Y-%m-%d',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID)
|
||||
from MSG
|
||||
where StrTalker = ?
|
||||
from (
|
||||
SELECT MsgSvrID, CreateTime
|
||||
FROM MSG
|
||||
WHERE StrTalker = ?
|
||||
GROUP BY MsgSvrID
|
||||
)
|
||||
group by days
|
||||
'''
|
||||
result = None
|
||||
@ -234,15 +250,23 @@ class Msg:
|
||||
if is_Annual_report_:
|
||||
sql = '''
|
||||
SELECT strftime('%Y-%m',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID)
|
||||
from MSG
|
||||
where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ?
|
||||
from (
|
||||
SELECT MsgSvrID, CreateTime
|
||||
FROM MSG
|
||||
WHERE StrTalker = ? AND strftime('%Y', CreateTime, 'unixepoch', 'localtime') = ?
|
||||
GROUP BY MsgSvrID
|
||||
)
|
||||
group by days
|
||||
'''
|
||||
else:
|
||||
sql = '''
|
||||
SELECT strftime('%Y-%m',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID)
|
||||
from MSG
|
||||
where StrTalker = ?
|
||||
from (
|
||||
SELECT MsgSvrID, CreateTime
|
||||
FROM MSG
|
||||
WHERE StrTalker = ?
|
||||
GROUP BY MsgSvrID
|
||||
)
|
||||
group by days
|
||||
'''
|
||||
result = None
|
||||
@ -266,15 +290,23 @@ class Msg:
|
||||
if is_Annual_report_:
|
||||
sql = '''
|
||||
SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID)
|
||||
from MSG
|
||||
from (
|
||||
SELECT MsgSvrID, CreateTime
|
||||
FROM MSG
|
||||
where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ?
|
||||
GROUP BY MsgSvrID
|
||||
)
|
||||
group by hours
|
||||
'''
|
||||
else:
|
||||
sql = '''
|
||||
SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID)
|
||||
from MSG
|
||||
from (
|
||||
SELECT MsgSvrID, CreateTime
|
||||
FROM MSG
|
||||
where StrTalker = ?
|
||||
GROUP BY MsgSvrID
|
||||
)
|
||||
group by hours
|
||||
'''
|
||||
result = None
|
||||
|
@ -293,12 +293,23 @@ class ChildThread(QThread):
|
||||
content = parser_reply(message[11])
|
||||
refer_msg = content.get('refer')
|
||||
if self.output_type == Output.HTML:
|
||||
contentText = content.get('title')
|
||||
emojiText = findall(r"(\[.+?\])", contentText)
|
||||
for emoji_text in emojiText:
|
||||
if emoji_text in emoji:
|
||||
contentText = contentText.replace(emoji_text, emoji[emoji_text])
|
||||
if refer_msg:
|
||||
referText = f"{refer_msg.get('displayname')}:{refer_msg.get('content')}"
|
||||
emojiText = findall(r"(\[.+?\])", referText)
|
||||
for emoji_text in emojiText:
|
||||
if emoji_text in emoji:
|
||||
referText = referText.replace(emoji_text, emoji[emoji_text])
|
||||
doc.write(
|
||||
f'''{{ type:1, text: '{content.get('title')}',is_send:{is_send},avatar_path:'{avatar}'}},'''
|
||||
f'''{{ type:49, text: '{contentText}',is_send:{is_send},sub_type:{content.get('type')},refer_text: '{referText}',avatar_path:'{avatar}'}},'''
|
||||
)
|
||||
|
||||
else:
|
||||
doc.write(
|
||||
f'''{{ type:{49},sub_type:{content.get('type')}, text: '{refer_msg.get('displayname')}:{refer_msg.get('content')}',is_send:{is_send},avatar_path:''}},'''
|
||||
f'''{{ type:49, text: '{contentText}',is_send:{is_send},sub_type:{content.get('type')},avatar_path:'{avatar}'}},'''
|
||||
)
|
||||
elif self.output_type==Output.TXT:
|
||||
name = '你' if is_send else self.contact.remark
|
||||
@ -641,7 +652,7 @@ body{
|
||||
}
|
||||
.chat-refer{
|
||||
max-width: 400px;
|
||||
padding: 3px;
|
||||
padding: 6px;
|
||||
border-radius: 5px;
|
||||
position: relative;
|
||||
color: #000;
|
||||
@ -686,10 +697,14 @@ body{
|
||||
right: -20px;
|
||||
}
|
||||
.item{
|
||||
white-space: pre-line;
|
||||
margin-top: 15px;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
}
|
||||
.item-refer{
|
||||
margin-top: 4px;
|
||||
}
|
||||
.item.item-right{
|
||||
justify-content: flex-end;
|
||||
}
|
||||
@ -908,63 +923,80 @@ html_end = '''
|
||||
for (let i = startIndex; i < endIndex && i < chatMessages.length; i++) {
|
||||
const message = chatMessages[i];
|
||||
const messageElement = document.createElement('div');
|
||||
const messageElementRefer = document.createElement('div');
|
||||
const formattedText = message.text.replace(/\\n/g, "<br>");
|
||||
var formattedReferText = "";
|
||||
if (message.type == 1) {
|
||||
if (message.is_send == 1) {
|
||||
messageElement.className = "item item-right";
|
||||
messageElement.innerHTML = `<div class='bubble bubble-right'>${message.text}</div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
messageElement.innerHTML = `<div class='bubble bubble-right'>${formattedText}</div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
}
|
||||
else if (message.is_send == 0) {
|
||||
messageElement.className = "item item-left";
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='bubble bubble-right'>${message.text}</div>`
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='bubble bubble-right'>${formattedText}</div>`
|
||||
}
|
||||
}
|
||||
else if (message.type == 0) {
|
||||
messageElement.className = "item item-center";
|
||||
messageElement.innerHTML = `<span>${message.text}</span>`
|
||||
messageElement.innerHTML = `<span>${formattedText}</span>`
|
||||
}
|
||||
else if (message.type == 3) {
|
||||
if (message.is_send == 1) {
|
||||
messageElement.className = "item item-right";
|
||||
messageElement.innerHTML = `<div class='chat-image' ><img src="${message.text}" onclick="showModal(this)"/></div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
messageElement.innerHTML = `<div class='chat-image' ><img src="${formattedText}" onclick="showModal(this)"/></div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
}
|
||||
else if (message.is_send == 0) {
|
||||
messageElement.className = "item item-left";
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}"/></div><div class='chat-image'><img src="${message.text}" onclick="showModal(this)"/></div>`
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}"/></div><div class='chat-image'><img src="${formattedText}" onclick="showModal(this)"/></div>`
|
||||
}
|
||||
}
|
||||
else if (message.type == 43) {
|
||||
if (message.is_send == 1) {
|
||||
messageElement.className = "item item-right";
|
||||
messageElement.innerHTML = `<div class='chat-video'><video src="${message.text}" controls /></div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
messageElement.innerHTML = `<div class='chat-video'><video src="${formattedText}" controls /></div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
}
|
||||
else if (message.is_send == 0) {
|
||||
messageElement.className = "item item-left";
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='chat-video'><video src="${message.text}" controls "/></div>`
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='chat-video'><video src="${formattedText}" controls "/></div>`
|
||||
}
|
||||
}
|
||||
else if (message.type == 49) {
|
||||
if (message.sub_type == 57){
|
||||
if (message.refer_text) {
|
||||
formattedReferText = message.refer_text.replace(/\\n/g, "<br>");
|
||||
}
|
||||
if (message.is_send == 1) {
|
||||
messageElement.className = "item item-right";
|
||||
messageElement.innerHTML = `<div class='chat-refer chat-refer-right'>${message.text}</div></div>`
|
||||
messageElement.innerHTML = `<div class='bubble bubble-right'>${formattedText}</div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
if (message.refer_text) {
|
||||
messageElementRefer.className = "item item-right item-refer";
|
||||
messageElementRefer.innerHTML = `<div class='chat-refer chat-refer-right'>${formattedReferText}</div></div>`
|
||||
}
|
||||
}
|
||||
else if (message.is_send == 0) {
|
||||
messageElement.className = "item item-left";
|
||||
messageElement.innerHTML = `<div class='chat-refer chat-refer-left'>${message.text}</div></div>`
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='bubble bubble-left'>${formattedText}</div>`
|
||||
if (message.refer_text) {
|
||||
messageElementRefer.className = "item item-left item-refer";
|
||||
messageElementRefer.innerHTML = `<div class='chat-refer chat-refer-left'>${formattedReferText}</div></div>`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (message.type == 34) {
|
||||
if (message.is_send == 1) {
|
||||
messageElement.className = "item item-right";
|
||||
messageElement.innerHTML = `<div class='chat-audio'>${message.voice_to_text == "" ? "" : `<div class="bubble">${message.voice_to_text}</div>`}<audio src="${message.text}" controls></audio></div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
messageElement.innerHTML = `<div class='chat-audio'>${message.voice_to_text == "" ? "" : `<div class="bubble">${message.voice_to_text}</div>`}<audio src="${formattedText}" controls></audio></div><div class='avatar'><img src="${message.avatar_path}" /></div>`
|
||||
}
|
||||
else if (message.is_send == 0) {
|
||||
messageElement.className = "item item-left";
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='chat-audio'>${message.voice_to_text == "" ? "" : `<div class="bubble">${message.voice_to_text}</div>`}<audio src="${message.text}" controls></audio></div>`
|
||||
messageElement.innerHTML = `<div class='avatar'><img src="${message.avatar_path}" /></div><div class='chat-audio'>${message.voice_to_text == "" ? "" : `<div class="bubble">${message.voice_to_text}</div>`}<audio src="${formattedText}" controls></audio></div>`
|
||||
}
|
||||
}
|
||||
chatContainer.appendChild(messageElement);
|
||||
if (message.type == 49 && message.sub_type == 57 && message.refer_text) {
|
||||
chatContainer.appendChild(messageElementRefer);
|
||||
}
|
||||
}
|
||||
document.querySelector("#chat-container").scrollTop = 0;
|
||||
updatePaginationInfo();
|
||||
|
@ -50,15 +50,15 @@ def parser_reply(data: bytes):
|
||||
}
|
||||
root = ET.XML(xml_content)
|
||||
appmsg = root.find('appmsg')
|
||||
msg_type = appmsg.find('type').text
|
||||
msg_type = int(appmsg.find('type').text)
|
||||
title = appmsg.find('title').text
|
||||
refermsg_content = appmsg.find('refermsg').find('content').text
|
||||
refermsg_type = appmsg.find('refermsg').find('type').text
|
||||
refermsg_type = int(appmsg.find('refermsg').find('type').text)
|
||||
refermsg_displayname = appmsg.find('refermsg').find('displayname').text
|
||||
return {
|
||||
'type': msg_type,
|
||||
'title': title,
|
||||
'refer': {
|
||||
'title': escape_js_and_html(title),
|
||||
'refer': None if refermsg_type != 1 else {
|
||||
'type': refermsg_type,
|
||||
'content': escape_js_and_html(refermsg_content),
|
||||
'displayname': escape_js_and_html(refermsg_displayname),
|
||||
|
Loading…
Reference in New Issue
Block a user