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 a8cc1ae..6788696 100644 --- a/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt +++ b/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt @@ -61,6 +61,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 df66219..72269aa 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() @@ -1670,6 +1671,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: (scope async): 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 6c1dc26..b3a9de4 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 b307ec8..fb8a97b 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -2215,6 +2215,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) { @@ -2587,6 +2622,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