Browse Source

update// fixed stuff

pull/130/head
Strider 4 years ago
parent
commit
008d3fd6c2
  1. 39
      src/chatmodel.cpp
  2. 32
      src/chatmodel.h
  3. 24
      src/controller.cpp
  4. 3
      src/controller.h

39
src/chatmodel.cpp

@ -28,22 +28,45 @@ void ChatModel::setItems(std::vector<ChatItem> items)
}
}
void ChatModel::renderChatBox(QListView &view)
void ChatModel::clear()
{
for(ChatItem c : items)
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)
{
view.getItems().add(QString("[Timestamp] <Contactname|Me>: lorem ipsum ...."));
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(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
}

32
src/chatmodel.h

@ -1,4 +1,4 @@
#include <string>
#include <QString>
#include <map>
#include <vector>
#include <QListView>
@ -7,32 +7,32 @@ class ChatItem
{
private:
long timestamp;
std::string address;
std::string contact;
std::string memo;
QString address;
QString contact;
QString memo;
bool outgoing = false;
public:
ChatItem() {}
ChatItem(long timestamp, std::string address, std::string contact, std::string 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);
ChatItem(long timestamp, QString address, QString contact, QString memo, bool outgoing = false);
long getTimestamp()
{
return this->timestamp;
}
std::string getAddress()
QString getAddress()
{
return this->address;
}
std::string getContact()
QString getContact()
{
return this->contact;
}
std::string getMemo()
QString getMemo()
{
return this->memo;
}
@ -47,17 +47,17 @@ class ChatItem
this->timestamp = timestamp;
}
void setAddress(std::string address)
void setAddress(QString address)
{
this->address = address;
}
void setContact(std::string contact)
void setContact(QString contact)
{
this->contact = contact;
}
void setMemo(std::string memo)
void setMemo(QString memo)
{
this->memo = memo;
}
@ -69,11 +69,11 @@ class ChatItem
~ChatItem()
{
delete timestamp;
/*delete timestamp;
delete address;
delete contact;
delete memo;
delete outgoing;
delete outgoing;*/
}
};
@ -91,4 +91,8 @@ class ChatModel
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);
};

24
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();
});
}

3
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;

Loading…
Cancel
Save