From 29e5e7942bef879b5f1c0918cc1003458e0613c4 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 7 Aug 2017 15:10:03 +0100 Subject: [PATCH] Create placeholder handler for room directory updates --- .../dendrite/clientapi/routing/routing.go | 14 ++++++ .../clientapi/writers/room_directory.go | 48 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/github.com/matrix-org/dendrite/clientapi/writers/room_directory.go diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go index 68a9de075..0cd9e8595 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go @@ -133,6 +133,20 @@ func Setup( }), ).Methods("DELETE") + r0mux.Handle("/directory/list/room/{roomID}", + common.MakeAPI("directory_list", func(req *http.Request) util.JSONResponse { + vars := mux.Vars(req) + return writers.GetVisibility(req, vars["roomID"]) + }), + ).Methods("GET") + + r0mux.Handle("/directory/list/room/{roomID}", + common.MakeAuthAPI("directory_list", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + vars := mux.Vars(req) + return writers.SetVisibility(req, *device, vars["roomID"], cfg) + }), + ).Methods("PUT", "OPTIONS") + r0mux.Handle("/logout", common.MakeAuthAPI("logout", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse { return readers.Logout(req, deviceDB, device) diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/room_directory.go b/src/github.com/matrix-org/dendrite/clientapi/writers/room_directory.go new file mode 100644 index 000000000..a4c175719 --- /dev/null +++ b/src/github.com/matrix-org/dendrite/clientapi/writers/room_directory.go @@ -0,0 +1,48 @@ +// 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 writers + +import ( + "net/http" + + "github.com/matrix-org/dendrite/clientapi/auth/authtypes" + "github.com/matrix-org/dendrite/common/config" + "github.com/matrix-org/util" +) + +type roomDirectoryVisibility struct { + Visibility string `json:"visibility"` +} + +// GetVisibility implements GET /directory/list/room/{roomID} +func GetVisibility( + req *http.Request, roomID string, +) util.JSONResponse { + return util.JSONResponse{ + Code: 200, + JSON: roomDirectoryVisibility{"public"}, + } +} + +// SetVisibility implements PUT /directory/list/room/{roomID} +func SetVisibility( + req *http.Request, device authtypes.Device, roomID string, + cfg config.Dendrite, +) util.JSONResponse { + return util.JSONResponse{ + Code: 200, + JSON: struct{}{}, + } +}