From e6268f307c644130fd5f532d544fedb656ba799d Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 6 Jan 2017 14:39:25 +0000 Subject: [PATCH] Add AS membership list APIs --- client.go | 20 ++++++++++++++++++++ responses.go | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/client.go b/client.go index dee17b2..87a1f73 100644 --- a/client.go +++ b/client.go @@ -539,6 +539,26 @@ func (cli *Client) UploadToContentRepo(content io.Reader, contentType string, co return &m, nil } +// JoinedMembers returns a map of joined room members. See TODO-SPEC. https://github.com/matrix-org/synapse/pull/1680 +// +// In general, usage of this API is discouraged in favour of /sync, as calling this API can race with incoming membership changes. +// This API is primarily designed for application services which may want to efficiently look up joined members in a room. +func (cli *Client) JoinedMembers(roomID string) (resp *RespJoinedMembers, err error) { + u := cli.BuildURL("rooms", roomID, "joined_members") + _, err = cli.MakeRequest("GET", u, nil, &resp) + return +} + +// JoinedRooms returns a list of rooms which the client is joined to. See TODO-SPEC. https://github.com/matrix-org/synapse/pull/1680 +// +// In general, usage of this API is discouraged in favour of /sync, as calling this API can race with incoming membership changes. +// This API is primarily designed for application services which may want to efficiently look up joined rooms. +func (cli *Client) JoinedRooms() (resp *RespJoinedRooms, err error) { + u := cli.BuildURL("joined_rooms") + _, err = cli.MakeRequest("GET", u, nil, &resp) + return +} + func txnID() string { return "go" + strconv.FormatInt(time.Now().UnixNano(), 10) } diff --git a/responses.go b/responses.go index cf10168..de7a8ae 100644 --- a/responses.go +++ b/responses.go @@ -45,6 +45,19 @@ type RespBanUser struct{} // RespUnbanUser is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-rooms-roomid-unban type RespUnbanUser struct{} +// RespJoinedRooms is the JSON response for TODO-SPEC https://github.com/matrix-org/synapse/pull/1680 +type RespJoinedRooms struct { + JoinedRooms []string `json:"joined_rooms"` +} + +// RespJoinedMembers is the JSON response for TODO-SPEC https://github.com/matrix-org/synapse/pull/1680 +type RespJoinedMembers struct { + Joined map[string]struct { + DisplayName *string `json:"display_name"` + AvatarURL *string `json:"avatar_url"` + } `json:"joined"` +} + // RespSendEvent is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid type RespSendEvent struct { EventID string `json:"event_id"`