2019-08-14 14:54:46 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CORE_ROSTERITEM_H
|
|
|
|
#define CORE_ROSTERITEM_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
2019-10-14 20:18:51 +00:00
|
|
|
#include <QStandardPaths>
|
2019-10-15 19:25:40 +00:00
|
|
|
#include <QImage>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QBuffer>
|
2019-08-14 14:54:46 +00:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
2019-12-30 20:22:04 +00:00
|
|
|
#include <QXmppVCardIq.h>
|
|
|
|
#include <QXmppPresence.h>
|
|
|
|
|
2020-04-03 22:28:15 +00:00
|
|
|
#include "shared/enums.h"
|
|
|
|
#include "shared/message.h"
|
|
|
|
#include "shared/vcard.h"
|
2019-08-14 14:54:46 +00:00
|
|
|
#include "archive.h"
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @todo write docs
|
|
|
|
*/
|
|
|
|
class RosterItem : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum ArchiveState {
|
|
|
|
empty, //have no messages stored for this contact
|
|
|
|
chunk, //have some chunk of history, don't have the beginning nor have the end
|
|
|
|
beginning, //have the history from the very beginning, don't have the end
|
|
|
|
end, //have the history to the end, but don't have the beginning
|
|
|
|
complete //have full history locally stored
|
|
|
|
};
|
|
|
|
|
|
|
|
RosterItem(const QString& pJid, const QString& account, QObject* parent = 0);
|
|
|
|
~RosterItem();
|
|
|
|
|
|
|
|
ArchiveState getArchiveState() const;
|
|
|
|
QString getName() const;
|
|
|
|
void setName(const QString& n);
|
2019-08-28 11:40:55 +00:00
|
|
|
QString getServer() const;
|
|
|
|
bool isMuc() const;
|
2019-08-14 14:54:46 +00:00
|
|
|
|
|
|
|
void addMessageToArchive(const Shared::Message& msg);
|
2020-03-28 14:05:49 +00:00
|
|
|
void correctMessageInArchive(const QString& originalId, const Shared::Message& msg);
|
2019-08-14 14:54:46 +00:00
|
|
|
void appendMessageToArchive(const Shared::Message& msg);
|
|
|
|
void flushMessagesToArchive(bool finished, const QString& firstId, const QString& lastId);
|
|
|
|
void requestHistory(int count, const QString& before);
|
2019-12-30 20:22:04 +00:00
|
|
|
QString avatarPath(const QString& resource = "") const;
|
2020-04-13 19:57:23 +00:00
|
|
|
QString folderPath() const;
|
2019-12-30 20:22:04 +00:00
|
|
|
bool readAvatarInfo(Archive::AvatarInfo& target, const QString& resource = "") const;
|
|
|
|
virtual bool setAutoGeneratedAvatar(const QString& resource = "");
|
|
|
|
virtual Shared::VCard handleResponseVCard(const QXmppVCardIq& card, const QString& resource);
|
|
|
|
virtual void handlePresence(const QXmppPresence& pres) = 0;
|
2019-08-14 14:54:46 +00:00
|
|
|
|
2020-03-28 14:05:49 +00:00
|
|
|
bool changeMessage(const QString& id, const QMap<QString, QVariant>& data);
|
2020-04-19 13:13:15 +00:00
|
|
|
void clearArchiveRequests();
|
2020-06-20 22:26:30 +00:00
|
|
|
void downgradeDatabaseState();
|
2020-03-25 15:28:36 +00:00
|
|
|
|
2019-08-14 14:54:46 +00:00
|
|
|
signals:
|
|
|
|
void nameChanged(const QString& name);
|
|
|
|
void subscriptionStateChanged(Shared::SubscriptionState state);
|
|
|
|
void historyResponse(const std::list<Shared::Message>& messages);
|
|
|
|
void needHistory(const QString& before, const QString& after, const QDateTime& afterTime = QDateTime());
|
2019-10-15 19:25:40 +00:00
|
|
|
void avatarChanged(Shared::Avatar, const QString& path);
|
2019-12-30 20:22:04 +00:00
|
|
|
void requestVCard(const QString& jid);
|
2019-08-14 14:54:46 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
const QString jid;
|
2019-10-14 20:18:51 +00:00
|
|
|
const QString account;
|
2019-08-14 14:54:46 +00:00
|
|
|
|
2020-04-13 19:57:23 +00:00
|
|
|
protected:
|
|
|
|
virtual bool setAvatar(const QByteArray& data, Archive::AvatarInfo& info, const QString& resource = "");
|
|
|
|
virtual bool setAutoGeneratedAvatar(Archive::AvatarInfo& info, const QString& resource = "");
|
|
|
|
|
2019-08-14 14:54:46 +00:00
|
|
|
protected:
|
|
|
|
QString name;
|
|
|
|
ArchiveState archiveState;
|
|
|
|
Archive* archive;
|
|
|
|
|
|
|
|
bool syncronizing;
|
|
|
|
int requestedCount;
|
|
|
|
QString requestedBefore;
|
|
|
|
std::list<Shared::Message> hisoryCache;
|
|
|
|
std::list<Shared::Message> appendCache;
|
|
|
|
std::list<Shared::Message> responseCache;
|
|
|
|
std::list<std::pair<int, QString>> requestCache;
|
2020-03-28 14:05:49 +00:00
|
|
|
std::map<QString, Shared::Message> toCorrect;
|
2019-08-28 11:40:55 +00:00
|
|
|
bool muc;
|
2020-04-13 19:57:23 +00:00
|
|
|
|
2019-08-14 14:54:46 +00:00
|
|
|
private:
|
|
|
|
void nextRequest();
|
|
|
|
void performRequest(int count, const QString& before);
|
2020-05-21 15:42:40 +00:00
|
|
|
QString getId(const Shared::Message& msg);
|
2019-08-14 14:54:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CORE_ROSTERITEM_H
|