diff --git a/silentdragon-lite.pro b/silentdragon-lite.pro index e8c50d5..b692159 100644 --- a/silentdragon-lite.pro +++ b/silentdragon-lite.pro @@ -67,7 +67,8 @@ SOURCES += \ src/liteinterface.cpp \ src/camount.cpp \ src/chatbubbleme.cpp \ - src/chatbubblepartner.cpp + src/chatbubblepartner.cpp \ + src/chatmodel.cpp HEADERS += \ src/firsttimewizard.h \ @@ -98,7 +99,8 @@ HEADERS += \ src/camount.h \ lib/silentdragonlitelib.h \ src/chatbubbleme.h \ - src/chatbubblepartner.h + src/chatbubblepartner.h \ + src/chatmodel.h FORMS += \ src/encryption.ui \ diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp new file mode 100644 index 0000000..f6fbb84 --- /dev/null +++ b/src/chatmodel.cpp @@ -0,0 +1,72 @@ +#include "chatmodel.h" + +ChatModel::ChatModel(std::map chatItems) +{ + this->chatItems = chatItems; +} + +ChatModel::ChatModel(std::vector chatItems) +{ + this->setItems(chatItems); +} + +std::map ChatModel::getItems() +{ + return this->chatItems; +} + +void ChatModel::setItems(std::map items) +{ + this->chatItems = chatItems; +} + +void ChatModel::setItems(std::vector items) +{ + for(ChatItem c : items) + { + this->chatItems[c.getTimestamp()] = c; + } +} + +void ChatModel::clear() +{ + 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) + { + 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(auto &c : this->chatItems) + { + //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 new file mode 100644 index 0000000..5a35db9 --- /dev/null +++ b/src/chatmodel.h @@ -0,0 +1,98 @@ +#include +#include +#include +#include + +class ChatItem +{ + private: + long timestamp; + QString address; + QString contact; + QString memo; + bool outgoing = false; + + public: + ChatItem() {} + 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; + } + + QString getAddress() + { + return this->address; + } + + QString getContact() + { + return this->contact; + } + + QString getMemo() + { + return this->memo; + } + + bool isOutgoing() + { + return this->outgoing; + } + + void setTimestamp(long timestamp) + { + this->timestamp = timestamp; + } + + void setAddress(QString address) + { + this->address = address; + } + + void setContact(QString contact) + { + this->contact = contact; + } + + void setMemo(QString memo) + { + this->memo = memo; + } + + void toggleOutgo() + { + this->outgoing = true; + } + + ~ChatItem() + { + /*delete timestamp; + delete address; + delete contact; + delete memo; + delete outgoing;*/ + } +}; + +class ChatModel +{ + private: + std::map chatItems; + + public: + ChatModel() {}; + ChatModel(std::map chatItems); + ChatModel(std::vector chatItems); + std::map getItems(); + void setItems(std::map items); + 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;