Implement join_room
This commit is contained in:
		@@ -38,6 +38,8 @@
 | 
				
			|||||||
 *                               incomplete
 | 
					 *                               incomplete
 | 
				
			||||||
 * @MATRIX_API_ERROR_BAD_RESPONSE: malformed response, or the response
 | 
					 * @MATRIX_API_ERROR_BAD_RESPONSE: malformed response, or the response
 | 
				
			||||||
 *                                 is not a JSON object
 | 
					 *                                 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
 | 
					 * @MATRIX_API_ERROR_MISSING_TOKEN: authorization token is missing
 | 
				
			||||||
 *                                  from the request
 | 
					 *                                  from the request
 | 
				
			||||||
 * @MATRIX_API_ERROR_FORBIDDEN: access was forbidden (e.g. due to a
 | 
					 * @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_COMMUNICATION_ERROR,
 | 
				
			||||||
    MATRIX_API_ERROR_INCOMPLETE,
 | 
					    MATRIX_API_ERROR_INCOMPLETE,
 | 
				
			||||||
    MATRIX_API_ERROR_BAD_RESPONSE,
 | 
					    MATRIX_API_ERROR_BAD_RESPONSE,
 | 
				
			||||||
 | 
					    MATRIX_API_ERROR_INVALID_ROOM_ID,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Add Matrix-defined error codes under here, changing `M_` to
 | 
					    /* Add Matrix-defined error codes under here, changing `M_` to
 | 
				
			||||||
     * `MATRIX_API_ERROR`, i.e. `M_FORBIDDEN` =>
 | 
					     * `MATRIX_API_ERROR`, i.e. `M_FORBIDDEN` =>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1025,7 +1025,7 @@ matrix_api_invite_user(MatrixAPI *api,
 | 
				
			|||||||
 *            finished
 | 
					 *            finished
 | 
				
			||||||
 * @user_data: (closure): user data to pass to the callback function
 | 
					 * @user_data: (closure): user data to pass to the callback function
 | 
				
			||||||
 *             @callback
 | 
					 *             @callback
 | 
				
			||||||
 * @room_id_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
 | 
					 * @error: return location for a #GError, or %NULL
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Join a room.
 | 
					 * Join a room.
 | 
				
			||||||
@@ -1034,7 +1034,7 @@ void
 | 
				
			|||||||
matrix_api_join_room(MatrixAPI *api,
 | 
					matrix_api_join_room(MatrixAPI *api,
 | 
				
			||||||
                     MatrixAPICallback callback,
 | 
					                     MatrixAPICallback callback,
 | 
				
			||||||
                     gpointer user_data,
 | 
					                     gpointer user_data,
 | 
				
			||||||
                     const gchar *room_id_or_alias,
 | 
					                     const gchar *room_id,
 | 
				
			||||||
                     GError **error)
 | 
					                     GError **error)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    g_return_if_fail(MATRIX_IS_API(api));
 | 
					    g_return_if_fail(MATRIX_IS_API(api));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -222,7 +222,7 @@ struct _MatrixAPIInterface {
 | 
				
			|||||||
    void (*join_room)(MatrixAPI *api,
 | 
					    void (*join_room)(MatrixAPI *api,
 | 
				
			||||||
                      MatrixAPICallback callback,
 | 
					                      MatrixAPICallback callback,
 | 
				
			||||||
                      gpointer user_data,
 | 
					                      gpointer user_data,
 | 
				
			||||||
                      const gchar *room_id_or_alias,
 | 
					                      const gchar *room_id,
 | 
				
			||||||
                      GError **error);
 | 
					                      GError **error);
 | 
				
			||||||
    void (*leave_room)(MatrixAPI *api,
 | 
					    void (*leave_room)(MatrixAPI *api,
 | 
				
			||||||
                       MatrixAPICallback callback,
 | 
					                       MatrixAPICallback callback,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -962,6 +962,35 @@ i_list_public_rooms(MatrixAPI *api,
 | 
				
			|||||||
          error);
 | 
					          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
 | 
					static void
 | 
				
			||||||
matrix_http_api_matrix_api_init(MatrixAPIInterface *iface)
 | 
					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->event_stream = i_event_stream;
 | 
				
			||||||
    iface->leave_room = i_leave_room;
 | 
					    iface->leave_room = i_leave_room;
 | 
				
			||||||
    iface->list_public_rooms = i_list_public_rooms;
 | 
					    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");
 | 
					        g_printf("Room registered\n");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    matrix_api_initial_sync(MATRIX_API(api),
 | 
					    matrix_api_join_room(api, NULL, NULL, "#matrix-glib-sdk-test:elxa4y5sd12", NULL);
 | 
				
			||||||
                            initial_sync_finished,
 | 
					    matrix_api_list_public_rooms(api, NULL, NULL, NULL);
 | 
				
			||||||
                            data, 10, TRUE,
 | 
					 | 
				
			||||||
                            NULL);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					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);
 | 
					        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,
 | 
					        matrix_api_create_room(api,
 | 
				
			||||||
                               create_room_finished, NULL,
 | 
					                               create_room_finished, NULL,
 | 
				
			||||||
                               MATRIX_API_ROOM_PRESET_PUBLIC,
 | 
					                               MATRIX_API_ROOM_PRESET_PUBLIC,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user