From cfbcc43b14eb1a21c02853d4fbf237efa9f06eff Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Wed, 27 May 2020 21:42:39 +0200 Subject: [PATCH] render only new requests --- src/Chat/Chat.cpp | 1 - src/DataStore/ChatDataStore.cpp | 9 +++--- src/FileSystem/FileSystem.cpp | 6 ++-- src/FileSystem/FileSystem.h | 4 ++- src/Model/ChatItem.cpp | 17 +++++++++-- src/Model/ChatItem.h | 7 +++-- src/Model/ContactItem.cpp | 7 ++++- src/Model/ContactItem.h | 5 +++- src/addressbook.cpp | 3 ++ src/addressbook.h | 9 +++++- src/chatmodel.cpp | 35 +++++++++++++++++++---- src/chatmodel.h | 6 +++- src/contactmodel.h | 3 +- src/controller.cpp | 38 ++++++++++++++++++++----- src/controller.h | 3 ++ src/mainwindow.cpp | 7 +---- src/requestContactDialog.ui | 50 +++++++++++++++++++++------------ src/sendtab.cpp | 2 +- 18 files changed, 157 insertions(+), 55 deletions(-) diff --git a/src/Chat/Chat.cpp b/src/Chat/Chat.cpp index c0482b8..cdc3814 100644 --- a/src/Chat/Chat.cpp +++ b/src/Chat/Chat.cpp @@ -55,7 +55,6 @@ void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label) { for (auto &c : DataStore::getChatDataStore()->getAllMemos()) { - //////Render only Memos for selected contacts. Do not render empty Memos //// Render only memos where cid=cid if ( (p.getName() == ui->contactNameMemo->text().trimmed()) && diff --git a/src/DataStore/ChatDataStore.cpp b/src/DataStore/ChatDataStore.cpp index 21ddef9..7bb3840 100644 --- a/src/DataStore/ChatDataStore.cpp +++ b/src/DataStore/ChatDataStore.cpp @@ -3,6 +3,8 @@ #include "ChatDataStore.h" #include "addressbook.h" +#include "chatmodel.h" + ChatDataStore* ChatDataStore::getInstance() { @@ -53,15 +55,14 @@ std::map ChatDataStore::getAllNewContactRequests() { std::map filteredItems; - for(auto &c: this->data) + for(auto &c: this->data) { if ( (c.second.isOutgoing() == false) && (c.second.getType() == "Cont") && - (c.second.getContact() == "") - - + (c.second.isContact() == false) ) + { filteredItems[c.first] = c.second; } diff --git a/src/FileSystem/FileSystem.cpp b/src/FileSystem/FileSystem.cpp index 2a60de1..208bfaa 100644 --- a/src/FileSystem/FileSystem.cpp +++ b/src/FileSystem/FileSystem.cpp @@ -1,8 +1,11 @@ -#include "FileSystem.h" +// Copyright 2019-2020 The Hush developers +// GPLv3 +#include "FileSystem.h" #include #include #include "../Crypto/passwd.h" +#include "addressbook.h" FileSystem::FileSystem() { @@ -99,7 +102,6 @@ QList FileSystem::readContactsOldFormat(QString file) qDebug() << "Detected old addressbook format"; QList> stuff; in >> stuff; - //qDebug() << "Stuff: " << stuff; for (int i=0; i < stuff.size(); i++) { ContactItem contact = ContactItem(stuff[i][0],stuff[i][1], stuff[i][2], stuff[i][3],stuff[i][4]); diff --git a/src/FileSystem/FileSystem.h b/src/FileSystem/FileSystem.h index 30dd5fc..34fc5fc 100644 --- a/src/FileSystem/FileSystem.h +++ b/src/FileSystem/FileSystem.h @@ -1,3 +1,5 @@ +// Copyright 2019-2020 The Hush developers +// GPLv3 #ifndef FILESYSTEM_H #define FILESYSTEM_H @@ -13,7 +15,7 @@ class FileSystem static bool instanced; static FileSystem* instance; FileSystem(); - + public: static FileSystem* getInstance(); QList readContacts(QString file); diff --git a/src/Model/ChatItem.cpp b/src/Model/ChatItem.cpp index 31ff448..6a30f56 100644 --- a/src/Model/ChatItem.cpp +++ b/src/Model/ChatItem.cpp @@ -5,7 +5,7 @@ ChatItem::ChatItem() {} -ChatItem::ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid, int confirmations, bool notarize) +ChatItem::ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid, int confirmations, bool notarize, bool iscontact) { _timestamp = timestamp; _address = address; @@ -18,9 +18,10 @@ ChatItem::ChatItem(long timestamp, QString address, QString contact, QString mem _confirmations = confirmations; _outgoing = false; _notarize = notarize; + _iscontact = iscontact; } -ChatItem::ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid, int confirmations, bool outgoing, bool notarize) +ChatItem::ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid, int confirmations, bool outgoing, bool notarize, bool iscontact) { _timestamp = timestamp; _address = address; @@ -33,6 +34,8 @@ ChatItem::ChatItem(long timestamp, QString address, QString contact, QString mem _confirmations = confirmations; _outgoing = outgoing; _notarize = notarize; + _iscontact = iscontact; + } long ChatItem::getTimestamp() @@ -88,6 +91,11 @@ bool ChatItem::isNotarized() return _notarize; } +bool ChatItem::isContact() +{ + return _iscontact; +} + void ChatItem::setTimestamp(long timestamp) { _timestamp = timestamp; @@ -140,6 +148,11 @@ void ChatItem::notarized() _notarize = false; } +void ChatItem::contact(bool iscontact) +{ + _iscontact = iscontact; +} + QString ChatItem::toChatLine() { diff --git a/src/Model/ChatItem.h b/src/Model/ChatItem.h index 11e3b65..900c994 100644 --- a/src/Model/ChatItem.h +++ b/src/Model/ChatItem.h @@ -21,11 +21,12 @@ class ChatItem int _confirmations; bool _outgoing = false; bool _notarize = false; + bool _iscontact = false; public: ChatItem(); - ChatItem(long timestamp, QString address, QString contact, QString memo,QString requestZaddr, QString type, QString cid, QString txid, int confirmations, bool notarize); - ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid, int confirmations, bool outgoing, bool notarize); + ChatItem(long timestamp, QString address, QString contact, QString memo,QString requestZaddr, QString type, QString cid, QString txid, int confirmations, bool notarize, bool iscontact); + ChatItem(long timestamp, QString address, QString contact, QString memo, QString requestZaddr, QString type, QString cid, QString txid, int confirmations, bool outgoing, bool notarize, bool iscontact); long getTimestamp(); QString getAddress(); QString getContact(); @@ -38,6 +39,7 @@ class ChatItem bool isOutgoing(); bool isdouble(); bool isNotarized(); + bool isContact(); void setTimestamp(long timestamp); void setAddress(QString address); void setContact(QString contact); @@ -49,6 +51,7 @@ class ChatItem void setConfirmations(int confirmations); void toggleOutgo(); void notarized(); + void contact(bool iscontact); QString toChatLine(); json toJson(); ~ChatItem(); diff --git a/src/Model/ContactItem.cpp b/src/Model/ContactItem.cpp index d38c1c5..d2321bd 100644 --- a/src/Model/ContactItem.cpp +++ b/src/Model/ContactItem.cpp @@ -1,4 +1,9 @@ +// Copyright 2019-2020 The Hush developers +// GPLv3 #include "ContactItem.h" +#include "chatmodel.h" +#include "Model/ChatItem.h" +#include "controller.h" ContactItem::ContactItem() {} @@ -8,7 +13,7 @@ ContactItem::ContactItem(QString name, QString partnerAddress, QString myAddress _myAddress = myAddress; _partnerAddress = partnerAddress; _cid = cid; - _avatar = avatar; + _avatar = avatar; } QString ContactItem::getName() const diff --git a/src/Model/ContactItem.h b/src/Model/ContactItem.h index f066740..7eda17d 100644 --- a/src/Model/ContactItem.h +++ b/src/Model/ContactItem.h @@ -1,8 +1,11 @@ +// Copyright 2019-2020 The Hush developers +// GPLv3 #ifndef CONTACTITEM_H #define CONTACTITEM_H #include #include +#include "mainwindow.h" using json = nlohmann::json; class ContactItem @@ -13,7 +16,7 @@ private: QString _name; QString _cid; QString _avatar; - + public: ContactItem(); ContactItem(QString name, QString partnerAddress, QString myAddress, QString cid, QString avatar); diff --git a/src/addressbook.cpp b/src/addressbook.cpp index f51e279..808ca40 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -40,7 +40,10 @@ void AddressBookModel::loadData() QSettings().value( "addresstablegeometry" ).toByteArray() + + ); + } void AddressBookModel::addNewLabel(QString label, QString addr, QString myAddr, QString cid, QString avatar) diff --git a/src/addressbook.h b/src/addressbook.h index 8e32fe8..fbd361b 100644 --- a/src/addressbook.h +++ b/src/addressbook.h @@ -23,6 +23,7 @@ public: int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role) const; + private: @@ -32,7 +33,8 @@ private: QTableView* parent; //QList> labels; QList labels; - QStringList headers; + QStringList headers; + }; class AddressBook { @@ -63,6 +65,10 @@ public: QString get_avatar_name(); void set_avatar_name(QString avatar_name); + + + + @@ -76,6 +82,7 @@ private: QString writeableFile(); QList allLabels; + static AddressBook* instance; }; diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index b0acb38..7bc1688 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -71,6 +71,26 @@ void ChatModel::showMessages() } } + +void ChatModel::addAddressbylabel(QString address, QString label) +{ + this->AddressbyLabelMap[address] = label; +} + +QString ChatModel::Addressbylabel(QString address) +{ + for(auto& pair : this->AddressbyLabelMap) + { + + } + + if(this->AddressbyLabelMap.count(address) > 0) + { + return this->AddressbyLabelMap[address]; + } + + return QString("0xdeadbeef"); +} void MainWindow::renderContactRequest(){ @@ -89,17 +109,22 @@ void MainWindow::renderContactRequest(){ contactRequest->appendRow(Items); requestContact.requestContact->setModel(contactRequest); requestContact.requestContact->show(); + requestContact.zaddrnew->setVisible(false); + requestContact.zaddrnew->setText(c.second.getAddress()); } QStandardItemModel* contactRequestOld = new QStandardItemModel(); + for (auto &p : AddressBook::getInstance()->getAllAddressLabels()) for (auto &c : DataStore::getChatDataStore()->getAllOldContactRequests()) { if (p.getPartnerAddress() == c.second.getRequestZaddr()) { - QStandardItem* Items = new QStandardItem(c.second.getAddress()); + QStandardItem* Items = new QStandardItem(p.getName()); contactRequestOld->appendRow(Items); requestContact.requestContactOld->setModel(contactRequestOld); + requestContact.zaddrold->setVisible(false); + requestContact.zaddrold->setText(c.second.getAddress()); requestContact.requestContactOld->show(); }else{} } @@ -135,11 +160,11 @@ void MainWindow::renderContactRequest(){ QObject::connect(requestContact.requestContactOld, &QTableView::clicked, [&] () { for (auto &c : DataStore::getChatDataStore()->getAllRawChatItems()){ - QModelIndex index = requestContact.requestContactOld->currentIndex(); - QString label_contactold = index.data(Qt::DisplayRole).toString(); + /* QModelIndex index = requestContact.requestContactOld->currentIndex(); + QString label_contactold = index.data(Qt::DisplayRole).toString();*/ QStandardItemModel* contactMemo = new QStandardItemModel(); - if ((c.second.isOutgoing() == false) && (label_contactold == c.second.getAddress()) && (c.second.getType() != "Cont")) + if ((c.second.isOutgoing() == false) && (requestContact.zaddrold->text() == c.second.getAddress()) && (c.second.getType() != "Cont")) { @@ -809,7 +834,7 @@ QString MainWindow::doSendRequestTxValidations(Tx tx) { auto available = rpc->getModel()->getAvailableBalance(); if (available < total) { - return tr("Not enough available funds to send this transaction\n\nHave: %1\nNeed: %2\n\nNote: Funds need 5 confirmations before they can be spent") + return tr("Not enough available funds to send this transaction\n\nHave: %1\nNeed: %2\n\nNote: Funds need 1 confirmations before they can be spent") .arg(available.toDecimalhushString(), total.toDecimalhushString()); } diff --git a/src/chatmodel.h b/src/chatmodel.h index 7ca5a0f..1768b9f 100644 --- a/src/chatmodel.h +++ b/src/chatmodel.h @@ -20,6 +20,7 @@ #include "Chat/Helper/ChatDelegator.h" #include "Chat/Helper/ChatIDGenerator.h" + namespace Ui { class MainWindow; } @@ -34,6 +35,7 @@ class ChatModel std::map requestZaddrMap; std::map confirmationsMap; std::map> sendrequestMap; + std::map AddressbyLabelMap; public: ChatModel() {}; @@ -46,6 +48,7 @@ class ChatModel void triggerRequest(); void showMessages(); void clear(); + void addAddressbylabel(QString addr, QString label); void addMessage(ChatItem item); void addMessage(QString timestamp, ChatItem item); void addCid(QString tx, QString cid); @@ -55,10 +58,11 @@ class ChatModel QString getCidByTx(QString tx); QString getrequestZaddrByTx(QString tx); QString getConfirmationByTx(QString tx); + QString Addressbylabel(QString addr); void killCidCache(); void killConfirmationCache(); void killrequestZaddrCache(); - + }; #endif \ No newline at end of file diff --git a/src/contactmodel.h b/src/contactmodel.h index f361ceb..5f79c47 100644 --- a/src/contactmodel.h +++ b/src/contactmodel.h @@ -15,8 +15,7 @@ class ContactModel ContactModel() {} void renderContactList(QListView* view); - - + }; #endif \ No newline at end of file diff --git a/src/controller.cpp b/src/controller.cpp index 10b41bb..83ee2e4 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -935,7 +935,8 @@ void Controller::refreshTransactions() { txid, confirmations, true, - isNotarized + isNotarized, + false ); DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); @@ -991,6 +992,28 @@ void Controller::refreshTransactions() { QString cid; int position; QString requestZaddr; + bool isContact; + + + for (auto &p : AddressBook::getInstance()->getAllAddressLabels()) + { + + if (p.getPartnerAddress() == requestZaddr) + { + + chatModel->addAddressbylabel(address, requestZaddr); + } else{} + + + if (chatModel->Addressbylabel(address) != QString("0xdeadbeef")){ + + isContact = true; + + }else{ + + isContact = false; + + } if (!it["memo"].is_null()) { @@ -1005,7 +1028,8 @@ void Controller::refreshTransactions() { chatModel->addCid(txid, cid); chatModel->addrequestZaddr(txid, requestZaddr); - } + } + if (chatModel->getCidByTx(txid) != QString("0xdeadbeef")){ @@ -1045,16 +1069,16 @@ void Controller::refreshTransactions() { txid, confirmations, false, - isNotarized + isNotarized, + isContact ); - qDebug()<< "Notarized : " << isNotarized; - + DataStore::getChatDataStore()->setData(ChatIDGenerator::getInstance()->generateID(item), item); } } - + } } - qDebug()<< getLag(); + qDebug()<<"get Lag" << getLag(); // Calculate the total unspent amount that's pending. This will need to be // shown in the UI so the user can keep track of pending funds diff --git a/src/controller.h b/src/controller.h index f35d636..9fd445b 100644 --- a/src/controller.h +++ b/src/controller.h @@ -1,3 +1,6 @@ +// Copyright 2019-2020 The Hush developers +// GPLv3 + #ifndef RPCCLIENT_H #define RPCCLIENT_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index de2583e..7db28cf 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1358,7 +1358,6 @@ void MainWindow::setupchatTab() { } }); - QMenu* contextMenu; QAction* requestAction; QAction* editAction; @@ -1397,7 +1396,6 @@ void MainWindow::setupchatTab() { for(auto &p : AddressBook::getInstance()->getAllAddressLabels()) if (label_contact == p.getName()) { - QString label1 = p.getName(); QString addr = p.getPartnerAddress(); @@ -1407,7 +1405,6 @@ void MainWindow::setupchatTab() { AddressBook::getInstance()->removeAddressLabel(label1, addr, myzaddr, cid,avatar); - // QList labels = AddressBook::getInstance()->getAllAddressLabels(); rpc->refreshContacts( ui->listContactWidget); rpc->refresh(true); @@ -1424,13 +1421,11 @@ void MainWindow::updateChat() { rpc->refreshChat(ui->listChat,ui->memoSizeChat); rpc->refresh(true); - - } void MainWindow::updateContacts() { - //rpc->refreshContacts(ui->listContactWidget); + } void MainWindow::addNewZaddr(bool sapling) { diff --git a/src/requestContactDialog.ui b/src/requestContactDialog.ui index 2eb4bc0..242e3ba 100644 --- a/src/requestContactDialog.ui +++ b/src/requestContactDialog.ui @@ -6,7 +6,7 @@ 0 0 - 812 + 850 495 @@ -27,7 +27,7 @@ - + <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Memo of the request</span></p></body></html> @@ -97,12 +97,12 @@ - + 256 - 192 + 190 @@ -119,14 +119,21 @@ - + + + + <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Details of the request</span></p></body></html> + + + + Request from : - + @@ -142,14 +149,14 @@ - + My Zaddr : - + @@ -165,24 +172,24 @@ - + Give a Nickname: - + - + <html><head/><body><p align="right">Choose a avatar for your contact :</p></body></html> - + @@ -328,7 +335,7 @@ - + @@ -353,7 +360,7 @@ - + @@ -369,17 +376,24 @@ - + - - + + - <html><head/><body><p align="center"><span style=" font-weight:600; text-decoration: underline;">Details of the request</span></p></body></html> + + + + + + + + diff --git a/src/sendtab.cpp b/src/sendtab.cpp index de61cf2..ce04a54 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -937,7 +937,7 @@ QString MainWindow::doSendTxValidations(Tx tx) { auto available = rpc->getModel()->getAvailableBalance(); if (available < total) { - return tr("Not enough available funds to send this transaction\n\nHave: %1\nNeed: %2\n\nNote: Funds need 5 confirmations before they can be spent") + return tr("Not enough available funds to send this transaction\n\nHave: %1\nNeed: %2\n\nNote: Funds need 1 confirmations before they can be spent") .arg(available.toDecimalhushString(), total.toDecimalhushString()); }