From f8919a8f6673f15e78ac40488c5aba98ea9a06b6 Mon Sep 17 00:00:00 2001 From: Kashiko Koibumi Date: Fri, 31 May 2024 18:03:39 +0900 Subject: [PATCH] fix bug in responsibility of message list on Qt GUI --- src/bitmessageqt/__init__.py | 45 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 7f87122c..9b6461d1 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -91,6 +91,13 @@ def openKeysFile(): os.startfile(keysfile) # pylint: disable=no-member +def as_msgid(id_data): + if six.PY3: + return escape_decode(id_data)[0][2:-1] + else: # assume six.PY2 + return id_data + + class MyForm(settingsmixin.SMainWindow): # the maximum frequency of message sounds in seconds @@ -1033,7 +1040,7 @@ class MyForm(settingsmixin.SMainWindow): # related = related.findItems(msgid, QtCore.Qt.MatchExactly), # returns an empty list for rrow in range(related.rowCount()): - if related.item(rrow, 3).data() == msgid: + if as_msgid(related.item(rrow, 3).data()) == msgid: break for col in range(widget.columnCount()): @@ -1938,8 +1945,6 @@ class MyForm(settingsmixin.SMainWindow): sent.item(i, 3).setText(textToDisplay) def updateSentItemStatusByAckdata(self, ackdata, textToDisplay): - if type(ackdata) is str: - ackdata = QtCore.QByteArray(ackdata) for sent in ( self.ui.tableWidgetInbox, self.ui.tableWidgetInboxSubscriptions, @@ -1950,7 +1955,7 @@ class MyForm(settingsmixin.SMainWindow): continue for i in range(sent.rowCount()): toAddress = sent.item(i, 0).data(QtCore.Qt.UserRole) - tableAckdata = sent.item(i, 3).data() + tableAckdata = as_msgid(sent.item(i, 3).data()) status, addressVersionNumber, streamNumber, ripe = decodeAddress( toAddress) if ackdata == tableAckdata: @@ -1976,7 +1981,7 @@ class MyForm(settingsmixin.SMainWindow): ): i = None for i in range(inbox.rowCount()): - if msgid == inbox.item(i, 3).data(): + if msgid == as_msgid(inbox.item(i, 3).data()): break else: continue @@ -2702,7 +2707,7 @@ class MyForm(settingsmixin.SMainWindow): msgids = [] for i in range(0, idCount): - msgids.append(sqlite3.Binary(tableWidget.item(i, 3).data())) + msgids.append(sqlite3.Binary(as_msgid(tableWidget.item(i, 3).data()))) for col in xrange(tableWidget.columnCount()): tableWidget.item(i, col).setUnread(False) @@ -2986,8 +2991,8 @@ class MyForm(settingsmixin.SMainWindow): # modified = 0 for row in tableWidget.selectedIndexes(): currentRow = row.row() - msgid = sqlite3.Binary(tableWidget.item(currentRow, 3).data()) - msgids.add(msgid) + msgid = as_msgid(tableWidget.item(currentRow, 3).data()) + msgids.add(sqlite3.Binary(msgid)) # if not tableWidget.item(currentRow, 0).unread: # modified += 1 self.updateUnreadStatus(tableWidget, currentRow, msgid, False) @@ -3081,7 +3086,7 @@ class MyForm(settingsmixin.SMainWindow): acct = accountClass(toAddressAtCurrentInboxRow) fromAddressAtCurrentInboxRow = tableWidget.item( currentInboxRow, column_from).address - msgid = tableWidget.item(currentInboxRow, 3).data() + msgid = as_msgid(tableWidget.item(currentInboxRow, 3).data()) queryreturn = sqlQuery( "SELECT message FROM inbox WHERE msgid=?", sqlite3.Binary(msgid) ) or sqlQuery("SELECT message FROM sent WHERE ackdata=?", sqlite3.Binary(msgid)) @@ -3235,15 +3240,15 @@ class MyForm(settingsmixin.SMainWindow): messageLists = (messageLists,) for messageList in messageLists: if row is not None: - inventoryHash = messageList.item(row, 3).data() + inventoryHash = as_msgid(messageList.item(row, 3).data()) messageList.removeRow(row) elif inventoryHash is not None: for i in range(messageList.rowCount() - 1, -1, -1): - if messageList.item(i, 3).data() == inventoryHash: + if as_msgid(messageList.item(i, 3).data()) == inventoryHash: messageList.removeRow(i) elif ackData is not None: for i in range(messageList.rowCount() - 1, -1, -1): - if messageList.item(i, 3).data() == ackData: + if as_msgid(messageList.item(i, 3).data()) == ackData: messageList.removeRow(i) # Send item on the Inbox tab to trash @@ -3263,7 +3268,7 @@ class MyForm(settingsmixin.SMainWindow): )[::-1]: for i in range(r.bottomRow() - r.topRow() + 1): inventoryHashesToTrash.add( - sqlite3.Binary(tableWidget.item(r.topRow() + i, 3).data())) + sqlite3.Binary(as_msgid(tableWidget.item(r.topRow() + i, 3).data()))) currentRow = r.topRow() self.getCurrentMessageTextedit().setText("") tableWidget.model().removeRows( @@ -3296,7 +3301,7 @@ class MyForm(settingsmixin.SMainWindow): )[::-1]: for i in range(r.bottomRow() - r.topRow() + 1): inventoryHashesToTrash.add( - sqlite3.Binary(tableWidget.item(r.topRow() + i, 3).data())) + sqlite3.Binary(as_msgid(tableWidget.item(r.topRow() + i, 3).data()))) currentRow = r.topRow() self.getCurrentMessageTextedit().setText("") tableWidget.model().removeRows( @@ -3327,7 +3332,7 @@ class MyForm(settingsmixin.SMainWindow): subjectAtCurrentInboxRow = '' # Retrieve the message data out of the SQL database - msgid = tableWidget.item(currentInboxRow, 3).data() + msgid = as_msgid(tableWidget.item(currentInboxRow, 3).data()) queryreturn = sqlQuery( '''select message from inbox where msgid=?''', sqlite3.Binary(msgid)) if len(queryreturn) < 1: @@ -3363,7 +3368,7 @@ class MyForm(settingsmixin.SMainWindow): shifted = QtGui.QApplication.queryKeyboardModifiers() & QtCore.Qt.ShiftModifier while tableWidget.selectedIndexes() != []: currentRow = tableWidget.selectedIndexes()[0].row() - ackdataToTrash = tableWidget.item(currentRow, 3).data() + ackdataToTrash = as_msgid(tableWidget.item(currentRow, 3).data()) rowcount = sqlExecute( "DELETE FROM sent" if folder == "trash" or shifted else "UPDATE sent SET folder='trash'" @@ -3646,11 +3651,7 @@ class MyForm(settingsmixin.SMainWindow): if messagelist: currentRow = messagelist.currentRow() if currentRow >= 0: - msgid_str = messagelist.item(currentRow, 3).data() - if six.PY3: - return escape_decode(msgid_str)[0][2:-1] - else: # assume six.PY2 - return msgid_str + return as_msgid(messagelist.item(currentRow, 3).data()) def getCurrentMessageTextedit(self): currentIndex = self.ui.tabWidget.currentIndex() @@ -4093,7 +4094,7 @@ class MyForm(settingsmixin.SMainWindow): # Check to see if this item is toodifficult and display an additional # menu option (Force Send) if it is. if currentRow >= 0: - ackData = self.ui.tableWidgetInbox.item(currentRow, 3).data() + ackData = as_msgid(self.ui.tableWidgetInbox.item(currentRow, 3).data()) queryreturn = sqlQuery('''SELECT status FROM sent where ackdata=?''', sqlite3.Binary(ackData)) if len(queryreturn) < 1: queryreturn = sqlQuery('''SELECT status FROM sent where ackdata=CAST(? AS TEXT)''', ackData)