Add API method for /account/whoami

This commit is contained in:
Gergely Polonkai 2018-02-28 11:02:37 +01:00
parent d310f34228
commit cec83e7bae
4 changed files with 40 additions and 0 deletions

View File

@ -10,6 +10,7 @@ matrix_api_get_3pids
matrix_api_add_3pid matrix_api_add_3pid
matrix_api_deactivate_account matrix_api_deactivate_account
matrix_api_change_password matrix_api_change_password
matrix_api_whoami
matrix_api_get_profile matrix_api_get_profile
matrix_api_get_avatar_url matrix_api_get_avatar_url
matrix_api_set_avatar_url matrix_api_set_avatar_url

View File

@ -38,6 +38,7 @@
* @add_3pid: the virtual function pointer to matrix_api_add_3pid() * @add_3pid: the virtual function pointer to matrix_api_add_3pid()
* @deactivate_account: the virtual function pointer to matrix_api_deactivate_account() * @deactivate_account: the virtual function pointer to matrix_api_deactivate_account()
* @change_password: the virtual function pointer to matrix_api_change_password() * @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_profile: the virtual function pointer to matrix_api_get_profile()
* @get_avatar_url: the virtual function pointer to matrix_api_get_avatar_url() * @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() * @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_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 users 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: * matrix_api_get_profile:
* @api: a #MatrixAPI * @api: a #MatrixAPI

View File

@ -66,6 +66,10 @@ struct _MatrixAPIInterface {
gpointer user_data, gpointer user_data,
const gchar *new_password, const gchar *new_password,
GError **error); GError **error);
void (*whoami)(MatrixAPI *api,
MatrixAPICallback callback,
gpointer user_data,
GError **error);
void (*get_profile)(MatrixAPI *api, void (*get_profile)(MatrixAPI *api,
MatrixAPICallback callback, MatrixAPICallback callback,
gpointer user_data, gpointer user_data,
@ -483,6 +487,10 @@ void matrix_api_change_password(MatrixAPI *api,
MatrixAPICallback callback, MatrixAPICallback callback,
gpointer user_data, gpointer user_data,
GError **error); GError **error);
void matrix_api_whoami(MatrixAPI *api,
MatrixAPICallback callback,
gpointer user_data,
GError **error);
void matrix_api_get_profile(MatrixAPI *api, void matrix_api_get_profile(MatrixAPI *api,
const gchar *user_id, const gchar *user_id,
MatrixAPICallback callback, MatrixAPICallback callback,

View File

@ -2161,6 +2161,15 @@ matrix_http_api_get_turn_server(MatrixAPI *matrix_api, MatrixAPICallback cb, voi
NULL, NULL, NULL, NULL, FALSE, error); 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 static void
matrix_http_api_abort_pending (MatrixAPI *matrix_api) 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->get_token = matrix_http_api_get_token;
iface->set_token = matrix_http_api_set_token; iface->set_token = matrix_http_api_set_token;
iface->get_homeserver = matrix_http_api_get_homeserver; iface->get_homeserver = matrix_http_api_get_homeserver;
iface->whoami = whoami;
} }
static void static void