aboutsummaryrefslogtreecommitdiff
path: root/syncapi
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2024-01-25 21:35:05 +0100
committerGitHub <noreply@github.com>2024-01-25 21:35:05 +0100
commit8f68f1ff539b54f82a1fa1026e863a4076d4c9f4 (patch)
tree810a7328ba70003f2771c693926f40e5fdbbf739 /syncapi
parenta4817f31c066fe82550f285d8662befac2468030 (diff)
Move `/joined_members` back to the clientapi/roomserver (#3312)
Partly reverts #2827 by moving `/joined_members` back to the clientAPI/roomserver
Diffstat (limited to 'syncapi')
-rw-r--r--syncapi/routing/memberships.go62
-rw-r--r--syncapi/routing/routing.go14
-rw-r--r--syncapi/syncapi_test.go33
3 files changed, 2 insertions, 107 deletions
diff --git a/syncapi/routing/memberships.go b/syncapi/routing/memberships.go
index e849adf6..9cc937d8 100644
--- a/syncapi/routing/memberships.go
+++ b/syncapi/routing/memberships.go
@@ -15,7 +15,6 @@
package routing
import (
- "encoding/json"
"math"
"net/http"
@@ -33,31 +32,13 @@ type getMembershipResponse struct {
Chunk []synctypes.ClientEvent `json:"chunk"`
}
-// https://matrix.org/docs/spec/client_server/r0.6.0#get-matrix-client-r0-rooms-roomid-joined-members
-type getJoinedMembersResponse struct {
- Joined map[string]joinedMember `json:"joined"`
-}
-
-type joinedMember struct {
- DisplayName string `json:"display_name"`
- AvatarURL string `json:"avatar_url"`
-}
-
-// The database stores 'displayname' without an underscore.
-// Deserialize into this and then change to the actual API response
-type databaseJoinedMember struct {
- DisplayName string `json:"displayname"`
- AvatarURL string `json:"avatar_url"`
-}
-
// GetMemberships implements
//
// GET /rooms/{roomId}/members
-// GET /rooms/{roomId}/joined_members
func GetMemberships(
req *http.Request, device *userapi.Device, roomID string,
syncDB storage.Database, rsAPI api.SyncRoomserverAPI,
- joinedOnly bool, membership, notMembership *string, at string,
+ membership, notMembership *string, at string,
) util.JSONResponse {
userID, err := spec.NewUserID(device.UserID, true)
if err != nil {
@@ -87,13 +68,6 @@ func GetMemberships(
}
}
- if joinedOnly && !queryRes.IsInRoom {
- return util.JSONResponse{
- Code: http.StatusForbidden,
- JSON: spec.Forbidden("You aren't a member of the room and weren't previously a member of the room."),
- }
- }
-
db, err := syncDB.NewDatabaseSnapshot(req.Context())
if err != nil {
return util.JSONResponse{
@@ -139,40 +113,6 @@ func GetMemberships(
result := qryRes.Events
- if joinedOnly {
- var res getJoinedMembersResponse
- res.Joined = make(map[string]joinedMember)
- for _, ev := range result {
- var content databaseJoinedMember
- if err := json.Unmarshal(ev.Content(), &content); err != nil {
- util.GetLogger(req.Context()).WithError(err).Error("failed to unmarshal event content")
- return util.JSONResponse{
- Code: http.StatusInternalServerError,
- JSON: spec.InternalServerError{},
- }
- }
-
- userID, err := rsAPI.QueryUserIDForSender(req.Context(), ev.RoomID(), ev.SenderID())
- if err != nil || userID == nil {
- util.GetLogger(req.Context()).WithError(err).Error("rsAPI.QueryUserIDForSender failed")
- return util.JSONResponse{
- Code: http.StatusInternalServerError,
- JSON: spec.InternalServerError{},
- }
- }
- if err != nil {
- return util.JSONResponse{
- Code: http.StatusForbidden,
- JSON: spec.Forbidden("You don't have permission to kick this user, unknown senderID"),
- }
- }
- res.Joined[userID.String()] = joinedMember(content)
- }
- return util.JSONResponse{
- Code: http.StatusOK,
- JSON: res,
- }
- }
return util.JSONResponse{
Code: http.StatusOK,
JSON: getMembershipResponse{synctypes.ToClientEvents(gomatrixserverlib.ToPDUs(result), synctypes.FormatAll, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
diff --git a/syncapi/routing/routing.go b/syncapi/routing/routing.go
index a837e169..78188d1b 100644
--- a/syncapi/routing/routing.go
+++ b/syncapi/routing/routing.go
@@ -197,19 +197,7 @@ func Setup(
}
at := req.URL.Query().Get("at")
- return GetMemberships(req, device, vars["roomID"], syncDB, rsAPI, false, membership, notMembership, at)
+ return GetMemberships(req, device, vars["roomID"], syncDB, rsAPI, membership, notMembership, at)
}, httputil.WithAllowGuests()),
).Methods(http.MethodGet, http.MethodOptions)
-
- v3mux.Handle("/rooms/{roomID}/joined_members",
- httputil.MakeAuthAPI("rooms_members", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
- vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
- if err != nil {
- return util.ErrorResponse(err)
- }
- at := req.URL.Query().Get("at")
- membership := spec.Join
- return GetMemberships(req, device, vars["roomID"], syncDB, rsAPI, true, &membership, nil, at)
- }),
- ).Methods(http.MethodGet, http.MethodOptions)
}
diff --git a/syncapi/syncapi_test.go b/syncapi/syncapi_test.go
index ac526851..0a2c38ab 100644
--- a/syncapi/syncapi_test.go
+++ b/syncapi/syncapi_test.go
@@ -754,24 +754,6 @@ func TestGetMembership(t *testing.T) {
wantOK: false,
},
{
- name: "/joined_members - Bob never joined",
- request: func(t *testing.T, room *test.Room) *http.Request {
- return test.NewRequest(t, "GET", fmt.Sprintf("/_matrix/client/v3/rooms/%s/joined_members", room.ID), test.WithQueryParams(map[string]string{
- "access_token": bobDev.AccessToken,
- }))
- },
- wantOK: false,
- },
- {
- name: "/joined_members - Alice joined",
- request: func(t *testing.T, room *test.Room) *http.Request {
- return test.NewRequest(t, "GET", fmt.Sprintf("/_matrix/client/v3/rooms/%s/joined_members", room.ID), test.WithQueryParams(map[string]string{
- "access_token": aliceDev.AccessToken,
- }))
- },
- wantOK: true,
- },
- {
name: "Alice leaves before Bob joins, should not be able to see Bob",
request: func(t *testing.T, room *test.Room) *http.Request {
return test.NewRequest(t, "GET", fmt.Sprintf("/_matrix/client/v3/rooms/%s/members", room.ID), test.WithQueryParams(map[string]string{
@@ -810,21 +792,6 @@ func TestGetMembership(t *testing.T) {
wantMemberCount: 2,
},
{
- name: "/joined_members - Alice leaves, shouldn't be able to see members ",
- request: func(t *testing.T, room *test.Room) *http.Request {
- return test.NewRequest(t, "GET", fmt.Sprintf("/_matrix/client/v3/rooms/%s/joined_members", room.ID), test.WithQueryParams(map[string]string{
- "access_token": aliceDev.AccessToken,
- }))
- },
- additionalEvents: func(t *testing.T, room *test.Room) {
- room.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
- "membership": "leave",
- }, test.WithStateKey(alice.ID))
- },
- useSleep: true,
- wantOK: false,
- },
- {
name: "'at' specified, returns memberships before Bob joins",
request: func(t *testing.T, room *test.Room) *http.Request {
return test.NewRequest(t, "GET", fmt.Sprintf("/_matrix/client/v3/rooms/%s/members", room.ID), test.WithQueryParams(map[string]string{