Implement join_room
This commit is contained in:
parent
c4cb8bd204
commit
ea7d9aaec4
@ -38,6 +38,8 @@
|
||||
* incomplete
|
||||
* @MATRIX_API_ERROR_BAD_RESPONSE: malformed response, or the response
|
||||
* is not a JSON object
|
||||
* @MATRIX_API_ERROR_INVALID_ROOM_ID: the provided string doesn’t
|
||||
* contain a valid room ID
|
||||
* @MATRIX_API_ERROR_MISSING_TOKEN: authorization token is missing
|
||||
* from the request
|
||||
* @MATRIX_API_ERROR_FORBIDDEN: access was forbidden (e.g. due to a
|
||||
|
@ -29,6 +29,7 @@ typedef enum {
|
||||
MATRIX_API_ERROR_COMMUNICATION_ERROR,
|
||||
MATRIX_API_ERROR_INCOMPLETE,
|
||||
MATRIX_API_ERROR_BAD_RESPONSE,
|
||||
MATRIX_API_ERROR_INVALID_ROOM_ID,
|
||||
|
||||
/* Add Matrix-defined error codes under here, changing `M_` to
|
||||
* `MATRIX_API_ERROR`, i.e. `M_FORBIDDEN` =>
|
||||
|
@ -1025,7 +1025,7 @@ matrix_api_invite_user(MatrixAPI *api,
|
||||
* finished
|
||||
* @user_data: (closure): user data to pass to the callback function
|
||||
* @callback
|
||||
* @room_id_or_alias: the room ID or room alias to join to
|
||||
* @room_ids: the room ID to join to
|
||||
* @error: return location for a #GError, or %NULL
|
||||
*
|
||||
* Join a room.
|
||||
@ -1034,7 +1034,7 @@ void
|
||||
matrix_api_join_room(MatrixAPI *api,
|
||||
MatrixAPICallback callback,
|
||||
gpointer user_data,
|
||||
const gchar *room_id_or_alias,
|
||||
const gchar *room_id,
|
||||
GError **error)
|
||||
{
|
||||
g_return_if_fail(MATRIX_IS_API(api));
|
||||
|
@ -222,7 +222,7 @@ struct _MatrixAPIInterface {
|
||||
void (*join_room)(MatrixAPI *api,
|
||||
MatrixAPICallback callback,
|
||||
gpointer user_data,
|
||||
const gchar *room_id_or_alias,
|
||||
const gchar *room_id,
|
||||
GError **error);
|
||||
void (*leave_room)(MatrixAPI *api,
|
||||
MatrixAPICallback callback,
|
||||
|
@ -962,6 +962,35 @@ i_list_public_rooms(MatrixAPI *api,
|
||||
error);
|
||||
}
|
||||
|
||||
static void
|
||||
i_join_room(MatrixAPI *api,
|
||||
MatrixAPICallback callback,
|
||||
gpointer user_data,
|
||||
const gchar *room_id,
|
||||
GError **error)
|
||||
{
|
||||
gchar *encoded_room_id, *path;
|
||||
|
||||
// TODO: a more thorough check should be used here
|
||||
if (*room_id != '!') {
|
||||
g_set_error(err,
|
||||
MATRIX_API_ERROR, MATRIX_API_ERROR_INVALID_ROOM_ID,
|
||||
"Invalid room ID");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
encoded_room_id = soup_uri_encode(room_id_or_alias, NULL);
|
||||
path = g_strdup_printf("rooms/%s/join", encoded_room_id);
|
||||
g_free(encoded_room_id);
|
||||
|
||||
_send(MATRIX_HTTP_API(api),
|
||||
callback, user_data,
|
||||
"POST", path, NULL, NULL,
|
||||
error);
|
||||
g_free(path);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_http_api_matrix_api_init(MatrixAPIInterface *iface)
|
||||
{
|
||||
@ -977,4 +1006,5 @@ matrix_http_api_matrix_api_init(MatrixAPIInterface *iface)
|
||||
iface->event_stream = i_event_stream;
|
||||
iface->leave_room = i_leave_room;
|
||||
iface->list_public_rooms = i_list_public_rooms;
|
||||
iface->join_room = i_join_room;
|
||||
}
|
||||
|
@ -58,10 +58,8 @@ create_room_finished(MatrixAPI *api,
|
||||
g_printf("Room registered\n");
|
||||
}
|
||||
|
||||
matrix_api_initial_sync(MATRIX_API(api),
|
||||
initial_sync_finished,
|
||||
data, 10, TRUE,
|
||||
NULL);
|
||||
matrix_api_join_room(api, NULL, NULL, "#matrix-glib-sdk-test:elxa4y5sd12", NULL);
|
||||
matrix_api_list_public_rooms(api, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -93,8 +91,10 @@ login_finished(MatrixAPI *api, JsonNode *content, gpointer data, GError *err)
|
||||
|
||||
g_printf("Logged in as %s\n", user_id);
|
||||
|
||||
matrix_api_list_public_rooms(api, NULL, NULL, NULL);
|
||||
|
||||
matrix_api_initial_sync(MATRIX_API(api),
|
||||
initial_sync_finished,
|
||||
data, 10, TRUE,
|
||||
NULL);
|
||||
matrix_api_create_room(api,
|
||||
create_room_finished, NULL,
|
||||
MATRIX_API_ROOM_PRESET_PUBLIC,
|
||||
|
Loading…
Reference in New Issue
Block a user