update// fixed stuff
This commit is contained in:
@@ -28,22 +28,45 @@ void ChatModel::setItems(std::vector<ChatItem> items)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
void ChatModel::renderChatBox(QListView &view)
|
||||||
{
|
{
|
||||||
for(ChatItem c : items)
|
/*for(auto &c : this->chatItems)
|
||||||
{
|
{
|
||||||
view.getItems().add(QString("[Timestamp] <Contactname|Me>: lorem ipsum ...."));
|
//view.getItems().add(QString("[Timestamp] <Contactname|Me>: lorem ipsum ...."));
|
||||||
}
|
}*/
|
||||||
|
qDebug() << "not implemented yet";
|
||||||
//todo render items to view
|
//todo render items to view
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatModel::renderChatBox(QListView *view)
|
void ChatModel::renderChatBox(QListView *view)
|
||||||
{
|
{
|
||||||
for(ChatItem c : items)
|
/*for(auto &c : this->chatItems)
|
||||||
{
|
{
|
||||||
view->getItems().add(QString("[Timestamp] <Contactname|Me>: lorem ipsum ...."));
|
//view->getItems().add(QString("[Timestamp] <Contactname|Me>: lorem ipsum ...."));
|
||||||
}
|
}*/
|
||||||
|
qDebug() << "not implemented yet blyat";
|
||||||
//todo render items to view
|
//todo render items to view
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include <string>
|
#include <QString>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
@@ -7,32 +7,32 @@ class ChatItem
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
long timestamp;
|
long timestamp;
|
||||||
std::string address;
|
QString address;
|
||||||
std::string contact;
|
QString contact;
|
||||||
std::string memo;
|
QString memo;
|
||||||
bool outgoing = false;
|
bool outgoing = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ChatItem() {}
|
ChatItem() {}
|
||||||
ChatItem(long timestamp, std::string address, std::string contact, std::string memo);
|
ChatItem(long timestamp, QString address, QString contact, QString 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, bool outgoing = false);
|
||||||
|
|
||||||
long getTimestamp()
|
long getTimestamp()
|
||||||
{
|
{
|
||||||
return this->timestamp;
|
return this->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getAddress()
|
QString getAddress()
|
||||||
{
|
{
|
||||||
return this->address;
|
return this->address;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getContact()
|
QString getContact()
|
||||||
{
|
{
|
||||||
return this->contact;
|
return this->contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getMemo()
|
QString getMemo()
|
||||||
{
|
{
|
||||||
return this->memo;
|
return this->memo;
|
||||||
}
|
}
|
||||||
@@ -47,17 +47,17 @@ class ChatItem
|
|||||||
this->timestamp = timestamp;
|
this->timestamp = timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAddress(std::string address)
|
void setAddress(QString address)
|
||||||
{
|
{
|
||||||
this->address = address;
|
this->address = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setContact(std::string contact)
|
void setContact(QString contact)
|
||||||
{
|
{
|
||||||
this->contact = contact;
|
this->contact = contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMemo(std::string memo)
|
void setMemo(QString memo)
|
||||||
{
|
{
|
||||||
this->memo = memo;
|
this->memo = memo;
|
||||||
}
|
}
|
||||||
@@ -69,11 +69,11 @@ class ChatItem
|
|||||||
|
|
||||||
~ChatItem()
|
~ChatItem()
|
||||||
{
|
{
|
||||||
delete timestamp;
|
/*delete timestamp;
|
||||||
delete address;
|
delete address;
|
||||||
delete contact;
|
delete contact;
|
||||||
delete memo;
|
delete memo;
|
||||||
delete outgoing;
|
delete outgoing;*/
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -91,4 +91,8 @@ class ChatModel
|
|||||||
void setItems(std::vector<ChatItem> items);
|
void setItems(std::vector<ChatItem> items);
|
||||||
void renderChatBox(QListView &view);
|
void renderChatBox(QListView &view);
|
||||||
void renderChatBox(QListView *view);
|
void renderChatBox(QListView *view);
|
||||||
|
void showMessages();
|
||||||
|
void clear();
|
||||||
|
void addMessage(ChatItem item);
|
||||||
|
void addMessage(long timestamp, ChatItem item);
|
||||||
};
|
};
|
||||||
@@ -876,7 +876,18 @@ void Controller::refreshTransactions()
|
|||||||
|
|
||||||
QString memo;
|
QString memo;
|
||||||
if (!o["memo"].is_null())
|
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"]);
|
memo = QString::fromStdString(o["memo"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
items.push_back(TransactionItemDetail{address, amount, memo});
|
items.push_back(TransactionItemDetail{address, amount, memo});
|
||||||
total_amount = total_amount + amount;
|
total_amount = total_amount + amount;
|
||||||
@@ -913,6 +924,15 @@ void Controller::refreshTransactions()
|
|||||||
model->markAddressUsed(address);
|
model->markAddressUsed(address);
|
||||||
QString memo;
|
QString memo;
|
||||||
if (!it["memo"].is_null())
|
if (!it["memo"].is_null())
|
||||||
|
{
|
||||||
|
ChatItem item = ChatItem(
|
||||||
|
datetime,
|
||||||
|
address,
|
||||||
|
QString(""),
|
||||||
|
memo
|
||||||
|
);
|
||||||
|
chatModel->addMessage(item);
|
||||||
|
}
|
||||||
memo = QString::fromStdString(it["memo"]);
|
memo = QString::fromStdString(it["memo"]);
|
||||||
|
|
||||||
items.push_back(
|
items.push_back(
|
||||||
@@ -958,7 +978,9 @@ void Controller::refreshTransactions()
|
|||||||
updateUIBalances();
|
updateUIBalances();
|
||||||
|
|
||||||
// Update model data, which updates the table view
|
// Update model data, which updates the table view
|
||||||
transactionsTableModel->replaceData(txdata);
|
transactionsTableModel->replaceData(txdata);
|
||||||
|
//chatModel->renderChatBox();
|
||||||
|
chatModel->showMessages();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,12 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "liteinterface.h"
|
#include "liteinterface.h"
|
||||||
#include "connection.h"
|
#include "connection.h"
|
||||||
|
#include "chatmodel.h"
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
ChatModel *chatModel = new ChatModel();
|
||||||
|
|
||||||
struct WatchedTx {
|
struct WatchedTx {
|
||||||
QString opid;
|
QString opid;
|
||||||
Tx tx;
|
Tx tx;
|
||||||
|
|||||||
Reference in New Issue
Block a user