1
0
forked from blue/squawk
squawk/core/components/archive.h

102 lines
3.3 KiB
C
Raw Normal View History

/*
* 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-14 23:23:39 +00:00
#pragma once
#include <QObject>
#include <QCryptographicHash>
#include <QMimeDatabase>
#include <QMimeType>
2023-11-05 01:12:15 +00:00
#include <QDataStream>
2023-11-05 01:12:15 +00:00
#include "shared/enums.h"
#include "shared/message.h"
2021-05-11 17:29:08 +00:00
#include "shared/exception.h"
2019-04-21 19:17:04 +00:00
#include <list>
2024-02-01 16:10:52 +00:00
#include <base.h>
#include <storage.h>
#include <cursor.h>
namespace Core {
class Archive : public QObject {
Q_OBJECT
public:
2019-12-30 20:22:04 +00:00
class AvatarInfo;
Archive(const QString& account, const QString& jid, QObject* parent = 0);
~Archive();
void open();
void close();
2019-04-21 19:17:04 +00:00
bool addElement(const Shared::Message& message);
2019-04-26 12:52:34 +00:00
unsigned int addElements(const std::list<Shared::Message>& messages);
Shared::Message getElement(const QString& id) const;
bool hasElement(const QString& id) const;
void changeMessage(const QString& id, const QMap<QString, QVariant>& data);
Shared::Message oldest() const;
QString oldestId() const;
Shared::Message newest() const;
QString newestId() const;
void clear();
2019-04-15 22:35:09 +00:00
long unsigned int size() const;
std::list<Shared::Message> getBefore(unsigned int count, const QString& id);
bool isFromTheBeginning() const;
void setFromTheBeginning(bool is);
2023-11-05 01:12:15 +00:00
Shared::EncryptionProtocol encryption() const;
bool setEncryption(Shared::EncryptionProtocol value); //returns true if changed, false otherwise
2020-04-13 19:57:23 +00:00
bool setAvatar(const QByteArray& data, AvatarInfo& info, bool generated = false, const QString& resource = "");
2019-12-30 20:22:04 +00:00
AvatarInfo getAvatarInfo(const QString& resource = "") const;
bool readAvatarInfo(AvatarInfo& target, const QString& resource = "") const;
2020-04-13 19:57:23 +00:00
void readAllResourcesAvatars(std::map<QString, AvatarInfo>& data) const;
QString idByStanzaId(const QString& stanzaId) const;
QString stanzaIdById(const QString& id) const;
public:
const QString jid;
const QString account;
2019-04-15 22:35:09 +00:00
public:
2019-12-30 20:22:04 +00:00
class AvatarInfo {
public:
AvatarInfo();
AvatarInfo(const QString& type, const QByteArray& hash, bool autogenerated);
QString type;
QByteArray hash;
bool autogenerated;
};
private:
bool opened;
LMDBAL::Base db;
LMDBAL::Storage<QString, Shared::Message>* messages;
LMDBAL::Storage<uint64_t, QString>* order;
LMDBAL::Storage<QString, QVariant>* stats;
LMDBAL::Storage<QString, AvatarInfo>* avatars;
LMDBAL::Storage<QString, QString>* stanzaIdToId;
mutable LMDBAL::Cursor<uint64_t, QString> cursor;
};
}
QDataStream& operator << (QDataStream &out, const Core::Archive::AvatarInfo& info);
QDataStream& operator >> (QDataStream &in, Core::Archive::AvatarInfo& info);