summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorkrombel <krombel@krombel.de>2018-01-11 15:33:50 +0100
committermujx <mujx@users.noreply.github.com>2018-01-11 16:33:50 +0200
commit0570135253ad6460c56e23ed4a4e995750cb9994 (patch)
treef3ee0e309a2195f23d0e291b0ac5277e1a34afc2 /src
parentRemove Connection header (diff)
downloadnheko-0570135253ad6460c56e23ed4a4e995750cb9994.tar.xz
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]
Diffstat (limited to 'src')
-rw-r--r--src/MatrixClient.cc38
1 files changed, 29 insertions, 9 deletions
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_);