Use gomatrixserverlib device structs (#1079)

This commit is contained in:
Neil Alexander 2020-06-02 11:29:47 +01:00 committed by GitHub
parent 353a5d6fc2
commit 484b6f694c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 17 deletions

View file

@ -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,
}
}