From 85555da81f05684ab87ab8c352161cc479daae11 Mon Sep 17 00:00:00 2001 From: blue Date: Sun, 7 Feb 2021 20:02:11 +0300 Subject: [PATCH] just a temp one --- core/account.cpp | 3 - core/account.h | 1 - core/handlers/messagehandler.cpp | 16 ++++- core/handlers/messagehandler.h | 5 +- core/squawk.cpp | 11 ---- core/squawk.h | 1 - main.cpp | 5 +- ui/squawk.cpp | 31 +++------ ui/squawk.h | 2 - ui/widgets/conversation.cpp | 110 ++----------------------------- ui/widgets/conversation.h | 21 ------ 11 files changed, 32 insertions(+), 174 deletions(-) diff --git a/core/account.cpp b/core/account.cpp index 21fe9e7..8452688 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -402,9 +402,6 @@ QString Core::Account::getFullJid() const { void Core::Account::sendMessage(const Shared::Message& data) { mh->sendMessage(data);} -void Core::Account::sendMessage(const Shared::Message& data, const QString& path) { - mh->sendMessage(data, path);} - void Core::Account::onMamMessageReceived(const QString& queryId, const QXmppMessage& msg) { if (msg.id().size() > 0 && (msg.body().size() > 0 || msg.outOfBandUrl().size() > 0)) { diff --git a/core/account.h b/core/account.h index 7b6b50d..1a46e24 100644 --- a/core/account.h +++ b/core/account.h @@ -88,7 +88,6 @@ public: void setPasswordType(Shared::AccountPassword pt); QString getFullJid() const; void sendMessage(const Shared::Message& data); - void sendMessage(const Shared::Message& data, const QString& path); void requestArchive(const QString& jid, int count, const QString& before); void subscribeToContact(const QString& jid, const QString& reason); void unsubscribeFromContact(const QString& jid, const QString& reason); diff --git a/core/handlers/messagehandler.cpp b/core/handlers/messagehandler.cpp index 0f0e09d..a236f1e 100644 --- a/core/handlers/messagehandler.cpp +++ b/core/handlers/messagehandler.cpp @@ -232,7 +232,16 @@ void Core::MessageHandler::onReceiptReceived(const QString& jid, const QString& } } -void Core::MessageHandler::sendMessage(Shared::Message data) +void Core::MessageHandler::sendMessage(const Shared::Message& data) +{ + if (data.getOutOfBandUrl().size() == 0 && data.getAttachPath().size() > 0) { + prepareUpload(data); + } else { + performSending(data); + } +} + +void Core::MessageHandler::performSending(Shared::Message data) { QString jid = data.getPenPalJid(); QString id = data.getId(); @@ -275,9 +284,10 @@ void Core::MessageHandler::sendMessage(Shared::Message data) }); } -void Core::MessageHandler::sendMessage(const Shared::Message& data, const QString& path) +void Core::MessageHandler::prepareUpload(const Shared::Message& data) { if (acc->state == Shared::ConnectionState::connected) { + QString path = data.getAttachPath(); QString url = acc->network->getFileRemoteUrl(path); if (url.size() != 0) { sendMessageWithLocalUploadedFile(data, url); @@ -366,6 +376,6 @@ void Core::MessageHandler::sendMessageWithLocalUploadedFile(Shared::Message msg, if (msg.getBody().size() == 0) { msg.setBody(url); } - sendMessage(msg); + performSending(msg); //TODO removal/progress update } diff --git a/core/handlers/messagehandler.h b/core/handlers/messagehandler.h index be1545f..0b53cc2 100644 --- a/core/handlers/messagehandler.h +++ b/core/handlers/messagehandler.h @@ -44,8 +44,7 @@ public: MessageHandler(Account* account); public: - void sendMessage(Shared::Message data); - void sendMessage(const Shared::Message& data, const QString& path); + void sendMessage(const Shared::Message& data); void initializeMessage(Shared::Message& target, const QXmppMessage& source, bool outgoing = false, bool forwarded = false, bool guessing = false) const; public slots: @@ -63,6 +62,8 @@ private: bool handleGroupMessage(const QXmppMessage& msg, bool outgoing = false, bool forwarded = false, bool guessing = false); void logMessage(const QXmppMessage& msg, const QString& reason = "Message wasn't handled: "); void sendMessageWithLocalUploadedFile(Shared::Message msg, const QString& url); + void performSending(Shared::Message data); + void prepareUpload(const Shared::Message& data); private: Account* acc; diff --git a/core/squawk.cpp b/core/squawk.cpp index 9116e47..c637c96 100644 --- a/core/squawk.cpp +++ b/core/squawk.cpp @@ -336,17 +336,6 @@ void Core::Squawk::sendMessage(const QString& account, const Shared::Message& da itr->second->sendMessage(data); } -void Core::Squawk::sendMessage(const QString& account, const Shared::Message& data, const QString& path) -{ - AccountsMap::const_iterator itr = amap.find(account); - if (itr == amap.end()) { - qDebug("An attempt to send a message with non existing account, skipping"); - return; - } - - itr->second->sendMessage(data, path); -} - void Core::Squawk::requestArchive(const QString& account, const QString& jid, int count, const QString& before) { AccountsMap::const_iterator itr = amap.find(account); diff --git a/core/squawk.h b/core/squawk.h index aa84f59..3aac06a 100644 --- a/core/squawk.h +++ b/core/squawk.h @@ -90,7 +90,6 @@ public slots: void disconnectAccount(const QString& account); void changeState(Shared::Availability state); void sendMessage(const QString& account, const Shared::Message& data); - void sendMessage(const QString& account, const Shared::Message& data, const QString& path); void requestArchive(const QString& account, const QString& jid, int count, const QString& before); void subscribeContact(const QString& account, const QString& jid, const QString& reason); void unsubscribeContact(const QString& account, const QString& jid, const QString& reason); diff --git a/main.cpp b/main.cpp index 4c4b3ea..0373af8 100644 --- a/main.cpp +++ b/main.cpp @@ -96,10 +96,7 @@ int main(int argc, char *argv[]) QObject::connect(&w, &Squawk::connectAccount, squawk, &Core::Squawk::connectAccount); QObject::connect(&w, &Squawk::disconnectAccount, squawk, &Core::Squawk::disconnectAccount); QObject::connect(&w, &Squawk::changeState, squawk, &Core::Squawk::changeState); - QObject::connect(&w, qOverload(&Squawk::sendMessage), - squawk, qOverload(&Core::Squawk::sendMessage)); - QObject::connect(&w, qOverload(&Squawk::sendMessage), - squawk, qOverload(&Core::Squawk::sendMessage)); + QObject::connect(&w, &Squawk::sendMessage, squawk,&Core::Squawk::sendMessage); QObject::connect(&w, &Squawk::requestArchive, squawk, &Core::Squawk::requestArchive); QObject::connect(&w, &Squawk::subscribeContact, squawk, &Core::Squawk::subscribeContact); QObject::connect(&w, &Squawk::unsubscribeContact, squawk, &Core::Squawk::unsubscribeContact); diff --git a/ui/squawk.cpp b/ui/squawk.cpp index 1709dd6..52e1d9f 100644 --- a/ui/squawk.cpp +++ b/ui/squawk.cpp @@ -578,31 +578,20 @@ void Squawk::notify(const QString& account, const Shared::Message& msg) void Squawk::onConversationMessage(const Shared::Message& msg) { Conversation* conv = static_cast(sender()); - emit sendMessage(conv->getAccount(), msg); Models::Roster::ElId id = conv->getId(); rosterModel.addMessage(conv->getAccount(), msg); -} - -void Squawk::onConversationMessage(const Shared::Message& msg, const QString& path) -{ - Conversation* conv = static_cast(sender()); - Models::Roster::ElId id = conv->getId(); - std::map>::iterator itr = requestedFiles.insert(std::make_pair(msg.getId(), std::set())).first; - itr->second.insert(id); - if (currentConversation != 0 && currentConversation->getId() == id) { - if (conv == currentConversation) { - Conversations::iterator itr = conversations.find(id); - if (itr != conversations.end()) { - itr->second->appendMessageWithUpload(msg, path); - } - } else { - currentConversation->appendMessageWithUpload(msg, path); - } + QString ap = msg.getAttachPath(); + QString oob = msg.getOutOfBandUrl(); + if ((ap.size() > 0 && oob.size() == 0) || (ap.size() == 0 && oob.size() > 0)) { + std::map>::iterator itr = requestedFiles.insert(std::make_pair(msg.getId(), std::set())).first; + itr->second.insert(id); + + //TODO can also start downloading here if someone attached the message with the remote url } - emit sendMessage(conv->getAccount(), msg, path); + emit sendMessage(conv->getAccount(), msg); } void Squawk::onConversationRequestArchive(const QString& account, const QString& jid, const QString& before) @@ -1052,9 +1041,7 @@ void Squawk::onPasswordPromptRejected() void Squawk::subscribeConversation(Conversation* conv) { connect(conv, &Conversation::destroyed, this, &Squawk::onConversationClosed); - connect(conv, qOverload(&Conversation::sendMessage), this, qOverload(&Squawk::onConversationMessage)); - connect(conv, qOverload(&Conversation::sendMessage), - this, qOverload(&Squawk::onConversationMessage)); + connect(conv, &Conversation::sendMessage, this, &Squawk::onConversationMessage); connect(conv, &Conversation::requestLocalFile, this, &Squawk::onConversationRequestLocalFile); connect(conv, &Conversation::downloadFile, this, &Squawk::onConversationDownloadFile); } diff --git a/ui/squawk.h b/ui/squawk.h index a0d776d..26f7753 100644 --- a/ui/squawk.h +++ b/ui/squawk.h @@ -63,7 +63,6 @@ signals: void disconnectAccount(const QString&); void changeState(Shared::Availability state); void sendMessage(const QString& account, const Shared::Message& data); - void sendMessage(const QString& account, const Shared::Message& data, const QString& path); void requestArchive(const QString& account, const QString& jid, int count, const QString& before); void subscribeContact(const QString& account, const QString& jid, const QString& reason); void unsubscribeContact(const QString& account, const QString& jid, const QString& reason); @@ -147,7 +146,6 @@ private slots: void onComboboxActivated(int index); void onRosterItemDoubleClicked(const QModelIndex& item); void onConversationMessage(const Shared::Message& msg); - void onConversationMessage(const Shared::Message& msg, const QString& path); void onConversationRequestArchive(const QString& account, const QString& jid, const QString& before); void onRosterContextMenu(const QPoint& point); void onConversationRequestLocalFile(const QString& messageId, const QString& url); diff --git a/ui/widgets/conversation.cpp b/ui/widgets/conversation.cpp index e10058d..017b9ba 100644 --- a/ui/widgets/conversation.cpp +++ b/ui/widgets/conversation.cpp @@ -37,8 +37,6 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el, activePalResource(pRes), m_ui(new Ui::Conversation()), ker(), - scrollResizeCatcher(), - vis(), thread(), statusIcon(0), statusLabel(0), @@ -69,11 +67,7 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el, statusLabel = m_ui->statusLabel; connect(&ker, &KeyEnterReceiver::enterPressed, this, &Conversation::onEnterPressed); - connect(&scrollResizeCatcher, &Resizer::resized, this, &Conversation::onScrollResize); - connect(&vis, &VisibilityCatcher::shown, this, &Conversation::onScrollResize); - connect(&vis, &VisibilityCatcher::hidden, this, &Conversation::onScrollResize); connect(m_ui->sendButton, &QPushButton::clicked, this, &Conversation::onEnterPressed); - //connect(line, &MessageLine::resize, this, &Conversation::onMessagesResize); //connect(line, &MessageLine::downloadFile, this, &Conversation::downloadFile); //connect(line, &MessageLine::uploadFile, this, qOverload(&Conversation::sendMessage)); //connect(line, &MessageLine::requestLocalFile, this, &Conversation::requestLocalFile); @@ -95,7 +89,6 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el, //m_ui->scrollArea->setBackgroundRole(QPalette::Base); //} - //connect(vs, &QScrollBar::valueChanged, this, &Conversation::onSliderValueChanged); //m_ui->scrollArea->installEventFilter(&scrollResizeCatcher); //line->setMyAvatarPath(acc->getAvatarPath()); @@ -221,78 +214,18 @@ void Conversation::onEnterPressed() m_ui->messageEditor->clear(); Shared::Message msg = createMessage(); msg.setBody(body); - //addMessage(msg); emit sendMessage(msg); } if (filesToAttach.size() > 0) { -// for (Badge* badge : filesToAttach) { -// Shared::Message msg = createMessage(); -// line->appendMessageWithUpload(msg, badge->id); -// usleep(1000); //this is required for the messages not to have equal time when appending into messageline -// } -// clearAttachedFiles(); + for (Badge* badge : filesToAttach) { + Shared::Message msg = createMessage(); + msg.setAttachPath(badge->id); + emit sendMessage(msg); + } + clearAttachedFiles(); } } -void Conversation::appendMessageWithUpload(const Shared::Message& data, const QString& path) -{ -// line->appendMessageWithUploadNoSiganl(data, path); -} - -void Conversation::onMessagesResize(int amount) -{ -// manualSliderChange = true; -// switch (scroll) { -// case down: -// m_ui->scrollArea->verticalScrollBar()->setValue(m_ui->scrollArea->verticalScrollBar()->maximum()); -// break; -// case keep: { -// int max = m_ui->scrollArea->verticalScrollBar()->maximum(); -// int value = m_ui->scrollArea->verticalScrollBar()->value() + amount; -// m_ui->scrollArea->verticalScrollBar()->setValue(value); -// -// if (value == max) { -// scroll = down; -// } else { -// scroll = nothing; -// } -// } -// break; -// default: -// break; -// } -// manualSliderChange = false; -} - -void Conversation::onSliderValueChanged(int value) -{ -// if (!manualSliderChange) { -// if (value == m_ui->scrollArea->verticalScrollBar()->maximum()) { -// scroll = down; -// } else { -// if (!requestingHistory && value == 0) { -// requestingHistory = true; -// line->showBusyIndicator(); -// emit requestArchive(line->firstMessageId()); -// scroll = keep; -// } else { -// scroll = nothing; -// } -// } -// } -} - -void Conversation::responseArchive(const std::list list) -{ -// requestingHistory = false; -// scroll = keep; -// -// line->hideBusyIndicator(); -// for (std::list::const_iterator itr = list.begin(), end = list.end(); itr != end; ++itr) { -// addMessage(*itr); -// } -} - void Conversation::showEvent(QShowEvent* event) { if (!everShown) { @@ -335,19 +268,6 @@ void Conversation::setStatus(const QString& status) statusLabel->setText(Shared::processMessageBody(status)); } -void Conversation::onScrollResize() -{ -// if (everShown) { -// int size = m_ui->scrollArea->width(); -// QScrollBar* bar = m_ui->scrollArea->verticalScrollBar(); -// if (bar->isVisible() && !tsb) { -// size -= bar->width(); -// -// } -// line->setMaximumWidth(size); -// } -} - void Conversation::responseFileProgress(const QString& messageId, qreal progress) { // line->fileProgress(messageId, progress); @@ -499,21 +419,3 @@ Shared::Message Conversation::createMessage() const return msg; } -bool VisibilityCatcher::eventFilter(QObject* obj, QEvent* event) -{ - if (event->type() == QEvent::Show) { - emit shown(); - } - - if (event->type() == QEvent::Hide) { - emit hidden(); - } - - return false; -} - -VisibilityCatcher::VisibilityCatcher(QWidget* parent): -QObject(parent) -{ -} - diff --git a/ui/widgets/conversation.h b/ui/widgets/conversation.h index 2331e34..ac1ffcd 100644 --- a/ui/widgets/conversation.h +++ b/ui/widgets/conversation.h @@ -30,7 +30,6 @@ #include "ui/models/account.h" #include "ui/models/roster.h" #include "ui/utils/messageline.h" -#include "ui/utils/resizer.h" #include "ui/utils/flowlayout.h" #include "ui/utils/badge.h" #include "ui/utils/feedview.h" @@ -56,19 +55,6 @@ signals: void enterPressed(); }; -class VisibilityCatcher : public QObject { - Q_OBJECT -public: - VisibilityCatcher(QWidget* parent = nullptr); - -protected: - bool eventFilter(QObject* obj, QEvent* event) override; - -signals: - void hidden(); - void shown(); -}; - class Conversation : public QWidget { Q_OBJECT @@ -82,7 +68,6 @@ public: Models::Roster::ElId getId() const; void setPalResource(const QString& res); - void responseArchive(const std::list list); void showEvent(QShowEvent * event) override; void responseLocalFile(const QString& messageId, const QString& path); void fileError(const QString& messageId, const QString& error); @@ -90,11 +75,9 @@ public: virtual void setAvatar(const QString& path); void changeMessage(const QString& id, const QMap& data); void setFeedFrames(bool top, bool right, bool bottom, bool left); - virtual void appendMessageWithUpload(const Shared::Message& data, const QString& path); signals: void sendMessage(const Shared::Message& message); - void sendMessage(const Shared::Message& message, const QString& path); void requestArchive(const QString& before); void shown(); void requestLocalFile(const QString& messageId, const QString& url); @@ -114,8 +97,6 @@ protected: protected slots: void onEnterPressed(); - void onMessagesResize(int amount); - void onSliderValueChanged(int value); void onAttach(); void onFileSelected(); void onScrollResize(); @@ -139,8 +120,6 @@ protected: QString activePalResource; QScopedPointer m_ui; KeyEnterReceiver ker; - Resizer scrollResizeCatcher; - VisibilityCatcher vis; QString thread; QLabel* statusIcon; QLabel* statusLabel;