Skip to content

Commit

Permalink
Fix /joined_members API response (#1606)
Browse files Browse the repository at this point in the history
* Fix /joined_members API response

* Fix golint issue
  • Loading branch information
alexkursell authored Dec 3, 2020
1 parent ec7a0e4 commit 2b03d24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions clientapi/routing/memberships.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions sytest-whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2b03d24

Please sign in to comment.