From 50f0b5fa7d581a2d26ae3a8a27944ddc0c3a47cb Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 24 May 2025 14:42:06 +0300 Subject: [PATCH] synapseadmin: add support for synchronous room delete --- synapseadmin/roomapi.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/synapseadmin/roomapi.go b/synapseadmin/roomapi.go index b2d82fb3..fa391b73 100644 --- a/synapseadmin/roomapi.go +++ b/synapseadmin/roomapi.go @@ -127,6 +127,14 @@ type RespDeleteRoom struct { DeleteID string `json:"delete_id"` } +type RespDeleteRoomStatus struct { + Status string `json:"status,omitempty"` + KickedUsers []id.UserID `json:"kicked_users,omitempty"` + FailedToKickUsers []id.UserID `json:"failed_to_kick_users,omitempty"` + LocalAliases []id.RoomAlias `json:"local_aliases,omitempty"` + NewRoomID id.RoomID `json:"new_room_id,omitempty"` +} + // DeleteRoom deletes a room from the server, optionally blocking it and/or purging all data from the database. // // This calls the async version of the endpoint, which will return immediately and delete the room in the background. @@ -139,6 +147,27 @@ func (cli *Client) DeleteRoom(ctx context.Context, roomID id.RoomID, req ReqDele return resp, err } +// DeleteRoomSync deletes a room from the server, optionally blocking it and/or purging all data from the database. +// +// This calls the synchronous version of the endpoint, which will block until the room is deleted. +// +// https://element-hq.github.io/synapse/latest/admin_api/rooms.html#version-1-old-version +func (cli *Client) DeleteRoomSync(ctx context.Context, roomID id.RoomID, req ReqDeleteRoom) (resp RespDeleteRoomStatus, err error) { + reqURL := cli.BuildAdminURL("v1", "rooms", roomID) + httpClient := &http.Client{} + _, err = cli.Client.MakeFullRequest(ctx, mautrix.FullRequest{ + Method: http.MethodDelete, + URL: reqURL, + RequestJSON: &req, + ResponseJSON: &resp, + MaxAttempts: 1, + // Use a fresh HTTP client without timeouts + Client: httpClient, + }) + httpClient.CloseIdleConnections() + return +} + type RespRoomsMembers struct { Members []id.UserID `json:"members"` Total int `json:"total"`