From 8f3bc21844a2c78fc646248959bf07a90401e706 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Thu, 30 Apr 2020 20:17:08 +0200 Subject: [PATCH] render only memos from selected nickname --- src/chatmodel.cpp | 57 +++++++++++++++++++--------------------------- src/chatmodel.h | 11 +++++++-- src/controller.cpp | 4 ++-- src/mainwindow.cpp | 12 ++++++---- src/mainwindow.h | 2 +- src/mainwindow.ui | 8 +++---- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 9adcd56..2b2b6a0 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -64,7 +64,7 @@ void ChatModel::showMessages() -void ChatModel::renderChatBox(QListWidget &view) +void ChatModel::renderChatBox(Ui::MainWindow* ui, QListWidget &view) { /*for(auto &c : this->chatItems) { @@ -74,49 +74,36 @@ void ChatModel::renderChatBox(QListWidget &view) //todo render items to view } -void ChatModel::renderChatBox(QListWidget *view) +void ChatModel::renderChatBox(Ui::MainWindow* ui, QListWidget *view) { - - qDebug() << "called ChatModel::renderChatBox(QListWidget *view)"; - QString line = ""; + while(view->count() > 0) { view->takeItem(0); } - - for(auto &c : this->chatItems) - - { - - if (c.second.getMemo().startsWith("{\n \"c\": \"true\"")){ - - // Render a incoming contact Request - - } - - if (c.second.getMemo().startsWith("{\n \"c\": \"false\"") ){ - - // we dont want to render this - - } - - if (c.second.getMemo().startsWith("{") == false){ //TOdo and is selected in Contact Widget - + QString line = ""; + + for(auto &c : this->chatItems){ + QDateTime myDateTime; myDateTime.setTime_t(c.second.getTimestamp()); - //qDebug() << "[" << myDateTime.toString("dd.MM.yyyy hh:mm:ss ") << "] " << "<" << c.second.getAddress() << "> :" << c.second.getMemo(); + + ////// + if ((ui->ContactZaddr->text().trimmed() == c.second.getAddress()) && (c.second.getMemo().startsWith("{") == false)) { line += QString("[") + myDateTime.toString("dd.MM.yyyy hh:mm:ss ") + QString("] "); line += QString("<") + QString(c.second.getContact()) + QString("> :\n"); - line += QString(c.second.getMemo()) + QString("\n"); + line += QString(c.second.getMemo()) + QString("\n"); view->addItem(line); line =""; - } + }else {} } + } -QString MainWindow::createHeaderMemo(QString safeContact, QString cid, QString zaddr, int version=0, int headerNumber=1) +QString MainWindow::createHeaderMemo(QString type, QString cid, QString zaddr, int version=0, int headerNumber=1) { QString header=""; @@ -128,15 +115,15 @@ QString MainWindow::createHeaderMemo(QString safeContact, QString cid, QString z h["v"] = version; // HushChat version h["z"] = zaddr; // zaddr to respond to h["cid"] = cid; // conversation id - h["c"] = safeContact; // Is this a safe Contact request? + h["t"] = type; // Memo or incoming contact request j.setObject(h); header = j.toJson(); qDebug() << "made header=" << header; - return header; } + // Create a Tx from the current state of the Chat page. Tx MainWindow::createTxFromChatPage() { Tx tx; @@ -144,9 +131,9 @@ Tx MainWindow::createTxFromChatPage() { // For each addr/amt in the Chat tab { - QString addr = ui->ContactZaddr->text().trimmed(); // We need to set the reply Address for our Contact here + // QString addr = ui->ContactZaddr->text().trimmed(); // We need to set the reply Address for our Contact here // Remove label if it exists - addr = AddressBook::addressFromAddressLabel(addr); + // addr = AddressBook::addressFromAddressLabel(addr); QString amtStr = "0"; @@ -160,15 +147,15 @@ Tx MainWindow::createTxFromChatPage() { for(auto &c : AddressBook::getInstance()->getAllAddressLabels()) - if (ui->ContactZaddr->text().trimmed() == c.getName()) { + if (ui->ContactZaddr->text().trimmed() == c.getPartnerAddress()) { QString cid = c.getCid(); QString myAddr = c.getMyAddress(); - QString safeContact = "false"; + QString type = "memo"; QString addr = c.getPartnerAddress(); - QString hmemo= createHeaderMemo(safeContact,cid,myAddr); + QString hmemo= createHeaderMemo(type,cid,myAddr); QString memo = ui->memoTxtChat->toPlainText().trimmed(); // ui->memoSizeChat->setLenDisplayLabel(); @@ -229,6 +216,7 @@ void MainWindow::sendChatButton() { connD->statusDetail->setText(tr("Your Message will be send")); d->show(); + ui->memoTxtChat->clear(); // And send the Tx rpc->executeTransaction(tx, @@ -248,6 +236,7 @@ void MainWindow::sendChatButton() { // Force a UI update so we get the unconfirmed Tx rpc->refresh(true); + ui->memoTxtChat->clear(); }, // Errored out diff --git a/src/chatmodel.h b/src/chatmodel.h index 524ce61..e0a6dd0 100644 --- a/src/chatmodel.h +++ b/src/chatmodel.h @@ -5,6 +5,10 @@ #include #include #include "precompiled.h" +#include "mainwindow.h" +#include "controller.h" +#include "settings.h" +#include "camount.h" class ChatItem { @@ -103,6 +107,8 @@ class ChatModel private: std::map chatItems; QTableView* parent; + Ui::MainWindow* ui; + MainWindow* main; public: ChatModel() {}; @@ -110,9 +116,10 @@ class ChatModel ChatModel(std::vector chatItems); std::map getItems(); void setItems(std::map items); + QString zaddr(); void setItems(std::vector items); - void renderChatBox(QListWidget &view); - void renderChatBox(QListWidget *view); + void renderChatBox(Ui::MainWindow* ui, QListWidget &view); + void renderChatBox(Ui::MainWindow* ui, QListWidget *view); void showMessages(); void clear(); void addMessage(ChatItem item); diff --git a/src/controller.cpp b/src/controller.cpp index 4a65ba9..0c557ca 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -985,7 +985,7 @@ void Controller::refreshTransactions() // Update model data, which updates the table view transactionsTableModel->replaceData(txdata); - chatModel->renderChatBox(ui->listChatMemo); + chatModel->renderChatBox(ui, ui->listChatMemo); refreshContacts( ui->listContactWidget ); @@ -994,7 +994,7 @@ void Controller::refreshTransactions() void Controller::refreshChat(QListWidget *listWidget) { - chatModel->renderChatBox(listWidget); + chatModel->renderChatBox(ui, listWidget); } void Controller::refreshContacts(QListWidget *listWidget) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 88a4d5f..ab37b27 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -994,10 +994,14 @@ void MainWindow::setupchatTab() { QObject::connect(ui->listContactWidget, &QTableView::clicked, [=] () { QModelIndex index = ui->listContactWidget->currentIndex(); - QString zaddr = index.data(Qt::DisplayRole).toString(); - ui->ContactZaddr->setText(zaddr); - - }); + QString label_contact = index.data(Qt::DisplayRole).toString(); + + for(auto &p : AddressBook::getInstance()->getAllAddressLabels()) + if (label_contact == p.getName()) + ui->ContactZaddr->setText(p.getPartnerAddress()); + + rpc->refresh(true); + }); } ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QPlainTextEdit(parent) { diff --git a/src/mainwindow.h b/src/mainwindow.h index f9f781b..7114eda 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -77,7 +77,7 @@ public: Logger* logger; void doClose(); - QString createHeaderMemo(QString safeContact, QString cid, QString zaddr, int version, int headerNumber); + QString createHeaderMemo(QString type, QString cid, QString zaddr, int version, int headerNumber); public slots: void slot_change_theme(const QString& themeName); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 7bb612e..ed63164 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1453,7 +1453,7 @@ - 690 + 520 490 67 17 @@ -1479,10 +1479,10 @@ - 740 + 550 490 - 171 - 17 + 691 + 20