refactorng

This commit is contained in:
Blue 2023-11-14 20:23:39 -03:00
parent 00af582287
commit 75554c7451
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
30 changed files with 515 additions and 627 deletions

View File

@ -1,52 +0,0 @@
#This file is taken from here https://gitlab.ralph.or.at/causal-rt/causal-cpp/, it was GPLv3 license
#Thank you so much, mr. Ralph Alexander Bariz, I hope you don't mind me using your code
# Try to find LMDB headers and library.
#
# Usage of this module as follows:
#
# find_package(LMDB)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# LMDB_ROOT_DIR Set this variable to the root installation of
# LMDB if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# LMDB_FOUND System has LMDB library/headers.
# LMDB_LIBRARIES The LMDB library.
# LMDB_INCLUDE_DIRS The location of LMDB headers.
find_path(LMDB_ROOT_DIR
NAMES include/lmdb.h
)
find_library(LMDB_LIBRARIES
NAMES liblmdb.a liblmdb.so liblmdb.so.a liblmdb.dll.a # We want lmdb to be static, if possible
HINTS ${LMDB_ROOT_DIR}/lib
)
add_library(lmdb UNKNOWN IMPORTED)
set_target_properties(lmdb PROPERTIES
IMPORTED_LOCATION ${LMDB_LIBRARIES}
)
find_path(LMDB_INCLUDE_DIRS
NAMES lmdb.h
HINTS ${LMDB_ROOT_DIR}/include
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LMDB DEFAULT_MSG
LMDB_LIBRARIES
LMDB_INCLUDE_DIRS
)
mark_as_advanced(
LMDB_ROOT_DIR
LMDB_LIBRARIES
LMDB_INCLUDE_DIRS
)

View File

@ -1,15 +0,0 @@
find_path(Signal_INCLUDE_DIR NAMES signal/signal_protocol.h)
find_library(Signal_LIBRARY signal-protocol-c)
mark_as_advanced(Signal_INCLUDE_DIR Signal_LIBRARY)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Signal REQUIRED_VARS Signal_LIBRARY Signal_INCLUDE_DIR)
if (Signal_FOUND AND NOT TARGET Signal::Signal)
add_library(Signal::Signal UNKNOWN IMPORTED)
set_target_properties(Signal::Signal PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${Signal_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${Signal_INCLUDE_DIR}"
)
endif ()

View File

@ -207,7 +207,6 @@ unsigned int Core::Archive::addElements(const std::list<Shared::Message>& messag
++success; ++success;
} }
txn.commit(); txn.commit();
return success; return success;
} }
@ -315,63 +314,63 @@ bool Core::Archive::setAvatar(const QByteArray& data, AvatarInfo& newInfo, bool
avatars->removeRecord(res, txn); avatars->removeRecord(res, txn);
txn.commit(); txn.commit();
return true; return true;
} else { }
QString currentPath = db.getPath();
bool needToRemoveOld = false;
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(data);
QByteArray newHash(hash.result());
if (haveAvatar) {
if (!generated && !oldInfo.autogenerated && oldInfo.hash == newHash)
return false;
QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type); QString currentPath = db.getPath();
if (oldAvatar.exists()) { bool needToRemoveOld = false;
if (oldAvatar.rename(currentPath + "/" + res + "." + oldInfo.type + ".bak")) { QCryptographicHash hash(QCryptographicHash::Sha1);
needToRemoveOld = true; hash.addData(data);
} else { QByteArray newHash(hash.result());
qDebug() << "Can't change avatar: couldn't get rid of the old avatar" << oldAvatar.fileName(); if (haveAvatar) {
return false; if (!generated && !oldInfo.autogenerated && oldInfo.hash == newHash)
} return false;
}
} QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type);
QMimeDatabase mimedb; if (oldAvatar.exists()) {
QMimeType type = mimedb.mimeTypeForData(data); if (oldAvatar.rename(currentPath + "/" + res + "." + oldInfo.type + ".bak")) {
QString ext = type.preferredSuffix(); needToRemoveOld = true;
QFile newAvatar(currentPath + "/" + res + "." + ext); } else {
if (newAvatar.open(QFile::WriteOnly)) { qDebug() << "Can't change avatar: couldn't get rid of the old avatar" << oldAvatar.fileName();
newAvatar.write(data);
newAvatar.close();
newInfo.type = ext;
newInfo.hash = newHash;
newInfo.autogenerated = generated;
try {
avatars->forceRecord(res, newInfo, txn);
txn.commit();
} catch (...) {
qDebug() << "Can't change avatar: couldn't store changes to database for" << newAvatar.fileName() << "rolling back to the previous state";
if (needToRemoveOld) {
QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type + ".bak");
oldAvatar.rename(currentPath + "/" + res + "." + oldInfo.type);
}
return false; return false;
} }
if (needToRemoveOld) {
QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type + ".bak");
oldAvatar.remove();
}
return true;
} else {
qDebug() << "Can't change avatar: cant open file to write" << newAvatar.fileName() << "rolling back to the previous state";
if (needToRemoveOld) {
QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type + ".bak");
oldAvatar.rename(currentPath + "/" + res + "." + oldInfo.type);
}
return false;
} }
} }
QMimeDatabase mimedb;
QMimeType type = mimedb.mimeTypeForData(data);
QString ext = type.preferredSuffix();
QFile newAvatar(currentPath + "/" + res + "." + ext);
if (!newAvatar.open(QFile::WriteOnly)) {
qDebug() << "Can't change avatar: cant open file to write" << newAvatar.fileName() << "rolling back to the previous state";
if (needToRemoveOld) {
QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type + ".bak");
oldAvatar.rename(currentPath + "/" + res + "." + oldInfo.type);
}
return false;
}
newAvatar.write(data);
newAvatar.close();
newInfo.type = ext;
newInfo.hash = newHash;
newInfo.autogenerated = generated;
try {
avatars->forceRecord(res, newInfo, txn);
txn.commit();
} catch (...) {
qDebug() << "Can't change avatar: couldn't store changes to database for" << newAvatar.fileName() << "rolling back to the previous state";
if (needToRemoveOld) {
QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type + ".bak");
oldAvatar.rename(currentPath + "/" + res + "." + oldInfo.type);
}
return false;
}
if (needToRemoveOld) {
QFile oldAvatar(currentPath + "/" + res + "." + oldInfo.type + ".bak");
oldAvatar.remove();
}
return true;
} }
bool Core::Archive::readAvatarInfo(Core::Archive::AvatarInfo& target, const QString& resource) const { bool Core::Archive::readAvatarInfo(Core::Archive::AvatarInfo& target, const QString& resource) const {

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CORE_ARCHIVE_H #pragma once
#define CORE_ARCHIVE_H
#include <QObject> #include <QObject>
#include <QCryptographicHash> #include <QCryptographicHash>
@ -101,5 +100,3 @@ private:
QDataStream& operator << (QDataStream &out, const Core::Archive::AvatarInfo& info); QDataStream& operator << (QDataStream &out, const Core::Archive::AvatarInfo& info);
QDataStream& operator >> (QDataStream &in, Core::Archive::AvatarInfo& info); QDataStream& operator >> (QDataStream &in, Core::Archive::AvatarInfo& info);
#endif // CORE_ARCHIVE_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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 "clientcache.h" #include "clientcache.h"

View File

@ -1,21 +1,22 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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_CLIENTCACHE_H #pragma once
#define CORE_CLIENTCACHE_H
#include <map> #include <map>
#include <set> #include <set>
@ -60,6 +61,3 @@ private:
}; };
} }
#endif // CORE_CLIENTCACHE_H

