From 3e93e9e77ddb5273299cb5bcffa5baccfd68690f Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Thu, 21 Jan 2016 11:52:12 +0100 Subject: [PATCH] Add 3rd party credential invite possibility to create_room() This is to comply with Matrix API r0.0.1 --- src/matrix-api.c | 6 +++++- src/matrix-api.h | 2 ++ src/matrix-http-api.c | 44 +++++++++++++++++++++++++++++++++++++++++++ src/test-client.c | 2 +- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/matrix-api.c b/src/matrix-api.c index 990b9f2..cf8fbb3 100644 --- a/src/matrix-api.c +++ b/src/matrix-api.c @@ -753,6 +753,9 @@ void matrix_api_toggle_pusher(MatrixAPI *api, * list of state events to set in the new room * @invitees: (element-type utf8) (allow-none): list of user IDs to * invite to the new room + * @invite_3pids: (element-type MatrixAPI3PidCredential) (allow-none): + * a list of 3rd party credentials to invite to the + * new room * @error: return location for a #GError, or %NULL * * Create a new room with the given name and invite the users in @@ -770,6 +773,7 @@ matrix_api_create_room(MatrixAPI *api, JsonNode *creation_content, GList *initial_state, GList *invitees, + GList *invite_3pids, GError **error) { g_return_if_fail(MATRIX_IS_API(api)); @@ -778,7 +782,7 @@ matrix_api_create_room(MatrixAPI *api, ->create_room(api, callback, user_data, preset, room_name, room_alias, topic, visibility, creation_content, - initial_state, invitees, + initial_state, invitees, invite_3pids, error); } diff --git a/src/matrix-api.h b/src/matrix-api.h index cf47b05..0e865c0 100644 --- a/src/matrix-api.h +++ b/src/matrix-api.h @@ -167,6 +167,7 @@ struct _MatrixAPIInterface { JsonNode *creation_content, GList *initial_state, GList *invitees, + GList *invite_3pids, GError **error); /* Room directory */ @@ -589,6 +590,7 @@ void matrix_api_create_room(MatrixAPI *api, JsonNode *creation_content, GList *initial_state, GList *invitees, + GList *invite_3pids, GError **error); /* Room directory */ diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index 1d4715e..acf09a9 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -870,6 +870,28 @@ add_string(gchar *str, JsonBuilder *builder) json_builder_add_string_value(builder, str); } +typedef struct { + JsonBuilder *builder; + GError *error; +} Add3PidCredData; + +static void +add_3pidcred(MatrixAPI3PidCredential *credential, Add3PidCredData *data) +{ + JsonNode *node; + + // If there is already an error set, return immediately + if (data->error) { + return; + } + + // Get the credentials’ JSON representation + node = matrix_api_3pid_credential_get_json_node(credential, &(data->error)); + + // Add it to the builder + json_builder_add_value(data->builder, node); +} + static void i_create_room(MatrixAPI *api, MatrixAPICallback callback, @@ -882,6 +904,7 @@ i_create_room(MatrixAPI *api, JsonNode *creation_content, GList *initial_state, GList *invitees, + GList *invite_3pids, GError **error) { JsonNode *body; @@ -910,6 +933,27 @@ i_create_room(MatrixAPI *api, json_builder_end_array(builder); } + if (invite_3pids) { + Add3PidCredData add_data; + + add_data.builder = builder; + add_data.error = NULL; + + json_builder_set_member_name(builder, "invite_3pid"); + json_builder_begin_array(builder); + g_list_foreach(invite_3pids, (GFunc)add_3pidcred, &add_data); + + if (add_data.error) { + g_propagate_error(error, add_data.error); + + g_object_unref(builder); + + return; + } + + json_builder_end_array(builder); + } + if (room_name) { json_builder_set_member_name(builder, "name"); json_builder_add_string_value(builder, room_name); diff --git a/src/test-client.c b/src/test-client.c index 74e800a..62268cf 100644 --- a/src/test-client.c +++ b/src/test-client.c @@ -141,7 +141,7 @@ login_finished(MatrixAPI *api, "GLib SDK test room", "matrix-glib-sdk-test", "GLib SDK test room", MATRIX_API_ROOM_VISIBILITY_DEFAULT, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL, NULL); matrix_api_get_presence_list(api, NULL, NULL, user_id, NULL); matrix_api_get_user_presence(api, get_user_presence_finished, NULL,