render only memos from selected nickname

This commit is contained in:
DenioD
2020-04-30 20:17:08 +02:00
parent d0b88255f2
commit 8f3bc21844
6 changed files with 47 additions and 47 deletions

View File

@@ -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)
{
@@ -74,49 +74,36 @@ void ChatModel::renderChatBox(QListWidget &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)
{
view->takeItem(0);
}
for(auto &c : this->chatItems)
QString line = "";
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 -
QDateTime myDateTime;
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("<") + QString(c.second.getContact()) + QString("> :\n");
line += QString(c.second.getMemo()) + QString("\n");
line += QString(c.second.getMemo()) + QString("\n");
view->addItem(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="";
@@ -128,15 +115,15 @@ QString MainWindow::createHeaderMemo(QString safeContact, QString cid, QString z
h["v"] = version; // HushChat version
h["z"] = zaddr; // zaddr to respond to
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);
header = j.toJson();
qDebug() << "made header=" << header;
return header;
}
// Create a Tx from the current state of the Chat page.
Tx MainWindow::createTxFromChatPage() {
Tx tx;
@@ -144,9 +131,9 @@ Tx MainWindow::createTxFromChatPage() {
// 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
addr = AddressBook::addressFromAddressLabel(addr);
// addr = AddressBook::addressFromAddressLabel(addr);
QString amtStr = "0";
@@ -160,15 +147,15 @@ Tx MainWindow::createTxFromChatPage() {
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 myAddr = c.getMyAddress();
QString safeContact = "false";
QString type = "memo";
QString addr = c.getPartnerAddress();
QString hmemo= createHeaderMemo(safeContact,cid,myAddr);
QString hmemo= createHeaderMemo(type,cid,myAddr);
QString memo = ui->memoTxtChat->toPlainText().trimmed();
// ui->memoSizeChat->setLenDisplayLabel();
@@ -229,6 +216,7 @@ void MainWindow::sendChatButton() {
connD->statusDetail->setText(tr("Your Message will be send"));
d->show();
ui->memoTxtChat->clear();
// And send the Tx
rpc->executeTransaction(tx,
@@ -248,6 +236,7 @@ void MainWindow::sendChatButton() {
// Force a UI update so we get the unconfirmed Tx
rpc->refresh(true);
ui->memoTxtChat->clear();
},
// Errored out

View File

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

View File

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

View File

@@ -994,10 +994,14 @@ void MainWindow::setupchatTab() {
QObject::connect(ui->listContactWidget, &QTableView::clicked, [=] () {
QModelIndex index = ui->listContactWidget->currentIndex();
QString zaddr = index.data(Qt::DisplayRole).toString();
ui->ContactZaddr->setText(zaddr);
});
QString label_contact = index.data(Qt::DisplayRole).toString();
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) {

View File

@@ -77,7 +77,7 @@ public:
Logger* logger;
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:
void slot_change_theme(const QString& themeName);

View File

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