From 2b03d24358aeac14ba7c8c63e35012d6e91c1509 Mon Sep 17 00:00:00 2001 From: alexkursell Date: Thu, 3 Dec 2020 06:01:49 -0500 Subject: [PATCH] Fix /joined_members API response (#1606) * Fix /joined_members API response * Fix golint issue --- clientapi/routing/memberships.go | 11 +++++++++-- sytest-whitelist | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/clientapi/routing/memberships.go b/clientapi/routing/memberships.go index 457f81cbd..513fcefd7 100644 --- a/clientapi/routing/memberships.go +++ b/clientapi/routing/memberships.go @@ -44,6 +44,13 @@ type joinedMember struct { 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 func GetMemberships( req *http.Request, device *userapi.Device, roomID string, joinedOnly bool, @@ -72,12 +79,12 @@ func GetMemberships( var res getJoinedMembersResponse res.Joined = make(map[string]joinedMember) for _, ev := range queryRes.JoinEvents { - var content joinedMember + 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 jsonerror.InternalServerError() } - res.Joined[ev.Sender] = content + res.Joined[ev.Sender] = joinedMember(content) } return util.JSONResponse{ Code: http.StatusOK, diff --git a/sytest-whitelist b/sytest-whitelist index ffcb1785a..17027041d 100644 --- a/sytest-whitelist +++ b/sytest-whitelist @@ -503,3 +503,4 @@ Forgetting room does not show up in v2 /sync Can forget room you've been kicked from Can re-join room if re-invited /whois +/joined_members return joined members