From 008d3fd6c2fbe22c68e188f076c70d1aab0d45bf Mon Sep 17 00:00:00 2001 From: Strider Date: Sun, 26 Apr 2020 22:28:27 +0200 Subject: [PATCH] update// fixed stuff --- src/chatmodel.cpp | 39 +++++++++++++++++++++++++++++++-------- src/chatmodel.h | 32 ++++++++++++++++++-------------- src/controller.cpp | 24 +++++++++++++++++++++++- src/controller.h | 3 +++ 4 files changed, 75 insertions(+), 23 deletions(-) diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index b65bd4a..f6fbb84 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -28,22 +28,45 @@ void ChatModel::setItems(std::vector items) } } -void ChatModel::renderChatBox(QListView &view) +void ChatModel::clear() { - for(ChatItem c : items) + this->chatItems.clear(); +} + +void ChatModel::addMessage(ChatItem item) +{ + this->chatItems[item.getTimestamp()] = item; +} + +void ChatModel::addMessage(long timestamp, ChatItem item) +{ + this->chatItems[timestamp] = item; +} + +void ChatModel::showMessages() +{ + for(auto &c : this->chatItems) { - view.getItems().add(QString("[Timestamp] : lorem ipsum ....")); + qDebug() << "[" << c.second.getTimestamp() << "] " << "<" << c.second.getAddress() << "> :" << c.second.getMemo(); } - +} + +void ChatModel::renderChatBox(QListView &view) +{ + /*for(auto &c : this->chatItems) + { + //view.getItems().add(QString("[Timestamp] : lorem ipsum ....")); + }*/ + qDebug() << "not implemented yet"; //todo render items to view } void ChatModel::renderChatBox(QListView *view) { - for(ChatItem c : items) + /*for(auto &c : this->chatItems) { - view->getItems().add(QString("[Timestamp] : lorem ipsum ....")); - } - + //view->getItems().add(QString("[Timestamp] : lorem ipsum ....")); + }*/ + qDebug() << "not implemented yet blyat"; //todo render items to view } \ No newline at end of file diff --git a/src/chatmodel.h b/src/chatmodel.h index 5dd8904..5a35db9 100644 --- a/src/chatmodel.h +++ b/src/chatmodel.h @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -7,32 +7,32 @@ class ChatItem { private: long timestamp; - std::string address; - std::string contact; - std::string memo; + QString address; + QString contact; + QString memo; bool outgoing = false; public: ChatItem() {} - ChatItem(long timestamp, std::string address, std::string contact, std::string memo); - ChatItem(long timestamp, std::string address, std::string contact, std::string memo, bool outgoing = false); + ChatItem(long timestamp, QString address, QString contact, QString memo); + ChatItem(long timestamp, QString address, QString contact, QString memo, bool outgoing = false); long getTimestamp() { return this->timestamp; } - std::string getAddress() + QString getAddress() { return this->address; } - std::string getContact() + QString getContact() { return this->contact; } - std::string getMemo() + QString getMemo() { return this->memo; } @@ -47,17 +47,17 @@ class ChatItem this->timestamp = timestamp; } - void setAddress(std::string address) + void setAddress(QString address) { this->address = address; } - void setContact(std::string contact) + void setContact(QString contact) { this->contact = contact; } - void setMemo(std::string memo) + void setMemo(QString memo) { this->memo = memo; } @@ -69,11 +69,11 @@ class ChatItem ~ChatItem() { - delete timestamp; + /*delete timestamp; delete address; delete contact; delete memo; - delete outgoing; + delete outgoing;*/ } }; @@ -91,4 +91,8 @@ class ChatModel void setItems(std::vector items); void renderChatBox(QListView &view); void renderChatBox(QListView *view); + void showMessages(); + void clear(); + void addMessage(ChatItem item); + void addMessage(long timestamp, ChatItem item); }; \ No newline at end of file diff --git a/src/controller.cpp b/src/controller.cpp index 18a158e..0661b06 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -876,7 +876,18 @@ void Controller::refreshTransactions() QString memo; if (!o["memo"].is_null()) + { + ChatItem item = ChatItem( + datetime, + address, + QString(""), + memo, + true // is an outgoing message + ); + chatModel->addMessage(item); memo = QString::fromStdString(o["memo"]); + } + items.push_back(TransactionItemDetail{address, amount, memo}); total_amount = total_amount + amount; @@ -913,6 +924,15 @@ void Controller::refreshTransactions() model->markAddressUsed(address); QString memo; if (!it["memo"].is_null()) + { + ChatItem item = ChatItem( + datetime, + address, + QString(""), + memo + ); + chatModel->addMessage(item); + } memo = QString::fromStdString(it["memo"]); items.push_back( @@ -958,7 +978,9 @@ void Controller::refreshTransactions() updateUIBalances(); // Update model data, which updates the table view - transactionsTableModel->replaceData(txdata); + transactionsTableModel->replaceData(txdata); + //chatModel->renderChatBox(); + chatModel->showMessages(); }); } diff --git a/src/controller.h b/src/controller.h index 29d5c0d..5071dee 100644 --- a/src/controller.h +++ b/src/controller.h @@ -11,9 +11,12 @@ #include "mainwindow.h" #include "liteinterface.h" #include "connection.h" +#include "chatmodel.h" using json = nlohmann::json; +ChatModel *chatModel = new ChatModel(); + struct WatchedTx { QString opid; Tx tx;