Hush lite wallet
https://faq.hush.is/sdl
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
4.6 KiB
140 lines
4.6 KiB
// Copyright 2019-2021 The Hush developers
|
|
// Released under the GPLv3
|
|
|
|
#include "Chat.h"
|
|
#include "../addressbook.h"
|
|
#include "../DataStore/DataStore.h"
|
|
Chat::Chat() {}
|
|
|
|
ChatMemoEdit::ChatMemoEdit(QWidget* parent) : QTextEdit(parent) {
|
|
QObject::connect(this, &QTextEdit::textChanged, this, &ChatMemoEdit::updateDisplayChat);
|
|
}
|
|
|
|
void ChatMemoEdit::updateDisplayChat() {
|
|
QString txt = this->toPlainText();
|
|
if (lenDisplayLabelchat)
|
|
lenDisplayLabelchat->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlenchat));
|
|
|
|
if (txt.toUtf8().size() <= maxlenchat) {
|
|
// Everything is fine
|
|
if (sendChatButton)
|
|
sendChatButton->setEnabled(true);
|
|
|
|
if (lenDisplayLabelchat)
|
|
lenDisplayLabelchat->setStyleSheet("");
|
|
} else {
|
|
// Overweight
|
|
if (sendChatButton)
|
|
sendChatButton->setEnabled(false);
|
|
|
|
if (lenDisplayLabelchat)
|
|
lenDisplayLabelchat->setStyleSheet("color: red;");
|
|
}
|
|
}
|
|
|
|
void ChatMemoEdit::setMaxLenChat(int len) {
|
|
this->maxlenchat = len;
|
|
updateDisplayChat();
|
|
}
|
|
|
|
void ChatMemoEdit::SetSendChatButton(QPushButton* button) {
|
|
this->sendChatButton = button;
|
|
}
|
|
|
|
void ChatMemoEdit::setLenDisplayLabelChat(QLabel* label) {
|
|
this->lenDisplayLabelchat = label;
|
|
}
|
|
|
|
ChatMemoEditRequest::ChatMemoEditRequest(QWidget* parent) : QTextEdit(parent) {
|
|
QObject::connect(this, &QTextEdit::textChanged, this, &ChatMemoEditRequest::updateDisplayChatRequest);
|
|
}
|
|
|
|
|
|
// TODO: unify this with updateDisplayChat()
|
|
void ChatMemoEditRequest::updateDisplayChatRequest() {
|
|
QString txt = this->toPlainText();
|
|
if (lenDisplayLabelchatRequest)
|
|
lenDisplayLabelchatRequest->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlenchatrequest));
|
|
|
|
if (txt.toUtf8().size() <= maxlenchatrequest) {
|
|
// Everything is fine
|
|
if (sendRequestButton)
|
|
sendRequestButton->setEnabled(true);
|
|
|
|
if (lenDisplayLabelchatRequest)
|
|
lenDisplayLabelchatRequest->setStyleSheet("");
|
|
} else {
|
|
// Overweight
|
|
if (sendRequestButton)
|
|
sendRequestButton->setEnabled(false);
|
|
|
|
if (lenDisplayLabelchatRequest)
|
|
lenDisplayLabelchatRequest->setStyleSheet("color: red;");
|
|
}
|
|
}
|
|
|
|
void ChatMemoEditRequest::setMaxLenChatRequest(int len) {
|
|
this->maxlenchatrequest = len;
|
|
updateDisplayChatRequest();
|
|
}
|
|
|
|
void ChatMemoEditRequest::SetSendRequestButton(QPushButton* button) {
|
|
this->sendRequestButton = button;
|
|
}
|
|
|
|
void ChatMemoEditRequest::setLenDisplayLabelChatRequest(QLabel* label) {
|
|
this->lenDisplayLabelchatRequest = label;
|
|
}
|
|
|
|
void Chat::renderChatBox(Ui::MainWindow *ui, QListView *view, QLabel *label)
|
|
{
|
|
|
|
QStandardItemModel *chat = new QStandardItemModel();
|
|
DataStore::getChatDataStore()->dump(); // test to see if the chat items in datastore are correctly dumped to json
|
|
|
|
qDebug() << __func__ << ": looking at memos...";
|
|
for (auto &p : AddressBook::getInstance()->getAllAddressLabels())
|
|
{
|
|
for (auto &c : DataStore::getChatDataStore()->getAllMemos())
|
|
{
|
|
|
|
if (
|
|
(p.getName() == ui->contactNameMemo->text().trimmed()) &&
|
|
(p.getPartnerAddress() == c.second.getAddress()) &&
|
|
(c.second.isOutgoing() == true))
|
|
{
|
|
|
|
QStandardItem *Items = new QStandardItem(c.second.toChatLine());
|
|
|
|
Items->setData(OUTGOING, Qt::UserRole + 1);
|
|
qDebug() << __func__ << ": appending row to OUTGOING chatitems to contact " << p.getName() << " with item " << Items;
|
|
chat->appendRow(Items);
|
|
ui->listChat->setModel(chat);
|
|
|
|
} else {
|
|
ui->listChat->setModel(chat);
|
|
}
|
|
|
|
if (
|
|
(p.getName() == ui->contactNameMemo->text().trimmed()) &&
|
|
(p.getMyAddress() == c.second.getAddress()) &&
|
|
(c.second.isOutgoing() == false) &&
|
|
(c.second.getCid() == p.getCid())
|
|
)
|
|
{
|
|
QStandardItem *Items1 = new QStandardItem(c.second.toChatLine());
|
|
Items1->setData(INCOMING, Qt::UserRole + 1);
|
|
qDebug() << __func__ << ": appending row to INCOMING chatitems to contact " << p.getName() << "with cid=" << p.getCid() << " and item " << Items1;
|
|
chat->appendRow(Items1);
|
|
ui->listChat->setModel(chat);
|
|
ui->memoTxtChat->setEnabled(true);
|
|
ui->emojiButton->setEnabled(true);
|
|
ui->sendChatButton->setEnabled(true);
|
|
|
|
} else {
|
|
ui->listChat->setModel(chat);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|