From cec83e7baee98942c7da8d8f6a9dd1a0a40af48e Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 28 Feb 2018 11:02:37 +0100 Subject: [PATCH] Add API method for /account/whoami --- .../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 8dba3a1..d36d076 100644 --- a/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt +++ b/docs/reference/matrix-glib-sdk/matrix-glib-sdk-sections.txt @@ -10,6 +10,7 @@ matrix_api_get_3pids matrix_api_add_3pid matrix_api_deactivate_account matrix_api_change_password +matrix_api_whoami matrix_api_get_profile matrix_api_get_avatar_url matrix_api_set_avatar_url diff --git a/src/matrix-api.c b/src/matrix-api.c index 558f88a..e2cf016 100644 --- a/src/matrix-api.c +++ b/src/matrix-api.c @@ -38,6 +38,7 @@ * @add_3pid: the virtual function pointer to matrix_api_add_3pid() * @deactivate_account: the virtual function pointer to matrix_api_deactivate_account() * @change_password: the virtual function pointer to matrix_api_change_password() + * @whoami: the virtual function pointer to matrix_api_whoami() * @get_profile: the virtual function pointer to matrix_api_get_profile() * @get_avatar_url: the virtual function pointer to matrix_api_get_avatar_url() * @set_avatar_url: the virtual function pointer to matrix_api_set_avatar_url() @@ -231,6 +232,26 @@ matrix_api_change_password(MatrixAPI *matrix_api, MATRIX_API_GET_IFACE(matrix_api)->change_password(matrix_api, callback, user_data, new_password, error); } +/** + * matrix_api_whoami: + * @api: a #MatrixAPI + * @callback: 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 user’s Matrix ID. + */ +void +matrix_api_whoami(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + GError **error) +{ + g_return_if_fail(api != NULL); + + MATRIX_API_GET_IFACE(api)->whoami(api, callback, user_data, error); +} + /** * matrix_api_get_profile: * @api: a #MatrixAPI diff --git a/src/matrix-api.h b/src/matrix-api.h index b8d9f24..da3d1d7 100644 --- a/src/matrix-api.h +++ b/src/matrix-api.h @@ -66,6 +66,10 @@ struct _MatrixAPIInterface { gpointer user_data, const gchar *new_password, GError **error); + void (*whoami)(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + GError **error); void (*get_profile)(MatrixAPI *api, MatrixAPICallback callback, gpointer user_data, @@ -483,6 +487,10 @@ void matrix_api_change_password(MatrixAPI *api, MatrixAPICallback callback, gpointer user_data, GError **error); +void matrix_api_whoami(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + GError **error); void matrix_api_get_profile(MatrixAPI *api, const gchar *user_id, MatrixAPICallback callback, diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index 6074521..0d93227 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -2161,6 +2161,15 @@ matrix_http_api_get_turn_server(MatrixAPI *matrix_api, MatrixAPICallback cb, voi NULL, NULL, NULL, NULL, FALSE, error); } +static void +whoami(MatrixAPI *api, MatrixAPICallback cb, void *cb_target, GError **error) +{ + _matrix_http_api_send(MATRIX_HTTP_API(api), + cb, cb_target, + CALL_TYPE_API, "GET", "account/whoami", + NULL, NULL, NULL, NULL, FALSE, error); +} + static void matrix_http_api_abort_pending (MatrixAPI *matrix_api) { @@ -2530,6 +2539,7 @@ matrix_http_api_matrix_api_interface_init(MatrixAPIInterface * iface) iface->get_token = matrix_http_api_get_token; iface->set_token = matrix_http_api_set_token; iface->get_homeserver = matrix_http_api_get_homeserver; + iface->whoami = whoami; } static void