View File

@ -16,7 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <QtCore/QDir> #include <QtCore/QDir>
@ -129,9 +128,9 @@ void Core::NetworkAccess::onDownloadError(QNetworkReply::NetworkError code) {
void Core::NetworkAccess::onDownloadSSLError(const QList<QSslError>& errors) { void Core::NetworkAccess::onDownloadSSLError(const QList<QSslError>& errors) {
qDebug() << "DEBUG: DOWNLOAD SSL ERRORS"; qDebug() << "DEBUG: DOWNLOAD SSL ERRORS";
for (const QSslError& err : errors) { for (const QSslError& err : errors)
qDebug() << err.errorString(); qDebug() << err.errorString();
}
QNetworkReply* rpl = static_cast<QNetworkReply*>(sender()); QNetworkReply* rpl = static_cast<QNetworkReply*>(sender());
QString url = rpl->url().toString(); QString url = rpl->url().toString();
std::map<QString, Transfer*>::const_iterator itr = downloads.find(url); std::map<QString, Transfer*>::const_iterator itr = downloads.find(url);

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CORE_NETWORKACCESS_H #pragma once
#define CORE_NETWORKACCESS_H
#include <QObject> #include <QObject>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
@ -36,8 +35,7 @@
namespace Core { namespace Core {
//TODO Need to describe how to get rid of records when file is no longer reachable; //TODO Need to describe how to get rid of records when file is no longer reachable;
class NetworkAccess : public QObject class NetworkAccess : public QObject {
{
Q_OBJECT Q_OBJECT
struct Transfer; struct Transfer;
public: public:
@ -100,5 +98,3 @@ private:
}; };
} }
#endif // CORE_NETWORKACCESS_H

View File

@ -193,9 +193,8 @@ Core::UrlStorage::UrlInfo::~UrlInfo() {}
bool Core::UrlStorage::UrlInfo::addMessage(const QString& acc, const QString& jid, const QString& id) { bool Core::UrlStorage::UrlInfo::addMessage(const QString& acc, const QString& jid, const QString& id) {
for (const Shared::MessageInfo& info : messages) { for (const Shared::MessageInfo& info : messages) {
if (info.account == acc && info.jid == jid && info.messageId == id) { if (info.account == acc && info.jid == jid && info.messageId == id)
return false; return false;
}
} }
messages.emplace_back(acc, jid, id); messages.emplace_back(acc, jid, id);
return true; return true;

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CORE_URLSTORAGE_H #pragma once
#define CORE_URLSTORAGE_H
#include <QString> #include <QString>
#include <QDataStream> #include <QDataStream>
@ -93,5 +92,3 @@ public:
QDataStream& operator >> (QDataStream &in, Core::UrlStorage::UrlInfo& info); QDataStream& operator >> (QDataStream &in, Core::UrlStorage::UrlInfo& info);
QDataStream& operator << (QDataStream &out, const Core::UrlStorage::UrlInfo& info); QDataStream& operator << (QDataStream &out, const Core::UrlStorage::UrlInfo& info);
#endif // CORE_URLSTORAGE_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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 "cardinternal.h" #include "cardinternal.h"

View File

@ -1,22 +1,22 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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_DELAYMANAGER_CARDINTERNAL_H */
#define CORE_DELAYMANAGER_CARDINTERNAL_H
#pragma once
#include <QString> #include <QString>
@ -33,5 +33,3 @@ public:
} }
} }
#endif // CORE_DELAYMANAGER_CARDINTERNAL_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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 "contact.h" #include "contact.h"

View File

@ -1,21 +1,22 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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_DELAYMANAGER_CONTACT_H #pragma once
#define CORE_DELAYMANAGER_CONTACT_H
#include <QString> #include <QString>
@ -35,5 +36,3 @@ public:
} }
} }
#endif // CORE_DELAYMANAGER_CONTACT_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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 "info.h" #include "info.h"

