aboutsummaryrefslogtreecommitdiff
path: root/roomserver/query/query.go
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-03-17 18:00:10 +0000
committerGitHub <noreply@github.com>2020-03-17 18:00:10 +0000
commitc2bd0b97b34c9040325bf31c5c4a2a06579239d9 (patch)
tree45af6cf66af901b1a285fb8be6f7db278bea4dcd /roomserver/query/query.go
parent1467cc10d8bd40b9ea85bc4f0aa4644b16cb37bb (diff)
Get room versions from database (#918)
* Retrieve room version where known in roomserver * Get room versions in alias code * Increase gocyclothreshold to 13, since we hit that number a lot * Remove gocyclo nolint from StoreEvent * Update interface to get room version from room ID instead of NID * Remove new API * Fixed this query for SQLite but not for Postgres
Diffstat (limited to 'roomserver/query/query.go')
-rw-r--r--roomserver/query/query.go35
1 files changed, 20 insertions, 15 deletions
diff --git a/roomserver/query/query.go b/roomserver/query/query.go
index 2de8e0d0..3ab12d60 100644
--- a/roomserver/query/query.go
+++ b/roomserver/query/query.go
@@ -91,7 +91,7 @@ type RoomserverQueryAPIDatabase interface {
) (map[types.EventStateKeyNID]string, error)
// Look up the room version for a given room.
GetRoomVersionForRoom(
- ctx context.Context, roomNID types.RoomNID,
+ ctx context.Context, roomID string,
) (gomatrixserverlib.RoomVersion, error)
}
@@ -121,7 +121,7 @@ func (r *RoomserverQueryAPI) QueryLatestEventsAndState(
}
response.RoomExists = true
- roomVersion, err := r.DB.GetRoomVersionForRoom(ctx, roomNID)
+ roomVersion, err := r.DB.GetRoomVersionForRoom(ctx, request.RoomID)
if err != nil {
return err
}
@@ -174,7 +174,7 @@ func (r *RoomserverQueryAPI) QueryStateAfterEvents(
}
response.RoomExists = true
- roomVersion, err := r.DB.GetRoomVersionForRoom(ctx, roomNID)
+ roomVersion, err := r.DB.GetRoomVersionForRoom(ctx, request.RoomID)
if err != nil {
return err
}
@@ -234,8 +234,10 @@ func (r *RoomserverQueryAPI) QueryEventsByID(
}
for _, event := range events {
- // TODO: Room version here
- roomVersion := gomatrixserverlib.RoomVersionV1
+ roomVersion, verr := r.DB.GetRoomVersionForRoom(ctx, event.RoomID())
+ if verr != nil {
+ return verr
+ }
response.Events = append(response.Events, event.Headered(roomVersion))
}
@@ -516,8 +518,10 @@ func (r *RoomserverQueryAPI) QueryMissingEvents(
response.Events = make([]gomatrixserverlib.HeaderedEvent, 0, len(loadedEvents)-len(eventsToFilter))
for _, event := range loadedEvents {
if !eventsToFilter[event.EventID()] {
- // TODO: Room version here
- roomVersion := gomatrixserverlib.RoomVersionV1
+ roomVersion, verr := r.DB.GetRoomVersionForRoom(ctx, event.RoomID())
+ if verr != nil {
+ return verr
+ }
response.Events = append(response.Events, event.Headered(roomVersion))
}
@@ -562,8 +566,10 @@ func (r *RoomserverQueryAPI) QueryBackfill(
}
for _, event := range loadedEvents {
- // TODO: Room version here
- roomVersion := gomatrixserverlib.RoomVersionV1
+ roomVersion, verr := r.DB.GetRoomVersionForRoom(ctx, event.RoomID())
+ if verr != nil {
+ return verr
+ }
response.Events = append(response.Events, event.Headered(roomVersion))
}
@@ -647,6 +653,11 @@ func (r *RoomserverQueryAPI) QueryStateAndAuthChain(
}
response.RoomExists = true
+ roomVersion, err := r.DB.GetRoomVersionForRoom(ctx, request.RoomID)
+ if err != nil {
+ return err
+ }
+
stateEvents, err := r.loadStateAtEventIDs(ctx, request.PrevEventIDs)
if err != nil {
return err
@@ -667,16 +678,10 @@ func (r *RoomserverQueryAPI) QueryStateAndAuthChain(
}
for _, event := range stateEvents {
- // TODO: Room version here
- roomVersion := gomatrixserverlib.RoomVersionV1
-
response.StateEvents = append(response.StateEvents, event.Headered(roomVersion))
}
for _, event := range authEvents {
- // TODO: Room version here
- roomVersion := gomatrixserverlib.RoomVersionV1
-
response.AuthChainEvents = append(response.AuthChainEvents, event.Headered(roomVersion))
}