From 91b28d2dc17324ea8855925d98780cc9328ee9ed Mon Sep 17 00:00:00 2001 From: nxshock Date: Mon, 5 Aug 2019 20:06:46 +0500 Subject: [PATCH] Make coomon.Filter synonym of filter request --- internal/backend.go | 6 +++--- internal/backends/memory/backend.go | 4 ++-- internal/backends/memory/user.go | 10 +++++----- internal/handlers.go | 2 +- internal/models/common/filter.go | 5 +++++ 5 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 internal/models/common/filter.go diff --git a/internal/backend.go b/internal/backend.go index ab1045f..3861e7f 100644 --- a/internal/backend.go +++ b/internal/backend.go @@ -2,9 +2,9 @@ package internal import ( "github.com/signaller-matrix/signaller/internal/models" + "github.com/signaller-matrix/signaller/internal/models/common" "github.com/signaller-matrix/signaller/internal/models/createroom" "github.com/signaller-matrix/signaller/internal/models/devices" - "github.com/signaller-matrix/signaller/internal/models/filter" "github.com/signaller-matrix/signaller/internal/models/rooms" "github.com/signaller-matrix/signaller/internal/models/sync" ) @@ -51,6 +51,6 @@ type User interface { LogoutAll() JoinRoom(Room) models.ApiError Invite(Room, User) models.ApiError - AddFilter(filterID string, filterReq filter.Request) - GetFilterByID(filterID string) *filter.Request + AddFilter(filterID string, filter common.Filter) + GetFilterByID(filterID string) *common.Filter } diff --git a/internal/backends/memory/backend.go b/internal/backends/memory/backend.go index 1bf5b1d..fdc0600 100644 --- a/internal/backends/memory/backend.go +++ b/internal/backends/memory/backend.go @@ -9,8 +9,8 @@ import ( "github.com/signaller-matrix/signaller/internal" "github.com/signaller-matrix/signaller/internal/models" + "github.com/signaller-matrix/signaller/internal/models/common" "github.com/signaller-matrix/signaller/internal/models/createroom" - "github.com/signaller-matrix/signaller/internal/models/filter" mSync "github.com/signaller-matrix/signaller/internal/models/sync" ) @@ -54,7 +54,7 @@ func (backend *Backend) Register(username, password, device string) (user intern password: password, Tokens: make(map[string]Token), backend: backend, - filters: make(map[string]filter.Request)} + filters: make(map[string]common.Filter)} backend.data[username] = user diff --git a/internal/backends/memory/user.go b/internal/backends/memory/user.go index 5ceb76c..a7ef3a5 100644 --- a/internal/backends/memory/user.go +++ b/internal/backends/memory/user.go @@ -6,9 +6,9 @@ import ( "github.com/signaller-matrix/signaller/internal" "github.com/signaller-matrix/signaller/internal/models" + "github.com/signaller-matrix/signaller/internal/models/common" "github.com/signaller-matrix/signaller/internal/models/createroom" "github.com/signaller-matrix/signaller/internal/models/devices" - "github.com/signaller-matrix/signaller/internal/models/filter" "github.com/signaller-matrix/signaller/internal/models/rooms" ) @@ -16,7 +16,7 @@ type User struct { name string password string Tokens map[string]Token - filters map[string]filter.Request + filters map[string]common.Filter backend *Backend @@ -278,14 +278,14 @@ func (user *User) JoinRoom(room internal.Room) models.ApiError { return nil } -func (user *User) AddFilter(filterID string, filterReq filter.Request) { +func (user *User) AddFilter(filterID string, filter common.Filter) { user.mutex.Lock() defer user.mutex.Unlock() - user.filters[filterID] = filterReq + user.filters[filterID] = filter } -func (user *User) GetFilterByID(filterID string) *filter.Request { +func (user *User) GetFilterByID(filterID string) *common.Filter { user.mutex.RLock() defer user.mutex.RUnlock() diff --git a/internal/handlers.go b/internal/handlers.go index 7f297d7..ef0f12c 100644 --- a/internal/handlers.go +++ b/internal/handlers.go @@ -351,7 +351,7 @@ func AddFilterHandler(w http.ResponseWriter, r *http.Request) { } filterID := RandomString(12) - user.AddFilter(filterID, request) + user.AddFilter(filterID, common.Filter(request)) response := filter.Response{FilterID: filterID} diff --git a/internal/models/common/filter.go b/internal/models/common/filter.go new file mode 100644 index 0000000..4501ec0 --- /dev/null +++ b/internal/models/common/filter.go @@ -0,0 +1,5 @@ +package common + +import "github.com/signaller-matrix/signaller/internal/models/filter" + +type Filter filter.Request