From db912dd701016747b73b84ebf050e7a0ad3de16c Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 28 Feb 2018 11:12:34 +0100 Subject: [PATCH] Add API method for /joined_rooms --- .../matrix-glib-sdk-sections.txt | 1 + src/matrix-api.c | 21 +++++++++++++++++++ src/matrix-api.h | 8 +++++++ src/matrix-http-api.c | 10 +++++++++ 4 files changed, 40 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 30dbdf9..a8cc1ae 100644 --- a/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt +++ b/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt @@ -48,6 +48,7 @@ matrix_api_forget_room matrix_api_invite_user_3rdparty matrix_api_invite_user matrix_api_join_room +matrix_api_get_joined_rooms matrix_api_kick_user matrix_api_leave_room matrix_api_unban_user diff --git a/src/matrix-api.c b/src/matrix-api.c index 83a5ebc..df66219 100644 --- a/src/matrix-api.c +++ b/src/matrix-api.c @@ -78,6 +78,7 @@ * @invite_user_3rdparty: the virtual function pointer to matrix_api_invite_user_3rdparty() * @invite_user: the virtual function pointer to matrix_api_invite_user() * @join_room: the virtual function pointer to matrix_api_join_room() + * @get_joined_rooms: the virtual function pointer to matrix_api_get_joined_rooms() * @kick_user: the virtual function pointer to matrix_api_kick_user() * @leave_room: the virtual function pointer to matrix_api_leave_room() * @unban_user: the virtual function pointer to matrix_api_unban_user() @@ -661,6 +662,26 @@ matrix_api_delete_room_alias(MatrixAPI *matrix_api, MATRIX_API_GET_IFACE(matrix_api)->delete_room_alias(matrix_api, callback, user_data, room_alias, error); } +/** + * matrix_api_get_joined_rooms: + * @api: a #MatrixAPI + * @callback: (scope async): the 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 the rooms the current user is joined to. + */ +void +matrix_api_get_joined_rooms(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + GError **error) +{ + g_return_if_fail(api != NULL); + + MATRIX_API_GET_IFACE(api)->get_joined_rooms(api, callback, user_data, error); +} + /** * matrix_api_get_room_id: * @api: a #MatrixAPI diff --git a/src/matrix-api.h b/src/matrix-api.h index 695c9fd..6c1dc26 100644 --- a/src/matrix-api.h +++ b/src/matrix-api.h @@ -172,6 +172,10 @@ struct _MatrixAPIInterface { gpointer user_data, const gchar *room_alias, GError **error); + void (*get_joined_rooms)(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + GError **error); void (*get_room_id)(MatrixAPI *api, MatrixAPICallback callback, gpointer user_data, @@ -601,6 +605,10 @@ void matrix_api_delete_room_alias(MatrixAPI *api, MatrixAPICallback callback, gpointer user_data, GError **error); +void matrix_api_get_joined_rooms(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + GError **error); void matrix_api_get_room_id(MatrixAPI *api, const gchar *room_alias, MatrixAPICallback callback, diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index 3a57de2..b307ec8 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -2206,6 +2206,15 @@ whoami(MatrixAPI *api, MatrixAPICallback cb, void *cb_target, GError **error) NULL, NULL, NULL, NULL, FALSE, error); } +static void +get_joined_rooms(MatrixAPI *api, MatrixAPICallback cb, void *cb_target, GError **error) +{ + _matrix_http_api_send(MATRIX_HTTP_API(api), + cb, cb_target, + CALL_TYPE_API, "GET", "joined_rooms", + NULL, NULL, NULL, NULL, FALSE, error); +} + static void matrix_http_api_abort_pending (MatrixAPI *matrix_api) { @@ -2577,6 +2586,7 @@ matrix_http_api_matrix_api_interface_init(MatrixAPIInterface * iface) iface->set_token = matrix_http_api_set_token; iface->get_homeserver = matrix_http_api_get_homeserver; iface->whoami = whoami; + iface->get_joined_rooms = get_joined_rooms; } static void