Move invite_user_3pid() to direct MatrixAPI3PidCredential use

This commit is contained in:
Gergely Polonkai 2016-01-21 14:12:24 +01:00
parent 3e93e9e77d
commit 7d5b516005
3 changed files with 33 additions and 34 deletions

View File

@ -911,7 +911,9 @@ matrix_api_list_public_rooms(MatrixAPI *api,
* @error: return location for a #GError, or %NULL * @error: return location for a #GError, or %NULL
* *
* Ban the specified user from the specified room. An optional reason * Ban the specified user from the specified room. An optional reason
* can be specified. * can be specified. If @room_id or @user_id is %NULL, this
* function returns immediately, and fills @error with
* %MATRIX_API_ERROR_INCOMPLETE.
*/ */
void void
matrix_api_ban_user(MatrixAPI *api, matrix_api_ban_user(MatrixAPI *api,
@ -924,6 +926,14 @@ matrix_api_ban_user(MatrixAPI *api,
{ {
g_return_if_fail(MATRIX_IS_API(api)); g_return_if_fail(MATRIX_IS_API(api));
if (!room_id || !user_id) {
g_set_error(error,
MATRIX_API_ERROR, MATRIX_API_ERROR_INCOMPLETE,
"room_id and user_id must be set.");
return;
}
MATRIX_API_GET_IFACE(api) MATRIX_API_GET_IFACE(api)
->ban_user(api, callback, user_data, room_id, user_id, reason, error); ->ban_user(api, callback, user_data, room_id, user_id, reason, error);
} }
@ -947,6 +957,9 @@ matrix_api_ban_user(MatrixAPI *api,
* *
* If the user is currently joined to the room, they will implicitly * If the user is currently joined to the room, they will implicitly
* leave the room as part of this API call. * leave the room as part of this API call.
*
* If @room_id is %NULL, this function returns immediately, and fills
* @error with %MATRIX_API_ERROR_INCOMPLETE.
*/ */
void void
matrix_api_forget_room(MatrixAPI *api, matrix_api_forget_room(MatrixAPI *api,
@ -957,6 +970,14 @@ matrix_api_forget_room(MatrixAPI *api,
{ {
g_return_if_fail(MATRIX_IS_API(api)); g_return_if_fail(MATRIX_IS_API(api));
if (!room_id) {
g_set_error(error,
MATRIX_API_ERROR, MATRIX_API_ERROR_INCOMPLETE,
"room_id must be set.");
return;
}
MATRIX_API_GET_IFACE(api) MATRIX_API_GET_IFACE(api)
->forget_room(api, callback, user_data, room_id, error); ->forget_room(api, callback, user_data, room_id, error);
} }
@ -969,11 +990,8 @@ matrix_api_forget_room(MatrixAPI *api,
* @user_data: (closure): user data to pass to the callback function * @user_data: (closure): user data to pass to the callback function
* @callback * @callback
* @room_id: the room ID to which to invite the user * @room_id: the room ID to which to invite the user
* @address: the invitee's 3rd party identifier * @credential: (transfer none): a #MatrixAPI3PidCredential that
* @medium: the kind of address being passed in the address field, * identifies a user to invite
* e.g. <code>email</code>
* @id_server: the hostname+port of the identity server which should
* be used for 3rd party identifier lookups
* @error: return location for a #GError, or %NULL * @error: return location for a #GError, or %NULL
* *
* Invite a user to the room by a 3rd party identifier. They do not * Invite a user to the room by a 3rd party identifier. They do not
@ -988,9 +1006,7 @@ void matrix_api_invite_user_3rdparty(MatrixAPI *api,
MatrixAPICallback callback, MatrixAPICallback callback,
gpointer user_data, gpointer user_data,
const gchar *room_id, const gchar *room_id,
const gchar *address, MatrixAPI3PidCredential *credential,
const gchar *medium,
const gchar *id_server,
GError **error) GError **error)
{ {
g_return_if_fail(MATRIX_IS_API(api)); g_return_if_fail(MATRIX_IS_API(api));
@ -998,7 +1014,7 @@ void matrix_api_invite_user_3rdparty(MatrixAPI *api,
MATRIX_API_GET_IFACE(api) MATRIX_API_GET_IFACE(api)
->invite_user_3rdparty(api, ->invite_user_3rdparty(api,
callback, user_data, callback, user_data,
room_id, address, medium, id_server, room_id, credential,
error); error);
} }

View File

@ -212,9 +212,7 @@ struct _MatrixAPIInterface {
MatrixAPICallback callback, MatrixAPICallback callback,
gpointer user_data, gpointer user_data,
const gchar *room_id, const gchar *room_id,
const gchar *address, MatrixAPI3PidCredential *credential,
const gchar *medium,
const gchar *id_server,
GError **error); GError **error);
void (*invite_user)(MatrixAPI *api, void (*invite_user)(MatrixAPI *api,
MatrixAPICallback callback, MatrixAPICallback callback,
@ -635,9 +633,7 @@ void matrix_api_invite_user_3rdparty(MatrixAPI *api,
MatrixAPICallback callback, MatrixAPICallback callback,
gpointer user_data, gpointer user_data,
const gchar *room_id, const gchar *room_id,
const gchar *address, MatrixAPI3PidCredential *credential,
const gchar *medium,
const gchar *id_server,
GError **error); GError **error);
void matrix_api_invite_user(MatrixAPI *api, void matrix_api_invite_user(MatrixAPI *api,
MatrixAPICallback callback, MatrixAPICallback callback,

View File

@ -1731,9 +1731,7 @@ i_invite_user_3rdparty(MatrixAPI *api,
MatrixAPICallback callback, MatrixAPICallback callback,
gpointer user_data, gpointer user_data,
const gchar *room_id, const gchar *room_id,
const gchar *address, MatrixAPI3PidCredential *credential,
const gchar *medium,
const gchar *id_server,
GError **error) GError **error)
{ {
gchar *encoded_room_id, *path; gchar *encoded_room_id, *path;
@ -1744,21 +1742,10 @@ i_invite_user_3rdparty(MatrixAPI *api,
path = g_strdup_printf("rooms/%s/invite", encoded_room_id); path = g_strdup_printf("rooms/%s/invite", encoded_room_id);
g_free(encoded_room_id); g_free(encoded_room_id);
builder = json_builder_new(); if ((body = matrix_api_3pid_credential_get_json_node(credential,
json_builder_begin_object(builder); error)) == NULL) {
return;
json_builder_set_member_name(builder, "id_server"); }
json_builder_add_string_value(builder, id_server);
json_builder_set_member_name(builder, "medium");
json_builder_add_string_value(builder, medium);
json_builder_set_member_name(builder, "address");
json_builder_add_string_value(builder, address);
json_builder_end_object(builder);
body = json_builder_get_root(builder);
g_object_unref(builder);
_send(MATRIX_HTTP_API(api), _send(MATRIX_HTTP_API(api),
callback, user_data, callback, user_data,