From d5833c4cee73f59fce3667159f8c2dd47275cc5f Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Thu, 18 Feb 2016 17:29:21 +0100 Subject: [PATCH] Rework MatrixAPI in Vala --- .gitignore | 3 +- src/Makefile.am | 5 +- src/c-api.vapi | 121 ++ src/matrix-api.c | 2736 -------------------------------------- src/matrix-api.h | 908 ------------- src/matrix-api.vala | 1294 ++++++++++++++++++ src/matrix-http-api.c | 8 +- src/matrix-http-api.h | 2 +- src/matrix-http-client.c | 12 +- src/test-api-client.c | 16 +- 10 files changed, 1438 insertions(+), 3667 deletions(-) create mode 100644 src/c-api.vapi delete mode 100644 src/matrix-api.c delete mode 100644 src/matrix-api.h create mode 100644 src/matrix-api.vala diff --git a/.gitignore b/.gitignore index f8ffe65..b0df6f9 100644 --- a/.gitignore +++ b/.gitignore @@ -60,4 +60,5 @@ Makefile.in /src/Matrix-0.0.vapi /src/vala-temp /src/vala-stamp -/src/matrix-glib.h \ No newline at end of file +/src/matrix-glib.h +/src/matrix-api.c diff --git a/src/Makefile.am b/src/Makefile.am index a8082d2..3ef395a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,6 +16,7 @@ lib_LTLIBRARIES = libmatrix-glib-0.0.la # Vala source files libmatrix_glib_0_0_la_VALA_SOURCES = \ + matrix-api.vala \ $(NULL) AM_CPPFLAGS += \ @@ -38,6 +39,7 @@ AM_VALAFLAGS += \ -C \ --use-header \ --gir=Matrix-$(MATRIX_GLIB_API_VERSION).gir \ + $(top_srcdir)/src/c-api.vapi \ $(NULL) vala-stamp: $(libmatrix_glib_0_0_la_VALA_SOURCES) @@ -69,7 +71,6 @@ bin_PROGRAMS = test-api-client INST_H_SRC_FILES = \ matrix-types.h \ - matrix-api.h \ matrix-http-api.h \ matrix-client.h \ matrix-http-client.h \ @@ -82,7 +83,6 @@ INST_H_BUILT_FILES = \ matrix_enum_headers = \ matrix-types.h \ - matrix-api.h \ $(NULL) libmatrix_glib_0_0_la_SOURCES = \ @@ -91,7 +91,6 @@ libmatrix_glib_0_0_la_SOURCES = \ $(libmatrix_glib_0_0_la_VALA_SOURCES:.vala=.c) \ matrix-version.c \ matrix-types.c \ - matrix-api.c \ matrix-http-api.c \ matrix-enumtypes.c \ utils.c \ diff --git a/src/c-api.vapi b/src/c-api.vapi new file mode 100644 index 0000000..59e0e14 --- /dev/null +++ b/src/c-api.vapi @@ -0,0 +1,121 @@ +/* + * This file is part of matrix-glib-sdk + * + * matrix-glib-sdk is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * matrix-glib-sdk is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with matrix-glib-sdk. If not, see + * . + */ + +[CCode (cprefix = "Matrix", gir_namespace = "Matrix", gir_version = "0.0", lower_case_cprefix = "matrix_")] +namespace Matrix { + [CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_ERROR_")] + public errordomain Error { + NONE, + COMMUNICATION_ERROR, + INCOMPLETE, + BAD_REQUEST, + BAD_RESPONSE, + INVALID_ROOM_ID, + UNKNOWN_VALUE, + INVALID_TYPE, + UNSUPPORTED, + INVALID_FORMAT, + M_MISSING_TOKEN, + M_FORBIDDEN, + M_UNKNOWN, + M_UNKNOWN_TOKEN, + M_NOT_JSON, + M_UNRECOGNIZED, + UNSPECIFIED, + UNKNOWN_ERROR; + public static GLib.Quark quark (); + } + + [CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_RESIZE_METHOD_")] + public enum ResizeMethod { + DEFAULT, + CROP, + SCALE; + } + + [CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_PRESENCE_")] + public enum Presence { + UNKNOWN, + ONLINE, + OFFLINE, + UNAVAILABLE, + FREE_FOR_CHAT; + } + + [CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_PUSHER_KIND_")] + public enum PusherKind { + OVERRIDE, + SENDER, + ROOM, + CONTENT, + UNDERRIDE; + } + + [CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_PUSHER_CONDITION_KIND_")] + public enum PusherConditionKind { + EVENT_MATCH, + PROFILE_TAG, + CONTAINS_DISPLAY_NAME, + ROOM_MEMBER_COUNT; + } + + [CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_ROOM_PRESET_")] + public enum RoomPreset { + NONE, + PRIVATE, + TRUSTED_PRIVATE, + PUBLIC; + } + + [CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_ROOM_VISIBILITY_")] + public enum RoomVisibility { + DEFAULT, + PUBLIC, + PRIVATE; + } + + [CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_EVENT_DIRECTION_")] + public enum EventDirection { + FORWARD, + BACKWARD; + } + + [CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_RECEIPT_TYPE_")] + public enum ReceiptType { + READ; + } + + [CCode (cheader_filename = "matrix-enumtypes.h", cprefix = "MATRIX_ACCOUNT_KIND_")] + public enum AccountKind { + DEFAULT, + USER, + GUEST; + } + + [CCode (cheader_filename = "matrix-types.h")] + public class Pusher {} + + [CCode (cheader_filename = "matrix-types.h")] + public class StateEvent {} + + [CCode (cheader_filename = "matrix-types.h")] + public class @3PidCredential {} + + [CCode (cheader_filename = "matrix-types.h")] + public class Filter {} +} diff --git a/src/matrix-api.c b/src/matrix-api.c deleted file mode 100644 index a5ae187..0000000 --- a/src/matrix-api.c +++ /dev/null @@ -1,2736 +0,0 @@ -/* - * This file is part of matrix-glib-sdk - * - * matrix-glib-sdk is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * matrix-glib-sdk is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with matrix-glib-sdk. If not, see - * . - */ - -#include "matrix-api.h" - -/** - * SECTION:matrix-api - * @title: MatrixAPI - * @short_description: An interface for actual API implementations, - * like #MatrixHTTPAPI - * - * This interface provides a skeleton for all API functionality for - * client communication with a Matrix.org homeserver. - **/ - -/** - * MatrixAPI: - * - * An opaque pointer type. - **/ - -/** - * MatrixAPIInterface: - * @get_token: virtual function for matrix_api_get_token() - * @set_token: virtual function for matrix_api_set_token() - * @get_refresh_token: virtual function for matrix_api_get_refresh_token() - * @set_refresh_token: virtual function for matrix_api_set_refresh_token() - * @get_user_id: virtual function for matrix_api_get_user_id() - * @get_homeserver: virtual function for matrix_api_get_homeserver() - * @media_download: virtual function for matrix_api_media_download() - * @media_thumbnail: virtual function for matrix_api_media_thumbnail() - * @media_upload: virtual function for matrix_api_media_upload() - * @get_presence_list: virtual function for matrix_api_get_presence_list() - * @update_presence_list: virtual function for matrix_api_update_presence_list() - * @get_user_presence: virtual function for matrix_api_get_user_presence() - * @set_user_presence: virtual function for matrix_api_set_user_presence() - * @update_pusher: virtual function for matrix_api_update_pusher() - * @get_pushers: virtual function for matrix_api_get_pushers() - * @delete_pusher: virtual function for matrix_api_delete_pusher() - * @get_pusher: virtual function for matrix_api_get_pusher() - * @add_pusher: virtual function for matrix_api_add_pusher() - * @toggle_pusher: virtual function for matrix_api_toggle_pusher() - * @create_room: virtual function for matrix_api_create_room() - * @delete_room_alias: virtual function for matrix_api_delete_room_alias() - * @get_room_id: virtual function for matrix_api_get_room_id() - * @create_room_alias: virtual function for matrix_api_create_room_alias() - * @list_public_rooms: virtual function for matrix_api_list_public_rooms() - * @ban_user: virtual function for matrix_api_ban_user() - * @forget_room: virtual function for matrix_api_forget_room() - * @invite_user_3rdparty: virtual function for matrix_api_invite_user_3rdparty() - * @invite_user: virtual function for matrix_api_invite_user() - * @join_room: virtual function for matrix_api_join_room() - * @leave_room: virtual function for matrix_api_leave_room() - * @event_stream: virtual function for matrix_api_event_stream() - * @get_event: virtual function for matrix_api_get_event() - * @initial_sync: virtual function for matrix_api_initial_sync() - * @get_event_context: virtual function for matrix_api_get_event_context() - * @initial_sync_room: virtual function for matrix_api_initial_sync_room() - * @list_room_members: virtual function for matrix_api_list_room_members() - * @list_room_messages: virtual function for matrix_api_list_room_messages() - * @send_event_receipt: virtual function for matrix_api_send_event_receipt() - * @redact_event: virtual function for matrix_api_redact_event() - * @send_message_event: virtual function for matrix_api_send_message_event() - * @get_room_state: virtual function for matrix_api_get_room_state() - * @send_room_event: virtual function for matrix_api_send_room_event() - * @notify_room_typing: virtual function for matrix_api_notify_room_typing() - * @sync: virtual function for matrix_api_sync() - * @create_filter: virtual function for matrix_api_create_filter() - * @download_filter: virtual function for matrix_api_download_filter() - * @whois: virtual function for matrix_api_whois() - * @versions: virtual function for matrix_api_versions() - * @login: virtual function for matrix_api_login() - * @token_refresh: virtual function for matrix_api_token_refresh() - * @get_3pids: virtual function for matrix_api_get_3pids() - * @add_3pid: virtual function for matrix_api_add_3pid() - * @change_password: virtual function for matrix_api_change_password() - * @get_profile: virtual function for matrix_api_get_profile() - * @get_avatar_url: virtual function for matrix_api_get_avatar_url() - * @set_avatar_url: virtual function for matrix_api_set_avatar_url() - * @get_display_name: virtual function for matrix_api_get_display_name() - * @set_display_name: virtual function for matrix_api_set_display_name() - * @register_account: virtual function for matrix_api_register_account() - * @set_account_data: virtual function for matrix_api_set_account_data() - * @get_room_tags: virtual function for matrix_api_get_room_tags() - * @delete_room_tag: virtual function for matrix_api_delete_room_tag() - * @add_room_tag: virtual function for matrix_api_add_room_tag() - * @get_turn_server: virtual function for matrix_api_get_turn_server() - * @abort_pending: virtual function for matrix_api_abort_pending() - * - * The interface vtable for #MatrixAPI - */ - -/** - * MatrixAPICallback: - * @api: A #MatrixAPI implementation - * @content_type: the content_type of the response - * @json_content: (allow-none): the JSON content of the response, as a - * #JsonNode - * @raw_content: (allow-none): the raw content of the response - * @user_data: User data specified when calling original request function - * @err: a #GError. It will hold any errors from the underlying API - * (including communication or type errors) - * - * A callback function to use with API calls. Either @json_content or - * @raw_content will be set. - */ - -/** - * MATRIX_API_CALLBACK: - * @f: a function pointer - * - * Cast a function pointer to a #MatrixAPICallback. - */ - -/** - * MATRIX_API_CALLBACK_PROTO: - * @name: the name of the function - * - * Convenience macro to define a #MatrixAPICallback function. The - * parameter names in the defined function will be the same as defined - * in #MatrixAPICallback. - * - * |[ - * // Use it for prototypes… - * MATRIX_API_CALLBACK_PROTO(my_fancy_callback); - * - * // …or for the implementation. - * MATRIX_API_CALLBACK_PROTO(my_fancy_callback) - * { - * do_callback_stuff(api, json_content); - * } - * ]| - */ - -G_DEFINE_INTERFACE(MatrixAPI, matrix_api, G_TYPE_OBJECT); - -static void -matrix_api_default_init(MatrixAPIInterface *iface) -{ - /** - * MatrixAPI:token: - * - * The token to use for authorization. The matrix_api_login() and - * matrix_api_register_account() calls must set this - * automatically. - */ - g_object_interface_install_property( - iface, - g_param_spec_string("token", "Authorization token", - "The authorization token to use in requests", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - /** - * MatrixAPI:refresh-token: - * - * The token to use for refreshing the authorization token. It is - * issued by the server after a successful registration, login, - * and token refresh, but can also be changed with - * matrix_api_set_refresh_token() (or setting this property). - */ - g_object_interface_install_property( - iface, - g_param_spec_string("refresh-token", "Refresh token", - "The token issued by the server for authorization token renewal", - NULL, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - /** - * MatrixAPI:user-id: - * - * The Matrix user ID that is currently authenticated to the - * server. It is set by the registration and login processes - * automatically, and cannot be set from outside. - */ - g_object_interface_install_property( - iface, - g_param_spec_string("user-id", "User ID", - "The Matrix user ID that is authenticated to the server", - NULL, - G_PARAM_READABLE)); - - /** - * MatrixAPI:homeserver: - * - * The Matrix home server, as it calls itself. It is filled - * automatically by login and register calls. - */ - g_object_interface_install_property( - iface, - g_param_spec_string("homeserver", "Homeserver", - "The home server, as it calls itself", - NULL, - G_PARAM_READABLE)); -} - -/* Property getters and setters */ - -/** - * matrix_api_get_token: - * @api: a #MatrixAPI implementation - * - * Get the authorization token currently set. See - * matrix_api_set_token() for limitations. - * - * Returns: (transfer none) (allow-none): the authorization token that - * will be used in subsequent requests, or %NULL if none - * set. The returned value is owned by the @api object and - * should not be freed nor modified - */ -const gchar * -matrix_api_get_token(MatrixAPI *api) -{ - g_return_val_if_fail(MATRIX_IS_API(api), NULL); - - return MATRIX_API_GET_IFACE(api) - ->get_token(api); -} - -/** - * matrix_api_set_token: - * @api: a #MatrixAPI implementation - * @token: (allow-none): the authorization token to set - * - * Set the authorization token to use in subsequent requests. If - * @token is %NULL, the token will be unset, and a new login must take - * place to get a new authorization token. - * - * Some implementations, like #MatrixHTTPAPI, use - * asynchronous requests. This means that pending requests will use - * the old token and thus, may fail because of this. - */ -void -matrix_api_set_token(MatrixAPI *api, const gchar *token) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->set_token(api, token); -} - -/** - * matrix_api_get_refresh_token: - * @api: a #MatrixAPI implementation - * - * Get the refresh token currently set. See matrix_api_set_token() for - * limitations. - * - * Returns: (transfer none) (allow-none): the refresh token to be used - * for authorization token refreshment, or %NULL if there is - * none set. The returned value is owned by the @api object - * and should not be freed nor modified - */ -const gchar * -matrix_api_get_refresh_token(MatrixAPI *api) -{ - g_return_val_if_fail(MATRIX_IS_API(api), NULL); - - return MATRIX_API_GET_IFACE(api) - ->get_refresh_token(api); -} - -/** - * matrix_api_set_refresh_token: - * @api: a #MatrixAPI implementation - * @refresh_token: (allow-none): the refresh token to set - * - * Set the refresh token to be used in subsequent requests. See - * matrix_api_set_token() for limitations. If @refresh_token is %NULL, - * the refresh token is unset, and a new login must take place to get - * a new one. - */ -void -matrix_api_set_refresh_token(MatrixAPI *api, const gchar *refresh_token) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->set_refresh_token(api, refresh_token); -} - -/** - * matrix_api_get_user_id: - * @api: a #MatrixAPI implementation - * - * Get the Matrix user ID that is currently authenticated with the - * server. - * - * Returns: (transfer none) (allow-none): the Matrix user ID - * authenticated by the last successful register or login - * call (ie. matrix_api_login() or - * matrix_api_register_account()). If no user is - * authenticated, this function returns %NULL. The returned - * value is owned by the @api object and should not be freed - * nor modified - */ -const gchar * -matrix_api_get_user_id(MatrixAPI *api) -{ - g_return_val_if_fail(MATRIX_IS_API(api), NULL); - - return MATRIX_API_GET_IFACE(api) - ->get_user_id(api); -} - -/** - * matrix_api_get_homeserver: - * @api: a #MatrixAPI implementation - * - * Get the homeserver's name, as it calls itself. It gets set - * automatically by login and register calls, e.g. matrix_api_login() - * or matrix_api_register_account(). - * - * Returns: (transfer none) (allow-none): the Matrix homeserver's - * name, as it calls itself. If no homeserver name is reported yet - * (e.g. because login or register wasn't called yet), this function - * returns %NULL. - */ -const gchar * -matrix_api_get_homeserver(MatrixAPI *api) -{ - g_return_val_if_fail(MATRIX_IS_API(api), NULL); - - return MATRIX_API_GET_IFACE(api) - ->get_homeserver(api); -} - -/* Media */ - -/** - * matrix_api_media_download: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @server_name: the server name from the mxc:// URI (the - * authority component) - * @media_id: the media ID from the mxc:// URI (the path - * component) - * @error: return location for a #GError, or %NULL - * - * Download content from the content repository. - * - * If @server_name or @media_id is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_media_download(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *server_name, - const gchar *media_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!server_name || !media_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "server_name and media_id must be specified."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->media_download(api, - callback, user_data, - server_name, media_id, error); -} - -/** - * matrix_api_media_thumbnail: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @server_name: the server name from the mxc:// URI (the - * authority component) - * @media_id: the media ID from the mxc:// URI (the path - * component) - * @width: the desired width of the thumbnail, or 0 to use the default - * @height: the desired height of the thumbnail, or 0 to use the - * default - * @method: the resizing method to use - * @error: return location for a #GError, or %NULL - * - * Download a thumbnail of the content from the content - * repository. The actual thumbnail may not match the size - * specified. - * - * If @server_name or @media_id is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_media_thumbnail(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *server_name, - const gchar *media_id, - guint width, - guint height, - MatrixResizeMethod method, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!server_name || !media_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "server_name and media_id must be specified."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->media_thumbnail(api, - callback, user_data, - server_name, media_id, - width, height, method, - error); -} - -/** - * matrix_api_media_upload: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @content_type: (allow-none): the content type of the file being - * uploaded - * @content: (transfer full): the content to be uploaded - * @error: return location for a #GError, or %NULL - * - * Upload some content to the content repository. - * - * If @content is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_media_upload(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *content_type, - GByteArray *content, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!content) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "content must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->media_upload(api, callback, user_data, content_type, content, error); -} - -/* Presence */ - -/** - * matrix_api_get_presence_list: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user whose presence list should be retrieved - * @error: return location for a #GError, or %NULL - * - * Retrieve a list of presence events for every user on this list. - * - * If @user_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_get_presence_list(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->get_presence_list(api, callback, user_data, user_id, error); -} - -/** - * matrix_api_update_presence_list: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user whose presence list is being modified - * @drop_ids: (element-type utf8): a list of user IDs to remove - * from the list - * @invite_ids: (element-type utf8): a list of user IDs to add to - * the list - * @error: return location for a #GError, or %NULL - * - * Add or remove users from the specified user's presence list. - * - * If @user_id, or both @drop_ids and @invite_ids are %NULL, this - * function returns immediately, and fills @error with - * %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_update_presence_list(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GList *drop_ids, - GList *invite_ids, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id || (!drop_ids && !invite_ids)) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id must be set, so as at least one of drop_ids or invite_ids"); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->update_presence_list(api, - callback, user_data, - user_id, drop_ids, invite_ids, error); -} - -/** - * matrix_api_get_user_presence: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user whose presence list is being modified - * @error: return location for a #GError, or %NULL - * - * Get the given user's presence state. - * - * If @user_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_get_user_presence(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->get_user_presence(api, - callback, user_data, - user_id, error); -} - -/** - * matrix_api_set_user_presence: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user whose presence list is being modified - * @presence: the new presence state - * @status_message: (allow-none): a status message attached to this - * state - * @error: return location for a #GError, or %NULL - * - * Set the given user's presence. You cannot set the presence of - * another user. - * - * If @user_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_set_user_presence(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - MatrixPresence presence, - const gchar *status_message, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->set_user_presence(api, - callback, user_data, - user_id, presence, status_message, - error); -} - -/* Push notifications */ - -/** - * matrix_api_update_pusher: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @pusher: the pusher information - * @error: return location for a #GError, or %NULL - * - * Create, update or delete a pusher for the active user on this - * homeserver. - * - * If @pusher is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_update_pusher(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - MatrixPusher *pusher, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!pusher) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "pusher must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->update_pusher(api, - callback, user_data, - pusher, error); -} - -/** - * matrix_api_get_pushers: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @error: return location for a #GError, or %NULL - * - * Retrieve all push rulesets. - */ -void -matrix_api_get_pushers(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->get_pushers(api, callback, user_data, error); -} - -/** - * matrix_api_delete_pusher: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @scope: either global to specify global rules, or - * device/<profile tag> for rules for a - * given profile tag. - * @kind: the kind of rule - * @rule_id: an identifier for the rule - * @error: return location for a #GError, or %NULL - * - * Delete a push rule. - * - * If @scope or @rule_id is %NULL, this function returns immediately, - * and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_delete_pusher(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!scope || !rule_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "scope and rule_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->delete_pusher(api, - callback, user_data, - scope, kind, rule_id, error); -} - -/** - * matrix_api_get_pusher: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @scope: either global to specify global rules, or - * device/<profile tag> for rules for a - * given profile tag. - * @kind: the kind of rule - * @rule_id: an identifier for the rule - * @error: return location for a #GError, or %NULL - * - * Retrieve a specific push rule. - * - * If @scope or @rule_id is %NULL, this function returns immediately, - * and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_get_pusher(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!scope || !rule_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "scope and rule_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->get_pusher(api, - callback, user_data, - scope, kind, rule_id, error); -} - -/** - * matrix_api_add_pusher: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @scope: either global to specify global rules, or - * device/<profile tag> for rules for a - * given profile tag. - * @kind: the kind of rule - * @rule_id: an identifier for the rule - * @before: (allow-none): make the new rule the next-most important - * than this rule ID - * @after: (allow-none): make the new rule the next-less important - * than this rule ID - * @actions: (element-type utf8): the actions to perform when the - * conditions for this rule are met - * @conditions: (element-type MatrixPusherConditionKind) (allow-none): - * the conditions that must hold true for an event for a - * rule to be applied. A rule with no conditions always - * matches - * @error: return location for a #GError, or %NULL - * - * Add or change a push rule. - * - * If either @scope, @rule_id or @actions are %NULL, this - * function returns immediately, and fills @error with - * %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_add_pusher(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - const gchar *before, - const gchar *after, - GList *actions, - GList *conditions, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!scope || !rule_id || !actions) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "scope, rule_id and actions must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->add_pusher(api, - callback, user_data, - scope, kind, rule_id, before, after, - actions, conditions, - error); -} - -/** - * matrix_api_toggle_pusher: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): a function to call when the - * request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @scope: either global to specify global rules, or - * device/<profile tag> for rules for a - * given profile tag. - * @kind: the kind of rule - * @rule_id: an identifier for the rule - * @enabled: if %TRUE, the rule will be enabled, otherwise it gets - * disabled - * @error: return location for a #GError, or %NULL - * - * Enable or disable the specified push rule. - * - * If @scope or @rule_id is %NULL, this function returns immediately, - * and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void matrix_api_toggle_pusher(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - gboolean enabled, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!scope || !rule_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "scope and rule_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->toggle_pusher(api, - callback, user_data, - scope, kind, rule_id, enabled, error); -} - -/* Room creation */ - -/** - * matrix_api_create_room: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): the function to call when - * the request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @preset: a room preset to use - * @room_name: (allow-none): the desired display name for the room - * @room_alias: (allow-none): an alias of the room - * @topic: (allow-none): the topic of the room - * @visibility: the initial visibility of the room - * @creation_content: (allow-none): extra keys to be added to the - * content of m.room.create - * @initial_state: (element-type MatrixStateEvent) (allow-none): A - * 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 Matrix3PidCredential) (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 - * @invitees. - */ -void -matrix_api_create_room(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - MatrixRoomPreset preset, - const gchar *room_name, - const gchar *room_alias, - const gchar *topic, - MatrixRoomVisibility visibility, - JsonNode *creation_content, - GList *initial_state, - GList *invitees, - GList *invite_3pids, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->create_room(api, callback, user_data, - preset, room_name, room_alias, topic, - visibility, creation_content, - initial_state, invitees, invite_3pids, - error); -} - -/* Room directory */ - -/** - * matrix_api_delete_room_alias: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): the function to call when - * the request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_alias: the alias name to remove - * @error: return location for a #GError, or %NULL - * - * Remove the mapping of @room_alias to its room ID - * - * Servers may choose to implement additional access control checks - * here, for instance that room aliases can only be deleted by their - * creator or a server administrator. - * - * If @room_alias is %NULL, this function returns immediately, and - * fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_delete_room_alias(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_alias, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_alias) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_alias must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->delete_room_alias(api, callback, user_data, room_alias, error); -} - -/** - * matrix_api_get_room_id: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): the function to call when - * the request is finished - * @user_data: (closure) (allow-none): user data to pass to the - * callback function - * @room_alias: the room alias - * @error: return location for a #GError, or %NULL - * - * Get the room ID corresponding to this room alias. - * - * If @room_alias is %NULL, this function returns immediately, and - * fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_get_room_id(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_alias, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_alias) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_alias must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->get_room_id(api, callback, user_data, room_alias, error); -} - -/** - * matrix_api_create_room_alias: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): the function to call when - * the request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room ID to add this alias to - * @room_alias: the room alias to set - * @error: return location for a #GError, or %NULL - * - * Create a new mapping from room alias to room ID. - * - * If @room_alias or @room_id is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_create_room_alias(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *room_alias, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_alias || !room_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_alias and room_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->create_room_alias(api, - callback, user_data, - room_id, room_alias, - error); -} - -/* Room discovery */ - -/** - * matrix_api_list_public_rooms: - * @api: a #MatrixAPI implementation - * @callback: (scope async) (allow-none): the function to call when - * the request is finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @error: return location for a #GError, or %NULL - * - * List the public rooms on the server. - */ -void -matrix_api_list_public_rooms(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->list_public_rooms(api, callback, user_data, error); -} - -/* Room membership */ - -/** - * matrix_api_ban_user: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room ID where the user should be banned - * @user_id: the user ID to ban - * @reason: (allow-none): the reason of the ban - * @error: return location for a #GError, or %NULL - * - * Ban the specified user from the specified room. An optional reason - * can be specified. - * - * If @room_id or @user_id is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_ban_user(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *user_id, - const gchar *reason, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id || !user_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id and user_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->ban_user(api, callback, user_data, room_id, user_id, reason, error); -} - -/** - * matrix_api_forget_room: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room ID to forget - * @error: return location for a #GError, or %NULL - * - * Stop the requesting user remembering about a particular room. - * - * In general, history is a first class citizen in Matrix. After this - * API is called, however, a user will no longer be able to retrieve - * history for this room. If all users on a homeserver forget a room, - * the room is eligible for deletion from that homeserver. - * - * If the user is currently joined to the room, they will implicitly - * leave the room as part of this API call. - * - * If @room_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_forget_room(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->forget_room(api, callback, user_data, room_id, error); -} - -/** - * matrix_api_invite_user_3rdparty: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room ID to which to invite the user - * @credential: (transfer none): a #Matrix3PidCredential that - * identifies a user to invite - * @error: return location for a #GError, or %NULL - * - * Invite a user to the room by a 3rd party identifier. They do not - * start participating in the room until they actually join the room. - * - * If the identity server does not know a Matrix user identifier for - * the passed third party identifier, the homeserver will issue an - * invitation which can be accepted upon providing proof of ownership - * of the third party identifier. - * - * If @credential is %NULL, this function immediately returns, and - * fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void matrix_api_invite_user_3rdparty(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - Matrix3PidCredential *credential, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!credential) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "credential must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->invite_user_3rdparty(api, - callback, user_data, - room_id, credential, - error); -} - -/** - * matrix_api_invite_user: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room ID to invite the user to - * @user_id: the user ID to invite - * @error: return location for a #GError, or %NULL - * - * Invite a user to a room. - * - * If @room_id or @user_id is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_invite_user(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *user_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id || !user_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id and user_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->invite_user(api, callback, user_data, room_id, user_id, error); -} - -/** - * matrix_api_join_room: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room ID to join to - * @error: return location for a #GError, or %NULL - * - * Join a room. - * - * If @room_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_join_room(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->join_room(api, callback, user_data, room_id, error); -} - -/** - * matrix_api_leave_room: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room ID to kick the user from - * @error: return location for a #GError, or %NULL - * - * Leave a room. - * - * If @room_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_leave_room(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->leave_room(api, callback, user_data, room_id, error); -} - -/* Room participation */ - -/** - * matrix_api_event_stream: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @from_token: (allow-none): events will be listed from this token - * @timeout: timeout of the request - * @error: return location for a #GError, or %NULL - * - * Get the event stream, optionally beginning from @from_token. - */ -void -matrix_api_event_stream(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *from_token, - gulong timeout, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->event_stream(api, callback, user_data, from_token, timeout, error); -} - -/** - * matrix_api_get_event: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @event_id: the event ID to get - * @error: return location for a #GError, or %NULL - * - * Get a single event by event ID. - * - * If @event_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_get_event(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *event_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!event_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "event_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->get_event(api, callback, user_data, event_id, error); -} - -/** - * matrix_api_initial_sync: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @limit: the maximum number of events to get - * @archived: whether to include rooms that the user has left - * @error: return location for a #GError, or %NULL - * - * perform an initial sync of events - */ -void -matrix_api_initial_sync(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - guint limit, - gboolean archived, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->initial_sync(api, callback, user_data, limit, archived, error); -} - -/** - * matrix_api_get_event_context: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room to get events from - * @event_id: the event to get context around - * @limit: the maximum number of events to get. If 0, a default value - * is used (10, according to the specification) - * @error: return location for a #GError, or %NULL - * - * Gets a number of events that happened just before and after the - * specified event. - * - * If @room_id or @event_id is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_get_event_context(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_id, - guint limit, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id || !event_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id and event_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->get_event_context(api, - callback, user_data, - room_id, event_id, limit, error); -} - -/** - * matrix_api_initial_sync_room: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room to get the data for - * @error: return location for a #GError, or %NULL - * - * Get a copy of the current state and the most recent messages in a - * room. - * - * If @room_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_initial_sync_room(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->initial_sync_room(api, callback, user_data, room_id, error); -} - -/** - * matrix_api_list_room_members: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room to get the member events for - * @error: return location for a #GError, or %NULL - * - * Get the list of members for a room. - * - * If @room_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_list_room_members(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->list_room_members(api, callback, user_data, room_id, error); -} - -/** - * matrix_api_list_room_messages: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room to get the events for - * @from_token: the token to start returning events from. This token - * can be obtained by calling matrix_api_initial_sync() - * or matrix_api_initial_sync_room() - * @direction: the direction of the returned events - * @limit: the maximum number of events to return. If 0, a default - * value will be used (10, according to the specification - * @error: return location for a #GError, or %NULL - * - * Get a list of message and state events for a room. - * - * If @room_id or @from_token is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_list_room_messages(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *from_token, - MatrixEventDirection direction, - guint limit, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id || !from_token) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id and from_token must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->list_room_messages(api, - callback, user_data, - room_id, from_token, direction, limit, - error); -} - -/** - * matrix_api_send_event_receipt: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room in which to send the event - * @receipt_type: type of the receipt - * @event_id: the event ID to acknowledge up to - * @receipt: extra receipt information to attach. Note that the server - * will automatically attach the ts field - * @error: return location for a #GError, or %NULL - * - * Update the marker for the given receipt type to the event ID - * specified. - * - * If @room_id, @event_id or @receipt is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_send_event_receipt(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - MatrixReceiptType receipt_type, - const gchar *event_id, - JsonNode *receipt, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id || !event_id || !receipt) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id, event_id and receipt must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->send_event_receipt(api, - callback, user_data, - room_id, receipt_type, event_id, receipt, - error); -} - -/** - * matrix_api_redact_event: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room from which to redact the event - * @event_id: the event ID to acknowledge up to - * @txn_id: the transaction ID for this event. Clients should generate - * a unique ID; it will be used by the server to ensure - * idempotency of requests - * @reason: (allow-none): the reason for the event being redacted - * @error: return location for a #GError, or %NULL - * - * Strip all information out of an event which isn't critical to the - * integrity of the server-side representation of the room. This - * cannot be undone. - * - * Users may redact their own events, and any user with a power level - * greater than or equal to redact power level of the - * room may redact events there. - * - * If @room_id, @event_id or @txn_id is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_redact_event(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_id, - const gchar *txn_id, - const gchar *reason, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id || !event_id || !txn_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id, event_id and txn_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->redact_event(api, - callback, user_data, - room_id, event_id, txn_id, reason, - error); -} - -/** - * matrix_api_send_message_event: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room to send the event to - * @event_type: the type of event to send - * @txn_id: the transaction ID for this event. Clients should generate - * a unique ID; it will be used by the server to ensure - * idempotency of requests - * @content: (transfer full): the content of the event as a #JsonNode - * @error: return location for a #GError, or %NULL - * - * Send a message event to the room. - * - * If @room_id, @event_type, @txn_id or @content is %NULL, this - * function returns immediately, and fills @error with - * %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_send_message_event(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_type, - const gchar *txn_id, - JsonNode *content, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id || !event_type || !txn_id || !content) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id, event_type, txn_id and content must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->send_message_event(api, - callback, user_data, - room_id, - event_type, txn_id, - content, error); -} - -/** - * matrix_api_get_room_state: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room ID to get a state for - * @event_type: (allow-none): the type of state to look up - * @state_key: (allow-none): the key of the state to look up. If - * @event_type is %NULL, this parameter is ignored - * @error: return location for a #GError, or %NULL - * - * Look up the contents of a state event in a room. If both - * @event_type and @state_key are empty, get a list of state events - * for that room. - * - * If @room_id is %NULL, or if @state_key is set with @event_type - * being %NULL, this function returns immediately, and fills @error - * with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_get_room_state(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_type, - const gchar *state_key, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id || (state_key && !event_type)) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id must be set, and event_type must be set if state_key is set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->get_room_state(api, - callback, user_data, - room_id, event_type, state_key, error); -} - -/** - * matrix_api_send_room_event: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @room_id: the room ID to get a state for - * @event_type: the type of state to look up - * @state_key: (allow-none): the key of the state to look up. If - * @event_type is %NULL, this parameter is ignored - * @content: (transfer full): the content of the state event - * @error: return location for a #GError, or %NULL - * - * Send a state event to the room. These events will be overwritten if - * @room_id, @event_type and @state_key all match. - * - * This request cannot use transaction IDs. - * - * The required fields in the body of the request (@content) vary - * depending on the type of the event. - * - * If @room_id or @content is %NULL, or if @state_key is set with - * @event_type being %NULL, this function returns immediately, and - * fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_send_room_event(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_type, - const gchar *state_key, - JsonNode *content, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!room_id || (state_key && !event_type) || !content) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "room_id must be set, and event_type must be set if state_key is set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->send_room_event(api, - callback, user_data, - room_id, event_type, state_key, content, - error); -} - -/** - * matrix_api_notify_room_typing: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user who has started to type - * @room_id: the room in which the user is typing - * @timeout: the length of time in milliseconds to mark this user as - * typing - * @typing: whether the user is typing or not. If %FALSE, @timeout can - * be omitted (ie. set to 0) - * @error: return location for a #GError, or %NULL - * - * Tell the server the user is typing for the next @timeout - * milliseconds. If @typing is %FALSE, it tells the server that the - * user stopped typing. - * - * If @user_id or @room_id is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_notify_room_typing(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - guint timeout, - gboolean typing, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id || !room_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id and room_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->notify_room_typing(api, - callback, user_data, - user_id, room_id, timeout, typing, - error); -} - -/** - * matrix_api_sync: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @filter_id: (allow-none): a filter ID created by the filter API - * (e.g. matrix_api_create_filter()) - * @filter: (allow-none): a definition on what events to fetch - * @since: (allow-none): a point in time to continue a sync from - * @full_state: if %TRUE, all state events will be returned, even if - * @since is not empty. If %FALSE, and @since is not - * empty, only states which have changed since the point - * indicated by @since will be returned - * @set_presence: controls whether the client is automatically marked - * as online by polling this API. - * @timeout: the maximum time to poll in milliseconds - * @error: return location for a #GError, or %NULL - * - * Synchronize the client's state with the latest state on the - * server. Clients should use this API when they first log in to get - * an initial snapshot of the state on the server and then continue to - * call this API to get incremental details to the state and to - * receive new messages. - * - * Only one of @filter and @filter_id should be specified, or both of - * them should be set to %NULL to receive all events. - */ -void -matrix_api_sync(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *filter_id, - const MatrixFilter *filter, - const gchar *since, - gboolean full_state, - gboolean set_presence, - gulong timeout, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->sync(api, - callback, user_data, - filter_id, filter, since, - full_state, set_presence, timeout, - error); -} - -/** - * matrix_api_create_filter: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the ID of the user uploading the filter. An access token - * must be present (either specifying one with - * matrix_api_set_token() or requested from the server via - * matrix_api_register_account() or matrix_api_login(). - * @filter: the filter to upload - * @error: return location for a #GError, or %NULL - * - * Upload a new filter definition to the homeserver. It will return a - * filter ID that may be used in future requests. - * - * If @user_id or @filter is %NULL, this function returns immediately, - * and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_create_filter(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - MatrixFilter *filter, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id || !filter) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id and filter must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->create_filter(api, - callback, user_data, - user_id, filter, - error); -} - -/** - * matrix_api_download_filter: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user ID to download a filter from - * @filter_id: the filter ID to download - * @error: return location for a #GError, or %NULL - * - * Download a filter. - * - * If @user_id or @filter_id is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_download_filter(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *filter_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id || !filter_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id and filter_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->download_filter(api, - callback, user_data, - user_id, filter_id, error); -} - -/* Search */ - -/* Server administration */ - -/** - * matrix_api_whois: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user ID to look up - * @error: return location for a #GError, or %NULL - * - * Get information about a particular user. - * - * If @user_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_whois(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->whois(api, callback, user_data, user_id, error); -} - -/** - * matrix_api_versions: - * @api: a #MatrixAPI iplementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @error: return location for a #GError, or %NULL - * - * Get the versions of the specification supported by the server. - */ -void -matrix_api_versions(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->versions(api, callback, user_data, error); -} - -/* Session management */ - -/** - * matrix_api_login: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @login_type: the login type to use - * @content: (allow-none): parameters to pass for the login request - * @error: return location for a #GError, or %NULL - * - * Attempt to login with type @type. Implementations of this method - * must set the token property on a successful login. - * - * If @login_type or @content is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_login(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *login_type, - const JsonNode *content, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!login_type || !content) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "login_type and content must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->login(api, callback, user_data, login_type, content, error); -} - -/** - * matrix_api_token_refresh: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @refresh_token: (allow-none): the refresh token that was issued by - * the server - * @error: return location for a #GError, or %NULL - * - * Exchanges a refresh token for a new access token. This is intended - * to be used if the access token has expired. If @refresh_token is - * %NULL, iplementations MUST send the stored refresh token. If it is - * not pesent (e.g. because login hasn’t happened yet), this function - * MUST yield an error. - */ -void -matrix_api_token_refresh(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *refresh_token, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->token_refresh(api, callback, user_data, refresh_token, error); -} - -/* User data */ - -/** - * matrix_api_get_3pids: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @error: return location for a #GError, or %NULL - * - * Get a list of the third party identifiers that a homeserver has - * associated with the user's account. - * - * This is not the same as the list of third party identifiers bound - * to the user's Matrix ID in Identity Servers. - * - * Identifiers in this list may be used by the homeserver as, for - * example, identifiers to accept to reset the user's account - * password. - */ -void -matrix_api_get_3pids(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->get_3pids(api, callback, user_data, error); -} - -/** - * matrix_api_add_3pid: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @bind_creds: whether the homeserver should also bind this third - * party identifier to the account's Matrix ID with the - * passed Identity Server. - * @threepid_creds: the credentials to associate with the account - * @error: return location for a #GError, or %NULL - * - * Add contact information to the user's account. - * - * If @threepid_creds is %NULL, this function returns immediately, and - * fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_add_3pid(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - gboolean bind_creds, - Matrix3PidCredential *threepid_creds, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!threepid_creds) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "threepid_creds must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->add_3pid(api, callback, user_data, bind_creds, threepid_creds, error); -} - -/** - * matrix_api_change_password: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @new_password: the new password for the account - * @error: return location for a #GError, or %NULL - * - * Change the active user's password. - * - * If @new_password is %NULL, this function returns immediately, and - * fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_change_password(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *new_password, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!new_password) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "new_password must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->change_password(api, callback, user_data, new_password, error); -} - -/** - * matrix_api_get_profile: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user whose profile to get - * @error: return location for a #GError, or %NULL - * - * Get a user's profile. - * - * If @user_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_get_profile(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->get_profile(api, callback, user_data, user_id, error); -} - -/** - * matrix_api_get_avatar_url: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user whose avatar URL to get - * @error: return location for a #GError, or %NULL - * - * Get the URL of the specified user's avatar. - * - * If @user_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_get_avatar_url(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->get_avatar_url(api, callback, user_data, user_id, error); -} - -/** - * matrix_api_set_avatar_url: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user whose avatar URL to set - * @avatar_url: the avatar URL info - * @error: return location for a #GError, or %NULL - * - * Set the user's avatar URL. - * - * If @user_id or @avatar_url is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_set_avatar_url(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *avatar_url, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id || !avatar_url) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id and avatar_url must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->set_avatar_url(api, callback, user_data, user_id, avatar_url, error); -} - -/** - * matrix_api_get_display_name: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user whose display name to get - * @error: return location for a #GError, or %NULL - * - * Get the user's display name. - * - * If @user_id is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_get_display_name(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->get_display_name(api, callback, user_data, user_id, error); -} - -/** - * matrix_api_set_display_name: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user whose display name to set - * @display_name: the display name info - * @error: return location for a #GError, or %NULL - * - * Set the user's display name. - * - * If @user_id or @display_name is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_set_display_name(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *display_name, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id || !display_name) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id and display_name must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->set_display_name(api, - callback, user_data, - user_id, display_name, error); -} - -/** - * matrix_api_register_account: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @account_kind: the type of account to register - * @bind_email: if %TRUE, the server binds the e-mail used for - * authentication to the Matrix ID with the ID server - * @username: (allow-none): the local part of the desired Matrix - * ID. If omitted, the server will generate a local part - * @password: the desired password for the account - * @error: return location for a #GError, or %NULL - * - * Attempt to register an account with the homeserver using @username - * and @password. - * - * Implementations of this method must set the token property on a - * successful login. - * - * If @password is %NULL, this function returns immediately, and fills - * @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_register_account(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - MatrixAccountKind account_kind, - gboolean bind_email, - const gchar *username, - const gchar *password, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!password) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "password must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->register_account(api, callback, user_data, account_kind, - bind_email, username, password, error); -} - -/** - * matrix_api_set_account_data: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the user to set account data for. An access token must be - * present and be authorized to make requests for this user - * ID - * @room_id: (allow-none): the room to set account data for. If %NULL, - * the account data will be set globally - * @event_type: the event type of the account data to set. Custom - * types should be namespaced to avoid clashes - * @content: (transfer full): the content of the account data - * @error: return location for a #GError, or %NULL - * - * Set some account data for the client. This config is only visible - * to the user who set the account data. The config will be synced to - * clients in the top-level account data. - * - * If @user_id, @event_type or @content is %NULL, this - * function returns immediately, and fills @error with - * %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_set_account_data(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - const gchar *event_type, - JsonNode *content, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id || !event_type || !content) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id2 event_type and content must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->set_account_data(api, - callback, user_data, - user_id, room_id, event_type, content, error); -} - -/** - * matrix_api_get_room_tags: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the ID of the user to get the tags for. An access token - * must be set, and it must be authorised to make requests - * for this user ID - * @room_id: the room to get tags for - * @error: return location for a #GError, or %NULL - * - * List the tags set by a user on a room. - * - * If @user_id or @room_id is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_get_room_tags(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id || !room_id) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id and room_id must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->get_room_tags(api, callback, user_data, user_id, room_id, error); -} - -/** - * matrix_api_delete_room_tag: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the id of the user to remove a tag for - * @room_id: the id of the room to remove the tag from - * @tag: the tag to remove - * @error: return location for a #GError, or %NULL - * - * Remove a tag from the room. - * - * If @user_id, @room_id or @tag is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_delete_room_tag(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - const gchar *tag, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id || !room_id || !tag) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id, room_id and tag must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->delete_room_tag(api, - callback, user_data, - user_id, room_id, tag, error); -} - -/** - * matrix_api_add_room_tag: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @user_id: the ID of the user to add the tag for - * @room_id: the ID of the room to add the tag for - * @tag: the tag to add - * @content: (transfer full) (allow-none): extra data for the tag, - * e.g. ordering - * @error: return location for a #GError, or %NULL - * - * Add a tag to the room. - * - * If @user_id, @room_id or @tag is %NULL, this function returns - * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. - */ -void -matrix_api_add_room_tag(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - const gchar *tag, - JsonNode *content, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (!user_id || !room_id || !tag) { - g_set_error(error, - MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE, - "user_id, room_id and tag must be set."); - - return; - } - - MATRIX_API_GET_IFACE(api) - ->add_room_tag(api, - callback, user_data, - user_id, room_id, tag, content, error); -} - -/* VoIP */ - -/** - * matrix_api_get_turn_server: - * @api: a #MatrixAPI implementation - * @callback: (scope async): the function to call when the request is - * finished - * @user_data: (closure): user data to pass to the callback function - * @callback - * @error: return location for a #GError, or %NULL - * - * Get credentials for the client to use when initiating calls. - */ -void -matrix_api_get_turn_server(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - MATRIX_API_GET_IFACE(api) - ->get_turn_server(api, callback, user_data, error); -} - -/* Non-spec methods */ - -/** - * matrix_api_abort_pending: - * @api: a #MatrixAPI implementation - * - * Abort all pending requests toward the Matrix server. Be aware that - * this may leave requests in an incosistent state. - * - * Implementations that provide only synchronous requests can choose - * not to implement this function. - */ -void -matrix_api_abort_pending(MatrixAPI *api) -{ - g_return_if_fail(MATRIX_IS_API(api)); - - if (MATRIX_API_GET_IFACE(api)->abort_pending) { - MATRIX_API_GET_IFACE(api)->abort_pending(api); - } -} diff --git a/src/matrix-api.h b/src/matrix-api.h deleted file mode 100644 index 413844f..0000000 --- a/src/matrix-api.h +++ /dev/null @@ -1,908 +0,0 @@ -/* - * This file is part of matrix-glib-sdk - * - * matrix-glib-sdk is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation, either - * version 3 of the License, or (at your option) any later version. - * - * matrix-glib-sdk is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with matrix-glib-sdk. If not, see - * . - */ - -#ifndef __MATRIX_API_IFACE_H__ -#define __MATRIX_API_IFACE_H__ - -#include -#include - -#include "matrix-types.h" - -G_BEGIN_DECLS - -#define MATRIX_TYPE_API (matrix_api_get_type()) -#define MATRIX_API(o) (G_TYPE_CHECK_INSTANCE_CAST((o), MATRIX_TYPE_API, MatrixAPI)) -#define MATRIX_IS_API(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), MATRIX_TYPE_API)) -#define MATRIX_API_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), MATRIX_TYPE_API, MatrixAPIInterface)) - -typedef struct _MatrixAPIInterface MatrixAPIInterface; -typedef struct _MatrixAPI MatrixAPI; - -typedef void (*MatrixAPICallback)(MatrixAPI *api, - const gchar *content_type, - JsonNode *json_content, - GByteArray *raw_content, - gpointer user_data, - GError *err); - -#define MATRIX_API_CALLBACK(f) ((MatrixAPICallback) (f) - -#define MATRIX_API_CALLBACK_PROTO(name) static void \ - name (MatrixAPI *api, \ - const gchar *content_type, \ - JsonNode *json_content, \ - GByteArray *raw_content, \ - gpointer user_data, \ - GError *error) - -struct _MatrixAPIInterface { - /*< private >*/ - GTypeInterface g_iface; - - /*< public >*/ - - /* Properties */ - void (*set_token)(MatrixAPI *api, const gchar *token); - const gchar *(*get_token)(MatrixAPI *api); - - void (*set_refresh_token)(MatrixAPI *api, const gchar *refresh_token); - const gchar *(*get_refresh_token)(MatrixAPI *api); - - const gchar *(*get_user_id)(MatrixAPI *api); - - const gchar *(*get_homeserver)(MatrixAPI *api); - - /*< private >*/ - void *properties_reserved[10]; - - /*< public >*/ - /* Media */ - void (*media_download)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *server_name, - const gchar *media_id, - GError **error); - void (*media_thumbnail)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *server_name, - const gchar *media_id, - guint width, - guint height, - MatrixResizeMethod method, - GError **error); - void (*media_upload)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *content_type, - GByteArray *content, - GError **error); - - /* Presence */ - void (*get_presence_list)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); - void (*update_presence_list)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GList *drop_ids, - GList *invite_ids, - GError **error); - void (*get_user_presence)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); - void (*set_user_presence)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - MatrixPresence presence, - const gchar *status_message, - GError **error); - - /* Push notifications */ - void (*update_pusher)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - MatrixPusher *pusher, - GError **error); - void (*get_pushers)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error); - void (*delete_pusher)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - GError **error); - void (*get_pusher)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - GError **error); - void (*add_pusher)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - const gchar *before, - const gchar *after, - GList *actions, - GList *conditions, - GError **error); - void (*toggle_pusher)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - gboolean enabled, - GError **error); - - /* Room creation */ - void (*create_room)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - MatrixRoomPreset preset, - const gchar *room_name, - const gchar *room_alias, - const gchar *topic, - MatrixRoomVisibility visibility, - JsonNode *creation_content, - GList *initial_state, - GList *invitees, - GList *invite_3pids, - GError **error); - - /* Room directory */ - void (*delete_room_alias)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_alias, - GError **error); - void (*get_room_id)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_alias, - GError **error); - void (*create_room_alias)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *room_alias, - GError **error); - - /* Room discovery */ - void (*list_public_rooms)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error); - - /* Room membership */ - - void (*ban_user)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *user_id, - const gchar *reason, - GError **error); - void (*forget_room)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error); - void (*invite_user_3rdparty)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - Matrix3PidCredential *credential, - GError **error); - void (*invite_user)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *user_id, - GError **error); - void (*join_room)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error); - void (*leave_room)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error); - - /* Room participation */ - - void (*event_stream)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *from_token, - gulong timeout, - GError **error); - void (*get_event)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *event_id, - GError **error); - void (*initial_sync)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - guint limit, - gboolean archived, - GError **error); - void (*get_event_context)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_id, - guint limit, - GError **error); - void (*initial_sync_room)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error); - void (*list_room_members)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error); - void (*list_room_messages)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *from_token, - MatrixEventDirection direction, - guint limit, - GError **error); - void (*send_event_receipt)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - MatrixReceiptType receipt_type, - const gchar *event_id, - JsonNode *receipt, - GError **error); - void (*redact_event)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_id, - const gchar *txn_id, - const gchar *reason, - GError **error); - void (*send_message_event)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_type, - const gchar *txn_id, - JsonNode *content, - GError **error); - void (*get_room_state)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_type, - const gchar *state_key, - GError **error); - void (*send_room_event)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_type, - const gchar *state_key, - JsonNode *content, - GError **error); - void (*notify_room_typing)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - guint timeout, - gboolean typing, - GError **error); - void (*sync)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *filter_id, - const MatrixFilter *filter, - const gchar *since, - gboolean full_state, - gboolean set_presence, - gulong timeout, - GError **error); - void (*create_filter)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - MatrixFilter *filter, - GError **error); - void (*download_filter)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *filter_id, - GError **error); - - /*< private >*/ - /* Search */ - void *search_reserved; - - /*< public >*/ - /* Server administration */ - - void (*whois)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); - void (*versions)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error); - - /* Session management */ - - void (*login)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *login_type, - const JsonNode *content, - GError **error); - void (*token_refresh)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *refresh_token, - GError **error); - - /* User data */ - - void (*get_3pids)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error); - void (*add_3pid)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - gboolean bind_creds, - Matrix3PidCredential *threepid_creds, - GError **error); - void (*change_password)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *new_password, - GError **error); - void (*get_profile)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); - void (*get_avatar_url)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); - void (*set_avatar_url)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *avatar_url, - GError **error); - void (*get_display_name)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); - void (*set_display_name)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *display_name, - GError **error); - void (*register_account)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - MatrixAccountKind account_kind, - gboolean bind_email, - const gchar *username, - const gchar *password, - GError **error); - void (*set_account_data)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - const gchar *event_type, - JsonNode *content, - GError **error); - void (*get_room_tags)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - GError **error); - void (*delete_room_tag)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - const gchar *tag, - GError **error); - void (*add_room_tag)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - const gchar *tag, - JsonNode *content, - GError **error); - - /* VoIP */ - - void (*get_turn_server)(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error); - - /* Non-spec methods */ - - void (*abort_pending)(MatrixAPI *api); - - /*< private >*/ - /* Leave room for endpoint expansion */ - void *padding[50]; -}; - -GType matrix_api_get_type(void) G_GNUC_CONST; - -/* Property getters and setters */ - -void matrix_api_set_token(MatrixAPI *api, const gchar *token); -const gchar *matrix_api_get_token(MatrixAPI *api); -void matrix_api_set_refresh_token(MatrixAPI *api, const gchar *refresh_token); -const gchar *matrix_api_get_refresh_token(MatrixAPI *api); -const gchar *matrix_api_get_user_id(MatrixAPI *api); -const gchar *matrix_api_get_homeserver(MatrixAPI *api); - -/* API definition */ - -/* Media */ -void matrix_api_media_download(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *server_name, - const gchar *media_id, - GError **error); -void matrix_api_media_thumbnail(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *server_name, - const gchar *media_id, - guint width, - guint height, - MatrixResizeMethod method, - GError **error); -void matrix_api_media_upload(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *content_type, - GByteArray *content, - GError **error); - -/* Presence */ -void matrix_api_get_presence_list(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); -void matrix_api_update_presence_list(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GList *drop_ids, - GList *invite_ids, - GError **error); -void matrix_api_get_user_presence(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); -void matrix_api_set_user_presence(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - MatrixPresence presence, - const gchar *status_message, - GError **error); - -/* Push notifications */ -void matrix_api_update_pusher(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - MatrixPusher *pusher, - GError **error); -void matrix_api_get_pushers(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error); -void matrix_api_delete_pusher(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - GError **error); -void matrix_api_get_pusher(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - GError **error); -void matrix_api_add_pusher(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - const gchar *before, - const gchar *after, - GList *actions, - GList *conditions, - GError **error); -void matrix_api_toggle_pusher(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *scope, - MatrixPusherKind kind, - const gchar *rule_id, - gboolean enabled, - GError **error); - -/* Room creation */ -void matrix_api_create_room(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - MatrixRoomPreset preset, - const gchar *room_name, - const gchar *room_alias, - const gchar *topic, - MatrixRoomVisibility visibility, - JsonNode *creation_content, - GList *initial_state, - GList *invitees, - GList *invite_3pids, - GError **error); - -/* Room directory */ -void matrix_api_delete_room_alias(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_alias, - GError **error); -void matrix_api_get_room_id(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_alias, - GError **error); -void matrix_api_create_room_alias(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *room_alias, - GError **error); - -/* Room discovery */ -void matrix_api_list_public_rooms(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error); - -/* Room membership */ - -void matrix_api_ban_user(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *user_id, - const gchar *reason, - GError **error); -void matrix_api_forget_room(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error); -void matrix_api_invite_user_3rdparty(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - Matrix3PidCredential *credential, - GError **error); -void matrix_api_invite_user(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *user_id, - GError **error); -void matrix_api_join_room(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error); -void matrix_api_leave_room(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error); - -/* Room participation */ - -void matrix_api_event_stream(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *from_token, - gulong timeout, - GError **error); -void matrix_api_get_event(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *event_id, - GError **error); -void matrix_api_initial_sync(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - guint limit, - gboolean archived, - GError **error); -void matrix_api_get_event_context(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_id, - guint limit, - GError **error); -void matrix_api_initial_sync_room(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error); -void matrix_api_list_room_members(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - GError **error); -void matrix_api_list_room_messages(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *from_token, - MatrixEventDirection direction, - guint limit, - GError **error); -void matrix_api_send_event_receipt(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - MatrixReceiptType receipt_type, - const gchar *event_id, - JsonNode *receipt, - GError **error); -void matrix_api_redact_event(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_id, - const gchar *txn_id, - const gchar *reason, - GError **error); -void matrix_api_send_message_event(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_type, - const gchar *txn_id, - JsonNode *content, - GError **error); -void matrix_api_get_room_state(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_type, - const gchar *state_key, - GError **error); -void matrix_api_send_room_event(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *room_id, - const gchar *event_type, - const gchar *state_key, - JsonNode *content, - GError **error); -void matrix_api_notify_room_typing(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - guint timeout, - gboolean typing, - GError **error); -void matrix_api_sync(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *filter_id, - const MatrixFilter *filter, - const gchar *since, - gboolean full_state, - gboolean set_presence, - gulong timeout, - GError **error); -void matrix_api_create_filter(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - MatrixFilter *filter, - GError **error); -void matrix_api_download_filter(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *filter_id, - GError **error); - -/* Search */ - -/* Add the search function here */ - -/* Server administration */ - -void matrix_api_whois(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); -void matrix_api_versions(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error); - -/* Session management */ - -void matrix_api_login(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *login_type, - const JsonNode *content, - GError **error); -void matrix_api_token_refresh(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *refresh_token, - GError **error); - -/* User data */ - -void matrix_api_get_3pids(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error); -void matrix_api_add_3pid(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - gboolean bind_creds, - Matrix3PidCredential *threepid_creds, - GError **error); -void matrix_api_change_password(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *new_password, - GError **error); -void matrix_api_get_profile(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); -void matrix_api_get_avatar_url(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); -void matrix_api_set_avatar_url(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *avatar_url, - GError **error); -void matrix_api_get_display_name(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - GError **error); -void matrix_api_set_display_name(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *display_name, - GError **error); -void matrix_api_register_account(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - MatrixAccountKind account_kind, - gboolean bind_email, - const gchar *username, - const gchar *password, - GError **error); -void matrix_api_set_account_data(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - const gchar *event_type, - JsonNode *content, - GError **error); -void matrix_api_get_room_tags(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - GError **error); -void matrix_api_delete_room_tag(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - const gchar *tag, - GError **error); -void matrix_api_add_room_tag(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - const gchar *user_id, - const gchar *room_id, - const gchar *tag, - JsonNode *content, - GError **error); - -/* VoIP */ - -void matrix_api_get_turn_server(MatrixAPI *api, - MatrixAPICallback callback, - gpointer user_data, - GError **error); - -/* Non-spec methods */ - -void matrix_api_abort_pending(MatrixAPI *api); - -G_END_DECLS - -#endif /* __MATRIX_API_IFACE_H__ */ diff --git a/src/matrix-api.vala b/src/matrix-api.vala new file mode 100644 index 0000000..73d6f78 --- /dev/null +++ b/src/matrix-api.vala @@ -0,0 +1,1294 @@ +/* + * This file is part of matrix-glib-sdk + * + * matrix-glib-sdk is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * matrix-glib-sdk is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with matrix-glib-sdk. If not, see + * . + */ + +/** + * Base interface for all Client/Server API functionality. + */ +public interface Matrix.API : GLib.Object { + /** + * The token to use for authorization. The Matrix.API.login() and + * Matrix.API.register_account() calls MUST set this + * automatically. + */ + public abstract string? token { get; set; default = null; } + + /** + * The token to use for refreshing the authorization token. It is + * issued by the server after a successful registration, login or + * token refresh. + */ + public abstract string? refresh_token { get; set; default = null; } + + /** + * The Matrix user ID that is currently authenticated with the + * server. It is set automatically by the registration and login + * process. + */ + public abstract string? user_id { get; default = null; } + + /** + * The name of the Matrix home server as it calls itself. It is + * set automatically by the registration and login process. + */ + public abstract string? homeserver { get; default = null; } + + /** + * A callback function to use with Client API calls. If the + * response is JSON, @param json_content is set and @param + * raw_content is not. If the response is not JSON, but still has + * a body (e.g. with media downloads), @param json_content is + * {{{null}}} and @raw_content holds the content body. + * + * @param api a Matrix.API instance + * @param content_type the content type of the response + * @param json_content the JSON content of the response + * @param raw_content the raw (ie. binary) content of the response + * @param err a GLib.Error that holds any errors that occured + * during the API call, or {{{null}}} + */ + public delegate void + Callback(Matrix.API api, + string content_type, + Json.Node? json_content, + GLib.ByteArray? raw_content, + Matrix.Error? err); + + /** + * Abort all pending requests toward a Matrix homeserver. Be aware + * that this may leave requests in an inconsistent state. + */ + public abstract void + abort_pending(); + + /* Media */ + + /** + * Download content from the content repository. + * + * Implementors: If server_name or media_id is {{{null}}}, + * implementations MUST throw Matrix.Error.INCOMPLETE. + * + * @param callback a function to call when the request is finished + * @param server_name the server name from the `mxc:` URI + * @param media_id the media ID from the `mxc:` URI + */ + public abstract void + media_download([CCode (delegate_target_pos = 1.5, scope = "async", destroy_notify_pos = -1)] + owned Matrix.API.Callback? @callback, + string server_name, + string media_id) + throws Matrix.Error; + + /** + * Download a thumbnail of the content from the content + * repository. The actual thumbnail may not match the size + * specified. + * + * If @param server_name or @param media_id is {{{null}}}, this + * function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback a function to call when the request is finished + * @param server_name the server name from the `mxc:` URI + * @param media_id the media ID from the `mxc:` URI + */ + public abstract void + media_thumbnail([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string server_name, + string media_id, + uint width, + uint height, + Matrix.ResizeMethod method) + throws Matrix.Error; + + /** + * Upload some content to the content repository. + * + * If @param content is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param content_type the type of the content to be uploaded + * @param content the content to be uploaded + */ + public abstract void + media_upload([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string? content_type, + owned GLib.ByteArray content) + throws Matrix.Error; + + /* Presence */ + + /** + * Retrieve a list of presence events for every user on this list. + * + * If @param user_id is {{{null}}}, this function returns immediately, + * and throws Matrix.Error.INCOMPLETE. + * + * @param user_id the user whose presence list should be retrieved + */ + public abstract void + get_presence_list([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id) + throws Matrix.Error; + + /** + * Add or remove users from the specified user's presence list. + * + * If @param user_id, or both @param drop_ids and @param + * invite_ids are {{{null}}}, this function returns immediately, + * and throws Matrix.Error.INCOMPLETE. + * + * @param user_id the user whose presence list is being modified + * @param drop_ids a list of user IDs to remove from the list + * @param invite_ids a list of user IDs to add to the list + */ + public abstract void + update_presence_list([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id, + GLib.List drop_ids, + GLib.List invite_ids) + throws Matrix.Error; + + /** + * Get the given user's presence state. + * + * If @param user_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param user_id the user whose presence list is being modified + */ + public abstract void + get_user_presence([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id) + throws Matrix.Error; + + /** + * Set the given user's presence. You cannot set the presence of + * another user. + * + * If @param user_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param user_id the user whose presence list is being modified + * @param presence the new presence state + * @param status_message a status message attached to this state + */ + public abstract void + set_user_presence([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id, + Matrix.Presence presence, + string? status_message) + throws Matrix.Error; + + /* Push notifications */ + + /** + * Create, update or delete a pusher for the active user on this + * homeserver. + * + * If @param pusher is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + */ + public abstract void + update_pusher([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + Matrix.Pusher pusher) + throws Matrix.Error; + + /** + * Retrieve all push rulesets. + */ + public abstract void + get_pushers([CCode (scope = "async")] + owned Matrix.API.Callback? @callback) + throws Matrix.Error; + + /** + * Delete a push rule. + * + * If @param scope or @param rule_id is {{{null}}}, this function + * returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback a function to call when the request is finished + * @param scope either {{{global}}} to specify global rules, or + * {{{device/<profile tag>}}} for rules for a + * given {{{profile tag}}} + * @param kind the kind of rule + * @param rule_id an identifier for the rule + */ + public abstract void + delete_pusher([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string scope, + Matrix.PusherKind kind, + string rule_id) + throws Matrix.Error; + + /** + * Retrieve a specific push rule. + * + * If @param scope or @param rule_id is {{{null}}}, this function + * returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback a function to call when the request is finished + * @param scope either {{{global}}} to specify global rules, or + * {{{device/<profile tag>}}} for rules for a + * given {{{profile tag}}}. + * @param kind the kind of rule + * @param rule_id an identifier for the rule + */ + public abstract void + get_pusher([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string scope, + Matrix.PusherKind kind, + string rule_id) + throws Matrix.Error; + + /** + * Add or change a push rule. + * + * If either @param scope, @param rule_id or @param actions are + * {{{null}}}, this function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback a function to call when the request is finished + * @param scope either {{{global}}} to specify global rules, or + * {{{device/<profile tag>}}} for rules for a + * given {{{profile tag}}} + * @param kind the kind of rule + * @param rule_id an identifier for the rule + * @param before make the new rule the next-most important than + * this rule ID + * @param after make the new rule the next-less important than + * this rule ID + * @param actions the actions to perform when the conditions for + * this rule are met + * @param conditions the conditions that must hold true for an + * event for a rule to be applied. A rule with + * no conditions always matches + */ + public abstract void + add_pusher([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string scope, + Matrix.PusherKind kind, + string rule_id, + string? before, + string? after, + GLib.List actions, + GLib.List? conditions) + throws Matrix.Error; + + /** + * Enable or disable the specified push rule. + * + * If @scope or @rule_id is %NULL, this function returns immediately, + * and fills @error with %MATRIX_ERROR_INCOMPLETE. + * + * @param callback a function to call when the request is finished + * @param scope either {{{global}}} to specify global rules, or + * {{{device/<profile tag>}}} for rules for a + * given {{{profile tag}}} + * @param kind the kind of rule + * @param rule_id an identifier for the rule + * @param enabled if {{{true}}}, the rule will be enabled, + * otherwise it gets disabled + */ + public abstract void + toggle_pusher([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string scope, + Matrix.PusherKind kind, + string rule_id, + bool enabled) + throws Matrix.Error; + + /* Room creation */ + + /** + * Create a new room with the given name and invite the users + * in @param invitees. + * + * @param callback the function to call when the request is + * finished + * @param preset a room preset to use + * @param room_name the desired display name for the room + * @param room_alias an alias of the room + * @param topic the topic of the room + * @param visibility the initial visibility of the room + * @param creation_content extra keys to be added to the content + * of m.room.create + * @param initial_state a list of state events to set in the new + * room + * @param invitees list of user IDs to invite to the new room + * @param invite_3pids a list of 3rd party credentials to invite + * to the new room + */ + public abstract void + create_room([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + Matrix.RoomPreset preset, + string? room_name, + string? room_alias, + string? topic, + Matrix.RoomVisibility visibility, + Json.Node? creation_content, + GLib.List? initial_state, + GLib.List? invitees, + GLib.List? invite_3pids) + throws Matrix.Error; + + /* Room directory */ + + /** + * Remove the mapping of @room_alias to its room ID + * + * Servers may choose to implement additional access control checks + * here, for instance that room aliases can only be deleted by their + * creator or a server administrator. + * + * If @room_alias is %NULL, this function returns immediately, and + * fills @error with %MATRIX_ERROR_INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_alias the alias name to remove + */ + public abstract void + delete_room_alias([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_alias) + throws Matrix.Error; + + /** + * Get the room ID corresponding to this room alias. + * + * If @param room_alias is {{{null}}}, this function returns + * immediately, throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_alias the room alias + */ + public abstract void + get_room_id([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_alias) + throws Matrix.Error; + + /** + * Create a new mapping from room alias to room ID. + * + * If @param room_alias or @param room_id is {{{null}}}, this + * function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room ID to add this alias to + * @param room_alias the room alias to set + */ + public abstract void + create_room_alias([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id, + string room_alias) + throws Matrix.Error; + + /* Room discovery */ + + /** + * List the public rooms on the server. + * + * @param callback the function to call when the request is + * finished + */ + public abstract void + list_public_rooms([CCode (scope = "async")] + owned Matrix.API.Callback? @callback) + throws Matrix.Error; + + /* Room membership */ + + /** + * Ban the specified user from the specified room. An optional reason + * can be specified. + * + * If @param room_id or @param user_id is {{{null}}}, this + * function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room ID where the user should be banned + * @param user_id the user ID to ban + * @param reason the reason of the ban + */ + public abstract void + ban_user([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id, + string user_id, string? reason) + throws Matrix.Error; + + /** + * Stop the requesting user remembering about a particular room. + * + * In general, history is a first class citizen in Matrix. After this + * API is called, however, a user will no longer be able to retrieve + * history for this room. If all users on a homeserver forget a room, + * the room is eligible for deletion from that homeserver. + * + * If the user is currently joined to the room, they will implicitly + * leave the room as part of this API call. + * + * If @param room_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room ID to forget + */ + public abstract void + forget_room([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id) + throws Matrix.Error; + + /** + * Invite a user to the room by a 3rd party identifier. They do not + * start participating in the room until they actually join the room. + * + * If the identity server does not know a Matrix user identifier for + * the passed third party identifier, the homeserver will issue an + * invitation which can be accepted upon providing proof of ownership + * of the third party identifier. + * + * If @param credential is {{{null}}}, this function immediately + * returns, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room ID to which to invite the user + * @param credential a {@link Matrix.3PidCredential} that + * identifies a user to invite + */ + public abstract void + invite_user_3rdparty([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id, + Matrix.3PidCredential credential) + throws Matrix.Error; + + /** + * Invite a user to a room. + * + * If @room_id or @user_id is %NULL, this function returns + * immediately, and fills @error with %MATRIX_ERROR_INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room ID to invite the user to + * @param user_id the user ID to invite + */ + public abstract void + invite_user([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id, + string user_id) + throws Matrix.Error; + + /** + * Join a room. + * + * If @param room_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room ID to join to + */ + public abstract void + join_room([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id) + throws Matrix.Error; + + /** + * Leave a room. + * + * If @param room_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room ID to kick the user from + */ + public abstract void + leave_room([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id) + throws Matrix.Error; + + /* Room participation */ + + /** + * Get the event stream, optionally beginning from @from_token. + * + * @param callback the function to call when the request is + * finished + * @param from_token events will be listed from this token + * @param timeout timeout of the request + */ + public abstract void + event_stream([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string? from_token, + ulong timeout) + throws Matrix.Error; + + /** + * Get a single event by event ID. + * + * If @param event_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param event_id the event ID to get + */ + public abstract void + get_event([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string event_id) + throws Matrix.Error; + + /** + * Perform an initial sync of events + * + * @param callback the function to call when the request is + * finished + * @param limit the maximum number of events to get + * @param archived whether to include rooms that the user has left + */ + public abstract void + initial_sync([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + uint limit, + bool archived) + throws Matrix.Error; + + /** + * Gets a number of events that happened just before and after the + * specified event. + * + * If @param room_id or @param event_id is {{{null}}}, this + * function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room to get events from + * @param event_id the event to get context around + * @param limit the maximum number of events to get. If 0, a + * default value is used (10, according to the + * specification) + */ + public abstract void + get_event_context([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? callback, + string room_id, + string event_id, + uint limit) + throws Matrix.Error; + + /** + * Get a copy of the current state and the most recent messages in a + * room. + * + * If @param room_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room to get the data for + */ + public abstract void + initial_sync_room([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id) + throws Matrix.Error; + + /** + * Get the list of members for a room. + * + * If @param room_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room to get the member events for + */ + public abstract void + list_room_members([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id) + throws Matrix.Error; + + /** + * Get a list of message and state events for a room. + * + * If @param room_id or @param from_token is {{{null}}}, this + * function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room to get the events for + * @param from_token the token to start returning events + * from. This token can be obtained by calling + * matrix_api_initial_sync() or + * matrix_api_initial_sync_room() + * @param direction the direction of the returned events + * @param limit the maximum number of events to return. If 0, a + * default value will be used (10, according to the + * specification + */ + public abstract void + list_room_messages([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id, + string from_token, + Matrix.EventDirection direction, + uint limit) + throws Matrix.Error; + + /** + * Update the marker for the given receipt type to the event ID + * specified. + * + * If @param room_id, @param event_id or @param receipt is + * {{{null}}}, this function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room in which to send the event + * @param receipt_type type of the receipt + * @param event_id the event ID to acknowledge up to + * @param receipt extra receipt information to attach. Note that + * the server will automatically attach the + * {{{ts}}} field + */ + public abstract void + send_event_receipt([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id, + Matrix.ReceiptType receipt_type, + string event_id, + Json.Node receipt) + throws Matrix.Error; + + /** + * Strip all information out of an event which isn't critical to + * the integrity of the server-side representation of the + * room. This cannot be undone. + * + * Users may redact their own events, and any user with a power + * level greater than or equal to {{{redact}}} power level of the + * room may redact events there. + * + * If @param room_id, @param event_id or @param txn_id is + * {{{null}}}, this function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room from which to redact the event + * @param event_id the event ID to acknowledge up to + * @param txn_id the transaction ID for this event. Clients should + * generate a unique ID; it will be used by the + * server to ensure idempotency of requests + * @param reason the reason for the event being redacted + */ + public abstract void + redact_event([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id, + string event_id, + string txn_id, + string? reason) + throws Matrix.Error; + + /** + * Send a message event to the room. + * + * If @param room_id, @param event_type, @param txn_id or @content + * is {{{null}}}, this function returns immediately, and + * throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room to send the event to + * @param event_type the type of event to send + * @param txn_id the transaction ID for this event. Clients should + * generate a unique ID; it will be used by the + * server to ensure idempotency of requests + * @param content the content of the event as a {@link Json.Node} + */ + public abstract void + send_message_event([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id, + string event_type, + string txn_id, + owned Json.Node content) + throws Matrix.Error; + + /** + * Look up the contents of a state event in a room. If + * both @param event_type and @param state_key are empty, get a + * list of state events for that room. + * + * If @param room_id is {{{null}}}, or if @param state_key is set + * with @param event_type being {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room ID to get a state for + * @param event_type the type of state to look up + * @param state_key the key of the state to look up. + * If @param event_type is {{{null}}}, this + * parameter is ignored + */ + public abstract void + get_room_state([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id, + string? event_type, + string? state_key) + throws Matrix.Error; + + /** + * Send a state event to the room. These events will be overwritten + * if @param room_id, @param event_type and @param state_key all + * match. + * + * This request cannot use transaction IDs. + * + * The required fields in the body of the request (@param content) + * vary depending on the type of the event. + * + * If @param room_id or @param content is {{{null}}}, or if @param + * state_key is set with @param event_type being {{{null}}}, this + * function returns immediately, and throw + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param room_id the room ID to get a state for + * @param event_type the type of state to look up + * @param state_key the key of the state to look up. + * If @param event_type is {{{null}}}, this + * parameter is ignored + * @param content the content of the state event + */ + public abstract void + send_room_event([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string room_id, + string event_type, + string? state_key, + owned Json.Node content) + throws Matrix.Error; + + /** + * Tell the server the user is typing for the next @param timeout + * milliseconds. If @param typing is {{{false}}}, it tells the + * server that the user stopped typing. + * + * If @param user_id or @param room_id is {{{null}}}, this + * function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the user who has started to type + * @param room_id the room in which the user is typing + * @param timeout the length of time in milliseconds to mark this + * user as typing + * @param typing whether the user is typing or not. If + * {{{false}}}, @param timeout can be omitted + * (ie. set to 0) + */ + public abstract void + notify_room_typing([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id, + string room_id, + uint timeout, + bool typing) + throws Matrix.Error; + + /** + * Synchronize the client's state with the latest state on the + * server. Clients should use this API when they first log in to + * get an initial snapshot of the state on the server and then + * continue to call this API to get incremental details to the + * state and to receive new messages. + * + * Only one of @param filter and @param filter_id should be + * specified, or both of them should be set to {{{null}}} to + * receive all events. + * + * @param callback the function to call when the request is + * finished + * @param filter_id a filter ID created by the filter API + * (e.g. matrix_api_create_filter()) + * @param filter a definition on what events to fetch + * @param since a point in time to continue a sync from + * @param full_state if {{{true}}}, all state events will be + * returned, even if @param since is not + * empty. If {{{false}}}, and @param since is + * not empty, only states which have changed + * since the point indicated by @param since + * will be returned + * @param set_presence controls whether the client is + * automatically marked as online by polling + * this API. + * @param timeout the maximum time to poll in milliseconds + */ + public abstract void + sync([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string? filter_id, + Matrix.Filter? filter, + string? since, + bool full_state, + bool set_presence, + ulong timeout) + throws Matrix.Error; + + /** + * Upload a new filter definition to the homeserver. It will return a + * filter ID that may be used in future requests. + * + * If @param user_id or @param filter is {{{null}}}, this function + * returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the ID of the user uploading the filter. An + * access token must be present (either specifying + * one with matrix_api_set_token() or requested + * from the server via + * matrix_api_register_account() or + * matrix_api_login()). + * @param filter the filter to upload + */ + public abstract void + create_filter([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id, + Matrix.Filter filter) + throws Matrix.Error; + + /** + * Download a filter. + * + * If @param user_id or @param filter_id is {{{null}}}, this + * function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the user ID to download a filter from + * @param filter_id the filter ID to download + */ + public abstract void + download_filter([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id, + string filter_id) + throws Matrix.Error; + + /* Search */ + + /* TODO: implement search! */ + + /* Server administration */ + + /** + * Get information about a particular user. + * + * If @param user_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the user ID to look up + */ + public abstract void + whois([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id) + throws Matrix.Error; + + /** + * Get the versions of the specification supported by the server. + * + * @param callback the function to call when the request is + * finished + */ + public abstract void + versions([CCode (scope = "async")] + owned Matrix.API.Callback? @callback) + throws Matrix.Error; + + /* Session management */ + + /** + * Attempt to login with type @param type. Implementations of this + * method must set the token property on a successful login. + * + * If @param login_type or @param content is {{{null}}}, this + * function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param login_type the login type to use + * @param content parameters to pass for the login request + */ + public abstract void + login([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string login_type, + Json.Node? content) + throws Matrix.Error; + + /** + * Exchanges a refresh token for a new access token. This is + * intended to be used if the access token has expired. If @param + * refresh_token is {{{null}}}, implementations MUST send the + * stored refresh token. If it is not pesent (e.g. because login + * hasn’t happened yet), this function MUST throw an error. + * + * @param callback the function to call when the request is + * finished + * @param refresh_token the refresh token that was issued by the + * server + */ + public abstract void + token_refresh([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string? refresh_token) + throws Matrix.Error; + + /* User data */ + + /** + * Get a list of the third party identifiers that a homeserver has + * associated with the user's account. + * + * This is not the same as the list of third party identifiers bound + * to the user's Matrix ID in Identity Servers. + * + * Identifiers in this list may be used by the homeserver as, for + * example, identifiers to accept to reset the user's account + * password. + * + * @param callback the function to call when the request is + * finished + */ + public abstract void + get_3pids([CCode (scope = "async")] + owned Matrix.API.Callback? @callback) + throws Matrix.Error; + + /** + * Add contact information to the user's account. + * + * If @param threepid_creds is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param bind_creds whether the homeserver should also bind this + * third party identifier to the account's + * Matrix ID with the passed Identity Server. + * @param threepid_creds the credentials to associate with the + * account + */ + public abstract void + add_3pid([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + bool bind_creds, + Matrix.3PidCredential threepid_creds) + throws Matrix.Error; + + /** + * Change the active user's password. + * + * If @param new_password is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param new_password the new password for the account + */ + public abstract void + change_password([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string new_password) + throws Matrix.Error; + + /** + * Get a user's profile. + * + * If @param user_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the user whose profile to get + */ + public abstract void + get_profile([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id) + throws Matrix.Error; + + /** + * Get the URL of the specified user's avatar. + * + * If @param user_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the user whose avatar URL to get + */ + public abstract void + get_avatar_url([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id) + throws Matrix.Error; + + /** + * Set the user's avatar URL. + * + * If @param user_id or @param avatar_url is {{{null}}}, this + * function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the user whose avatar URL to set + * @param avatar_url the avatar URL info + */ + public abstract void + set_avatar_url([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id, + string avatar_url) + throws Matrix.Error; + + /** + * Get the user's display name. + * + * If @param user_id is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the user whose display name to get + */ + public abstract void + get_display_name([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id) + throws Matrix.Error; + + /** + * Set the user's display name. + * + * If @param user_id or @param display_name is {{{null}}}, this + * function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the user whose display name to set + * @param display_name the display name info + */ + public abstract void + set_display_name([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id, + string display_name) + throws Matrix.Error; + + /** + * Attempt to register an account with the homeserver using @param + * username and @param password. + * + * Implementations of this method must set the token property on a + * successful login. + * + * If @param password is {{{null}}}, this function returns + * immediately, and throws Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param account_kind the type of account to register + * @param bind_email if {{{true}}}, the server binds the e-mail + * used for authentication to the Matrix ID with + * the ID server + * @param username the local part of the desired Matrix ID. If + * omitted, the server will generate a local part + * @param password the desired password for the account + */ + public abstract void + register_account([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + Matrix.AccountKind account_kind, + bool bind_email, + string? username, + string password) + throws Matrix.Error; + + /** + * Set some account data for the client. This config is only + * visible to the user who set the account data. The config will + * be synced to clients in the top-level account data. + * + * If @param user_id, @param event_type or @param content is + * {{{null}}}, this function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the user to set account data for. An access + * token must be present and be authorized to make + * requests for this user ID + * @param room_id the room to set account data for. If {{{null}}}, + * the account data will be set globally + * @param event_type the event type of the account data to + * set. Custom types should be namespaced to + * avoid clashes + * @param content the content of the account data + */ + public abstract void + set_account_data([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id, + string? room_id, + string event_type, + owned Json.Node content) + throws Matrix.Error; + + /** + * List the tags set by a user on a room. + * + * If @param user_id or @param room_id is {{{null}}}, this + * function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the ID of the user to get the tags for. An + * access token must be set, and it must be + * authorised to make requests for this user ID + * @param room_id the room to get tags for + */ + public abstract void + get_room_tags([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id, + string room_id) + throws Matrix.Error; + + /** + * Remove a tag from the room. + * + * If @param user_id, @param room_id or @param tag is {{{null}}}, + * this function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the id of the user to remove a tag for + * @param room_id the id of the room to remove the tag from + * @param tag the tag to remove + */ + public abstract void + delete_room_tag([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id, + string room_id, + string tag) + throws Matrix.Error; + + /** + * Add a tag to the room. + * + * If @param user_id, @param room_id or @param tag is {{{null}}}, + * this function returns immediately, and throws + * Matrix.Error.INCOMPLETE. + * + * @param callback the function to call when the request is + * finished + * @param user_id the ID of the user to add the tag for + * @param room_id the ID of the room to add the tag for + * @param tag the tag to add + * @param content extra data for the tag, e.g. ordering + */ + public abstract void + add_room_tag([CCode (delegate_target_pos = 1.5, scope = "async")] + owned Matrix.API.Callback? @callback, + string user_id, + string room_id, + string tag, + owned Json.Node? content) + throws Matrix.Error; + + /* VoIP */ + + /** + * Get credentials for the client to use when initiating calls. + * + * @param callback the function to call when the request is + * finished + */ + public abstract void + get_turn_server([CCode (scope = "async")] + owned Matrix.API.Callback? @callback) + throws Matrix.Error; +} diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index 31d2554..f8c04f4 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -90,7 +90,7 @@ typedef struct { static GParamSpec *obj_properties[N_PROPERTIES] = {NULL,}; -static void matrix_http_api_matrix_api_init(MatrixAPIInterface *iface); +static void matrix_http_api_matrix_api_init(MatrixAPIIface *iface); static void i_set_token(MatrixAPI *api, const gchar *token); static const gchar *i_get_token(MatrixAPI *api); static void i_set_refresh_token(MatrixAPI *api, const gchar *refresh_token); @@ -844,7 +844,7 @@ i_login(MatrixAPI *api, MatrixAPICallback callback, gpointer user_data, const gchar *login_type, - const JsonNode *content, + JsonNode *content, GError **error) { JsonNode *body; @@ -2175,7 +2175,7 @@ i_sync(MatrixAPI *api, MatrixAPICallback callback, gpointer user_data, const gchar *filter_id, - const MatrixFilter *filter, + MatrixFilter *filter, const gchar *since, gboolean full_state, gboolean set_presence, @@ -2756,7 +2756,7 @@ i_abort_pending(MatrixAPI *api) } static void -matrix_http_api_matrix_api_init(MatrixAPIInterface *iface) +matrix_http_api_matrix_api_init(MatrixAPIIface *iface) { iface->set_token = i_set_token; iface->get_token = i_get_token; diff --git a/src/matrix-http-api.h b/src/matrix-http-api.h index d767b37..f8641fb 100644 --- a/src/matrix-http-api.h +++ b/src/matrix-http-api.h @@ -21,7 +21,7 @@ #include -#include "matrix-api.h" +#include "matrix-glib.h" G_BEGIN_DECLS diff --git a/src/matrix-http-client.c b/src/matrix-http-client.c index 06dc2b2..308a97b 100644 --- a/src/matrix-http-client.c +++ b/src/matrix-http-client.c @@ -58,8 +58,8 @@ cb_login(MatrixAPI *api, const gchar *content_type, JsonNode *json_content, GByteArray *raw_content, - gpointer user_data, - GError *error) + GError *error, + gpointer user_data) { matrix_client_login_finished(MATRIX_CLIENT(api), (error == NULL)); } @@ -97,8 +97,8 @@ cb_register_account(MatrixAPI *api, const gchar *content_type, JsonNode *json_content, GByteArray *raw_content, - gpointer user_data, - GError *error) + GError *error, + gpointer user_data) { matrix_client_login_finished(MATRIX_CLIENT(api), (error == NULL)); } @@ -137,8 +137,8 @@ cb_event_stream(MatrixAPI *api, const gchar *content_type, JsonNode *json_content, GByteArray *raw_content, - gpointer user_data, - GError *error) + GError *error, + gpointer user_data) { MatrixHTTPClientPrivate *priv = matrix_http_client_get_instance_private( MATRIX_HTTP_CLIENT(api)); diff --git a/src/test-api-client.c b/src/test-api-client.c index 4e3080f..59d35a5 100644 --- a/src/test-api-client.c +++ b/src/test-api-client.c @@ -41,8 +41,8 @@ initial_sync_finished(MatrixAPI *api, const gchar *content_type, JsonNode *json_content, GByteArray *raw_content, - gpointer user_data, - GError *err) + GError *err, + gpointer user_data) { g_printf("initialSync finished\n"); @@ -54,8 +54,8 @@ create_room_finished(MatrixAPI *api, const gchar *content_type, JsonNode *json_content, GByteArray *raw_content, - gpointer data, - GError *err) + GError *err, + gpointer data) { if (err) { g_debug("Error: %s", err->message); @@ -72,8 +72,8 @@ get_user_presence_finished(MatrixAPI *api, const gchar *content_type, JsonNode *json_content, GByteArray *raw_content, - gpointer data, - GError *err) + GError *err, + gpointer data) { JsonObject *root_obj; const gchar *avatar_url; @@ -102,8 +102,8 @@ login_finished(MatrixAPI *api, const gchar *content_type, JsonNode *json_content, GByteArray *raw_content, - gpointer data, - GError *err) + GError *err, + gpointer data) { JsonPath *path = json_path_new(); JsonNode *result;