diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2020-05-04 18:34:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-04 18:34:09 +0100 |
commit | 9b1b095b495a5cd4a6494bc309dd8c4e92d8661f (patch) | |
tree | f65566a84ed4524a6dbd4c45deac63d175c2f94b /clientapi/routing/leaveroom.go | |
parent | df80e424081ff962a137b05b977d465f1c97a481 (diff) |
Roomserver perform leave (#1004)
* First pass at PerformLeave
* Fix SQLite bulkSelectEventStateKey
* Update gomatrixserverlib
* Fix bugs
* Tidy a bit
* Satisfy King Linter
* Review comments
* Review comments
* Fix constants in SQLite event state keys table
Diffstat (limited to 'clientapi/routing/leaveroom.go')
-rw-r--r-- | clientapi/routing/leaveroom.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/clientapi/routing/leaveroom.go b/clientapi/routing/leaveroom.go new file mode 100644 index 00000000..bd769618 --- /dev/null +++ b/clientapi/routing/leaveroom.go @@ -0,0 +1,51 @@ +// Copyright 2017 Vector Creations Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package routing + +import ( + "net/http" + + "github.com/matrix-org/dendrite/clientapi/auth/authtypes" + "github.com/matrix-org/dendrite/clientapi/jsonerror" + roomserverAPI "github.com/matrix-org/dendrite/roomserver/api" + "github.com/matrix-org/util" +) + +func LeaveRoomByID( + req *http.Request, + device *authtypes.Device, + rsAPI roomserverAPI.RoomserverInternalAPI, + roomID string, +) util.JSONResponse { + // Prepare to ask the roomserver to perform the room join. + leaveReq := roomserverAPI.PerformLeaveRequest{ + RoomID: roomID, + UserID: device.UserID, + } + leaveRes := roomserverAPI.PerformLeaveResponse{} + + // Ask the roomserver to perform the leave. + if err := rsAPI.PerformLeave(req.Context(), &leaveReq, &leaveRes); err != nil { + return util.JSONResponse{ + Code: http.StatusBadRequest, + JSON: jsonerror.Unknown(err.Error()), + } + } + + return util.JSONResponse{ + Code: http.StatusOK, + JSON: struct{}{}, + } +} |