View File

@ -1,21 +1,22 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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_DELAYMANAGER_INFO_H #pragma once
#define CORE_DELAYMANAGER_INFO_H
#include "job.h" #include "job.h"
@ -52,5 +53,3 @@ private:
} }
} }
#endif // CORE_DELAYMANAGER_INFO_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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 "infoforuser.h" #include "infoforuser.h"

View File

@ -1,21 +1,22 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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_DELAYMANAGER_INFOFORUSER_H #pragma once
#define CORE_DELAYMANAGER_INFOFORUSER_H
#include "contact.h" #include "contact.h"
#include "info.h" #include "info.h"
@ -31,5 +32,3 @@ public:
} }
} }
#endif // CORE_DELAYMANAGER_INFOFORUSER_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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 "job.h" #include "job.h"

View File

@ -1,21 +1,22 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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_DELAYMANAGER_JOB_H #pragma once
#define CORE_DELAYMANAGER_JOB_H
#include <stdint.h> #include <stdint.h>
@ -51,5 +52,3 @@ public:
} }
} }
#endif // CORE_DELAYMANAGER_JOB_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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 "owncardinternal.h" #include "owncardinternal.h"

View File

@ -1,21 +1,22 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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_DELAYMANAGER_OWNCARDINTERNAL_H #pragma once
#define CORE_DELAYMANAGER_OWNCARDINTERNAL_H
#include "job.h" #include "job.h"
@ -33,5 +34,3 @@ public:
} }
} }
#endif // CORE_DELAYMANAGER_OWNCARDINTERNAL_H

View File

@ -1,18 +1,20 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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 "owninfoforuser.h" #include "owninfoforuser.h"

View File

@ -1,21 +1,22 @@
// Squawk messenger. /*
// Copyright (C) 2019 Yury Gubich <blue@macaw.me> * 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 * This program is free software: you can redistribute it and/or modify
// the Free Software Foundation, either version 3 of the License, or * it under the terms of the GNU General Public License as published by
// (at your option) any later version. * 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 * This program is distributed in the hope that it will be useful,
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * but WITHOUT ANY WARRANTY; without even the implied warranty of
// GNU General Public License for more details. * 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/>. * 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_DELAYMANAGER_OWNINFOFORUSER_H #pragma once
#define CORE_DELAYMANAGER_OWNINFOFORUSER_H
#include "contact.h" #include "contact.h"
#include "info.h" #include "info.h"
@ -31,5 +32,3 @@ public:
} }
} }
#endif // CORE_DELAYMANAGER_OWNINFOFORUSER_H

View File

