From f6754c0db8561620bfa073fb1c8d3a08c9a41ef2 Mon Sep 17 00:00:00 2001 From: CoderKang Date: Wed, 6 Dec 2023 23:54:12 +0800 Subject: [PATCH 1/3] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E8=AE=B0=E5=BD=95=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=85=A8?= =?UTF-8?q?=20#88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/msg.py | 28 +++++++++++++++++++++++----- app/components/bubble_message.py | 2 ++ app/ui_pc/chat/chat_info.py | 2 +- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/app/DataBase/msg.py b/app/DataBase/msg.py index a6bdc7e4..580d6e83 100644 --- a/app/DataBase/msg.py +++ b/app/DataBase/msg.py @@ -58,7 +58,7 @@ def get_messages(self, username_): sql = ''' 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 StrTalker=? + where TRIM(StrTalker)=? order by CreateTime ''' try: @@ -87,11 +87,29 @@ def get_messages_all(self): result.sort(key=lambda x: x[5]) return result + def get_messages_length(self): + sql = ''' + select count(*) + from MSG + ''' + if not self.open_flag: + return None + try: + lock.acquire(True) + self.cursor.execute(sql) + result = self.cursor.fetchone() + except Exception as e: + result = None + finally: + lock.release() + return result[0] + + def get_message_by_num(self, username_, local_id): sql = ''' select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime from MSG - where StrTalker = ? and localId < ? + where TRIM(StrTalker) = ? and localId < ? order by CreateTime desc limit 10 ''' @@ -115,7 +133,7 @@ def get_messages_by_type(self, username_, type_): sql = ''' 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 StrTalker=? and Type=? + where TRIM(StrTalker)=? and Type=? order by CreateTime ''' try: @@ -132,7 +150,7 @@ def get_messages_by_keyword(self, username_, keyword, num=5, max_len=10): sql = ''' 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 StrTalker=? and Type=1 and LENGTH(StrContent) None: From a8d72d2894e0a82c1563ef3148a12afaad142619 Mon Sep 17 00:00:00 2001 From: ZhangKang Date: Thu, 7 Dec 2023 11:15:21 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/msg.py | 20 +++++++++++++++++++- app/ui_pc/chat/chat_info.py | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/DataBase/msg.py b/app/DataBase/msg.py index a6bdc7e4..915efa7b 100644 --- a/app/DataBase/msg.py +++ b/app/DataBase/msg.py @@ -87,6 +87,24 @@ def get_messages_all(self): result.sort(key=lambda x: x[5]) return result + def get_messages_length(self): + sql = ''' + select count(*) + from MSG + ''' + if not self.open_flag: + return None + try: + lock.acquire(True) + self.cursor.execute(sql) + result = self.cursor.fetchone() + except Exception as e: + result = None + finally: + lock.release() + return result[0] + + def get_message_by_num(self, username_, local_id): sql = ''' select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime @@ -213,4 +231,4 @@ def __del__(self): pprint(msg.get_message_by_num('wxid_0o18ef858vnu22', local_id)) print(msg.get_messages_by_keyword(wxid, '干嘛')) pprint(msg.get_messages_by_keyword(wxid, '干嘛')[0]) - print(msg.get_first_time_of_message('wxid_0o18ef858vnu22')) + print(msg.get_first_time_of_message('wxid_fervbwign7m822')) diff --git a/app/ui_pc/chat/chat_info.py b/app/ui_pc/chat/chat_info.py index 9e8e36a3..5464be6a 100644 --- a/app/ui_pc/chat/chat_info.py +++ b/app/ui_pc/chat/chat_info.py @@ -142,7 +142,7 @@ class ShowChatThread(QThread): # heightSingal = pyqtSignal(int) def __init__(self, contact): super().__init__() - self.last_message_id = 9999999 + self.last_message_id = msg_db.get_messages_length() or 9999999 self.wxid = contact.wxid def run(self) -> None: From 56fe90cd80f9b2e6df4cf75adbf4f51c0690a0ac Mon Sep 17 00:00:00 2001 From: ZhangKang Date: Thu, 7 Dec 2023 11:57:08 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/msg.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/DataBase/msg.py b/app/DataBase/msg.py index 6d8c66d9..915efa7b 100644 --- a/app/DataBase/msg.py +++ b/app/DataBase/msg.py @@ -58,7 +58,7 @@ def get_messages(self, username_): sql = ''' 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 TRIM(StrTalker)=? + where StrTalker=? order by CreateTime ''' try: @@ -109,7 +109,7 @@ def get_message_by_num(self, username_, local_id): sql = ''' select localId,TalkerId,Type,SubType,IsSender,CreateTime,Status,StrContent,strftime('%Y-%m-%d %H:%M:%S',CreateTime,'unixepoch','localtime') as StrTime from MSG - where TRIM(StrTalker) = ? and localId < ? + where StrTalker = ? and localId < ? order by CreateTime desc limit 10 ''' @@ -133,7 +133,7 @@ def get_messages_by_type(self, username_, type_): sql = ''' 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 TRIM(StrTalker)=? and Type=? + where StrTalker=? and Type=? order by CreateTime ''' try: @@ -150,7 +150,7 @@ def get_messages_by_keyword(self, username_, keyword, num=5, max_len=10): sql = ''' 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 TRIM(StrTalker)=? and Type=1 and LENGTH(StrContent)