mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
Add more keys endpoints and to-device events
This commit is contained in:
parent
e7d41d6fb9
commit
86aa914702
5 changed files with 67 additions and 2 deletions
21
client.go
21
client.go
|
|
@ -967,6 +967,27 @@ func (cli *Client) UploadKeys(req *ReqUploadKeys) (resp *RespUploadKeys, err err
|
|||
return
|
||||
}
|
||||
|
||||
func (cli *Client) QueryKeys(req *ReqQueryKeys) (resp *RespQueryKeys, err error) {
|
||||
urlPath := cli.BuildURL("keys", "query")
|
||||
_, err = cli.MakeRequest("POST", urlPath, req, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
func (cli *Client) ClaimKeys(req *ReqClaimKeys) (resp *RespClaimKeys, err error) {
|
||||
urlPath := cli.BuildURL("keys", "claim")
|
||||
_, err = cli.MakeRequest("POST", urlPath, req, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
func (cli *Client) GetKeyChanges(from, to string) (resp *RespKeyChanges, err error) {
|
||||
urlPath := cli.BuildURLWithQuery(URLPath{"keys", "changes"}, map[string]string{
|
||||
"from": from,
|
||||
"to": to,
|
||||
})
|
||||
_, err = cli.MakeRequest("POST", urlPath, nil, &resp)
|
||||
return
|
||||
}
|
||||
|
||||
// GetPushRules returns the push notification rules for the global scope.
|
||||
func (cli *Client) GetPushRules() (*pushrules.PushRuleset, error) {
|
||||
return cli.GetScopedPushRules("global")
|
||||
|
|
|
|||
|
|
@ -102,11 +102,19 @@ type Content struct {
|
|||
// Membership key for easy access in m.room.member events
|
||||
Membership Membership `json:"membership,omitempty"`
|
||||
|
||||
Algorithm string `json:"algorithm,omitempty"`
|
||||
// Encryption stuff
|
||||
Algorithm string `json:"algorithm,omitempty"`
|
||||
// These are for m.room.encrypted
|
||||
SenderKey string `json:"sender_key,omitempty"`
|
||||
DeviceID id.DeviceID `json:"device_id,omitempty"`
|
||||
SessionID string `json:"session_id,omitempty"`
|
||||
Ciphertext string `json:"ciphertext,omitempty"`
|
||||
// These are for m.room_key and m.forwarded_room_key
|
||||
RoomID id.RoomID `json:"room_id"`
|
||||
SessionKey string `json:"session_key"`
|
||||
// These are only for m.forwarded_room_key
|
||||
SenderClaimedKey string `json:"sender_claimed_ed25519_key"`
|
||||
ForwardingKeyChain []string `json:"forwarding_curve25519_key_chain"`
|
||||
|
||||
// m.room.canonical_alias state
|
||||
Alias id.RoomAlias `json:"alias,omitempty"`
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ func (et *Type) GuessClass() EventTypeClass {
|
|||
return AccountDataEventType
|
||||
case EventRedaction.Type, EventMessage.Type, EventEncrypted.Type, EventReaction.Type, EventSticker.Type:
|
||||
return MessageEventType
|
||||
case ToDeviceNewDevice.Type:
|
||||
case ToDeviceNewDevice.Type, ToDeviceRoomKey.Type, ToDeviceRoomKeyRequest.Type, ToDeviceForwardedRoomKey.Type:
|
||||
return ToDeviceEventType
|
||||
default:
|
||||
return UnknownEventType
|
||||
|
|
@ -137,4 +137,7 @@ var (
|
|||
// Device-to-device events
|
||||
var (
|
||||
ToDeviceNewDevice = Type{"m.new_device", ToDeviceEventType}
|
||||
ToDeviceRoomKey = Type{"m.room_key", ToDeviceEventType}
|
||||
ToDeviceRoomKeyRequest = Type{"m.room_key_request", ToDeviceEventType}
|
||||
ToDeviceForwardedRoomKey = Type{"m.forwarded_room_key", ToDeviceEventType}
|
||||
)
|
||||
|
|
|
|||
18
requests.go
18
requests.go
|
|
@ -118,4 +118,22 @@ type DeviceKeys struct {
|
|||
Algorithms []string `json:"algorithms"`
|
||||
Keys map[id.KeyID]string `json:"keys"`
|
||||
Signatures map[id.UserID]map[string]string `json:"signatures"`
|
||||
Unsigned *UnsignedDeviceInfo `json:"unsigned,omitempty"`
|
||||
}
|
||||
|
||||
type UnsignedDeviceInfo struct {
|
||||
Name string `json:"device_display_name,omitempty"`
|
||||
}
|
||||
|
||||
type ReqQueryKeys struct {
|
||||
DeviceKeys map[id.UserID][]id.DeviceID `json:"device_keys"`
|
||||
|
||||
Timeout int64 `json:"timeout,omitempty"`
|
||||
Token string `json:"token,omitempty"`
|
||||
}
|
||||
|
||||
type ReqClaimKeys struct {
|
||||
OneTimeKeys map[id.UserID]map[id.DeviceID]string `json:"one_time_keys"`
|
||||
|
||||
Timeout int64 `json:"timeout,omitempty"`
|
||||
}
|
||||
|
|
|
|||
15
responses.go
15
responses.go
|
|
@ -228,3 +228,18 @@ type RespAliasResolve struct {
|
|||
|
||||
type RespUploadKeys struct {
|
||||
}
|
||||
|
||||
type RespQueryKeys struct {
|
||||
Failures map[string]map[string]interface{} `json:"failures"`
|
||||
DeviceKeys map[string]map[string]DeviceKeys `json:"device_keys"`
|
||||
}
|
||||
|
||||
type RespClaimKeys struct {
|
||||
Failures map[string]map[string]interface{} `json:"failures"`
|
||||
OneTimeKeys map[id.UserID]map[id.KeyID]string `json:"one_time_keys"`
|
||||
}
|
||||
|
||||
type RespKeyChanges struct {
|
||||
Changed []id.UserID `json:"changed"`
|
||||
Left []id.UserID `json:"left"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue