From 7f149035a05f269574b2a18044defdcb46b915cd Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 15 Dec 2015 09:32:40 +0100 Subject: [PATCH] Implement /createRoom --- .../matrix-glib/matrix-glib-sections.txt | 1 + src/matrix-http-api.c | 64 +++++++++++++++++++ src/matrix-http-api.h | 6 ++ 3 files changed, 71 insertions(+) diff --git a/docs/reference/matrix-glib/matrix-glib-sections.txt b/docs/reference/matrix-glib/matrix-glib-sections.txt index 801df7d..5ad82b8 100644 --- a/docs/reference/matrix-glib/matrix-glib-sections.txt +++ b/docs/reference/matrix-glib/matrix-glib-sections.txt @@ -61,6 +61,7 @@ matrix_http_api_gen_parameters matrix_http_api_register_account matrix_http_api_login matrix_http_api_initial_sync +matrix_http_api_create_room MatrixHTTPAPI MatrixHTTPAPIClass diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index 8d6600d..cc0591d 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -84,6 +84,7 @@ matrix_http_api_matrix_api_init(MatrixAPIInterface *iface) iface->login = matrix_http_api_login; iface->register_account = matrix_http_api_register_account; iface->initial_sync = matrix_http_api_initial_sync; + iface->create_room = matrix_http_api_create_room; } static void @@ -631,3 +632,66 @@ matrix_http_api_initial_sync(MatrixAPI *api, content, NULL); } + +/** + * matrix_http_api_create_room: + * @callback: (scope async): the function to call when the request is + * finished + * @user_data: user data to pass to the callback function + * @room_alias: an alias for the room + * @is_public: set to %TRUE if the room should be publicly visible + * @invitees: a list of user IDs to initially invite to the room + * + * Perform /createRoom + */ +void +matrix_http_api_create_room(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + gchar *room_alias, + gboolean is_public, + GStrv invitees) +{ + JsonBuilder *builder; + JsonNode *content, + *node; + + builder = json_builder_new(); + json_builder_begin_object(builder); + + node = json_node_new(JSON_NODE_VALUE); + json_node_set_string(node, is_public ? "public" : "private"); + json_builder_set_member_name(builder, "visibility"); + json_builder_add_value(builder, node); + + if (room_alias && *room_alias) { + node = json_node_new(JSON_NODE_VALUE); + json_node_set_string(node, room_alias); + json_builder_set_member_name(builder, "room_alias_name"); + json_builder_add_value(builder, node); + } + + if (invitees && *invitees) { + JsonArray *user_array = json_array_new(); + gchar **user_id; + + for (user_id = invitees; *user_id; user_id++) { + json_array_add_string_element(user_array, *user_id); + } + + node = json_node_new(JSON_NODE_ARRAY); + json_node_set_array(node, user_array); + json_builder_set_member_name(builder, "invite"); + json_builder_add_value(builder, node); + } + + json_builder_end_object(builder); + + content = json_builder_get_root(builder); + + matrix_http_api_send(MATRIX_HTTP_API(api), + callback, user_data, + "POST", "/createRoom", + content, + NULL); +} diff --git a/src/matrix-http-api.h b/src/matrix-http-api.h index f92a00e..f112a19 100644 --- a/src/matrix-http-api.h +++ b/src/matrix-http-api.h @@ -68,6 +68,12 @@ void matrix_http_api_initial_sync(MatrixAPI *api, MatrixAPICallback callback, gpointer user_data, guint limit); +void matrix_http_api_create_room(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + gchar *room_alias, + gboolean is_public, + GStrv invitees); G_END_DECLS