This commit is contained in:
DenioD
2020-04-27 20:37:43 +02:00
3 changed files with 44 additions and 22 deletions

View File

@@ -1,3 +1,5 @@
#ifndef CHATMODEL_H
#define CHATMODEL_H
#include <QString> #include <QString>
#include <map> #include <map>
#include <vector> #include <vector>
@@ -6,65 +8,83 @@
class ChatItem class ChatItem
{ {
private: private:
long timestamp; long _timestamp;
QString address; QString _address;
QString contact; QString _contact;
QString memo; QString _memo;
bool outgoing = false; bool _outgoing = false;
public: public:
ChatItem() {} ChatItem() {}
ChatItem(long timestamp, QString address, QString contact, QString memo);
ChatItem(long timestamp, QString address, QString contact, QString memo, bool outgoing = false); ChatItem(long timestamp, QString address, QString contact, QString memo)
{
_timestamp = timestamp;
_address = address;
_contact = contact;
_memo = memo;
_outgoing = false;
}
ChatItem(long timestamp, QString address, QString contact, QString memo, bool outgoing)
{
_timestamp = timestamp;
_address = address;
_contact = contact;
_memo = memo;
_outgoing = outgoing;
}
long getTimestamp() long getTimestamp()
{ {
return this->timestamp; return _timestamp;
} }
QString getAddress() QString getAddress()
{ {
return this->address; return _address;
} }
QString getContact() QString getContact()
{ {
return this->contact; return _contact;
} }
QString getMemo() QString getMemo()
{ {
return this->memo; return _memo;
} }
bool isOutgoing() bool isOutgoing()
{ {
return this->outgoing; return _outgoing;
} }
void setTimestamp(long timestamp) void setTimestamp(long timestamp)
{ {
this->timestamp = timestamp; _timestamp = timestamp;
} }
void setAddress(QString address) void setAddress(QString address)
{ {
this->address = address; _address = address;
} }
void setContact(QString contact) void setContact(QString contact)
{ {
this->contact = contact; _contact = contact;
} }
void setMemo(QString memo) void setMemo(QString memo)
{ {
this->memo = memo; _memo = memo;
} }
void toggleOutgo() void toggleOutgo()
{ {
this->outgoing = true; _outgoing = true;
} }
~ChatItem() ~ChatItem()
@@ -96,3 +116,4 @@ class ChatModel
void addMessage(ChatItem item); void addMessage(ChatItem item);
void addMessage(long timestamp, ChatItem item); void addMessage(long timestamp, ChatItem item);
}; };
#endif

View File

@@ -10,6 +10,7 @@ template<>
DataStore<QString>* DataStore<QString>::instance = nullptr; DataStore<QString>* DataStore<QString>::instance = nullptr;
template<> template<>
bool DataStore<QString>::instanced = false; bool DataStore<QString>::instanced = false;
ChatModel *chatModel = new ChatModel();
using json = nlohmann::json; using json = nlohmann::json;
@@ -877,6 +878,7 @@ void Controller::refreshTransactions()
QString memo; QString memo;
if (!o["memo"].is_null()) if (!o["memo"].is_null())
{ {
memo = QString::fromStdString(o["memo"]);
ChatItem item = ChatItem( ChatItem item = ChatItem(
datetime, datetime,
address, address,
@@ -885,7 +887,7 @@ void Controller::refreshTransactions()
true // is an outgoing message true // is an outgoing message
); );
chatModel->addMessage(item); chatModel->addMessage(item);
memo = QString::fromStdString(o["memo"]);
} }
@@ -925,6 +927,7 @@ void Controller::refreshTransactions()
QString memo; QString memo;
if (!it["memo"].is_null()) if (!it["memo"].is_null())
{ {
memo = QString::fromStdString(it["memo"]);
ChatItem item = ChatItem( ChatItem item = ChatItem(
datetime, datetime,
address, address,
@@ -933,7 +936,7 @@ void Controller::refreshTransactions()
); );
chatModel->addMessage(item); chatModel->addMessage(item);
} }
memo = QString::fromStdString(it["memo"]);
items.push_back( items.push_back(
TransactionItemDetail{ TransactionItemDetail{

View File

@@ -15,8 +15,6 @@
using json = nlohmann::json; using json = nlohmann::json;
ChatModel *chatModel = new ChatModel();
struct WatchedTx { struct WatchedTx {
QString opid; QString opid;
Tx tx; Tx tx;