2019-04-14 20:37:02 +00:00
|
|
|
/*
|
2019-08-14 14:54:46 +00:00
|
|
|
* Squawk messenger.
|
2019-04-14 20:37:02 +00:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "archive.h"
|
2023-11-05 01:12:15 +00:00
|
|
|
|
2019-04-14 20:37:02 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2023-11-05 01:12:15 +00:00
|
|
|
|
2019-04-14 20:37:02 +00:00
|
|
|
#include <QDebug>
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
Core::Archive::Archive(const QString& account, const QString& p_jid, QObject* parent):
|
2019-04-14 20:37:02 +00:00
|
|
|
QObject(parent),
|
|
|
|
jid(p_jid),
|
2023-11-02 22:55:11 +00:00
|
|
|
account(account),
|
2019-04-14 20:37:02 +00:00
|
|
|
opened(false),
|
2023-11-02 22:55:11 +00:00
|
|
|
db(account + "/" + jid),
|
|
|
|
messages(db.addStorage<QString, Shared::Message>("messages")),
|
2023-11-09 22:36:30 +00:00
|
|
|
order(db.addStorage<uint64_t, QString>("order", true)),
|
2023-11-02 22:55:11 +00:00
|
|
|
stats(db.addStorage<QString, QVariant>("stats")),
|
|
|
|
avatars(db.addStorage<QString, AvatarInfo>("avatars")),
|
|
|
|
stanzaIdToId(db.addStorage<QString, QString>("stanzaIdToId")),
|
|
|
|
cursor(order->createCursor())
|
|
|
|
{}
|
|
|
|
|
|
|
|
Core::Archive::~Archive() {
|
2019-04-17 20:08:56 +00:00
|
|
|
close();
|
2019-04-14 20:37:02 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
void Core::Archive::open() {
|
|
|
|
db.open();
|
|
|
|
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
2023-03-16 19:38:05 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
AvatarInfo info;
|
|
|
|
bool hasAvatar = false;
|
|
|
|
try {
|
|
|
|
avatars->getRecord(jid, info, txn);
|
|
|
|
hasAvatar = true;
|
|
|
|
} catch (const LMDBAL::NotFound& e) {}
|
|
|
|
|
|
|
|
if (!hasAvatar)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QFile ava(db.getPath() + "/" + jid + "." + info.type);
|
|
|
|
if (ava.exists())
|
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
avatars->removeRecord(jid, txn);
|
|
|
|
txn.commit();
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
qDebug() << e.what();
|
|
|
|
qDebug() << "error opening archive" << jid << "for account" << account
|
|
|
|
<< ". There is supposed to be avatar but the file doesn't exist, couldn't even drop it, it surely will lead to an error";
|
2019-04-15 22:35:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
void Core::Archive::close() {
|
|
|
|
db.close();
|
2019-04-17 20:08:56 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
bool Core::Archive::addElement(const Shared::Message& message) {
|
|
|
|
QString id = message.getId();
|
|
|
|
qDebug() << "Adding message with id " << id;
|
|
|
|
|
|
|
|
try {
|
|
|
|
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
|
|
|
messages->addRecord(id, message, txn);
|
|
|
|
order->addRecord(message.getTime().toMSecsSinceEpoch(), id, txn);
|
|
|
|
QString stanzaId = message.getStanzaId();
|
|
|
|
if (!stanzaId.isEmpty())
|
2023-11-03 23:13:45 +00:00
|
|
|
stanzaIdToId->addRecord(stanzaId, id, txn);
|
2023-11-02 22:55:11 +00:00
|
|
|
|
|
|
|
txn.commit();
|
|
|
|
return true;
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
qDebug() << "Could not add message with id " + id;
|
|
|
|
qDebug() << e.what();
|
2019-04-15 22:35:09 +00:00
|
|
|
}
|
2023-11-02 22:55:11 +00:00
|
|
|
|
|
|
|
return false;
|
2019-04-15 22:35:09 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
void Core::Archive::clear() {
|
|
|
|
db.drop();
|
2019-04-15 22:35:09 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
Shared::Message Core::Archive::getElement(const QString& id) const {
|
|
|
|
return messages->getRecord(id);
|
2020-01-07 09:26:07 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
bool Core::Archive::hasElement(const QString& id) const {
|
|
|
|
return messages->checkRecord(id);
|
2020-08-09 16:28:03 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
void Core::Archive::changeMessage(const QString& id, const QMap<QString, QVariant>& data) {
|
|
|
|
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
|
|
|
Shared::Message msg = messages->getRecord(id, txn);
|
|
|
|
|
|
|
|
bool hadStanzaId = !msg.getStanzaId().isEmpty();
|
|
|
|
QDateTime oTime = msg.getTime();
|
|
|
|
bool idChange = msg.change(data);
|
|
|
|
QString newId = msg.getId();
|
|
|
|
QDateTime nTime = msg.getTime();
|
|
|
|
|
|
|
|
bool orderChange = oTime != nTime;
|
|
|
|
if (idChange || orderChange) {
|
|
|
|
if (idChange)
|
|
|
|
messages->removeRecord(id, txn);
|
|
|
|
|
|
|
|
if (orderChange)
|
|
|
|
order->removeRecord(oTime.toMSecsSinceEpoch(), txn);
|
|
|
|
|
|
|
|
order->forceRecord(nTime.toMSecsSinceEpoch(), newId, txn);
|
2020-01-07 09:26:07 +00:00
|
|
|
}
|
2023-11-02 22:55:11 +00:00
|
|
|
|
|
|
|
QString sid = msg.getStanzaId();
|
|
|
|
if (!sid.isEmpty() && (idChange || !hadStanzaId))
|
|
|
|
stanzaIdToId->forceRecord(sid, newId, txn);
|
|
|
|
|
|
|
|
messages->forceRecord(newId, msg, txn);
|
|
|
|
txn.commit();
|
2020-01-07 09:26:07 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
Shared::Message Core::Archive::newest() const {
|
|
|
|
LMDBAL::Transaction txn = db.beginReadOnlyTransaction();
|
|
|
|
|
2020-01-07 09:26:07 +00:00
|
|
|
try {
|
2023-11-02 22:55:11 +00:00
|
|
|
cursor.open(txn);
|
|
|
|
while (true) {
|
|
|
|
std::pair<uint64_t, QString> pair = cursor.prev();
|
|
|
|
Shared::Message msg = messages->getRecord(pair.second, txn);
|
|
|
|
if (msg.serverStored()) {
|
|
|
|
cursor.close();
|
|
|
|
return msg;
|
2020-03-27 20:59:30 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-07 09:26:07 +00:00
|
|
|
} catch (...) {
|
2023-11-02 22:55:11 +00:00
|
|
|
cursor.close();
|
2020-01-07 09:26:07 +00:00
|
|
|
throw;
|
2019-04-14 20:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
QString Core::Archive::newestId() const {
|
2020-03-28 14:05:49 +00:00
|
|
|
Shared::Message msg = newest();
|
|
|
|
return msg.getId();
|
2019-04-15 22:35:09 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
QString Core::Archive::oldestId() const {
|
2020-03-28 14:05:49 +00:00
|
|
|
Shared::Message msg = oldest();
|
|
|
|
return msg.getId();
|
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
Shared::Message Core::Archive::oldest() const {
|
|
|
|
LMDBAL::Transaction txn = db.beginReadOnlyTransaction();
|
2019-07-11 08:51:52 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
try {
|
|
|
|
cursor.open(txn);
|
|
|
|
while (true) {
|
|
|
|
std::pair<uint64_t, QString> pair = cursor.next();
|
|
|
|
Shared::Message msg = messages->getRecord(pair.second, txn);
|
2020-03-28 14:05:49 +00:00
|
|
|
if (msg.serverStored()) {
|
2023-11-02 22:55:11 +00:00
|
|
|
cursor.close();
|
|
|
|
return msg;
|
2020-03-28 14:05:49 +00:00
|
|
|
}
|
|
|
|
}
|
2023-11-02 22:55:11 +00:00
|
|
|
} catch (...) {
|
|
|
|
cursor.close();
|
|
|
|
throw;
|
2020-03-28 14:05:49 +00:00
|
|
|
}
|
2019-04-15 22:35:09 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
unsigned int Core::Archive::addElements(const std::list<Shared::Message>& messages) {
|
|
|
|
unsigned int success = 0;
|
|
|
|
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
|
|
|
for (const Shared::Message& message : messages) {
|
|
|
|
QString id = message.getId();
|
|
|
|
bool added = false;
|
|
|
|
try {
|
|
|
|
Core::Archive::messages->addRecord(id, message, txn);
|
|
|
|
added = true;
|
|
|
|
} catch (const LMDBAL::Exist& e) {}
|
2019-04-28 21:34:28 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
if (!added)
|
|
|
|
continue;
|
2019-04-21 19:17:04 +00:00
|
|
|
|
2023-11-03 23:13:45 +00:00
|
|
|
order->addRecord(message.getTime().toMSecsSinceEpoch(), id, txn);
|
2023-11-02 22:55:11 +00:00
|
|
|
|
|
|
|
QString sid = message.getStanzaId();
|
|
|
|
if (!sid.isEmpty())
|
2023-11-03 23:13:45 +00:00
|
|
|
stanzaIdToId->addRecord(sid, id, txn);
|
2023-11-02 22:55:11 +00:00
|
|
|
|
|
|
|
++success;
|
2019-04-21 19:17:04 +00:00
|
|
|
}
|
2023-11-03 23:13:45 +00:00
|
|
|
txn.commit();
|
2019-04-21 19:17:04 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
return success;
|
2019-04-21 19:17:04 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
long unsigned int Core::Archive::size() const {
|
|
|
|
return order->count();
|
2019-04-21 19:17:04 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
std::list<Shared::Message> Core::Archive::getBefore(unsigned int count, const QString& id) {
|
|
|
|
LMDBAL::Transaction txn = db.beginReadOnlyTransaction();
|
2023-11-03 23:13:45 +00:00
|
|
|
std::list<Shared::Message> res;
|
2023-11-02 22:55:11 +00:00
|
|
|
try {
|
|
|
|
cursor.open(txn);
|
2023-11-03 23:13:45 +00:00
|
|
|
if (!id.isEmpty()) {
|
2023-11-02 22:55:11 +00:00
|
|
|
Shared::Message reference = messages->getRecord(id, txn);
|
|
|
|
uint64_t stamp = reference.getTime().toMSecsSinceEpoch();
|
|
|
|
cursor.set(stamp);
|
2019-04-21 19:17:04 +00:00
|
|
|
}
|
2023-03-16 19:38:05 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
for (unsigned int i = 0; i < count; ++i) {
|
|
|
|
std::pair<uint64_t, QString> pair;
|
2023-11-03 23:13:45 +00:00
|
|
|
cursor.prev(pair.first, pair.second);
|
2023-03-16 19:38:05 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
res.emplace_back();
|
|
|
|
Shared::Message& msg = res.back();
|
|
|
|
messages->getRecord(pair.second, msg, txn);
|
2023-03-16 19:38:05 +00:00
|
|
|
}
|
2023-11-02 22:55:11 +00:00
|
|
|
cursor.close();
|
2020-05-21 15:42:40 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
return res;
|
2023-11-03 23:13:45 +00:00
|
|
|
} catch (const LMDBAL::NotFound& e) {
|
|
|
|
cursor.close();
|
|
|
|
if (res.empty())
|
|
|
|
throw e;
|
|
|
|
else
|
|
|
|
return res;
|
2020-05-21 15:42:40 +00:00
|
|
|
} catch (...) {
|
2023-11-02 22:55:11 +00:00
|
|
|
cursor.close();
|
2020-05-21 15:42:40 +00:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
bool Core::Archive::isFromTheBeginning() const {
|
|
|
|
try {
|
|
|
|
return stats->getRecord("fromTheBeginning").toBool();
|
|
|
|
} catch (const LMDBAL::NotFound& e) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-15 17:36:37 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
void Core::Archive::setFromTheBeginning(bool is) {
|
|
|
|
stats->forceRecord("fromTheBeginning", is);
|
2019-05-15 17:36:37 +00:00
|
|
|
}
|
2019-10-14 20:18:51 +00:00
|
|
|
|
2023-11-05 01:12:15 +00:00
|
|
|
Shared::EncryptionProtocol Core::Archive::encryption() const {
|
2023-11-02 22:55:11 +00:00
|
|
|
try {
|
2023-11-05 01:12:15 +00:00
|
|
|
return stats->getRecord("encryption").value<Shared::EncryptionProtocol>();
|
2023-11-02 22:55:11 +00:00
|
|
|
} catch (const LMDBAL::NotFound& e) {
|
2023-11-05 01:12:15 +00:00
|
|
|
return Shared::EncryptionProtocol::none;
|
2019-10-14 20:18:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-05 01:12:15 +00:00
|
|
|
bool Core::Archive::setEncryption(Shared::EncryptionProtocol is) {
|
2023-11-02 22:55:11 +00:00
|
|
|
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
2023-11-05 01:12:15 +00:00
|
|
|
Shared::EncryptionProtocol current = Shared::EncryptionProtocol::none;
|
2023-11-02 22:55:11 +00:00
|
|
|
try {
|
2023-11-05 01:12:15 +00:00
|
|
|
current = stats->getRecord("encryption", txn).value<Shared::EncryptionProtocol>();
|
2023-11-02 22:55:11 +00:00
|
|
|
} catch (const LMDBAL::NotFound& e) {}
|
2019-10-14 20:18:51 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
if (is != current) {
|
2023-11-05 01:12:15 +00:00
|
|
|
stats->forceRecord("encryption", static_cast<uint8_t>(is), txn);
|
2023-11-02 22:55:11 +00:00
|
|
|
txn.commit();
|
|
|
|
return true;
|
2019-10-14 20:18:51 +00:00
|
|
|
}
|
2023-11-02 22:55:11 +00:00
|
|
|
|
|
|
|
return false;
|
2019-10-14 20:18:51 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
QString Core::Archive::idByStanzaId(const QString& stanzaId) const {
|
|
|
|
return stanzaIdToId->getRecord(stanzaId);
|
2019-10-14 20:18:51 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
QString Core::Archive::stanzaIdById(const QString& id) const {
|
|
|
|
try {
|
|
|
|
Shared::Message msg = getElement(id);
|
|
|
|
return msg.getStanzaId();
|
|
|
|
} catch (const LMDBAL::NotFound& e) {
|
|
|
|
return QString();
|
2019-10-15 19:25:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
bool Core::Archive::setAvatar(const QByteArray& data, AvatarInfo& newInfo, bool generated, const QString& resource) {
|
|
|
|
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
2019-12-30 20:22:04 +00:00
|
|
|
AvatarInfo oldInfo;
|
2023-11-02 22:55:11 +00:00
|
|
|
bool haveAvatar = false;
|
|
|
|
QString res = resource.isEmpty() ? jid : resource;
|
|
|
|
try {
|
|
|
|
avatars->getRecord(res, oldInfo, txn);
|
|
|
|
haveAvatar = true;
|
|
|
|
} catch (const LMDBAL::NotFound& e) {}
|
2019-12-30 20:22:04 +00:00
|
|
|
|
2019-10-15 19:25:40 +00:00
|
|
|
if (data.size() == 0) {
|
2023-11-02 22:55:11 +00:00
|
|
|
if (!haveAvatar)
|
2019-10-15 19:25:40 +00:00
|
|
|
return false;
|
2023-11-02 22:55:11 +00:00
|
|
|
|
|
|
|
avatars->removeRecord(res, txn);
|
|
|
|
txn.commit();
|
|
|
|
return true;
|
2019-10-15 19:25:40 +00:00
|
|
|
} else {
|
2023-11-02 22:55:11 +00:00
|
|
|
QString currentPath = db.getPath();
|
2019-10-15 19:25:40 +00:00
|
|
|
bool needToRemoveOld = false;
|
|
|
|
QCryptographicHash hash(QCryptographicHash::Sha1);
|
|
|
|
hash.addData(data);
|
2019-12-30 20:22:04 +00:00
|
|
|
QByteArray newHash(hash.result());
|
2023-11-02 22:55:11 +00:00
|
|
|
if (haveAvatar) {
|
|
|
|
if (!generated && !oldInfo.autogenerated && oldInfo.hash == newHash)
|
2019-10-15 19:25:40 +00:00
|
|
|
return false;
|
2023-11-02 22:55:11 +00:00
|
|
|
|
|
|
|
QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type);
|
2019-10-15 19:25:40 +00:00
|
|
|
if (oldAvatar.exists()) {
|
2023-11-02 22:55:11 +00:00
|
|
|
if (oldAvatar.rename(currentPath + "/" + res + "." + oldInfo.type + ".bak")) {
|
2019-10-15 19:25:40 +00:00
|
|
|
needToRemoveOld = true;
|
|
|
|
} else {
|
|
|
|
qDebug() << "Can't change avatar: couldn't get rid of the old avatar" << oldAvatar.fileName();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-02 22:55:11 +00:00
|
|
|
QMimeDatabase mimedb;
|
|
|
|
QMimeType type = mimedb.mimeTypeForData(data);
|
2019-10-15 19:25:40 +00:00
|
|
|
QString ext = type.preferredSuffix();
|
2023-11-02 22:55:11 +00:00
|
|
|
QFile newAvatar(currentPath + "/" + res + "." + ext);
|
2019-10-15 19:25:40 +00:00
|
|
|
if (newAvatar.open(QFile::WriteOnly)) {
|
|
|
|
newAvatar.write(data);
|
|
|
|
newAvatar.close();
|
|
|
|
|
2020-04-13 19:57:23 +00:00
|
|
|
newInfo.type = ext;
|
|
|
|
newInfo.hash = newHash;
|
|
|
|
newInfo.autogenerated = generated;
|
2023-11-02 22:55:11 +00:00
|
|
|
try {
|
|
|
|
avatars->forceRecord(res, newInfo, txn);
|
|
|
|
txn.commit();
|
|
|
|
} catch (...) {
|
2019-10-15 19:25:40 +00:00
|
|
|
qDebug() << "Can't change avatar: couldn't store changes to database for" << newAvatar.fileName() << "rolling back to the previous state";
|
|
|
|
if (needToRemoveOld) {
|
2023-11-02 22:55:11 +00:00
|
|
|
QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type + ".bak");
|
|
|
|
oldAvatar.rename(currentPath + "/" + res + "." + oldInfo.type);
|
2019-10-15 19:25:40 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2023-11-02 22:55:11 +00:00
|
|
|
|
|
|
|
if (needToRemoveOld) {
|
|
|
|
QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type + ".bak");
|
|
|
|
oldAvatar.remove();
|
|
|
|
}
|
|
|
|
return true;
|
2019-10-15 19:25:40 +00:00
|
|
|
} else {
|
|
|
|
qDebug() << "Can't change avatar: cant open file to write" << newAvatar.fileName() << "rolling back to the previous state";
|
|
|
|
if (needToRemoveOld) {
|
2023-11-02 22:55:11 +00:00
|
|
|
QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type + ".bak");
|
|
|
|
oldAvatar.rename(currentPath + "/" + res + "." + oldInfo.type);
|
2019-10-15 19:25:40 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-30 20:22:04 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
bool Core::Archive::readAvatarInfo(Core::Archive::AvatarInfo& target, const QString& resource) const {
|
2019-12-30 20:22:04 +00:00
|
|
|
try {
|
2023-11-02 22:55:11 +00:00
|
|
|
avatars->getRecord(resource.isEmpty() ? jid : resource, target);
|
2019-12-30 20:22:04 +00:00
|
|
|
return true;
|
2023-11-02 22:55:11 +00:00
|
|
|
} catch (const LMDBAL::NotFound& e) {
|
|
|
|
return false;
|
2019-12-30 20:22:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
void Core::Archive::readAllResourcesAvatars(std::map<QString, AvatarInfo>& data) const {
|
|
|
|
avatars->readAll(data);
|
2020-04-13 19:57:23 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
Core::Archive::AvatarInfo Core::Archive::getAvatarInfo(const QString& resource) const {
|
|
|
|
return avatars->getRecord(resource);
|
2019-12-30 20:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Core::Archive::AvatarInfo::AvatarInfo():
|
2023-11-02 22:55:11 +00:00
|
|
|
type(),
|
|
|
|
hash(),
|
|
|
|
autogenerated(false)
|
|
|
|
{}
|
2019-12-30 20:22:04 +00:00
|
|
|
|
|
|
|
Core::Archive::AvatarInfo::AvatarInfo(const QString& p_type, const QByteArray& p_hash, bool p_autogenerated):
|
2023-11-02 22:55:11 +00:00
|
|
|
type(p_type),
|
|
|
|
hash(p_hash),
|
|
|
|
autogenerated(p_autogenerated)
|
|
|
|
{}
|
2019-12-30 20:22:04 +00:00
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
QDataStream & operator<<(QDataStream& out, const Core::Archive::AvatarInfo& info) {
|
|
|
|
out << info.type;
|
|
|
|
out << info.hash;
|
|
|
|
out << info.autogenerated;
|
|
|
|
|
|
|
|
return out;
|
2019-12-30 20:22:04 +00:00
|
|
|
}
|
|
|
|
|
2023-11-02 22:55:11 +00:00
|
|
|
QDataStream & operator>>(QDataStream& in, Core::Archive::AvatarInfo& info) {
|
|
|
|
in >> info.type;
|
|
|
|
in >> info.hash;
|
|
|
|
in >> info.autogenerated;
|
|
|
|
|
|
|
|
return in;
|
2019-12-30 20:22:04 +00:00
|
|
|
}
|