/* * Squawk messenger. * Copyright (C) 2019 Yury Gubich * * 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 . */ #pragma once #include #include #include #include #include #include #include #include #ifdef WITH_OMEMO #include #endif #include #include #include namespace Core { class Account; class MessageHandler : public QObject { Q_OBJECT public: MessageHandler(Account* account); public: void sendMessage(const Shared::Message& data, bool newMessage = true, QString originalId = ""); void initializeMessage(Shared::Message& target, const QXmppMessage& source, bool outgoing = false, bool forwarded = false, bool guessing = false) const; void resendMessage(const QString& jid, const QString& id); public slots: void onMessageReceived(const QXmppMessage& message); #if (QXMPP_VERSION) < QT_VERSION_CHECK(1, 5, 0) void onCarbonMessageReceived(const QXmppMessage& message); void onCarbonMessageSent(const QXmppMessage& message); #endif void onReceiptReceived(const QString& jid, const QString& id); void onUploadSlotReceived(const QXmppHttpUploadSlotIq& slot); void onUploadSlotRequestFailed(const QXmppHttpUploadRequestIq& request); void onDownloadFileComplete(const std::list& msgs, const QString& path); void onUploadFileComplete(const std::list& msgs, const QString& url, const QString& path); void onLoadFileError(const std::list& msgs, const QString& path, bool up); void requestChangeMessage(const QString& jid, const QString& messageId, const QMap& data); 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: "); void sendMessageWithLocalUploadedFile(Shared::Message msg, const QString& url, bool newMessage = true); void performSending(Shared::Message data, const QString& originalId, bool newMessage = true); void prepareUpload(const Shared::Message& data, bool newMessage = true); void handleUploadError(const QString& jid, const QString& messageId, const QString& errorText); QXmppMessage createPacket(const Shared::Message& data, const QDateTime& time, const QString& originalId) const; QMap getChanges(Shared::Message& data, const QDateTime& time, bool newMessage, const QString& originalId) const; std::optional getOriginalPendingMessageId(const QString& id, bool clear = true); bool handlePendingMessageError(const QString& id, const QString& errorText); std::pair scheduleSending(const Shared::Message& message, const QDateTime& sendTime, const QString& originalId); bool adjustPendingMessage(const QString& messageId, const QMap& data, bool final); private: Account* acc; std::map pendingStateMessages; //key is message id, value is JID std::map pendingCorrectionMessages; //key is new mesage, value is originalOne std::deque> uploadingSlotsQueue; }; }