Add 3rd party credential invite possibility to create_room()

This is to comply with Matrix API r0.0.1
This commit is contained in:
Gergely Polonkai 2016-01-21 11:52:12 +01:00
parent c73f76a235
commit 3e93e9e77d
4 changed files with 52 additions and 2 deletions

View File

@ -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);
}

View File

@ -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 */

View File

@ -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);

View File

@ -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,