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,7 +314,8 @@ 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(); QString currentPath = db.getPath();
bool needToRemoveOld = false; bool needToRemoveOld = false;
QCryptographicHash hash(QCryptographicHash::Sha1); QCryptographicHash hash(QCryptographicHash::Sha1);
@ -339,7 +339,15 @@ bool Core::Archive::setAvatar(const QByteArray& data, AvatarInfo& newInfo, bool
QMimeType type = mimedb.mimeTypeForData(data); QMimeType type = mimedb.mimeTypeForData(data);
QString ext = type.preferredSuffix(); QString ext = type.preferredSuffix();
QFile newAvatar(currentPath + "/" + res + "." + ext); QFile newAvatar(currentPath + "/" + res + "." + ext);
if (newAvatar.open(QFile::WriteOnly)) { 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.write(data);
newAvatar.close(); newAvatar.close();
@ -363,15 +371,6 @@ bool Core::Archive::setAvatar(const QByteArray& data, AvatarInfo& newInfo, bool
oldAvatar.remove(); oldAvatar.remove();
} }
return true; 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;
}
}
} }
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,10 +193,9 @@ 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,28 +89,16 @@ 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())
return false;
Shared::Message sMsg(Shared::Message::chat); Shared::Message sMsg(Shared::Message::chat);
initializeMessage(sMsg, msg, outgoing, forwarded, guessing); initializeMessage(sMsg, msg, outgoing, forwarded, guessing);
QString jid = sMsg.getPenPalJid(); QString jid = sMsg.getPenPalJid();
@ -136,12 +128,11 @@ bool Core::MessageHandler::handleChatMessage(const QXmppMessage& msg, bool outgo
return true; return true;
} }
return false;
}
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); Shared::Message sMsg(Shared::Message::groupChat);
initializeMessage(sMsg, msg, outgoing, forwarded, guessing); initializeMessage(sMsg, msg, outgoing, forwarded, guessing);
@ -150,12 +141,10 @@ bool Core::MessageHandler::handleGroupMessage(const QXmppMessage& msg, bool outg
if (cnt == 0) if (cnt == 0)
return false; return false;
std::tuple<bool, QString, QString> ids = getOriginalPendingMessageId(msg.id()); bool result = adjustPendingMessage(msg.id(), stateDelivered, true);
if (std::get<0>(ids)) { if (result) //then it was an echo of my own sent message, nothing else needs to be done
QMap<QString, QVariant> cData = {{"state", static_cast<uint>(Shared::Message::State::delivered)}}; return result;
cnt->changeMessage(std::get<1>(ids), cData);
emit acc->changeMessage(std::get<2>(ids), std::get<1>(ids), cData);
} else {
QString oId = msg.replaceId(); QString oId = msg.replaceId();
if (oId.size() > 0) { if (oId.size() > 0) {
QMap<QString, QVariant> cData = { QMap<QString, QVariant> cData = {
@ -167,19 +156,12 @@ bool Core::MessageHandler::handleGroupMessage(const QXmppMessage& msg, bool outg
} else { } else {
cnt->appendMessageToArchive(sMsg); cnt->appendMessageToArchive(sMsg);
QDateTime minAgo = QDateTime::currentDateTimeUtc().addSecs(-60); QDateTime minAgo = QDateTime::currentDateTimeUtc().addSecs(-60);
if (sMsg.getTime() > minAgo) { //otherwise it's considered a delayed delivery, most probably MUC history receipt if (sMsg.getTime() > minAgo) //otherwise it's considered a delayed delivery, most probably MUC history initial fetch
emit acc->message(sMsg); emit acc->message(sMsg);
} else {
//qDebug() << "Delayed delivery: ";
}
}
} }
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());
@ -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,7 +451,12 @@ 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) {
handleUploadError(data.getPenPalJid(), data.getId(), "Account is offline or reconnecting");
qDebug() << "An attempt to send message with not connected account " << acc->name << ", skipping";
return;
}
QString jid = data.getPenPalJid(); QString jid = data.getPenPalJid();
QString id = data.getId(); QString id = data.getId();
RosterItem* ri = acc->rh->getRosterItem(jid); RosterItem* ri = acc->rh->getRosterItem(jid);
@ -489,24 +464,31 @@ void Core::MessageHandler::prepareUpload(const Shared::Message& data, bool newMe
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"; 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; return;
} }
QString path = data.getAttachPath(); QString path = data.getAttachPath();
QString url = acc->network->getFileRemoteUrl(path); QString url = acc->network->getFileRemoteUrl(path);
if (url.size() != 0) { if (url.size() != 0)
sendMessageWithLocalUploadedFile(data, url, newMessage); return sendMessageWithLocalUploadedFile(data, url, newMessage);
} else {
pendingStateMessages.insert(std::make_pair(id, jid)); pendingStateMessages.insert(std::make_pair(id, jid));
if (newMessage) { if (newMessage) {
ri->appendMessageToArchive(data); ri->appendMessageToArchive(data);
} else { } else {
QMap<QString, QVariant> changes({ ri->changeMessage(id, statePending);
{"state", (uint)Shared::Message::State::pending} emit acc->changeMessage(jid, id, statePending);
});
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)) { //this checks if the file is already uploading, and if so it subscribes to it's success,
if (acc->um->serviceFound()) { //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); QFileInfo file(path);
if (file.exists() && file.isReadable()) { if (file.exists() && file.isReadable()) {
pendingStateMessages.insert(std::make_pair(id, jid)); pendingStateMessages.insert(std::make_pair(id, jid));
@ -517,16 +499,6 @@ void Core::MessageHandler::prepareUpload(const Shared::Message& data, bool newMe
handleUploadError(jid, id, "Uploading file no longer exists or your system user has no permission to read it"); 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"; 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");
qDebug() << "An attempt to send message with not connected account " << acc->name << ", skipping";
}
} }
void Core::MessageHandler::onUploadSlotReceived(const QXmppHttpUploadSlotIq& slot) { void Core::MessageHandler::onUploadSlotReceived(const QXmppHttpUploadSlotIq& slot) {
@ -565,7 +537,9 @@ 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())
continue;
RosterItem* cnt = acc->rh->getRosterItem(info.jid); RosterItem* cnt = acc->rh->getRosterItem(info.jid);
if (cnt != nullptr) { if (cnt != nullptr) {
bool changed = cnt->changeMessage(info.messageId, cData); bool changed = cnt->changeMessage(info.messageId, cData);
@ -574,16 +548,15 @@ void Core::MessageHandler::onDownloadFileComplete(const std::list<Shared::Messag
} }
} }
} }
}
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;
for (const Shared::MessageInfo& info : msgs)
if (info.account == acc->getName()) if (info.account == acc->getName())
handleUploadError(info.jid, info.messageId, text); 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) {
emit acc->uploadFileError(jid, messageId, "Error requesting slot to upload file: " + errorText); emit acc->uploadFileError(jid, messageId, "Error requesting slot to upload file: " + errorText);
@ -597,7 +570,9 @@ 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())
continue;
RosterItem* ri = acc->rh->getRosterItem(info.jid); RosterItem* ri = acc->rh->getRosterItem(info.jid);
if (ri != nullptr) { if (ri != nullptr) {
Shared::Message msg = ri->getMessage(info.messageId); Shared::Message msg = ri->getMessage(info.messageId);
@ -608,7 +583,6 @@ void Core::MessageHandler::onUploadFileComplete(const std::list<Shared::MessageI
} }
} }
} }
}
void Core::MessageHandler::sendMessageWithLocalUploadedFile(Shared::Message msg, const QString& url, bool newMessage) { void Core::MessageHandler::sendMessageWithLocalUploadedFile(Shared::Message msg, const QString& url, bool newMessage) {
msg.setOutOfBandUrl(url); msg.setOutOfBandUrl(url);

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()) {
@ -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