aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmatrix.h8
-rw-r--r--matrix-api.c12
-rw-r--r--matrix-api.h4
-rw-r--r--matrix-sync.c9
4 files changed, 25 insertions, 8 deletions
diff --git a/libmatrix.h b/libmatrix.h
index 7f08c67..9722b97 100644
--- a/libmatrix.h
+++ b/libmatrix.h
@@ -35,8 +35,14 @@
/* our protocol ID string */
#define PRPL_ID "prpl-matrix"
-/* identifiers for account options */
+/* identifiers for account options
+ *
+ * some of these are registered as options for the UI, and some are strictly
+ * internal. But they end up in the same place in the settings file, so they
+ * share a namespace.
+ */
#define PRPL_ACCOUNT_OPT_HOME_SERVER "home_server"
+#define PRPL_ACCOUNT_OPT_NEXT_BATCH "next_batch"
/* defaults for account options */
#define DEFAULT_HOME_SERVER "https://matrix.org"
diff --git a/matrix-api.c b/matrix-api.c
index 8c5396f..5d9273c 100644
--- a/matrix-api.c
+++ b/matrix-api.c
@@ -462,7 +462,7 @@ PurpleUtilFetchUrlData *matrix_api_password_login(MatrixAccount *account,
PurpleUtilFetchUrlData *matrix_api_sync(MatrixAccount *account,
- const gchar *since,
+ const gchar *since, int timeout,
MatrixApiCallback callback,
gpointer user_data)
{
@@ -471,14 +471,18 @@ PurpleUtilFetchUrlData *matrix_api_sync(MatrixAccount *account,
url = g_string_new("");
g_string_append_printf(url,
- "%s/_matrix/client/v2_alpha/sync?access_token=%s",
- account->homeserver, purple_url_encode(account->access_token));
+ "%s/_matrix/client/v2_alpha/sync?access_token=%s&timeout=%i",
+ account->homeserver, purple_url_encode(account->access_token),
+ timeout);
if(since != NULL)
- g_string_append_printf(url, "&timeout=30000&since=%s", since);
+ g_string_append_printf(url, "&since=%s", purple_url_encode(since));
if(purple_debug_is_verbose())
purple_debug_info("matrixprpl", "request %s\n", url->str);
+ else
+ purple_debug_info("matrixprpl", "syncing %s since %s\n",
+ account->pa->username, since);
/* XXX: stream the response, so that we don't need to allocate so much
* memory? But it's JSON
diff --git a/matrix-api.h b/matrix-api.h
index 5a52b11..b0ccba5 100644
--- a/matrix-api.h
+++ b/matrix-api.h
@@ -118,11 +118,13 @@ PurpleUtilFetchUrlData *matrix_api_password_login(MatrixAccount *account,
*
* @param account The MatrixAccount for which to make the request
* @param since If non-null, the batch token to start sync from
+ * @param timeout Number of milliseconds after which the API will time out if
+ * no events
* @param callback Function to be called when the request completes
* @param user_data Opaque data to be passed to the callback
*/
PurpleUtilFetchUrlData *matrix_api_sync(MatrixAccount *account,
- const gchar *since,
+ const gchar *since, int timeout,
MatrixApiCallback callback,
gpointer user_data);
diff --git a/matrix-sync.c b/matrix-sync.c
index fcd8551..bb2d094 100644
--- a/matrix-sync.c
+++ b/matrix-sync.c
@@ -159,7 +159,9 @@ static void matrix_handle_sync(MatrixAccount *ma, JsonNode *body)
PURPLE_CONNECTION_ERROR_OTHER_ERROR, "No next_batch field");
return;
}
- matrix_api_sync(ma, next_batch, matrix_sync_complete, NULL);
+ purple_account_set_string(ma->pa, PRPL_ACCOUNT_OPT_NEXT_BATCH,
+ next_batch);
+ matrix_api_sync(ma, next_batch, 30000, matrix_sync_complete, NULL);
}
/* callback which is called when a /sync request completes */
@@ -175,6 +177,9 @@ static void matrix_sync_complete(MatrixAccount *ma, gpointer user_data,
void matrix_sync_start_loop(MatrixAccount *ma)
{
+ const char *next_batch;
purple_connection_update_progress(ma->pc, _("Initial Sync"), 1, 3);
- matrix_api_sync(ma, NULL, matrix_sync_complete, NULL);
+ next_batch = purple_account_get_string(ma->pa,
+ PRPL_ACCOUNT_OPT_NEXT_BATCH, NULL);
+ matrix_api_sync(ma, next_batch, 0, matrix_sync_complete, NULL);
}