diff --git a/app/DataBase/media_msg.py b/app/DataBase/media_msg.py
index 9b77605..b188f8e 100644
--- a/app/DataBase/media_msg.py
+++ b/app/DataBase/media_msg.py
@@ -73,7 +73,7 @@ class MediaMsg:
root = ET.fromstring(content)
transtext = root.find(".//voicetrans").get("transtext")
return transtext
- except ET.ParseError:
+ except:
return ""
diff --git a/app/DataBase/merge.py b/app/DataBase/merge.py
index 2038a84..05d51ac 100644
--- a/app/DataBase/merge.py
+++ b/app/DataBase/merge.py
@@ -20,10 +20,13 @@ def merge_MediaMSG_databases(source_paths, target_path):
cursor.execute(sql)
result = cursor.fetchall()
# 附加源数据库
- target_cursor.executemany(
- "INSERT INTO Media (Key,Reserved0,Buf,Reserved1,Reserved2)"
- "VALUES(?,?,?,?,?)",
- result)
+ try:
+ target_cursor.executemany(
+ "INSERT INTO Media (Key,Reserved0,Buf,Reserved1,Reserved2)"
+ "VALUES(?,?,?,?,?)",
+ result)
+ except sqlite3.IntegrityError:
+ print("有重复key", "跳过")
cursor.close()
db.close()
# 提交事务
diff --git a/app/DataBase/msg.py b/app/DataBase/msg.py
index a3c525b..a3edea3 100644
--- a/app/DataBase/msg.py
+++ b/app/DataBase/msg.py
@@ -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
@@ -233,16 +249,24 @@ class Msg:
def get_messages_by_month(self, username_, is_Annual_report_=False, year_='2023'):
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') = ?
- group by days
+ SELECT strftime('%Y-%m',CreateTime,'unixepoch','localtime') as days,count(MsgSvrID)
+ 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
@@ -265,16 +289,24 @@ class Msg:
def get_messages_by_hour(self, username_, is_Annual_report_=False, year_='2023'):
if is_Annual_report_:
sql = '''
- SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID)
- from MSG
+ SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID)
+ from (
+ SELECT MsgSvrID, CreateTime
+ FROM MSG
where StrTalker = ? and strftime('%Y',CreateTime,'unixepoch','localtime') = ?
- group by hours
+ GROUP BY MsgSvrID
+ )
+ group by hours
'''
else:
sql = '''
SELECT strftime('%H:00',CreateTime,'unixepoch','localtime') as hours,count(MsgSvrID)
- from MSG
- where StrTalker = ?
+ from (
+ SELECT MsgSvrID, CreateTime
+ FROM MSG
+ where StrTalker = ?
+ GROUP BY MsgSvrID
+ )
group by hours
'''
result = None
diff --git a/app/DataBase/output_pc.py b/app/DataBase/output_pc.py
index ed1db8c..3966dac 100644
--- a/app/DataBase/output_pc.py
+++ b/app/DataBase/output_pc.py
@@ -293,13 +293,24 @@ class ChildThread(QThread):
content = parser_reply(message[11])
refer_msg = content.get('refer')
if self.output_type == Output.HTML:
- doc.write(
- f'''{{ type:1, text: '{content.get('title')}',is_send:{is_send},avatar_path:'{avatar}'}},'''
- )
-
- 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:''}},'''
- )
+ 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:49, text: '{contentText}',is_send:{is_send},sub_type:{content.get('type')},refer_text: '{referText}',avatar_path:'{avatar}'}},'''
+ )
+ else:
+ doc.write(
+ 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
doc.write(
@@ -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, "
");
+ var formattedReferText = "";
if (message.type == 1) {
if (message.is_send == 1) {
messageElement.className = "item item-right";
- messageElement.innerHTML = `