From 350e6cbfed0f6bac32fd4e741ec581119d04445c Mon Sep 17 00:00:00 2001 From: "Crom (Thibaut CHARLES)" Date: Fri, 12 Jan 2018 18:27:24 +0100 Subject: [PATCH] Filter retrieval from db Signed-off-by: Thibaut CHARLES cromfr@gmail.com --- .../dendrite/syncapi/sync/request.go | 20 +++++++++++++++---- .../dendrite/syncapi/sync/requestpool.go | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/syncapi/sync/request.go b/src/github.com/matrix-org/dendrite/syncapi/sync/request.go index 42494b9b5..e175c4569 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/sync/request.go +++ b/src/github.com/matrix-org/dendrite/syncapi/sync/request.go @@ -17,13 +17,14 @@ package sync import ( "context" "encoding/json" - "errors" "net/http" "strconv" "time" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" + "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" "github.com/matrix-org/gomatrix" + "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/dendrite/syncapi/types" "github.com/matrix-org/util" @@ -43,7 +44,7 @@ type syncRequest struct { filter gomatrix.Filter } -func newSyncRequest(req *http.Request, device authtypes.Device) (*syncRequest, error) { +func newSyncRequest(req *http.Request, device authtypes.Device, accountDB *accounts.Database) (*syncRequest, error) { timeout := getTimeout(req.URL.Query().Get("timeout")) fullState := req.URL.Query().Get("full_state") wantFullState := fullState != "" && fullState != "false" @@ -68,8 +69,19 @@ func newSyncRequest(req *http.Request, device authtypes.Device) (*syncRequest, e } } else { // Filter ID - // TODO retrieve filter from DB - return nil, errors.New("Filter ID retrieval not implemented") + filterID, err := strconv.Atoi(filterStr) + if err != nil { + return nil, err + } + localpart, _, err := gomatrixserverlib.SplitID('@', device.UserID) + if err != nil { + return nil, err + } + recvFilter, err := accountDB.GetFilter(req.Context(), localpart, strconv.Itoa(filterID)) //TODO GetFilter should receive filterID as an int + if err != nil { + return nil, err + } + filter = *recvFilter } } diff --git a/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go b/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go index 3b21fe9ab..2ca1e9cf7 100644 --- a/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go +++ b/src/github.com/matrix-org/dendrite/syncapi/sync/requestpool.go @@ -48,7 +48,7 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype // Extract values from request logger := util.GetLogger(req.Context()) userID := device.UserID - syncReq, err := newSyncRequest(req, *device) + syncReq, err := newSyncRequest(req, *device, rp.accountDB) if err != nil { return util.JSONResponse{ Code: 400,