@ -19,6 +19,10 @@
#include "messagehandler.h" #include "messagehandler.h"
#include "core/account.h" #include "core/account.h"
static const QMap<QString, QVariant> statePending({{"state", static_cast<uint8_t>(Shared::Message::State::pending)}});
static const QMap<QString, QVariant> stateDelivered({{"state", static_cast<uint8_t>(Shared::Message::State::delivered)}});
static const QMap<QString, QVariant> stateSent({{"state", static_cast<uint8_t>(Shared::Message::State::sent)}});
Core::MessageHandler::MessageHandler(Core::Account* account): Core::MessageHandler::MessageHandler(Core::Account* account):
QObject(), QObject(),
acc(account), acc(account),
@ -85,102 +89,80 @@ void Core::MessageHandler::onMessageReceived(const QXmppMessage& msg) {
} }
bool Core::MessageHandler::handlePendingMessageError(const QString& id, const QString& errorText) { bool Core::MessageHandler::handlePendingMessageError(const QString& id, const QString& errorText) {
std::tuple<bool, QString, QString> ids = getOriginalPendingMessageId(id); return adjustPendingMessage(id, {
if (std::get<0>(ids)) { {"state", static_cast<uint8_t>(Shared::Message::State::error)},
QString id = std::get<1>(ids);
QString jid = std::get<2>(ids);
RosterItem* ri = acc->rh->getRosterItem(jid);
QMap<QString, QVariant> cData = {
{"state", static_cast<uint>(Shared::Message::State::error)},
{"errorText", errorText} {"errorText", errorText}
}; }, true);
if (ri != nullptr)
ri->changeMessage(id, cData);
emit acc->changeMessage(jid, id, cData);
return true;
}
return false;
} }
bool Core::MessageHandler::handleChatMessage(const QXmppMessage& msg, bool outgoing, bool forwarded, bool guessing) { bool Core::MessageHandler::handleChatMessage(const QXmppMessage& msg, bool outgoing, bool forwarded, bool guessing) {
if (msg.body().size() != 0 || msg.outOfBandUrl().size() > 0) { if (msg.body().isEmpty() && msg.outOfBandUrl().isEmpty())
Shared::Message sMsg(Shared::Message::chat); return false;
initializeMessage(sMsg, msg, outgoing, forwarded, guessing);
QString jid = sMsg.getPenPalJid(); Shared::Message sMsg(Shared::Message::chat);
Contact* cnt = acc->rh->getContact(jid); initializeMessage(sMsg, msg, outgoing, forwarded, guessing);
if (cnt == 0) { QString jid = sMsg.getPenPalJid();
cnt = acc->rh->addOutOfRosterContact(jid); Contact* cnt = acc->rh->getContact(jid);
qDebug() << "appending message" << sMsg.getId() << "to an out of roster contact"; if (cnt == 0) {
} cnt = acc->rh->addOutOfRosterContact(jid);
if (sMsg.getOutgoing()) { qDebug() << "appending message" << sMsg.getId() << "to an out of roster contact";
if (sMsg.getForwarded())
sMsg.setState(Shared::Message::State::sent);
} else {
sMsg.setState(Shared::Message::State::delivered);
}
QString oId = msg.replaceId();
if (oId.size() > 0) {
QMap<QString, QVariant> cData = {
{"body", sMsg.getBody()},
{"stamp", sMsg.getTime()}
};
cnt->correctMessageInArchive(oId, sMsg);
emit acc->changeMessage(jid, oId, cData);
} else {
cnt->appendMessageToArchive(sMsg);
emit acc->message(sMsg);
}
return true;
} }
return false; if (sMsg.getOutgoing()) {
if (sMsg.getForwarded())
sMsg.setState(Shared::Message::State::sent);
} else {
sMsg.setState(Shared::Message::State::delivered);
}
QString oId = msg.replaceId();
if (oId.size() > 0) {
QMap<QString, QVariant> cData = {
{"body", sMsg.getBody()},
{"stamp", sMsg.getTime()}
};
cnt->correctMessageInArchive(oId, sMsg);
emit acc->changeMessage(jid, oId, cData);
} else {
cnt->appendMessageToArchive(sMsg);
emit acc->message(sMsg);
}
return true;
} }
bool Core::MessageHandler::handleGroupMessage(const QXmppMessage& msg, bool outgoing, bool forwarded, bool guessing) { bool Core::MessageHandler::handleGroupMessage(const QXmppMessage& msg, bool outgoing, bool forwarded, bool guessing) {
const QString& body(msg.body()); const QString& body(msg.body());
if (body.size() != 0) { if (body.isEmpty())
return false;
Shared::Message sMsg(Shared::Message::groupChat);
initializeMessage(sMsg, msg, outgoing, forwarded, guessing);
QString jid = sMsg.getPenPalJid();
Conference* cnt = acc->rh->getConference(jid);
if (cnt == 0)
return false;
std::tuple<bool, QString, QString> ids = getOriginalPendingMessageId(msg.id()); Shared::Message sMsg(Shared::Message::groupChat);
if (std::get<0>(ids)) { initializeMessage(sMsg, msg, outgoing, forwarded, guessing);
QMap<QString, QVariant> cData = {{"state", static_cast<uint>(Shared::Message::State::delivered)}}; QString jid = sMsg.getPenPalJid();
cnt->changeMessage(std::get<1>(ids), cData); Conference* cnt = acc->rh->getConference(jid);
emit acc->changeMessage(std::get<2>(ids), std::get<1>(ids), cData); if (cnt == 0)
} else { return false;
QString oId = msg.replaceId();
if (oId.size() > 0) { bool result = adjustPendingMessage(msg.id(), stateDelivered, true);
QMap<QString, QVariant> cData = { if (result) //then it was an echo of my own sent message, nothing else needs to be done
{"body", sMsg.getBody()}, return result;
{"stamp", sMsg.getTime()}
}; QString oId = msg.replaceId();
cnt->correctMessageInArchive(oId, sMsg); if (oId.size() > 0) {
emit acc->changeMessage(jid, oId, cData); QMap<QString, QVariant> cData = {
} else { {"body", sMsg.getBody()},
cnt->appendMessageToArchive(sMsg); {"stamp", sMsg.getTime()}
QDateTime minAgo = QDateTime::currentDateTimeUtc().addSecs(-60); };
if (sMsg.getTime() > minAgo) { //otherwise it's considered a delayed delivery, most probably MUC history receipt cnt->correctMessageInArchive(oId, sMsg);
emit acc->message(sMsg); emit acc->changeMessage(jid, oId, cData);
} else { } else {
//qDebug() << "Delayed delivery: "; cnt->appendMessageToArchive(sMsg);
} QDateTime minAgo = QDateTime::currentDateTimeUtc().addSecs(-60);
} if (sMsg.getTime() > minAgo) //otherwise it's considered a delayed delivery, most probably MUC history initial fetch
} emit acc->message(sMsg);
}
return true;
} return true;
return false;
} }
void Core::MessageHandler::initializeMessage(Shared::Message& target, const QXmppMessage& source, bool outgoing, bool forwarded, bool guessing) const { void Core::MessageHandler::initializeMessage(Shared::Message& target, const QXmppMessage& source, bool outgoing, bool forwarded, bool guessing) const {
const QDateTime& time(source.stamp()); const QDateTime& time(source.stamp());
QString id; QString id;
@ -254,45 +236,31 @@ void Core::MessageHandler::onCarbonMessageSent(const QXmppMessage& msg) {
} }
#endif #endif
std::tuple<bool, QString, QString> Core::MessageHandler::getOriginalPendingMessageId(const QString& id, bool clear) { std::optional<Shared::MessageInfo> Core::MessageHandler::getOriginalPendingMessageId(const QString& id, bool clear) {
std::tuple<bool, QString, QString> result({false, "", ""});
std::map<QString, QString>::const_iterator itr = pendingStateMessages.find(id); std::map<QString, QString>::const_iterator itr = pendingStateMessages.find(id);
if (itr != pendingStateMessages.end()) { if (itr != pendingStateMessages.end()) {
std::get<0>(result) = true; Shared::MessageInfo info(acc->name, itr->second, itr->first);
std::get<2>(result) = itr->second;
std::map<QString, QString>::const_iterator itrC = pendingCorrectionMessages.find(id); std::map<QString, QString>::const_iterator itrC = pendingCorrectionMessages.find(id);
if (itrC != pendingCorrectionMessages.end()) { if (itrC != pendingCorrectionMessages.end()) {
if (itrC->second.size() > 0) if (itrC->second.size() > 0)
std::get<1>(result) = itrC->second; info.jid = itrC->second;
else
std::get<1>(result) = itr->first;
if (clear) if (clear)
pendingCorrectionMessages.erase(itrC); pendingCorrectionMessages.erase(itrC);
} else {
std::get<1>(result) = itr->first;
} }
if (clear) if (clear)
pendingStateMessages.erase(itr); pendingStateMessages.erase(itr);
return info;
} }
return result; return std::nullopt;
} }
void Core::MessageHandler::onReceiptReceived(const QString& jid, const QString& id) { void Core::MessageHandler::onReceiptReceived(const QString& jid, const QString& id) {
SHARED_UNUSED(jid); SHARED_UNUSED(jid);
std::tuple<bool, QString, QString> ids = getOriginalPendingMessageId(id); adjustPendingMessage(id, {{"state", static_cast<uint>(Shared::Message::State::delivered)}}, true);
if (std::get<0>(ids)) {
QMap<QString, QVariant> cData = {{"state", static_cast<uint>(Shared::Message::State::delivered)}};
RosterItem* ri = acc->rh->getRosterItem(std::get<2>(ids));
if (ri != nullptr)
ri->changeMessage(std::get<1>(ids), cData);
emit acc->changeMessage(std::get<2>(ids), std::get<1>(ids), cData);
}
} }
void Core::MessageHandler::sendMessage(const Shared::Message& data, bool newMessage, QString originalId) { void Core::MessageHandler::sendMessage(const Shared::Message& data, bool newMessage, QString originalId) {
@ -386,19 +354,8 @@ std::pair<Shared::Message::State, QString> Core::MessageHandler::scheduleSending
bool success = acc->client.sendPacket(*encrypted.get()); bool success = acc->client.sendPacket(*encrypted.get());
if (success) { if (success) {
qDebug() << "Successfully sent an encrypted message"; qDebug() << "Successfully sent an encrypted message";
std::tuple<bool, QString, QString> ids = getOriginalPendingMessageId(id, false); if (!adjustPendingMessage(id, stateSent, false))
if (std::get<0>(ids)) {
QString id = std::get<1>(ids);
QString jid = std::get<2>(ids);
RosterItem* ri = acc->rh->getRosterItem(jid);
QMap<QString, QVariant> cData = {{"state", static_cast<uint>(Shared::Message::State::sent)}};
if (ri != nullptr)
ri->changeMessage(id, cData);
emit acc->changeMessage(jid, id, cData);
} else {
qDebug() << "Encrypted message has been successfully sent, but it couldn't be found to update the sate"; qDebug() << "Encrypted message has been successfully sent, but it couldn't be found to update the sate";
}
} else { } else {
qDebug() << "Couldn't sent an encrypted message"; qDebug() << "Couldn't sent an encrypted message";
handlePendingMessageError(id, "Error sending successfully encrypted message"); handlePendingMessageError(id, "Error sending successfully encrypted message");
@ -425,6 +382,19 @@ std::pair<Shared::Message::State, QString> Core::MessageHandler::scheduleSending
} }
} }
bool Core::MessageHandler::adjustPendingMessage(const QString& messageId, const QMap<QString, QVariant>& data, bool final) {
std::optional<Shared::MessageInfo> info = getOriginalPendingMessageId(messageId, final);
if (info) {
RosterItem* ri = acc->rh->getRosterItem(info->jid);
if (ri != nullptr)
ri->changeMessage(info->messageId, data);
emit acc->changeMessage(info->jid, info->messageId, data);
return true;
}
return false;
}
QMap<QString, QVariant> Core::MessageHandler::getChanges(Shared::Message& data, const QDateTime& time, bool newMessage, const QString& originalId) const { QMap<QString, QVariant> Core::MessageHandler::getChanges(Shared::Message& data, const QDateTime& time, bool newMessage, const QString& originalId) const {
QMap<QString, QVariant> changes; QMap<QString, QVariant> changes;
@ -481,51 +451,53 @@ QXmppMessage Core::MessageHandler::createPacket(const Shared::Message& data, con
} }
void Core::MessageHandler::prepareUpload(const Shared::Message& data, bool newMessage) { void Core::MessageHandler::prepareUpload(const Shared::Message& data, bool newMessage) {
if (acc->state == Shared::ConnectionState::connected) { if (acc->state != Shared::ConnectionState::connected) {
QString jid = data.getPenPalJid();
QString id = data.getId();
RosterItem* ri = acc->rh->getRosterItem(jid);
if (ri == nullptr) {
qDebug() << "An attempt to initialize upload in" << acc->name << "for pal" << jid << "but the object for this pal wasn't found, something went terrebly wrong, skipping send";
return;
}
QString path = data.getAttachPath();
QString url = acc->network->getFileRemoteUrl(path);
if (url.size() != 0) {
sendMessageWithLocalUploadedFile(data, url, newMessage);
} else {
pendingStateMessages.insert(std::make_pair(id, jid));
if (newMessage) {
ri->appendMessageToArchive(data);
} else {
QMap<QString, QVariant> changes({
{"state", (uint)Shared::Message::State::pending}
});
ri->changeMessage(id, changes);
emit acc->changeMessage(jid, id, changes);
}
//this checks if the file is already uploading, and if so it subscribes to it's success, so, i need to do stuff only if the network knows nothing of this file
if (!acc->network->checkAndAddToUploading(acc->getName(), jid, id, path)) {
if (acc->um->serviceFound()) {
QFileInfo file(path);
if (file.exists() && file.isReadable()) {
pendingStateMessages.insert(std::make_pair(id, jid));
uploadingSlotsQueue.emplace_back(path, id);
if (uploadingSlotsQueue.size() == 1)
acc->um->requestUploadSlot(file);
} else {
handleUploadError(jid, id, "Uploading file no longer exists or your system user has no permission to read it");
qDebug() << "Requested upload slot in account" << acc->name << "for file" << path << "but the file doesn't exist or is not readable";
}
} else {
handleUploadError(jid, id, "Your server doesn't support file upload service, or it's prohibited for your account");
qDebug() << "Requested upload slot in account" << acc->name << "for file" << path << "but upload manager didn't discover any upload services";
}
}
}
} else {
handleUploadError(data.getPenPalJid(), data.getId(), "Account is offline or reconnecting"); handleUploadError(data.getPenPalJid(), data.getId(), "Account is offline or reconnecting");
qDebug() << "An attempt to send message with not connected account " << acc->name << ", skipping"; qDebug() << "An attempt to send message with not connected account " << acc->name << ", skipping";
return;
}
QString jid = data.getPenPalJid();
QString id = data.getId();
RosterItem* ri = acc->rh->getRosterItem(jid);
if (ri == nullptr) {
qDebug() << "An attempt to initialize upload in" << acc->name << "for pal" << jid << "but the object for this pal wasn't found, something went terrebly wrong, skipping send";
return;
}
QString path = data.getAttachPath();
QString url = acc->network->getFileRemoteUrl(path);
if (url.size() != 0)
return sendMessageWithLocalUploadedFile(data, url, newMessage);
pendingStateMessages.insert(std::make_pair(id, jid));
if (newMessage) {
ri->appendMessageToArchive(data);
} else {
ri->changeMessage(id, statePending);
emit acc->changeMessage(jid, id, statePending);
}
//this checks if the file is already uploading, and if so it subscribes to it's success,
//So, I need to do stuff only if the network knows nothing of this file
if (acc->network->checkAndAddToUploading(acc->getName(), jid, id, path))
return;
if (!acc->um->serviceFound()) {
handleUploadError(jid, id, "Your server doesn't support file upload service, or it's prohibited for your account");
qDebug() << "Requested upload slot in account" << acc->name << "for file" << path << "but upload manager didn't discover any upload services";
return;
}
QFileInfo file(path);
if (file.exists() && file.isReadable()) {
pendingStateMessages.insert(std::make_pair(id, jid));
uploadingSlotsQueue.emplace_back(path, id);
if (uploadingSlotsQueue.size() == 1)
acc->um->requestUploadSlot(file);
} else {
handleUploadError(jid, id, "Uploading file no longer exists or your system user has no permission to read it");
qDebug() << "Requested upload slot in account" << acc->name << "for file" << path << "but the file doesn't exist or is not readable";
} }
} }
@ -565,24 +537,25 @@ void Core::MessageHandler::onDownloadFileComplete(const std::list<Shared::Messag
{"attachPath", path} {"attachPath", path}
}; };
for (const Shared::MessageInfo& info : msgs) { for (const Shared::MessageInfo& info : msgs) {
if (info.account == acc->getName()) { if (info.account != acc->getName())
RosterItem* cnt = acc->rh->getRosterItem(info.jid); continue;
if (cnt != nullptr) {
bool changed = cnt->changeMessage(info.messageId, cData); RosterItem* cnt = acc->rh->getRosterItem(info.jid);
if (changed) if (cnt != nullptr) {
emit acc->changeMessage(info.jid, info.messageId, cData); bool changed = cnt->changeMessage(info.messageId, cData);
} if (changed)
emit acc->changeMessage(info.jid, info.messageId, cData);
} }
} }
} }
void Core::MessageHandler::onLoadFileError(const std::list<Shared::MessageInfo>& msgs, const QString& text, bool up) { void Core::MessageHandler::onLoadFileError(const std::list<Shared::MessageInfo>& msgs, const QString& text, bool up) {
if (up) { if (!up)
for (const Shared::MessageInfo& info : msgs) { return;
if (info.account == acc->getName())
handleUploadError(info.jid, info.messageId, text); for (const Shared::MessageInfo& info : msgs)
} if (info.account == acc->getName())
} handleUploadError(info.jid, info.messageId, text);
} }
void Core::MessageHandler::handleUploadError(const QString& jid, const QString& messageId, const QString& errorText) { void Core::MessageHandler::handleUploadError(const QString& jid, const QString& messageId, const QString& errorText) {
@ -597,15 +570,16 @@ void Core::MessageHandler::handleUploadError(const QString& jid, const QString&
void Core::MessageHandler::onUploadFileComplete(const std::list<Shared::MessageInfo>& msgs, const QString& url, const QString& path) { void Core::MessageHandler::onUploadFileComplete(const std::list<Shared::MessageInfo>& msgs, const QString& url, const QString& path) {
for (const Shared::MessageInfo& info : msgs) { for (const Shared::MessageInfo& info : msgs) {
if (info.account == acc->getName()) { if (info.account != acc->getName())
RosterItem* ri = acc->rh->getRosterItem(info.jid); continue;
if (ri != nullptr) {
Shared::Message msg = ri->getMessage(info.messageId); RosterItem* ri = acc->rh->getRosterItem(info.jid);
msg.setAttachPath(path); if (ri != nullptr) {
sendMessageWithLocalUploadedFile(msg, url, false); Shared::Message msg = ri->getMessage(info.messageId);
} else { msg.setAttachPath(path);
qDebug() << "A signal received about complete upload to" << acc->name << "for pal" << info.jid << "but the object for this pal wasn't found, something went terrebly wrong, skipping send"; sendMessageWithLocalUploadedFile(msg, url, false);
} } else {
qDebug() << "A signal received about complete upload to" << acc->name << "for pal" << info.jid << "but the object for this pal wasn't found, something went terrebly wrong, skipping send";
} }
} }
} }
@ -654,7 +628,7 @@ void Core::MessageHandler::resendMessage(const QString& jid, const QString& id)
try { try {
Shared::Message msg = cnt->getMessage(id); Shared::Message msg = cnt->getMessage(id);
if (msg.getState() == Shared::Message::State::error) { if (msg.getState() == Shared::Message::State::error) {
if (msg.getEdited()){ if (msg.getEdited()) {
QString originalId = msg.getId(); QString originalId = msg.getId();
msg.generateRandomId(); msg.generateRandomId();
sendMessage(msg, false, originalId); sendMessage(msg, false, originalId);

View File

@ -23,6 +23,7 @@
#include <deque> #include <deque>
#include <map> #include <map>
#include <functional> #include <functional>
#include <optional>
#include <QXmppMessage.h> #include <QXmppMessage.h>
#include <QXmppHttpUploadIq.h> #include <QXmppHttpUploadIq.h>
@ -71,9 +72,10 @@ private:
void handleUploadError(const QString& jid, const QString& messageId, const QString& errorText); void handleUploadError(const QString& jid, const QString& messageId, const QString& errorText);
QXmppMessage createPacket(const Shared::Message& data, const QDateTime& time, const QString& originalId) const; QXmppMessage createPacket(const Shared::Message& data, const QDateTime& time, const QString& originalId) const;
QMap<QString, QVariant> getChanges(Shared::Message& data, const QDateTime& time, bool newMessage, const QString& originalId) const; QMap<QString, QVariant> getChanges(Shared::Message& data, const QDateTime& time, bool newMessage, const QString& originalId) const;
std::tuple<bool, QString, QString> getOriginalPendingMessageId(const QString& id, bool clear = true); std::optional<Shared::MessageInfo> getOriginalPendingMessageId(const QString& id, bool clear = true);
bool handlePendingMessageError(const QString& id, const QString& errorText); bool handlePendingMessageError(const QString& id, const QString& errorText);
std::pair<Shared::Message::State, QString> scheduleSending(const Shared::Message& message, const QDateTime& sendTime, const QString& originalId); std::pair<Shared::Message::State, QString> scheduleSending(const Shared::Message& message, const QDateTime& sendTime, const QString& originalId);
bool adjustPendingMessage(const QString& messageId, const QMap<QString, QVariant>& data, bool final);
private: private:
Account* acc; Account* acc;

View File

@ -54,22 +54,20 @@ QXmppTask<QXmppOmemoStorage::OmemoData> Core::OmemoHandler::allData() {
OmemoData data; OmemoData data;
data.ownDevice = ownDevice; data.ownDevice = ownDevice;
// LMDBAL::Transaction txn = db.beginReadOnlyTransaction(); TODO need to enable transaction after fixing LMDBAL LMDBAL::Transaction txn = db.beginReadOnlyTransaction();
std::map<uint32_t, QByteArray> pkeys = preKeyPairs->readAll(); std::map<uint32_t, QByteArray> pkeys = preKeyPairs->readAll(txn);
for (const std::pair<const uint32_t, QByteArray>& pair : pkeys) { for (const std::pair<const uint32_t, QByteArray>& pair : pkeys)
data.preKeyPairs.insert(pair.first, pair.second); data.preKeyPairs.insert(pair.first, pair.second);
}
std::map<uint32_t, SignedPreKeyPair> spre = signedPreKeyPairs->readAll(); std::map<uint32_t, SignedPreKeyPair> spre = signedPreKeyPairs->readAll(txn);
for (const std::pair<const uint32_t, SignedPreKeyPair>& pair : spre) { for (const std::pair<const uint32_t, SignedPreKeyPair>& pair : spre) {
QXmppOmemoStorage::SignedPreKeyPair qxpair = {pair.second.first, pair.second.second}; QXmppOmemoStorage::SignedPreKeyPair qxpair = {pair.second.first, pair.second.second};
data.signedPreKeyPairs.insert(pair.first, qxpair); data.signedPreKeyPairs.insert(pair.first, qxpair);
} }
std::map<QString, QHash<uint32_t, Device>> devs = devices->readAll(); std::map<QString, QHash<uint32_t, Device>> devs = devices->readAll(txn);
for (const std::pair<const QString, QHash<uint32_t, Device>>& pair : devs) { for (const std::pair<const QString, QHash<uint32_t, Device>>& pair : devs)
data.devices.insert(pair.first, pair.second); data.devices.insert(pair.first, pair.second);
}
return Core::makeReadyTask(std::move(data)); return Core::makeReadyTask(std::move(data));
} }

View File

@ -60,7 +60,6 @@ void Core::RosterHandler::clear() {
conferences.clear(); conferences.clear();
} }
void Core::RosterHandler::onRosterReceived() { void Core::RosterHandler::onRosterReceived() {
QStringList bj = acc->rm->getRosterBareJids(); QStringList bj = acc->rm->getRosterBareJids();
for (int i = 0; i < bj.size(); ++i) { for (int i = 0; i < bj.size(); ++i) {
@ -260,7 +259,6 @@ void Core::RosterHandler::onTrustChanged(const QString& jid, const Shared::Trust
emit acc->changeContact(jid, {{"trust", QVariant::fromValue(trust)}}); emit acc->changeContact(jid, {{"trust", QVariant::fromValue(trust)}});
} }
void Core::RosterHandler::addToGroup(const QString& jid, const QString& group) { void Core::RosterHandler::addToGroup(const QString& jid, const QString& group) {
std::map<QString, std::set<QString>>::iterator gItr = groups.find(group); std::map<QString, std::set<QString>>::iterator gItr = groups.find(group);
if (gItr == groups.end()) { if (gItr == groups.end()) {
@ -288,7 +286,7 @@ void Core::RosterHandler::removeFromGroup(const QString& jid, const QString& gro
} }
} }
Core::RosterItem * Core::RosterHandler::getRosterItem(const QString& jid) { Core::RosterItem* Core::RosterHandler::getRosterItem(const QString& jid) {
RosterItem* item = nullptr; RosterItem* item = nullptr;
QString lcJid = jid.toLower(); QString lcJid = jid.toLower();
std::map<QString, Contact*>::const_iterator citr = contacts.find(lcJid); std::map<QString, Contact*>::const_iterator citr = contacts.find(lcJid);
@ -302,7 +300,7 @@ Core::RosterItem * Core::RosterHandler::getRosterItem(const QString& jid) {
return item; return item;
} }
Core::Conference * Core::RosterHandler::getConference(const QString& jid) { Core::Conference* Core::RosterHandler::getConference(const QString& jid) {
Conference* item = 0; Conference* item = 0;
std::map<QString, Conference*>::const_iterator coitr = conferences.find(jid.toLower()); std::map<QString, Conference*>::const_iterator coitr = conferences.find(jid.toLower());
if (coitr != conferences.end()) if (coitr != conferences.end())
@ -311,7 +309,7 @@ Core::Conference * Core::RosterHandler::getConference(const QString& jid) {
return item; return item;
} }
Core::Contact * Core::RosterHandler::getContact(const QString& jid) { Core::Contact* Core::RosterHandler::getContact(const QString& jid) {
Contact* item = 0; Contact* item = 0;
std::map<QString, Contact*>::const_iterator citr = contacts.find(jid.toLower()); std::map<QString, Contact*>::const_iterator citr = contacts.find(jid.toLower());
if (citr != contacts.end()) if (citr != contacts.end())
@ -320,7 +318,7 @@ Core::Contact * Core::RosterHandler::getContact(const QString& jid) {
return item; return item;
} }
Core::Contact * Core::RosterHandler::addOutOfRosterContact(const QString& jid) { Core::Contact* Core::RosterHandler::addOutOfRosterContact(const QString& jid) {
QString lcJid = jid.toLower(); QString lcJid = jid.toLower();
Contact* cnt = new Contact(lcJid, acc->name); Contact* cnt = new Contact(lcJid, acc->name);
contacts.insert(std::make_pair(lcJid, cnt)); contacts.insert(std::make_pair(lcJid, cnt));
@ -446,9 +444,9 @@ void Core::RosterHandler::clearConferences() {
void Core::RosterHandler::removeRoomRequest(const QString& jid) { void Core::RosterHandler::removeRoomRequest(const QString& jid) {
QString lcJid = jid.toLower(); QString lcJid = jid.toLower();
std::map<QString, Conference*>::const_iterator itr = conferences.find(lcJid); std::map<QString, Conference*>::const_iterator itr = conferences.find(lcJid);
if (itr == conferences.end()) { if (itr == conferences.end())
qDebug() << "An attempt to remove non existing room" << lcJid << "from account" << acc->name << ", skipping"; qDebug() << "An attempt to remove non existing room" << lcJid << "from account" << acc->name << ", skipping";
}
itr->second->deleteLater(); itr->second->deleteLater();
conferences.erase(itr); conferences.erase(itr);
emit acc->removeRoom(lcJid); emit acc->removeRoom(lcJid);

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef CORE_ROSTERHANDLER_H #pragma once
#define CORE_ROSTERHANDLER_H
#include <QObject> #include <QObject>
#include <QSet> #include <QSet>
@ -27,6 +26,7 @@
#include <list> #include <list>
#include <map> #include <map>
#include <set> #include <set>
#include <optional>
#include <QXmppBookmarkSet.h> #include <QXmppBookmarkSet.h>
#include <QXmppMucManager.h> #include <QXmppMucManager.h>
@ -45,8 +45,7 @@ namespace Core {
class Account; class Account;
class RosterHandler : public QObject class RosterHandler : public QObject {
{
Q_OBJECT Q_OBJECT
public: public:
RosterHandler(Account* account); RosterHandler(Account* account);
@ -119,5 +118,3 @@ private:
}; };
} }
#endif // CORE_ROSTERHANDLER_H

View File

@ -16,16 +16,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef SHARED_MESSAGEINFO_H #pragma once
#define SHARED_MESSAGEINFO_H
#include <QString> #include <QString>
namespace Shared { namespace Shared {
/**
* @todo write docs
*/
struct MessageInfo { struct MessageInfo {
MessageInfo(); MessageInfo();
MessageInfo(const QString& acc, const QString& j, const QString& id); MessageInfo(const QString& acc, const QString& j, const QString& id);
@ -39,5 +34,3 @@ struct MessageInfo {
}; };
} }
#endif // SHARED_MESSAGEINFO_H