1
0
forked from blue/squawk

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) {
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)) {

View File

@ -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);

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 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
}

View File

@ -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;

View File

@ -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);

View File

@ -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);

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::disconnectAccount, squawk, &Core::Squawk::disconnectAccount);
QObject::connect(&w, &Squawk::changeState, squawk, &Core::Squawk::changeState);
QObject::connect(&w, qOverload<const QString&, const Shared::Message&>(&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::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);

View File

@ -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<Conversation*>(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<Conversation*>(sender());
Models::Roster::ElId id = conv->getId();
QString ap = msg.getAttachPath();
QString oob = msg.getOutOfBandUrl();
if ((ap.size() > 0 && oob.size() == 0) || (ap.size() == 0 && oob.size() > 0)) {
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) {
if (conv == currentConversation) {
Conversations::iterator itr = conversations.find(id);
if (itr != conversations.end()) {
itr->second->appendMessageWithUpload(msg, path);
}
} else {
currentConversation->appendMessageWithUpload(msg, path);
}
//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<const Shared::Message&>(&Conversation::sendMessage), this, qOverload<const Shared::Message&>(&Squawk::onConversationMessage));
connect(conv, qOverload<const Shared::Message&, const QString&>(&Conversation::sendMessage),
this, qOverload<const Shared::Message&, const QString&>(&Squawk::onConversationMessage));
connect(conv, &Conversation::sendMessage, this, &Squawk::onConversationMessage);
connect(conv, &Conversation::requestLocalFile, this, &Squawk::onConversationRequestLocalFile);
connect(conv, &Conversation::downloadFile, this, &Squawk::onConversationDownloadFile);
}

View File

@ -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);

View File

@ -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<const Shared::Message&, const QString&>(&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,76 +214,16 @@ 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<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)
@ -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)
{
}

View File

@ -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<Shared::Message> 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<QString, QVariant>& 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<Ui::Conversation> m_ui;
KeyEnterReceiver ker;
Resizer scrollResizeCatcher;
VisibilityCatcher vis;
QString thread;
QLabel* statusIcon;
QLabel* statusLabel;