From 2a96aaa6afe3ffbe62c1b37f7d955a8efc4b5e40 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 12 Jan 2016 17:10:02 +0100 Subject: [PATCH] Implement event_stream --- src/matrix-http-api.c | 28 ++++++++++++++++++++++++++++ src/test-client.c | 16 +++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index eeb3c34..726510d 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -869,6 +869,33 @@ i_initial_sync(MatrixAPI *api, err); } +static void +i_event_stream(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + const gchar *from_token, + gulong timeout, + GError **err) +{ + GHashTable *params; + + params = create_query_params(); + + if (from_token) { + g_hash_table_replace(params, "from", g_strdup(from_token)); + } + + if (timeout != 0) { + g_hash_table_replace(params, + "timeout", g_strdup_printf("%ul", timeout)); + } + + _send(MATRIX_HTTP_API(api), + callback, user_data, + "GET", "events", params, NULL, + err); +} + static void matrix_http_api_matrix_api_init(MatrixAPIInterface *iface) { @@ -881,4 +908,5 @@ matrix_http_api_matrix_api_init(MatrixAPIInterface *iface) iface->login = i_login; iface->create_room = i_create_room; iface->initial_sync = i_initial_sync; + iface->event_stream = i_event_stream; } diff --git a/src/test-client.c b/src/test-client.c index 7f3407d..fe98391 100644 --- a/src/test-client.c +++ b/src/test-client.c @@ -30,6 +30,17 @@ static GOptionEntry entries[] = { {"password", 'p', 0, G_OPTION_ARG_STRING, &password}, }; +static void +initial_sync_finished(MatrixAPI *api, + JsonNode *content, + gpointer data, + GError *err) +{ + g_printf("initialSync finished\n"); + + matrix_api_event_stream(MATRIX_API(api), NULL, NULL, NULL, 0, NULL); +} + static void create_room_finished(MatrixAPI *api, JsonNode *content, @@ -42,7 +53,10 @@ create_room_finished(MatrixAPI *api, g_printf("Room registered\n"); } - matrix_api_initial_sync(MATRIX_API(api), NULL, NULL, 10, TRUE, NULL); + matrix_api_initial_sync(MATRIX_API(api), + initial_sync_finished, + data, 10, TRUE, + NULL); } static void