Add client wrapper functions for Device Management endpoints

https://matrix.org/docs/spec/client_server/r0.6.1#id73

Signed-off-by: David Florness <david@florness.com>
This commit is contained in:
David Florness 2021-02-20 15:35:40 -05:00
commit 93eac986d6
No known key found for this signature in database
GPG key ID: 060576B7352B8DE3
3 changed files with 59 additions and 0 deletions

View file

@ -1097,6 +1097,36 @@ func (cli *Client) SendToDevice(eventType event.Type, req *ReqSendToDevice) (res
return
}
func (cli *Client) GetDevicesInfo() (resp *RespDevicesInfo, err error) {
urlPath := cli.BuildURL("devices")
_, err = cli.MakeRequest("GET", urlPath, nil, &resp)
return
}
func (cli *Client) GetDeviceInfo(deviceID id.DeviceID) (resp *RespDeviceInfo, err error) {
urlPath := cli.BuildURL("devices", deviceID)
_, err = cli.MakeRequest("GET", urlPath, nil, &resp)
return
}
func (cli *Client) SetDeviceInfo(deviceID id.DeviceID, req *ReqDeviceInfo) error {
urlPath := cli.BuildURL("devices", deviceID)
_, err := cli.MakeRequest("PUT", urlPath, req, nil)
return err
}
func (cli *Client) DeleteDevice(deviceID id.DeviceID, req *ReqDeleteDevice) error {
urlPath := cli.BuildURL("devices", deviceID)
_, err := cli.MakeRequest("DELETE", urlPath, req, nil)
return err
}
func (cli *Client) DeleteDevices(req *ReqDeleteDevices) error {
urlPath := cli.BuildURL("delete_devices")
_, err := cli.MakeRequest("DELETE", urlPath, req, nil)
return err
}
type UIACallback = func(*RespUserInteractive) interface{}
// UploadCrossSigningKeys uploads the given cross-signing keys to the server.

View file

@ -271,6 +271,22 @@ type ReqSendToDevice struct {
Messages map[id.UserID]map[id.DeviceID]*event.Content `json:"messages"`
}
// ReqDeviceInfo is the JSON request for https://matrix.org/docs/spec/client_server/r0.6.1#put-matrix-client-r0-devices-deviceid
type ReqDeviceInfo struct {
DisplayName string `json:"display_name,omitempty"`
}
// ReqDeleteDevice is the JSON request for https://matrix.org/docs/spec/client_server/r0.6.1#delete-matrix-client-r0-devices-deviceid
type ReqDeleteDevice struct {
Auth interface{} `json:"auth,omitempty"`
}
// ReqDeleteDevices is the JSON request for https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-delete-devices
type ReqDeleteDevices struct {
Devices []id.DeviceID `json:"devices"`
Auth interface{} `json:"auth,omitempty"`
}
type ReqPutPushRule struct {
Before string `json:"-"`
After string `json:"-"`

View file

@ -268,3 +268,16 @@ type RespKeyChanges struct {
}
type RespSendToDevice struct{}
// RespDevicesInfo is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-devices
type RespDevicesInfo struct {
Devices []RespDeviceInfo `json:"devices"`
}
// RespDeviceInfo is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.1#get-matrix-client-r0-devices-deviceid
type RespDeviceInfo struct {
DeviceID id.DeviceID `json:"device_id"`
DisplayName string `json:"display_name"`
LastSeenIP string `json:"last_seen_ip"`
LastSeenTS int64 `json:"last_seen_ts"`
}