2019-08-14 17:54:46 +03: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/>.
|
|
|
|
*/
|
|
|
|
|
2019-03-29 17:54:34 +03:00
|
|
|
#ifndef CORE_ACCOUNT_H
|
|
|
|
#define CORE_ACCOUNT_H
|
|
|
|
|
2019-10-16 22:38:35 +03:00
|
|
|
#include <QObject>
|
|
|
|
#include <QCryptographicHash>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QMimeDatabase>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QDir>
|
2020-05-21 18:42:40 +03:00
|
|
|
#include <QTimer>
|
2019-10-16 22:38:35 +03:00
|
|
|
|
2019-04-04 00:23:51 +03:00
|
|
|
#include <map>
|
2019-04-06 13:14:32 +03:00
|
|
|
#include <set>
|
2019-03-29 17:54:34 +03:00
|
|
|
|
2019-06-28 18:15:30 +03:00
|
|
|
#include <QXmppRosterManager.h>
|
|
|
|
#include <QXmppCarbonManager.h>
|
2019-11-12 16:38:01 +03:00
|
|
|
#include <QXmppDiscoveryManager.h>
|
2019-06-28 18:15:30 +03:00
|
|
|
#include <QXmppMamManager.h>
|
2019-07-11 11:51:52 +03:00
|
|
|
#include <QXmppMucManager.h>
|
2019-06-28 18:15:30 +03:00
|
|
|
#include <QXmppClient.h>
|
2019-07-11 11:51:52 +03:00
|
|
|
#include <QXmppBookmarkManager.h>
|
|
|
|
#include <QXmppBookmarkSet.h>
|
2019-11-09 17:04:27 +03:00
|
|
|
#include <QXmppUploadRequestManager.h>
|
2019-10-15 22:25:40 +03:00
|
|
|
#include <QXmppVCardIq.h>
|
|
|
|
#include <QXmppVCardManager.h>
|
2020-03-27 23:59:30 +03:00
|
|
|
#include <QXmppMessageReceiptManager.h>
|
|
|
|
|
2021-05-11 20:29:08 +03:00
|
|
|
#include "shared/shared.h"
|
2019-04-17 23:08:56 +03:00
|
|
|
#include "contact.h"
|
2019-08-21 12:35:07 +03:00
|
|
|
#include "conference.h"
|
2019-11-09 17:04:27 +03:00
|
|
|
#include "networkaccess.h"
|
2019-03-29 17:54:34 +03:00
|
|
|
|
2020-04-28 23:35:52 +03:00
|
|
|
#include "handlers/messagehandler.h"
|
2020-06-15 00:23:43 +03:00
|
|
|
#include "handlers/rosterhandler.h"
|
2020-04-28 23:35:52 +03:00
|
|
|
|
2019-03-29 17:54:34 +03:00
|
|
|
namespace Core
|
|
|
|
{
|
|
|
|
|
|
|
|
class Account : public QObject
|
|
|
|
{
|
2019-04-01 00:05:09 +03:00
|
|
|
Q_OBJECT
|
2020-04-28 23:35:52 +03:00
|
|
|
friend class MessageHandler;
|
2020-06-15 00:23:43 +03:00
|
|
|
friend class RosterHandler;
|
2019-03-29 17:54:34 +03:00
|
|
|
public:
|
2020-04-04 19:40:32 +03:00
|
|
|
Account(
|
|
|
|
const QString& p_login,
|
|
|
|
const QString& p_server,
|
|
|
|
const QString& p_password,
|
|
|
|
const QString& p_name,
|
|
|
|
NetworkAccess* p_net,
|
|
|
|
QObject* parent = 0);
|
2019-03-29 17:54:34 +03:00
|
|
|
~Account();
|
|
|
|
|
2019-04-01 00:05:09 +03:00
|
|
|
Shared::ConnectionState getState() const;
|
|
|
|
QString getName() const;
|
2019-04-03 00:58:43 +03:00
|
|
|
QString getLogin() const;
|
|
|
|
QString getServer() const;
|
|
|
|
QString getPassword() const;
|
2019-04-07 23:14:15 +03:00
|
|
|
QString getResource() const;
|
2019-10-16 22:38:35 +03:00
|
|
|
QString getAvatarPath() const;
|
2019-04-07 23:14:15 +03:00
|
|
|
Shared::Availability getAvailability() const;
|
2020-04-04 19:40:32 +03:00
|
|
|
Shared::AccountPassword getPasswordType() const;
|
2019-04-07 23:14:15 +03:00
|
|
|
|
|
|
|
void setName(const QString& p_name);
|
|
|
|
void setLogin(const QString& p_login);
|
|
|
|
void setServer(const QString& p_server);
|
|
|
|
void setPassword(const QString& p_password);
|
|
|
|
void setResource(const QString& p_resource);
|
|
|
|
void setAvailability(Shared::Availability avail);
|
2020-04-04 19:40:32 +03:00
|
|
|
void setPasswordType(Shared::AccountPassword pt);
|
2019-04-10 01:01:25 +03:00
|
|
|
QString getFullJid() const;
|
2020-04-28 23:35:52 +03:00
|
|
|
void sendMessage(const Shared::Message& data);
|
2019-04-21 22:17:04 +03:00
|
|
|
void requestArchive(const QString& jid, int count, const QString& before);
|
2019-06-12 20:18:18 +03:00
|
|
|
void subscribeToContact(const QString& jid, const QString& reason);
|
|
|
|
void unsubscribeFromContact(const QString& jid, const QString& reason);
|
2019-06-14 19:36:04 +03:00
|
|
|
void removeContactRequest(const QString& jid);
|
|
|
|
void addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups);
|
2019-09-28 17:30:16 +03:00
|
|
|
void addContactToGroupRequest(const QString& jid, const QString& groupName);
|
|
|
|
void removeContactFromGroupRequest(const QString& jid, const QString& groupName);
|
2019-10-01 11:47:40 +03:00
|
|
|
void renameContactRequest(const QString& jid, const QString& newName);
|
2021-04-28 23:26:19 +03:00
|
|
|
void requestChangeMessage(const QString& jid, const QString& messageId, const QMap<QString, QVariant>& data);
|
2019-04-01 00:05:09 +03:00
|
|
|
|
2019-08-29 17:19:35 +03:00
|
|
|
void setRoomJoined(const QString& jid, bool joined);
|
|
|
|
void setRoomAutoJoin(const QString& jid, bool joined);
|
2019-09-03 23:28:58 +03:00
|
|
|
void removeRoomRequest(const QString& jid);
|
2019-09-04 19:38:52 +03:00
|
|
|
void addRoomRequest(const QString& jid, const QString& nick, const QString& password, bool autoJoin);
|
2019-10-24 12:42:38 +03:00
|
|
|
void uploadVCard(const Shared::VCard& card);
|
2021-05-23 01:03:14 +03:00
|
|
|
void resendMessage(const QString& jid, const QString& id);
|
2022-03-28 23:25:33 +03:00
|
|
|
void replaceMessage(const QString& originalId, const Shared::Message& data);
|
2019-08-29 17:19:35 +03:00
|
|
|
|
2019-12-30 23:22:04 +03:00
|
|
|
public slots:
|
2020-05-21 18:42:40 +03:00
|
|
|
void connect();
|
|
|
|
void disconnect();
|
|
|
|
void reconnect();
|
2019-12-30 23:22:04 +03:00
|
|
|
void requestVCard(const QString& jid);
|
|
|
|
|
2019-04-01 00:05:09 +03:00
|
|
|
signals:
|
2019-10-16 22:38:35 +03:00
|
|
|
void changed(const QMap<QString, QVariant>& data);
|
2020-04-04 01:28:15 +03:00
|
|
|
void connectionStateChanged(Shared::ConnectionState);
|
|
|
|
void availabilityChanged(Shared::Availability);
|
2019-04-04 00:23:51 +03:00
|
|
|
void addGroup(const QString& name);
|
|
|
|
void removeGroup(const QString& name);
|
2019-07-11 11:51:52 +03:00
|
|
|
void addRoom(const QString& jid, const QMap<QString, QVariant>& data);
|
|
|
|
void changeRoom(const QString& jid, const QMap<QString, QVariant>& data);
|
|
|
|
void removeRoom(const QString& jid);
|
2019-04-07 23:14:15 +03:00
|
|
|
void addContact(const QString& jid, const QString& group, const QMap<QString, QVariant>& data);
|
2019-04-06 13:14:32 +03:00
|
|
|
void removeContact(const QString& jid);
|
|
|
|
void removeContact(const QString& jid, const QString& group);
|
2019-04-07 23:14:15 +03:00
|
|
|
void changeContact(const QString& jid, const QMap<QString, QVariant>& data);
|
2019-04-07 17:02:41 +03:00
|
|
|
void addPresence(const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
|
|
|
|
void removePresence(const QString& jid, const QString& name);
|
2019-04-11 17:58:59 +03:00
|
|
|
void message(const Shared::Message& data);
|
2020-03-25 18:28:36 +03:00
|
|
|
void changeMessage(const QString& jid, const QString& id, const QMap<QString, QVariant>& data);
|
2020-08-21 23:57:48 +03:00
|
|
|
void responseArchive(const QString& jid, const std::list<Shared::Message>& list, bool last);
|
2019-05-24 17:46:34 +03:00
|
|
|
void error(const QString& text);
|
2019-09-01 22:46:12 +03:00
|
|
|
void addRoomParticipant(const QString& jid, const QString& nickName, const QMap<QString, QVariant>& data);
|
|
|
|
void changeRoomParticipant(const QString& jid, const QString& nickName, const QMap<QString, QVariant>& data);
|
|
|
|
void removeRoomParticipant(const QString& jid, const QString& nickName);
|
2019-10-19 22:34:25 +03:00
|
|
|
void receivedVCard(const QString& jid, const Shared::VCard& card);
|
2019-11-09 17:04:27 +03:00
|
|
|
void uploadFile(const QFileInfo& file, const QUrl& set, const QUrl& get, QMap<QString, QString> headers);
|
2021-04-18 15:49:20 +03:00
|
|
|
void uploadFileError(const QString& jid, const QString& messageId, const QString& error);
|
2019-04-01 00:05:09 +03:00
|
|
|
|
2019-03-29 17:54:34 +03:00
|
|
|
private:
|
2019-03-30 23:13:13 +03:00
|
|
|
QString name;
|
2020-06-21 01:26:30 +03:00
|
|
|
std::map<QString, QString> archiveQueries;
|
2019-03-29 17:54:34 +03:00
|
|
|
QXmppClient client;
|
2019-04-07 23:14:15 +03:00
|
|
|
QXmppConfiguration config;
|
|
|
|
QXmppPresence presence;
|
2019-04-01 00:05:09 +03:00
|
|
|
Shared::ConnectionState state;
|
2019-04-12 18:22:10 +03:00
|
|
|
QXmppCarbonManager* cm;
|
2019-04-13 23:38:20 +03:00
|
|
|
QXmppMamManager* am;
|
2019-07-11 11:51:52 +03:00
|
|
|
QXmppMucManager* mm;
|
|
|
|
QXmppBookmarkManager* bm;
|
2019-11-02 23:50:25 +03:00
|
|
|
QXmppRosterManager* rm;
|
|
|
|
QXmppVCardManager* vm;
|
2019-11-09 17:04:27 +03:00
|
|
|
QXmppUploadRequestManager* um;
|
2019-11-12 16:38:01 +03:00
|
|
|
QXmppDiscoveryManager* dm;
|
2020-03-27 23:59:30 +03:00
|
|
|
QXmppMessageReceiptManager* rcpm;
|
2020-05-21 18:42:40 +03:00
|
|
|
bool reconnectScheduled;
|
|
|
|
QTimer* reconnectTimer;
|
2019-04-01 00:05:09 +03:00
|
|
|
|
2019-10-15 22:25:40 +03:00
|
|
|
std::set<QString> pendingVCardRequests;
|
2019-06-18 18:08:03 +03:00
|
|
|
|
2019-10-16 22:38:35 +03:00
|
|
|
QString avatarHash;
|
|
|
|
QString avatarType;
|
|
|
|
bool ownVCardRequestInProgress;
|
2019-11-09 17:04:27 +03:00
|
|
|
NetworkAccess* network;
|
2020-04-04 19:40:32 +03:00
|
|
|
Shared::AccountPassword passwordType;
|
2019-06-18 18:08:03 +03:00
|
|
|
|
2020-04-28 23:35:52 +03:00
|
|
|
MessageHandler* mh;
|
2020-06-15 00:23:43 +03:00
|
|
|
RosterHandler* rh;
|
2020-04-28 23:35:52 +03:00
|
|
|
|
2019-04-01 00:05:09 +03:00
|
|
|
private slots:
|
2020-05-21 18:42:40 +03:00
|
|
|
void onClientStateChange(QXmppClient::State state);
|
2019-05-15 20:36:37 +03:00
|
|
|
void onClientError(QXmppClient::Error err);
|
2019-04-19 12:12:12 +03:00
|
|
|
|
2019-04-07 17:02:41 +03:00
|
|
|
void onPresenceReceived(const QXmppPresence& presence);
|
2020-06-15 00:23:43 +03:00
|
|
|
void onContactNeedHistory(const QString& before, const QString& after, const QDateTime& at);
|
|
|
|
|
2019-04-13 23:38:20 +03:00
|
|
|
void onMamMessageReceived(const QString& bareJid, const QXmppMessage& message);
|
|
|
|
void onMamResultsReceived(const QString &queryId, const QXmppResultSetReply &resultSetReply, bool complete);
|
2020-06-15 00:23:43 +03:00
|
|
|
|
2019-06-28 18:15:30 +03:00
|
|
|
void onMamLog(QXmppLogger::MessageType type, const QString &msg);
|
2019-10-15 22:25:40 +03:00
|
|
|
|
|
|
|
void onVCardReceived(const QXmppVCardIq& card);
|
2019-10-16 22:38:35 +03:00
|
|
|
void onOwnVCardReceived(const QXmppVCardIq& card);
|
2020-04-28 23:35:52 +03:00
|
|
|
|
2019-11-12 16:38:01 +03:00
|
|
|
void onDiscoveryItemsReceived (const QXmppDiscoveryIq& items);
|
|
|
|
void onDiscoveryInfoReceived (const QXmppDiscoveryIq& info);
|
2020-08-21 23:57:48 +03:00
|
|
|
void onContactHistoryResponse(const std::list<Shared::Message>& list, bool last);
|
2019-04-06 13:14:32 +03:00
|
|
|
|
|
|
|
private:
|
2020-08-08 02:33:03 +03:00
|
|
|
void handleDisconnection();
|
2020-06-21 01:26:30 +03:00
|
|
|
void onReconnectTimer();
|
2019-03-29 17:54:34 +03:00
|
|
|
};
|
|
|
|
|
2019-11-05 21:55:21 +03:00
|
|
|
void initializeVCard(Shared::VCard& vCard, const QXmppVCardIq& card);
|
|
|
|
void initializeQXmppVCard(QXmppVCardIq& card, const Shared::VCard& vCard);
|
2019-03-29 17:54:34 +03:00
|
|
|
}
|
|
|
|
|
2019-07-11 11:51:52 +03:00
|
|
|
|
2019-03-29 17:54:34 +03:00
|
|
|
#endif // CORE_ACCOUNT_H
|