From 429b1711cd9880b7e9ee2df5991648022b145456 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 28 Feb 2018 11:13:09 +0100 Subject: [PATCH] Add API method for /notifications --- .../matrix-glib-sdk-sections.txt | 1 + src/matrix-api.c | 28 +++++++++++++++ src/matrix-api.h | 14 ++++++++ src/matrix-http-api.c | 36 +++++++++++++++++++ 4 files changed, 79 insertions(+) diff --git a/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt b/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt index e0f09f3..734d713 100644 --- a/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt +++ b/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt @@ -63,6 +63,7 @@ matrix_api_set_presence matrix_api_list_public_rooms matrix_api_get_pushers matrix_api_update_pusher +matrix_api_get_notifications matrix_api_get_pushrules matrix_api_delete_pushrule matrix_api_get_pushrule diff --git a/src/matrix-api.c b/src/matrix-api.c index fd8e1e0..b443a65 100644 --- a/src/matrix-api.c +++ b/src/matrix-api.c @@ -91,6 +91,7 @@ * @list_public_rooms: the virtual function pointer to matrix_api_list_public_rooms() * @get_pushers: the virtual function pointer to matrix_api_get_pushers() * @update_pusher: the virtual function pointer to matrix_api_update_pusher() + * @get_notifications: the virtual function pointer to matrix_api_get_notifications() * @get_pushrules: the virtual function pointer to matrix_api_get_pushrules() * @delete_pushrule: the virtual function pointer to matrix_api_delete_pushrule() * @get_pushrule: the virtual function pointer to matrix_api_get_pushrule() @@ -1666,6 +1667,33 @@ matrix_api_update_pusher(MatrixAPI *matrix_api, MATRIX_API_GET_IFACE(matrix_api)->update_pusher(matrix_api, callback, user_data, pusher, error); } +/** + * matrix_api_get_notifications: + * @api: a #MatrixAPI + * @from_token: (nullable): Pagination token to retrieve the next set of events + * @limit: Limit on the number of events to return in the request. Set to 0 for no limit + * @filter: (nullable): Allows basic filtering of the events returned. Set it to `"highlight"` to + * return only events where the notification had the highlight tweak set. + * @callback: a function to call when the request is finished + * @user_data: user data to be passed to @callback + * @error: (nullable): a #GError, or %NULL to ignore errors + * + * Get notifications from the server. + */ +void +matrix_api_get_notifications(MatrixAPI *api, + const gchar *from_token, + guint limit, + const gchar *filter, + MatrixAPICallback callback, + gpointer user_data, + GError **error) +{ + g_return_if_fail(api != NULL); + + MATRIX_API_GET_IFACE(api)->get_notifications(api, from_token, limit, filter, callback, user_data, error); +} + /** * matrix_api_get_pushrules: * @api: a #MatrixAPI diff --git a/src/matrix-api.h b/src/matrix-api.h index 9c73b54..0a45751 100644 --- a/src/matrix-api.h +++ b/src/matrix-api.h @@ -399,6 +399,13 @@ struct _MatrixAPIInterface { gpointer user_data, MatrixPusher *pusher, GError **error); + void (*get_notifications)(MatrixAPI *api, + const gchar *from_token, + guint limit, + const gchar *filter, + MatrixAPICallback callback, + gpointer user_data, + GError **error); void (*get_pushrules)(MatrixAPI *api, MatrixAPICallback callback, gpointer user_data, @@ -836,6 +843,13 @@ void matrix_api_update_pusher(MatrixAPI *api, MatrixAPICallback callback, gpointer user_data, GError **error); +void matrix_api_get_notifications(MatrixAPI *api, + const gchar *from_token, + guint limit, + const gchar *filter, + MatrixAPICallback callback, + gpointer user_data, + GError **error); void matrix_api_get_pushrules(MatrixAPI *api, MatrixAPICallback callback, gpointer user_data, diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index a24709c..03eb366 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -2221,6 +2221,41 @@ get_joined_rooms(MatrixAPI *api, MatrixAPICallback cb, void *cb_target, GError * NULL, NULL, NULL, NULL, FALSE, error); } +static void +get_notifications(MatrixAPI *api, const gchar *from_token, guint limit, const gchar *filter, MatrixAPICallback callback, gpointer user_data, GError **error) +{ + GHashTable *parms = NULL; + + if (from_token != NULL) { + parms = _matrix_http_api_create_query_params(); + + g_hash_table_replace(parms, g_strdup("from"), g_strdup(from_token)); + } + + if (limit != 0) { + if (parms == NULL) { + parms = _matrix_http_api_create_query_params(); + } + + g_hash_table_replace(parms, g_strdup("limit"), g_strdup_printf("%u", limit)); + } + + if (filter != NULL) { + if (parms == NULL) { + parms = _matrix_http_api_create_query_params(); + } + + g_hash_table_replace(parms, g_strdup("only"), g_strdup(filter)); + } + + _matrix_http_api_send(MATRIX_HTTP_API(api), + callback, user_data, + CALL_TYPE_API, "POST", "register", + parms, NULL, NULL, NULL, FALSE, error); + + g_hash_table_unref(parms); +} + static void matrix_http_api_abort_pending (MatrixAPI *matrix_api) { @@ -2593,6 +2628,7 @@ matrix_http_api_matrix_api_interface_init(MatrixAPIInterface * iface) iface->get_homeserver = matrix_http_api_get_homeserver; iface->whoami = whoami; iface->get_joined_rooms = get_joined_rooms; + iface->get_notifications = get_notifications; } static void