/*
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QFile>
#include <QImageReader>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMimeDatabase>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QPixmap>
#include <QSettings>
#include <QUrlQuery>
#include "MatrixClient.h"
#include "Register.h"
MatrixClient::MatrixClient(QString server, QObject *parent)
: QNetworkAccessManager(parent)
, clientApiUrl_{"/_matrix/client/r0"}
, mediaApiUrl_{"/_matrix/media/r0"}
, server_{"https://" + server}
{
QSettings settings;
txn_id_ = settings.value("client/transaction_id", 1).toInt();
QJsonObject default_filter{
{
"room",
QJsonObject{
{"include_leave", true},
{
"account_data",
QJsonObject{
{"not_types", QJsonArray{"*"}},
},
},
},
},
{
"account_data",
QJsonObject{
{"not_types", QJsonArray{"*"}},
},
},
{
"presence",
QJsonObject{
{"not_types", QJsonArray{"*"}},
},
},
};
filter_ = settings
.value("client/sync_filter",
QJsonDocument(default_filter).toJson(QJsonDocument::Compact))
.toString();
connect(this,
&QNetworkAccessManager::networkAccessibleChanged,
this,
[this](NetworkAccessibility status) {
if (status != NetworkAccessibility::Accessible)
setNetworkAccessible(NetworkAccessibility::Accessible);
});
}
void
MatrixClient::reset() noexcept
{
next_batch_.clear();
server_.