Browse Source

render only memos from selected nickname

pull/130/head
DenioD 4 years ago
parent
commit
8f3bc21844
  1. 57
      src/chatmodel.cpp
  2. 11
      src/chatmodel.h
  3. 4
      src/controller.cpp
  4. 12
      src/mainwindow.cpp
  5. 2
      src/mainwindow.h
  6. 8
      src/mainwindow.ui

57
src/chatmodel.cpp

@ -64,7 +64,7 @@ void ChatModel::showMessages()
void ChatModel::renderChatBox(QListWidget &view) void ChatModel::renderChatBox(Ui::MainWindow* ui, QListWidget &view)
{ {
/*for(auto &c : this->chatItems) /*for(auto &c : this->chatItems)
{ {
@ -74,49 +74,36 @@ void ChatModel::renderChatBox(QListWidget &view)
//todo render items to view //todo render items to view
} }
void ChatModel::renderChatBox(QListWidget *view) void ChatModel::renderChatBox(Ui::MainWindow* ui, QListWidget *view)
{ {
qDebug() << "called ChatModel::renderChatBox(QListWidget *view)";
QString line = "";
while(view->count() > 0) while(view->count() > 0)
{ {
view->takeItem(0); view->takeItem(0);
} }
for(auto &c : this->chatItems)
{
if (c.second.getMemo().startsWith("{\n \"c\": \"true\"")){
// Render a incoming contact Request
}
if (c.second.getMemo().startsWith("{\n \"c\": \"false\"") ){
// we dont want to render this
}
if (c.second.getMemo().startsWith("{") == false){ //TOdo and is selected in Contact Widget -
QString line = "";
for(auto &c : this->chatItems){
QDateTime myDateTime; QDateTime myDateTime;
myDateTime.setTime_t(c.second.getTimestamp()); myDateTime.setTime_t(c.second.getTimestamp());
//qDebug() << "[" << myDateTime.toString("dd.MM.yyyy hh:mm:ss ") << "] " << "<" << c.second.getAddress() << "> :" << c.second.getMemo();
//////
if ((ui->ContactZaddr->text().trimmed() == c.second.getAddress()) && (c.second.getMemo().startsWith("{") == false)) {
line += QString("[") + myDateTime.toString("dd.MM.yyyy hh:mm:ss ") + QString("] "); line += QString("[") + myDateTime.toString("dd.MM.yyyy hh:mm:ss ") + QString("] ");
line += QString("<") + QString(c.second.getContact()) + QString("> :\n"); line += QString("<") + QString(c.second.getContact()) + QString("> :\n");
line += QString(c.second.getMemo()) + QString("\n"); line += QString(c.second.getMemo()) + QString("\n");
view->addItem(line); view->addItem(line);
line =""; line ="";
} }else {}
} }
} }
QString MainWindow::createHeaderMemo(QString safeContact, QString cid, QString zaddr, int version=0, int headerNumber=1) QString MainWindow::createHeaderMemo(QString type, QString cid, QString zaddr, int version=0, int headerNumber=1)
{ {
QString header=""; QString header="";
@ -128,15 +115,15 @@ QString MainWindow::createHeaderMemo(QString safeContact, QString cid, QString z
h["v"] = version; // HushChat version h["v"] = version; // HushChat version
h["z"] = zaddr; // zaddr to respond to h["z"] = zaddr; // zaddr to respond to
h["cid"] = cid; // conversation id h["cid"] = cid; // conversation id
h["c"] = safeContact; // Is this a safe Contact request? h["t"] = type; // Memo or incoming contact request
j.setObject(h); j.setObject(h);
header = j.toJson(); header = j.toJson();
qDebug() << "made header=" << header; qDebug() << "made header=" << header;
return header; return header;
} }
// Create a Tx from the current state of the Chat page. // Create a Tx from the current state of the Chat page.
Tx MainWindow::createTxFromChatPage() { Tx MainWindow::createTxFromChatPage() {
Tx tx; Tx tx;
@ -144,9 +131,9 @@ Tx MainWindow::createTxFromChatPage() {
// For each addr/amt in the Chat tab // For each addr/amt in the Chat tab
{ {
QString addr = ui->ContactZaddr->text().trimmed(); // We need to set the reply Address for our Contact here // QString addr = ui->ContactZaddr->text().trimmed(); // We need to set the reply Address for our Contact here
// Remove label if it exists // Remove label if it exists
addr = AddressBook::addressFromAddressLabel(addr); // addr = AddressBook::addressFromAddressLabel(addr);
QString amtStr = "0"; QString amtStr = "0";
@ -160,15 +147,15 @@ Tx MainWindow::createTxFromChatPage() {
for(auto &c : AddressBook::getInstance()->getAllAddressLabels()) for(auto &c : AddressBook::getInstance()->getAllAddressLabels())
if (ui->ContactZaddr->text().trimmed() == c.getName()) { if (ui->ContactZaddr->text().trimmed() == c.getPartnerAddress()) {
QString cid = c.getCid(); QString cid = c.getCid();
QString myAddr = c.getMyAddress(); QString myAddr = c.getMyAddress();
QString safeContact = "false"; QString type = "memo";
QString addr = c.getPartnerAddress(); QString addr = c.getPartnerAddress();
QString hmemo= createHeaderMemo(safeContact,cid,myAddr); QString hmemo= createHeaderMemo(type,cid,myAddr);
QString memo = ui->memoTxtChat->toPlainText().trimmed(); QString memo = ui->memoTxtChat->toPlainText().trimmed();
// ui->memoSizeChat->setLenDisplayLabel(); // ui->memoSizeChat->setLenDisplayLabel();
@ -229,6 +216,7 @@ void MainWindow::sendChatButton() {
connD->statusDetail->setText(tr("Your Message will be send")); connD->statusDetail->setText(tr("Your Message will be send"));
d->show(); d->show();
ui->memoTxtChat->clear();
// And send the Tx // And send the Tx
rpc->executeTransaction(tx, rpc->executeTransaction(tx,
@ -248,6 +236,7 @@ void MainWindow::sendChatButton() {
// Force a UI update so we get the unconfirmed Tx // Force a UI update so we get the unconfirmed Tx
rpc->refresh(true); rpc->refresh(true);
ui->memoTxtChat->clear();
}, },
// Errored out // Errored out

11
src/chatmodel.h

@ -5,6 +5,10 @@
#include <vector> #include <vector>
#include <QListWidget> #include <QListWidget>
#include "precompiled.h" #include "precompiled.h"
#include "mainwindow.h"
#include "controller.h"
#include "settings.h"
#include "camount.h"
class ChatItem class ChatItem
{ {
@ -103,6 +107,8 @@ class ChatModel
private: private:
std::map<long, ChatItem> chatItems; std::map<long, ChatItem> chatItems;
QTableView* parent; QTableView* parent;
Ui::MainWindow* ui;
MainWindow* main;
public: public:
ChatModel() {}; ChatModel() {};
@ -110,9 +116,10 @@ class ChatModel
ChatModel(std::vector<ChatItem> chatItems); ChatModel(std::vector<ChatItem> chatItems);
std::map<long, ChatItem> getItems(); std::map<long, ChatItem> getItems();
void setItems(std::map<long, ChatItem> items); void setItems(std::map<long, ChatItem> items);
QString zaddr();
void setItems(std::vector<ChatItem> items); void setItems(std::vector<ChatItem> items);
void renderChatBox(QListWidget &view); void renderChatBox(Ui::MainWindow* ui, QListWidget &view);
void renderChatBox(QListWidget *view); void renderChatBox(Ui::MainWindow* ui, QListWidget *view);
void showMessages(); void showMessages();
void clear(); void clear();
void addMessage(ChatItem item); void addMessage(ChatItem item);

4
src/controller.cpp

@ -985,7 +985,7 @@ void Controller::refreshTransactions()
// Update model data, which updates the table view // Update model data, which updates the table view
transactionsTableModel->replaceData(txdata); transactionsTableModel->replaceData(txdata);
chatModel->renderChatBox(ui->listChatMemo); chatModel->renderChatBox(ui, ui->listChatMemo);
refreshContacts( refreshContacts(
ui->listContactWidget ui->listContactWidget
); );
@ -994,7 +994,7 @@ void Controller::refreshTransactions()
void Controller::refreshChat(QListWidget *listWidget) void Controller::refreshChat(QListWidget *listWidget)
{ {
chatModel->renderChatBox(listWidget); chatModel->renderChatBox(ui, listWidget);
} }
void Controller::refreshContacts(QListWidget *listWidget) void Controller::refreshContacts(QListWidget *listWidget)

12
src/mainwindow.cpp

@ -994,10 +994,14 @@ void MainWindow::setupchatTab() {
QObject::connect(ui->listContactWidget, &QTableView::clicked, [=] () { QObject::connect(ui->listContactWidget, &QTableView::clicked, [=] () {
QModelIndex index = ui->listContactWidget->currentIndex(); QModelIndex index = ui->listContactWidget->currentIndex();
QString zaddr = index.data(Qt::DisplayRole).toString(); QString label_contact = index.data(Qt::DisplayRole).toString();
ui->ContactZaddr->setText(zaddr);
for(auto &p : AddressBook::getInstance()->getAllAddressLabels())
}); if (label_contact == p.getName())
ui->ContactZaddr->setText(p.getPartnerAddress());
rpc->refresh(true);
});
} }
ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QPlainTextEdit(parent) { ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QPlainTextEdit(parent) {

2
src/mainwindow.h

@ -77,7 +77,7 @@ public:
Logger* logger; Logger* logger;
void doClose(); void doClose();
QString createHeaderMemo(QString safeContact, QString cid, QString zaddr, int version, int headerNumber); QString createHeaderMemo(QString type, QString cid, QString zaddr, int version, int headerNumber);
public slots: public slots:
void slot_change_theme(const QString& themeName); void slot_change_theme(const QString& themeName);

8
src/mainwindow.ui

@ -1453,7 +1453,7 @@
<widget class="QLabel" name="label_42"> <widget class="QLabel" name="label_42">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>690</x> <x>520</x>
<y>490</y> <y>490</y>
<width>67</width> <width>67</width>
<height>17</height> <height>17</height>
@ -1479,10 +1479,10 @@
<widget class="QLabel" name="ContactZaddr"> <widget class="QLabel" name="ContactZaddr">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>740</x> <x>550</x>
<y>490</y> <y>490</y>
<width>171</width> <width>691</width>
<height>17</height> <height>20</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">

Loading…
Cancel
Save