Merge branch 'chat' of https://github.com/strider-paff-shell/SilentDragonLite-1 into chat
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
|
||||
}
|
||||
98
src/chatmodel.h
Normal file
98
src/chatmodel.h
Normal file
@@ -0,0 +1,98 @@
|
||||
#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);
|
||||
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<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);
|
||||
};
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user