2020-04-28 20:35:52 +00:00
|
|
|
/*
|
|
|
|
* Squawk messenger.
|
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-11-13 22:05:26 +00:00
|
|
|
#pragma once
|
2020-04-28 20:35:52 +00:00
|
|
|
|
|
|
|
#include <QObject>
|
2024-12-13 23:53:04 +00:00
|
|
|
#include <QFileInfo>
|
2020-04-28 20:35:52 +00:00
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
#include <map>
|
2023-11-05 19:29:44 +00:00
|
|
|
#include <functional>
|
2023-11-14 23:23:39 +00:00
|
|
|
#include <optional>
|
2020-04-28 20:35:52 +00:00
|
|
|
|
|
|
|
#include <QXmppMessage.h>
|
|
|
|
#include <QXmppHttpUploadIq.h>
|
2023-11-05 19:29:44 +00:00
|
|
|
#ifdef WITH_OMEMO
|
|
|
|
#include <QXmppE2eeExtension.h>
|
|
|
|
#endif
|
2020-04-28 20:35:52 +00:00
|
|
|
|
2020-06-14 21:23:43 +00:00
|
|
|
#include <shared/message.h>
|
2021-04-18 12:49:20 +00:00
|
|
|
#include <shared/messageinfo.h>
|
2022-02-19 18:31:49 +00:00
|
|
|
#include <shared/pathcheck.h>
|
2020-04-28 20:35:52 +00:00
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class Account;
|
|
|
|
|
2023-11-13 22:05:26 +00:00
|
|
|
class MessageHandler : public QObject {
|
2020-04-28 20:35:52 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
MessageHandler(Account* account);
|
|
|
|
|
|
|
|
public:
|
2022-03-28 20:25:33 +00:00
|
|
|
void sendMessage(const Shared::Message& data, bool newMessage = true, QString originalId = "");
|
2020-04-28 20:35:52 +00:00
|
|
|
void initializeMessage(Shared::Message& target, const QXmppMessage& source, bool outgoing = false, bool forwarded = false, bool guessing = false) const;
|
2021-05-22 22:03:14 +00:00
|
|
|
void resendMessage(const QString& jid, const QString& id);
|
2020-04-28 20:35:52 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onMessageReceived(const QXmppMessage& message);
|
2023-03-11 22:38:54 +00:00
|
|
|
#if (QXMPP_VERSION) < QT_VERSION_CHECK(1, 5, 0)
|
2020-04-28 20:35:52 +00:00
|
|
|
void onCarbonMessageReceived(const QXmppMessage& message);
|
|
|
|
void onCarbonMessageSent(const QXmppMessage& message);
|
2023-03-11 22:38:54 +00:00
|
|
|
#endif
|
2020-04-28 20:35:52 +00:00
|
|
|
void onReceiptReceived(const QString& jid, const QString& id);
|
|
|
|
void onUploadSlotReceived(const QXmppHttpUploadSlotIq& slot);
|
|
|
|
void onUploadSlotRequestFailed(const QXmppHttpUploadRequestIq& request);
|
2021-04-18 12:49:20 +00:00
|
|
|
void onDownloadFileComplete(const std::list<Shared::MessageInfo>& msgs, const QString& path);
|
2022-02-18 21:27:09 +00:00
|
|
|
void onUploadFileComplete(const std::list<Shared::MessageInfo>& msgs, const QString& url, const QString& path);
|
2021-04-18 12:49:20 +00:00
|
|
|
void onLoadFileError(const std::list<Shared::MessageInfo>& msgs, const QString& path, bool up);
|
2021-04-28 20:26:19 +00:00
|
|
|
void requestChangeMessage(const QString& jid, const QString& messageId, const QMap<QString, QVariant>& data);
|
2020-04-28 20:35:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool handleChatMessage(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: ");
|
2021-05-07 18:26:02 +00:00
|
|
|
void sendMessageWithLocalUploadedFile(Shared::Message msg, const QString& url, bool newMessage = true);
|
2022-03-28 20:25:33 +00:00
|
|
|
void performSending(Shared::Message data, const QString& originalId, bool newMessage = true);
|
2021-05-22 22:03:14 +00:00
|
|
|
void prepareUpload(const Shared::Message& data, bool newMessage = true);
|
2021-04-18 12:49:20 +00:00
|
|
|
void handleUploadError(const QString& jid, const QString& messageId, const QString& errorText);
|
2022-03-28 20:25:33 +00:00
|
|
|
QXmppMessage createPacket(const Shared::Message& data, const QDateTime& time, const QString& originalId) const;
|
|
|
|
QMap<QString, QVariant> getChanges(Shared::Message& data, const QDateTime& time, bool newMessage, const QString& originalId) const;
|
2023-11-14 23:23:39 +00:00
|
|
|
std::optional<Shared::MessageInfo> getOriginalPendingMessageId(const QString& id, bool clear = true);
|
2023-11-05 19:29:44 +00:00
|
|
|
bool handlePendingMessageError(const QString& id, const QString& errorText);
|
|
|
|
std::pair<Shared::Message::State, QString> scheduleSending(const Shared::Message& message, const QDateTime& sendTime, const QString& originalId);
|
2023-11-14 23:23:39 +00:00
|
|
|
bool adjustPendingMessage(const QString& messageId, const QMap<QString, QVariant>& data, bool final);
|
2020-04-28 20:35:52 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Account* acc;
|
2021-05-07 18:26:02 +00:00
|
|
|
std::map<QString, QString> pendingStateMessages; //key is message id, value is JID
|
2022-03-28 20:25:33 +00:00
|
|
|
std::map<QString, QString> pendingCorrectionMessages; //key is new mesage, value is originalOne
|
2024-12-13 23:53:04 +00:00
|
|
|
std::deque<std::pair<QFileInfo, QString>> uploadingSlotsQueue;
|
2020-04-28 20:35:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|