From 484b6f694c74104c641cfcb240219f287754e090 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 2 Jun 2020 11:29:47 +0100 Subject: [PATCH] Use gomatrixserverlib device structs (#1079) --- federationapi/routing/devices.go | 32 ++++++++++++++++++-------------- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/federationapi/routing/devices.go b/federationapi/routing/devices.go index 49686c761..caf5fe592 100644 --- a/federationapi/routing/devices.go +++ b/federationapi/routing/devices.go @@ -15,19 +15,13 @@ package routing import ( "net/http" - "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/storage/devices" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/userutil" + "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" ) -type userDevicesResponse struct { - UserID string `json:"user_id"` - StreamID int `json:"stream_id"` - Devices []authtypes.Device `json:"devices"` -} - // GetUserDevices for the given user id func GetUserDevices( req *http.Request, @@ -42,20 +36,30 @@ func GetUserDevices( } } + response := gomatrixserverlib.RespUserDevices{ + UserID: userID, + // TODO: we should return an incrementing stream ID each time the device + // list changes for delta changes to be recognised + StreamID: 0, + } + devs, err := deviceDB.GetDevicesByLocalpart(req.Context(), localpart) if err != nil { util.GetLogger(req.Context()).WithError(err).Error("deviceDB.GetDevicesByLocalPart failed") return jsonerror.InternalServerError() } + for _, dev := range devs { + device := gomatrixserverlib.RespUserDevice{ + DeviceID: dev.ID, + DisplayName: dev.DisplayName, + Keys: []gomatrixserverlib.RespUserDeviceKeys{}, + } + response.Devices = append(response.Devices, device) + } + return util.JSONResponse{ Code: 200, - // TODO: we should return an incrementing stream ID each time the device - // list changes for delta changes to be recognised - JSON: userDevicesResponse{ - UserID: userID, - StreamID: 0, - Devices: devs, - }, + JSON: response, } } diff --git a/go.mod b/go.mod index cc60e1a22..014ddd7d9 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4 github.com/matrix-org/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3 github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 - github.com/matrix-org/gomatrixserverlib v0.0.0-20200601162724-79e93fe989cf + github.com/matrix-org/gomatrixserverlib v0.0.0-20200602095934-0117edafc57a github.com/matrix-org/naffka v0.0.0-20200422140631-181f1ee7401f github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7 github.com/mattn/go-sqlite3 v2.0.2+incompatible diff --git a/go.sum b/go.sum index 6d9c2725d..70e980b9a 100644 --- a/go.sum +++ b/go.sum @@ -356,8 +356,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3 h1:Yb+Wlf github.com/matrix-org/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 h1:Hr3zjRsq2bhrnp3Ky1qgx/fzCtCALOoGYylh2tpS9K4= github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0= -github.com/matrix-org/gomatrixserverlib v0.0.0-20200601162724-79e93fe989cf h1:iT2dfJ6JmYNRZBQTXeCNwsZIvfkBbFggzclM8iKnbR0= -github.com/matrix-org/gomatrixserverlib v0.0.0-20200601162724-79e93fe989cf/go.mod h1:JsAzE1Ll3+gDWS9JSUHPJiiyAksvOOnGWF2nXdg4ZzU= +github.com/matrix-org/gomatrixserverlib v0.0.0-20200602095934-0117edafc57a h1:TX8oRfmzq84CFTcEuk1uvDPzV+jA9SlRSEj8MU/W3o0= +github.com/matrix-org/gomatrixserverlib v0.0.0-20200602095934-0117edafc57a/go.mod h1:JsAzE1Ll3+gDWS9JSUHPJiiyAksvOOnGWF2nXdg4ZzU= github.com/matrix-org/naffka v0.0.0-20200422140631-181f1ee7401f h1:pRz4VTiRCO4zPlEMc3ESdUOcW4PXHH4Kj+YDz1XyE+Y= github.com/matrix-org/naffka v0.0.0-20200422140631-181f1ee7401f/go.mod h1:y0oDTjZDv5SM9a2rp3bl+CU+bvTRINQsdb7YlDql5Go= github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7 h1:ntrLa/8xVzeSs8vHFHK25k0C+NV74sYMJnNSg5NoSRo=