just a temp one

This commit is contained in:
Blue 2021-02-07 20:02:11 +03:00
parent ebe5addfb5
commit 85555da81f
11 changed files with 32 additions and 174 deletions

View File

@ -402,9 +402,6 @@ QString Core::Account::getFullJid() const {
void Core::Account::sendMessage(const Shared::Message& data) { void Core::Account::sendMessage(const Shared::Message& data) {
mh->sendMessage(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) void Core::Account::onMamMessageReceived(const QString& queryId, const QXmppMessage& msg)
{ {
if (msg.id().size() > 0 && (msg.body().size() > 0 || msg.outOfBandUrl().size() > 0)) { if (msg.id().size() > 0 && (msg.body().size() > 0 || msg.outOfBandUrl().size() > 0)) {

View File

@ -88,7 +88,6 @@ public:
void setPasswordType(Shared::AccountPassword pt); void setPasswordType(Shared::AccountPassword pt);
QString getFullJid() const; QString getFullJid() const;
void sendMessage(const Shared::Message& data); 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 requestArchive(const QString& jid, int count, const QString& before);
void subscribeToContact(const QString& jid, const QString& reason); void subscribeToContact(const QString& jid, const QString& reason);
void unsubscribeFromContact(const QString& jid, const QString& reason); void unsubscribeFromContact(const QString& jid, const QString& reason);

View File

@ -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 jid = data.getPenPalJid();
QString id = data.getId(); 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) { if (acc->state == Shared::ConnectionState::connected) {
QString path = data.getAttachPath();
QString url = acc->network->getFileRemoteUrl(path); QString url = acc->network->getFileRemoteUrl(path);
if (url.size() != 0) { if (url.size() != 0) {
sendMessageWithLocalUploadedFile(data, url); sendMessageWithLocalUploadedFile(data, url);
@ -366,6 +376,6 @@ void Core::MessageHandler::sendMessageWithLocalUploadedFile(Shared::Message msg,
if (msg.getBody().size() == 0) { if (msg.getBody().size() == 0) {
msg.setBody(url); msg.setBody(url);
} }
sendMessage(msg); performSending(msg);
//TODO removal/progress update //TODO removal/progress update
} }

View File

@ -44,8 +44,7 @@ public:
MessageHandler(Account* account); MessageHandler(Account* account);
public: public:
void sendMessage(Shared::Message data); void sendMessage(const Shared::Message& data);
void sendMessage(const Shared::Message& data, const QString& path);
void initializeMessage(Shared::Message& target, const QXmppMessage& source, bool outgoing = false, bool forwarded = false, bool guessing = false) const; void initializeMessage(Shared::Message& target, const QXmppMessage& source, bool outgoing = false, bool forwarded = false, bool guessing = false) const;
public slots: public slots:
@ -63,6 +62,8 @@ private:
bool handleGroupMessage(const QXmppMessage& msg, bool outgoing = false, bool forwarded = false, bool guessing = false); 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 logMessage(const QXmppMessage& msg, const QString& reason = "Message wasn't handled: ");
void sendMessageWithLocalUploadedFile(Shared::Message msg, const QString& url); void sendMessageWithLocalUploadedFile(Shared::Message msg, const QString& url);
void performSending(Shared::Message data);
void prepareUpload(const Shared::Message& data);
private: private:
Account* acc; Account* acc;

View File

@ -336,17 +336,6 @@ void Core::Squawk::sendMessage(const QString& account, const Shared::Message& da
itr->second->sendMessage(data); 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) void Core::Squawk::requestArchive(const QString& account, const QString& jid, int count, const QString& before)
{ {
AccountsMap::const_iterator itr = amap.find(account); AccountsMap::const_iterator itr = amap.find(account);

View File

@ -90,7 +90,6 @@ public slots:
void disconnectAccount(const QString& account); void disconnectAccount(const QString& account);
void changeState(Shared::Availability state); void changeState(Shared::Availability state);
void sendMessage(const QString& account, const Shared::Message& data); 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 requestArchive(const QString& account, const QString& jid, int count, const QString& before);
void subscribeContact(const QString& account, const QString& jid, const QString& reason); void subscribeContact(const QString& account, const QString& jid, const QString& reason);
void unsubscribeContact(const QString& account, const QString& jid, const QString& reason); void unsubscribeContact(const QString& account, const QString& jid, const QString& reason);

View File

@ -96,10 +96,7 @@ int main(int argc, char *argv[])
QObject::connect(&w, &Squawk::connectAccount, squawk, &Core::Squawk::connectAccount); QObject::connect(&w, &Squawk::connectAccount, squawk, &Core::Squawk::connectAccount);
QObject::connect(&w, &Squawk::disconnectAccount, squawk, &Core::Squawk::disconnectAccount); QObject::connect(&w, &Squawk::disconnectAccount, squawk, &Core::Squawk::disconnectAccount);
QObject::connect(&w, &Squawk::changeState, squawk, &Core::Squawk::changeState); QObject::connect(&w, &Squawk::changeState, squawk, &Core::Squawk::changeState);
QObject::connect(&w, qOverload<const QString&, const Shared::Message&>(&Squawk::sendMessage), QObject::connect(&w, &Squawk::sendMessage, squawk,&Core::Squawk::sendMessage);
squawk, qOverload<const QString&, const Shared::Message&>(&Core::Squawk::sendMessage));
QObject::connect(&w, qOverload<const QString&, const Shared::Message&, const QString&>(&Squawk::sendMessage),
squawk, qOverload<const QString&, const Shared::Message&, const QString&>(&Core::Squawk::sendMessage));
QObject::connect(&w, &Squawk::requestArchive, squawk, &Core::Squawk::requestArchive); QObject::connect(&w, &Squawk::requestArchive, squawk, &Core::Squawk::requestArchive);
QObject::connect(&w, &Squawk::subscribeContact, squawk, &Core::Squawk::subscribeContact); QObject::connect(&w, &Squawk::subscribeContact, squawk, &Core::Squawk::subscribeContact);
QObject::connect(&w, &Squawk::unsubscribeContact, squawk, &Core::Squawk::unsubscribeContact); QObject::connect(&w, &Squawk::unsubscribeContact, squawk, &Core::Squawk::unsubscribeContact);

View File

@ -578,31 +578,20 @@ void Squawk::notify(const QString& account, const Shared::Message& msg)
void Squawk::onConversationMessage(const Shared::Message& msg) void Squawk::onConversationMessage(const Shared::Message& msg)
{ {
Conversation* conv = static_cast<Conversation*>(sender()); Conversation* conv = static_cast<Conversation*>(sender());
emit sendMessage(conv->getAccount(), msg);
Models::Roster::ElId id = conv->getId(); Models::Roster::ElId id = conv->getId();
rosterModel.addMessage(conv->getAccount(), msg); rosterModel.addMessage(conv->getAccount(), msg);
}
void Squawk::onConversationMessage(const Shared::Message& msg, const QString& path)
{
Conversation* conv = static_cast<Conversation*>(sender());
Models::Roster::ElId id = conv->getId();
std::map<QString, std::set<Models::Roster::ElId>>::iterator itr = requestedFiles.insert(std::make_pair(msg.getId(), std::set<Models::Roster::ElId>())).first;
itr->second.insert(id);
if (currentConversation != 0 && currentConversation->getId() == id) { QString ap = msg.getAttachPath();
if (conv == currentConversation) { QString oob = msg.getOutOfBandUrl();
Conversations::iterator itr = conversations.find(id); if ((ap.size() > 0 && oob.size() == 0) || (ap.size() == 0 && oob.size() > 0)) {
if (itr != conversations.end()) { std::map<QString, std::set<Models::Roster::ElId>>::iterator itr = requestedFiles.insert(std::make_pair(msg.getId(), std::set<Models::Roster::ElId>())).first;
itr->second->appendMessageWithUpload(msg, path); itr->second.insert(id);
}
} else { //TODO can also start downloading here if someone attached the message with the remote url
currentConversation->appendMessageWithUpload(msg, path);
}
} }
emit sendMessage(conv->getAccount(), msg, path); emit sendMessage(conv->getAccount(), msg);
} }
void Squawk::onConversationRequestArchive(const QString& account, const QString& jid, const QString& before) void Squawk::onConversationRequestArchive(const QString& account, const QString& jid, const QString& before)
@ -1052,9 +1041,7 @@ void Squawk::onPasswordPromptRejected()
void Squawk::subscribeConversation(Conversation* conv) void Squawk::subscribeConversation(Conversation* conv)
{ {
connect(conv, &Conversation::destroyed, this, &Squawk::onConversationClosed); connect(conv, &Conversation::destroyed, this, &Squawk::onConversationClosed);
connect(conv, qOverload<const Shared::Message&>(&Conversation::sendMessage), this, qOverload<const Shared::Message&>(&Squawk::onConversationMessage)); connect(conv, &Conversation::sendMessage, this, &Squawk::onConversationMessage);
connect(conv, qOverload<const Shared::Message&, const QString&>(&Conversation::sendMessage),
this, qOverload<const Shared::Message&, const QString&>(&Squawk::onConversationMessage));
connect(conv, &Conversation::requestLocalFile, this, &Squawk::onConversationRequestLocalFile); connect(conv, &Conversation::requestLocalFile, this, &Squawk::onConversationRequestLocalFile);
connect(conv, &Conversation::downloadFile, this, &Squawk::onConversationDownloadFile); connect(conv, &Conversation::downloadFile, this, &Squawk::onConversationDownloadFile);
} }

View File

@ -63,7 +63,6 @@ signals:
void disconnectAccount(const QString&); void disconnectAccount(const QString&);
void changeState(Shared::Availability state); void changeState(Shared::Availability state);
void sendMessage(const QString& account, const Shared::Message& data); 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 requestArchive(const QString& account, const QString& jid, int count, const QString& before);
void subscribeContact(const QString& account, const QString& jid, const QString& reason); void subscribeContact(const QString& account, const QString& jid, const QString& reason);
void unsubscribeContact(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 onComboboxActivated(int index);
void onRosterItemDoubleClicked(const QModelIndex& item); void onRosterItemDoubleClicked(const QModelIndex& item);
void onConversationMessage(const Shared::Message& msg); 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 onConversationRequestArchive(const QString& account, const QString& jid, const QString& before);
void onRosterContextMenu(const QPoint& point); void onRosterContextMenu(const QPoint& point);
void onConversationRequestLocalFile(const QString& messageId, const QString& url); void onConversationRequestLocalFile(const QString& messageId, const QString& url);

View File

@ -37,8 +37,6 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
activePalResource(pRes), activePalResource(pRes),
m_ui(new Ui::Conversation()), m_ui(new Ui::Conversation()),
ker(), ker(),
scrollResizeCatcher(),
vis(),
thread(), thread(),
statusIcon(0), statusIcon(0),
statusLabel(0), statusLabel(0),
@ -69,11 +67,7 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
statusLabel = m_ui->statusLabel; statusLabel = m_ui->statusLabel;
connect(&ker, &KeyEnterReceiver::enterPressed, this, &Conversation::onEnterPressed); 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(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::downloadFile, this, &Conversation::downloadFile);
//connect(line, &MessageLine::uploadFile, this, qOverload<const Shared::Message&, const QString&>(&Conversation::sendMessage)); //connect(line, &MessageLine::uploadFile, this, qOverload<const Shared::Message&, const QString&>(&Conversation::sendMessage));
//connect(line, &MessageLine::requestLocalFile, this, &Conversation::requestLocalFile); //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); //m_ui->scrollArea->setBackgroundRole(QPalette::Base);
//} //}
//connect(vs, &QScrollBar::valueChanged, this, &Conversation::onSliderValueChanged);
//m_ui->scrollArea->installEventFilter(&scrollResizeCatcher); //m_ui->scrollArea->installEventFilter(&scrollResizeCatcher);
//line->setMyAvatarPath(acc->getAvatarPath()); //line->setMyAvatarPath(acc->getAvatarPath());
@ -221,78 +214,18 @@ void Conversation::onEnterPressed()
m_ui->messageEditor->clear(); m_ui->messageEditor->clear();
Shared::Message msg = createMessage(); Shared::Message msg = createMessage();
msg.setBody(body); msg.setBody(body);
//addMessage(msg);
emit sendMessage(msg); emit sendMessage(msg);
} }
if (filesToAttach.size() > 0) { if (filesToAttach.size() > 0) {
// for (Badge* badge : filesToAttach) { for (Badge* badge : filesToAttach) {
// Shared::Message msg = createMessage(); Shared::Message msg = createMessage();
// line->appendMessageWithUpload(msg, badge->id); msg.setAttachPath(badge->id);
// usleep(1000); //this is required for the messages not to have equal time when appending into messageline emit sendMessage(msg);
// } }
// clearAttachedFiles(); 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<Shared::Message> list)
{
// requestingHistory = false;
// scroll = keep;
//
// line->hideBusyIndicator();
// for (std::list<Shared::Message>::const_iterator itr = list.begin(), end = list.end(); itr != end; ++itr) {
// addMessage(*itr);
// }
}
void Conversation::showEvent(QShowEvent* event) void Conversation::showEvent(QShowEvent* event)
{ {
if (!everShown) { if (!everShown) {
@ -335,19 +268,6 @@ void Conversation::setStatus(const QString& status)
statusLabel->setText(Shared::processMessageBody(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) void Conversation::responseFileProgress(const QString& messageId, qreal progress)
{ {
// line->fileProgress(messageId, progress); // line->fileProgress(messageId, progress);
@ -499,21 +419,3 @@ Shared::Message Conversation::createMessage() const
return msg; 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)
{
}

View File

@ -30,7 +30,6 @@
#include "ui/models/account.h" #include "ui/models/account.h"
#include "ui/models/roster.h" #include "ui/models/roster.h"
#include "ui/utils/messageline.h" #include "ui/utils/messageline.h"
#include "ui/utils/resizer.h"
#include "ui/utils/flowlayout.h" #include "ui/utils/flowlayout.h"
#include "ui/utils/badge.h" #include "ui/utils/badge.h"
#include "ui/utils/feedview.h" #include "ui/utils/feedview.h"
@ -56,19 +55,6 @@ signals:
void enterPressed(); 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 class Conversation : public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -82,7 +68,6 @@ public:
Models::Roster::ElId getId() const; Models::Roster::ElId getId() const;
void setPalResource(const QString& res); void setPalResource(const QString& res);
void responseArchive(const std::list<Shared::Message> list);
void showEvent(QShowEvent * event) override; void showEvent(QShowEvent * event) override;
void responseLocalFile(const QString& messageId, const QString& path); void responseLocalFile(const QString& messageId, const QString& path);
void fileError(const QString& messageId, const QString& error); void fileError(const QString& messageId, const QString& error);
@ -90,11 +75,9 @@ public:
virtual void setAvatar(const QString& path); virtual void setAvatar(const QString& path);
void changeMessage(const QString& id, const QMap<QString, QVariant>& data); void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
void setFeedFrames(bool top, bool right, bool bottom, bool left); void setFeedFrames(bool top, bool right, bool bottom, bool left);
virtual void appendMessageWithUpload(const Shared::Message& data, const QString& path);
signals: signals:
void sendMessage(const Shared::Message& message); void sendMessage(const Shared::Message& message);
void sendMessage(const Shared::Message& message, const QString& path);
void requestArchive(const QString& before); void requestArchive(const QString& before);
void shown(); void shown();
void requestLocalFile(const QString& messageId, const QString& url); void requestLocalFile(const QString& messageId, const QString& url);
@ -114,8 +97,6 @@ protected:
protected slots: protected slots:
void onEnterPressed(); void onEnterPressed();
void onMessagesResize(int amount);
void onSliderValueChanged(int value);
void onAttach(); void onAttach();
void onFileSelected(); void onFileSelected();
void onScrollResize(); void onScrollResize();
@ -139,8 +120,6 @@ protected:
QString activePalResource; QString activePalResource;
QScopedPointer<Ui::Conversation> m_ui; QScopedPointer<Ui::Conversation> m_ui;
KeyEnterReceiver ker; KeyEnterReceiver ker;
Resizer scrollResizeCatcher;
VisibilityCatcher vis;
QString thread; QString thread;
QLabel* statusIcon; QLabel* statusIcon;
QLabel* statusLabel; QLabel* statusLabel;