Fix /joined_members API response (#1606)

* Fix /joined_members API response

* Fix golint issue
This commit is contained in:
alexkursell 2020-12-03 06:01:49 -05:00 committed by GitHub
parent ec7a0e42ae
commit 2b03d24358
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -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,

View File

@ -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