client: add wrapper for /knock endpoint (#359)
Some checks are pending
Go / Lint (latest) (push) Waiting to run
Go / Build (old, libolm) (push) Waiting to run
Go / Build (latest, libolm) (push) Waiting to run
Go / Build (old, goolm) (push) Waiting to run
Go / Build (latest, goolm) (push) Waiting to run

This commit is contained in:
nexy7574 2025-03-09 17:16:31 +00:00 committed by GitHub
commit d83b63aeaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 0 deletions

View file

@ -974,6 +974,28 @@ func (cli *Client) JoinRoom(ctx context.Context, roomIDorAlias string, req *ReqJ
return
}
// KnockRoom requests to join a room ID or alias. See https://spec.matrix.org/v1.13/client-server-api/#post_matrixclientv3knockroomidoralias
//
// The last parameter contains optional extra fields and can be left nil.
func (cli *Client) KnockRoom(ctx context.Context, roomIDorAlias string, req *ReqKnockRoom) (resp *RespKnockRoom, err error) {
if req == nil {
req = &ReqKnockRoom{}
}
urlPath := cli.BuildURLWithFullQuery(ClientURLPath{"v3", "knock", roomIDorAlias}, func(q url.Values) {
if len(req.Via) > 0 {
q["via"] = req.Via
}
})
_, err = cli.MakeRequest(ctx, http.MethodPost, urlPath, req, &resp)
if err == nil && cli.StateStore != nil {
err = cli.StateStore.SetMembership(ctx, resp.RoomID, cli.UserID, event.MembershipKnock)
if err != nil {
err = fmt.Errorf("failed to update state store: %w", err)
}
}
return
}
// JoinRoomByID joins the client to a room ID. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidjoin
//
// Unlike JoinRoom, this method can only be used to join rooms that the server already knows about.

View file

@ -156,6 +156,11 @@ type ReqJoinRoom struct {
ThirdPartySigned any `json:"third_party_signed,omitempty"`
}
type ReqKnockRoom struct {
Via []string `json:"-"`
Reason string `json:"reason,omitempty"`
}
type ReqMutualRooms struct {
From string `json:"-"`
}

View file

@ -33,6 +33,11 @@ type RespJoinRoom struct {
RoomID id.RoomID `json:"room_id"`
}
// RespKnockRoom is the JSON response for https://spec.matrix.org/v1.13/client-server-api/#post_matrixclientv3knockroomidoralias
type RespKnockRoom struct {
RoomID id.RoomID `json:"room_id"`
}
// RespLeaveRoom is the JSON response for https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3roomsroomidleave
type RespLeaveRoom struct{}