From 25801ed3b8d1260c4da064d2ea9e4a2d158b57a0 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Sat, 16 Jan 2016 14:12:03 +0100 Subject: [PATCH] Implement set_display_name --- src/matrix-http-api.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index 3f90732..2262d6c 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -2477,6 +2477,40 @@ i_get_display_name(MatrixAPI *api, g_free(path); } +static void +i_set_display_name(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + const gchar *user_id, + const gchar *display_name, + GError **error) +{ + gchar *encoded_user_id, *path; + JsonBuilder *builder; + JsonNode *body; + + encoded_user_id = soup_uri_encode(user_id, NULL); + path = g_strdup_printf("profile/%s/displayname", encoded_user_id); + g_free(encoded_user_id); + + builder = json_builder_new(); + json_builder_begin_object(builder); + + json_builder_set_member_name(builder, "displayname"); + json_builder_add_string_value(builder, display_name); + + json_builder_end_object(builder); + body = json_builder_get_root(builder); + g_object_unref(builder); + + _send(MATRIX_HTTP_API(api), + callback, user_data, + CALL_API, + "PUT", path, NULL, NULL, body, NULL, + FALSE, error); + g_free(path); +} + static void matrix_http_api_matrix_api_init(MatrixAPIInterface *iface) { @@ -2561,7 +2595,7 @@ matrix_http_api_matrix_api_init(MatrixAPIInterface *iface) iface->get_avatar_url = i_get_avatar_url; iface->set_avatar_url = i_set_avatar_url; iface->get_display_name = i_get_display_name; - iface->set_display_name = NULL; + iface->set_display_name = i_set_display_name; iface->register_account = NULL; iface->set_account_data = NULL; iface->get_room_tags = NULL;