From b0b39054a78fb17056c9f3e39ce820cb7b210276 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 30 May 2021 16:06:00 -0400 Subject: [PATCH] Prevent chats from being showed twice, fixes qa#1 --- src/Chat/Chat.cpp | 27 ++++++++++++++++++++++----- src/controller.cpp | 11 ++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Chat/Chat.cpp b/src/Chat/Chat.cpp index 0f6fb44..09f9199 100644 --- a/src/Chat/Chat.cpp +++ b/src/Chat/Chat.cpp @@ -91,6 +91,7 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label) QStandardItemModel *chat = new QStandardItemModel(); DataStore::getChatDataStore()->dump(); // test to see if the chat items in datastore are correctly dumped to json + std::map seenTxids; qDebug() << __func__ << ": looking at memos..."; for (auto &contact : AddressBook::getInstance()->getAllAddressLabels()) @@ -120,11 +121,27 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label) QStandardItem *Items1 = new QStandardItem(memo.second.toChatLine()); Items1->setData(INCOMING, Qt::UserRole + 1); qDebug() << __func__ << ": appending row to INCOMING chatitems to contact " << contact.getName() << "with txid=" << memo.second.getTxid() << " cid=" << contact.getCid() << " item " << Items1 << " memo=" << memo.second.getMemo(); - chat->appendRow(Items1); - ui->listChat->setModel(chat); - ui->memoTxtChat->setEnabled(true); - ui->emojiButton->setEnabled(true); - ui->sendChatButton->setEnabled(true); + + + if(seenTxids.count( memo.second.getTxid() ) > 0) { + // Do not render the same chat multiple times + // TODO: this should also look at outputindex to allow for multi-part memos, when that is supported + qDebug() << __func__ << ": INCOMING ignoring txid=" << memo.second.getTxid(); + continue; + } + + // TODO: better header memo detection + if (memo.second.getMemo().startsWith("{")) { + qDebug() << __func__ << ": ignoring header memo=" << memo.second.getMemo(); + } else { + chat->appendRow(Items1); + ui->listChat->setModel(chat); + ui->memoTxtChat->setEnabled(true); + ui->emojiButton->setEnabled(true); + ui->sendChatButton->setEnabled(true); + + seenTxids[ memo.second.getTxid() ] = 1; + } } else { ui->listChat->setModel(chat); diff --git a/src/controller.cpp b/src/controller.cpp index 4d9eefd..6388842 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -1348,8 +1348,9 @@ void Controller::refreshTransactions() { isContact ); - qDebug() << "refreshTransactions: adding chatItem with memodecrypt=" << memodecrypt; - DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); + auto iid = ChatIDGenerator::getInstance()->generateID(item); + qDebug() << "refreshTransactions: adding chatItem with item id=" << iid << " memodecrypt=" << memodecrypt; + DataStore::getChatDataStore()->setData(iid, item); } else { qDebug() << __func__ << ": ignoring txid="<< txid; @@ -1373,9 +1374,9 @@ void Controller::refreshTransactions() { isNotarized, isContact ); - - qDebug() << "refreshTransactions: adding chatItem for initial CR with memo=" << memo; - DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); + auto iid = ChatIDGenerator::getInstance()->generateID(item); + qDebug() << "refreshTransactions: adding chatItem for initial CR with item id="<< iid << " memo='" << memo << "'"; + DataStore::getChatDataStore()->setData(iid, item); } } }