From 6dba957e5fc583f330e3250725709cec8c837b3f Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Mon, 5 Aug 2019 14:12:48 +0400 Subject: [PATCH] fix: Fix bug with filter adding --- internal/backends/memory/backend.go | 5 ++++- internal/handlers.go | 2 +- internal/server.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/backends/memory/backend.go b/internal/backends/memory/backend.go index 913d41e..b480d95 100644 --- a/internal/backends/memory/backend.go +++ b/internal/backends/memory/backend.go @@ -7,6 +7,8 @@ import ( "strings" "sync" + "github.com/signaller-matrix/signaller/internal/models/common" + "github.com/signaller-matrix/signaller/internal" "github.com/signaller-matrix/signaller/internal/models" "github.com/signaller-matrix/signaller/internal/models/createroom" @@ -52,7 +54,8 @@ func (backend *Backend) Register(username, password, device string) (user intern name: username, password: password, Tokens: make(map[string]Token), - backend: backend} + backend: backend, + filters: make(map[string]common.Filter)} backend.data[username] = user diff --git a/internal/handlers.go b/internal/handlers.go index a79dc8a..1075153 100644 --- a/internal/handlers.go +++ b/internal/handlers.go @@ -324,7 +324,7 @@ func CapabilitiesHandler(w http.ResponseWriter, r *http.Request) { } func AddFilterHandler(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodGet { + if r.Method != http.MethodPost { errorResponse(w, models.M_UNKNOWN, http.StatusBadRequest, "wrong method: "+r.Method) return } diff --git a/internal/server.go b/internal/server.go index 4f04122..3d966d9 100644 --- a/internal/server.go +++ b/internal/server.go @@ -40,7 +40,7 @@ func NewServer(port int) (*Server, error) { router.HandleFunc("/_matrix/client/r0/rooms/{roomId}/leave", leaveRoomHandler) router.HandleFunc("/_matrix/client/r0/register/available", registerAvailableHandler) router.HandleFunc("/_matrix/client/r0/publicRooms", publicRoomsHandler) - router.HandleFunc("/_matrix/client/r0/user/{userId}/filter/{filterId}", GetFilterHandler).Methods("GET") + router.HandleFunc("/_matrix/client/r0/user/{userId}/filter/{filterID}", GetFilterHandler).Methods("GET") router.HandleFunc("/_matrix/client/r0/user/{userId}/filter", AddFilterHandler).Methods("POST") router.HandleFunc("/", RootHandler)