mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Add synapse admin wrappers for getting device list and user info
This commit is contained in:
parent
e06eb7269c
commit
5bb88ab698
2 changed files with 58 additions and 1 deletions
|
|
@ -16,3 +16,7 @@ import (
|
|||
type Client struct {
|
||||
*mautrix.Client
|
||||
}
|
||||
|
||||
func (cli *Client) BuildAdminURL(path ...any) string {
|
||||
return cli.BuildURL(mautrix.SynapseAdminURLPath(path))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/id"
|
||||
"maunium.net/go/mautrix/util/jsontime"
|
||||
)
|
||||
|
||||
// ReqResetPassword is the request content for Client.ResetPassword.
|
||||
|
|
@ -30,7 +31,7 @@ type ReqResetPassword struct {
|
|||
//
|
||||
// https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#reset-password
|
||||
func (cli *Client) ResetPassword(ctx context.Context, req ReqResetPassword) error {
|
||||
reqURL := cli.BuildURL(mautrix.SynapseAdminURLPath{"v1", "reset_password", req.UserID})
|
||||
reqURL := cli.BuildAdminURL("v1", "reset_password", req.UserID)
|
||||
_, err := cli.MakeFullRequest(mautrix.FullRequest{
|
||||
Method: http.MethodPost,
|
||||
URL: reqURL,
|
||||
|
|
@ -59,3 +60,55 @@ func (cli *Client) UsernameAvailable(ctx context.Context, username string) (resp
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
type DeviceInfo struct {
|
||||
mautrix.RespDeviceInfo
|
||||
LastSeenUserAgent string `json:"last_seen_user_agent"`
|
||||
}
|
||||
|
||||
type RespListDevices struct {
|
||||
Devices []DeviceInfo `json:"devices"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
|
||||
// ListDevices gets information about all the devices of a specific user.
|
||||
//
|
||||
// https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#list-all-devices
|
||||
func (cli *Client) ListDevices(ctx context.Context, userID id.UserID) (resp *RespListDevices, err error) {
|
||||
_, err = cli.MakeFullRequest(mautrix.FullRequest{
|
||||
Method: http.MethodGet,
|
||||
URL: cli.BuildAdminURL("v2", "users", userID, "devices"),
|
||||
ResponseJSON: &resp,
|
||||
Context: ctx,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
type RespUserInfo struct {
|
||||
UserID id.UserID `json:"name"`
|
||||
DisplayName string `json:"displayname"`
|
||||
AvatarURL id.ContentURIString `json:"avatar_url"`
|
||||
Guest int `json:"is_guest"`
|
||||
Admin bool `json:"admin"`
|
||||
Deactivated bool `json:"deactivated"`
|
||||
Erased bool `json:"erased"`
|
||||
ShadowBanned bool `json:"shadow_banned"`
|
||||
CreationTS jsontime.Unix `json:"creation_ts"`
|
||||
AppserviceID string `json:"appservice_id"`
|
||||
UserType string `json:"user_type"`
|
||||
|
||||
// TODO: consent fields, threepids, external IDs
|
||||
}
|
||||
|
||||
// GetUserInfo gets information about a specific user account.
|
||||
//
|
||||
// https://matrix-org.github.io/synapse/latest/admin_api/user_admin_api.html#query-user-account
|
||||
func (cli *Client) GetUserInfo(ctx context.Context, userID id.UserID) (resp *RespUserInfo, err error) {
|
||||
_, err = cli.MakeFullRequest(mautrix.FullRequest{
|
||||
Method: http.MethodGet,
|
||||
URL: cli.BuildAdminURL("v2", "users", userID),
|
||||
ResponseJSON: &resp,
|
||||
Context: ctx,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue