From 0570135253ad6460c56e23ed4a4e995750cb9994 Mon Sep 17 00:00:00 2001 From: krombel Date: Thu, 11 Jan 2018 15:33:50 +0100 Subject: [PATCH] Filter out content in sync that is currently unhandled (#198) I had a look at sync.cpp and checked which parts of the sync response are currently handled and which not. As I think it is unnecessary to let the unhandled data be transmitted without being handled I added these filters. In the same term I increased the timeout server-side to 30s as Riot defaults to this value as well. Especially now when a lots of presence-updates are not send anymore this value is more relevant. It is now also possible to use a filter that is defined in`client/sync_filter`. Advanced users might want to set an own filter here. [ci skip] --- include/MatrixClient.h | 3 +++ src/MatrixClient.cc | 38 +++++++++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/include/MatrixClient.h b/include/MatrixClient.h index df21ccdb..66b30dce 100644 --- a/include/MatrixClient.h +++ b/include/MatrixClient.h @@ -159,4 +159,7 @@ private: // Token to be used for the next sync. QString next_batch_; + + // filter to be send as filter-param for (initial) /sync requests + QString filter_; }; diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index 607fc1ae..05832c24 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -41,6 +41,32 @@ MatrixClient::MatrixClient(QString server, QObject *parent) 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, @@ -194,17 +220,10 @@ MatrixClient::registerUser(const QString &user, const QString &pass, const QStri void MatrixClient::sync() noexcept { - QJsonObject filter{ - {"room", - QJsonObject{ - {"include_leave", true}, - }}, - }; - QUrlQuery query; query.addQueryItem("set_presence", "online"); - query.addQueryItem("filter", QJsonDocument(filter).toJson(QJsonDocument::Compact)); - query.addQueryItem("timeout", "15000"); + query.addQueryItem("filter", filter_); + query.addQueryItem("timeout", "30000"); query.addQueryItem("access_token", token_); if (next_batch_.isEmpty()) { @@ -334,6 +353,7 @@ MatrixClient::initialSync() noexcept { QUrlQuery query; query.addQueryItem("timeout", "0"); + query.addQueryItem("filter", filter_); query.addQueryItem("access_token", token_); QUrl endpoint(server_);