Merge pull request #2 from strider-paff-shell/chat
update//add chatmodel.h chatmodel.cpp to realize the whole chat history
This commit is contained in:
@@ -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 \
|
||||
|
||||
72
src/chatmodel.cpp
Normal file
72
src/chatmodel.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "chatmodel.h"
|
||||
|
||||
ChatModel::ChatModel(std::map<long, ChatItem> chatItems)
|
||||
{
|
||||
this->chatItems = chatItems;
|
||||
}
|
||||
|
||||
ChatModel::ChatModel(std::vector<ChatItem> chatItems)
|
||||
{
|
||||
this->setItems(chatItems);
|
||||
}
|
||||
|
||||
std::map<long, ChatItem> ChatModel::getItems()
|
||||
{
|
||||
return this->chatItems;
|
||||
}
|
||||
|
||||
void ChatModel::setItems(std::map<long, ChatItem> items)
|
||||
{
|
||||
this->chatItems = chatItems;
|
||||
}
|
||||
|
||||
void ChatModel::setItems(std::vector<ChatItem> 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] <Contactname|Me>: 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] <Contactname|Me>: lorem ipsum ...."));
|
||||
}*/
|
||||
qDebug() << "not implemented yet blyat";
|
||||
//todo render items to view
|
||||
}
|
||||
119
src/chatmodel.h
Normal file
119
src/chatmodel.h
Normal file
@@ -0,0 +1,119 @@
|
||||
#ifndef CHATMODEL_H
|
||||
#define CHATMODEL_H
|
||||
#include <QString>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <QListView>
|
||||
|
||||
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)
|
||||
{
|
||||
_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()
|
||||
{
|
||||
return _timestamp;
|
||||
}
|
||||
|
||||
QString getAddress()
|
||||
{
|
||||
return _address;
|
||||
}
|
||||
|
||||
QString getContact()
|
||||
{
|
||||
return _contact;
|
||||
}
|
||||
|
||||
QString getMemo()
|
||||
{
|
||||
return _memo;
|
||||
}
|
||||
|
||||
bool isOutgoing()
|
||||
{
|
||||
return _outgoing;
|
||||
}
|
||||
|
||||
void setTimestamp(long timestamp)
|
||||
{
|
||||
_timestamp = timestamp;
|
||||
}
|
||||
|
||||
void setAddress(QString address)
|
||||
{
|
||||
_address = address;
|
||||
}
|
||||
|
||||
void setContact(QString contact)
|
||||
{
|
||||
_contact = contact;
|
||||
}
|
||||
|
||||
void setMemo(QString memo)
|
||||
{
|
||||
_memo = memo;
|
||||
}
|
||||
|
||||
void toggleOutgo()
|
||||
{
|
||||
_outgoing = true;
|
||||
}
|
||||
|
||||
~ChatItem()
|
||||
{
|
||||
/*delete timestamp;
|
||||
delete address;
|
||||
delete contact;
|
||||
delete memo;
|
||||
delete outgoing;*/
|
||||
}
|
||||
};
|
||||
|
||||
class ChatModel
|
||||
{
|
||||
private:
|
||||
std::map<long, ChatItem> chatItems;
|
||||
|
||||
public:
|
||||
ChatModel() {};
|
||||
ChatModel(std::map<long, ChatItem> chatItems);
|
||||
ChatModel(std::vector<ChatItem> chatItems);
|
||||
std::map<long, ChatItem> getItems();
|
||||
void setItems(std::map<long, ChatItem> items);
|
||||
void setItems(std::vector<ChatItem> items);
|
||||
void renderChatBox(QListView &view);
|
||||
void renderChatBox(QListView *view);
|
||||
void showMessages();
|
||||
void clear();
|
||||
void addMessage(ChatItem item);
|
||||
void addMessage(long timestamp, ChatItem item);
|
||||
};
|
||||
#endif
|
||||
@@ -10,6 +10,7 @@ template<>
|
||||
DataStore<QString>* DataStore<QString>::instance = nullptr;
|
||||
template<>
|
||||
bool DataStore<QString>::instanced = false;
|
||||
ChatModel *chatModel = new ChatModel();
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
@@ -876,7 +877,19 @@ void Controller::refreshTransactions()
|
||||
|
||||
QString memo;
|
||||
if (!o["memo"].is_null())
|
||||
{
|
||||
memo = QString::fromStdString(o["memo"]);
|
||||
ChatItem item = ChatItem(
|
||||
datetime,
|
||||
address,
|
||||
QString(""),
|
||||
memo,
|
||||
true // is an outgoing message
|
||||
);
|
||||
chatModel->addMessage(item);
|
||||
|
||||
}
|
||||
|
||||
|
||||
items.push_back(TransactionItemDetail{address, amount, memo});
|
||||
total_amount = total_amount + amount;
|
||||
@@ -913,7 +926,17 @@ void Controller::refreshTransactions()
|
||||
model->markAddressUsed(address);
|
||||
QString memo;
|
||||
if (!it["memo"].is_null())
|
||||
{
|
||||
memo = QString::fromStdString(it["memo"]);
|
||||
ChatItem item = ChatItem(
|
||||
datetime,
|
||||
address,
|
||||
QString(""),
|
||||
memo
|
||||
);
|
||||
chatModel->addMessage(item);
|
||||
}
|
||||
|
||||
|
||||
items.push_back(
|
||||
TransactionItemDetail{
|
||||
@@ -958,7 +981,9 @@ void Controller::refreshTransactions()
|
||||
updateUIBalances();
|
||||
|
||||
// Update model data, which updates the table view
|
||||
transactionsTableModel->replaceData(txdata);
|
||||
transactionsTableModel->replaceData(txdata);
|
||||
//chatModel->renderChatBox();
|
||||
chatModel->showMessages();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "liteinterface.h"
|
||||
#include "connection.h"
|
||||
#include "chatmodel.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user