diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go index 31dc64c65..26f4ac305 100644 --- a/syncapi/sync/requestpool.go +++ b/syncapi/sync/requestpool.go @@ -262,6 +262,8 @@ func (rp *RequestPool) appendAccountData( } if len(res.RoomAccountData[roomID]) > 0 { events = append(events, res.RoomAccountData[roomID]...) + } else if len(res.GlobalAccountData) > 0 { + events = append(events, res.GlobalAccountData...) } } diff --git a/userapi/api/api.go b/userapi/api/api.go index e210fd8d0..1578268ac 100644 --- a/userapi/api/api.go +++ b/userapi/api/api.go @@ -44,9 +44,12 @@ type QueryAccessTokenResponse struct { // QueryAccountDataRequest is the request for QueryAccountData type QueryAccountDataRequest struct { - UserID string // required - RoomID string // optional: if specified only returns room account data - DataType string // optional: if specified only returns data matching this type + UserID string // required: the user to get account data for. + // TODO: This is a terribly confusing API shape :/ + DataType string // optional: if specified returns only a single event matching this data type. + // optional: Only used if DataType is set. If blank returns global account data matching the data type. + // If set, returns only room account data matching this data type. + RoomID string } // QueryAccountDataResponse is the response for QueryAccountData diff --git a/userapi/internal/api.go b/userapi/internal/api.go index 4cac60a79..6e737b81f 100644 --- a/userapi/internal/api.go +++ b/userapi/internal/api.go @@ -81,14 +81,20 @@ func (a *UserInternalAPI) QueryAccountData(ctx context.Context, req *api.QueryAc if domain != a.ServerName { return fmt.Errorf("cannot query account data of remote users: got %s want %s", domain, a.ServerName) } - if req.DataType != "" && req.RoomID != "" { + if req.DataType != "" { var event *gomatrixserverlib.ClientEvent event, err = a.AccountDB.GetAccountDataByType(ctx, local, req.RoomID, req.DataType) if err != nil { return err } - res.RoomAccountData = make(map[string][]gomatrixserverlib.ClientEvent) - res.RoomAccountData[req.RoomID] = []gomatrixserverlib.ClientEvent{*event} + if event != nil { + if req.RoomID != "" { + res.RoomAccountData = make(map[string][]gomatrixserverlib.ClientEvent) + res.RoomAccountData[req.RoomID] = []gomatrixserverlib.ClientEvent{*event} + } else { + res.GlobalAccountData = append(res.GlobalAccountData, *event) + } + } return nil } global, rooms, err := a.AccountDB.GetAccountData(ctx, local)