Fix tests

This commit is contained in:
Kegan Dougal 2020-06-16 16:31:43 +01:00
parent 8a2115f026
commit b4f158707f
3 changed files with 17 additions and 6 deletions

View file

@ -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...)
}
}

View file

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

View file

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