mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 21:32:46 +00:00
Add Queryer and Inputer and factor out more RSAPI stuff (#1382)
* Add Queryer and use embedded structs * Add Inputer and factor out more RS API stuff This neatly splits up the RS API based on the functionality it provides, whilst providing a useful place for code sharing via the `helpers` package.
This commit is contained in:
parent
f06637435b
commit
9d9e854fe0
21 changed files with 292 additions and 185 deletions
|
@ -324,3 +324,56 @@ BFSLoop:
|
|||
|
||||
return resultNIDs, err
|
||||
}
|
||||
|
||||
func QueryLatestEventsAndState(
|
||||
ctx context.Context, db storage.Database,
|
||||
request *api.QueryLatestEventsAndStateRequest,
|
||||
response *api.QueryLatestEventsAndStateResponse,
|
||||
) error {
|
||||
roomInfo, err := db.RoomInfo(ctx, request.RoomID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if roomInfo == nil || roomInfo.IsStub {
|
||||
response.RoomExists = false
|
||||
return nil
|
||||
}
|
||||
|
||||
roomState := state.NewStateResolution(db, *roomInfo)
|
||||
response.RoomExists = true
|
||||
response.RoomVersion = roomInfo.RoomVersion
|
||||
|
||||
var currentStateSnapshotNID types.StateSnapshotNID
|
||||
response.LatestEvents, currentStateSnapshotNID, response.Depth, err =
|
||||
db.LatestEventIDs(ctx, roomInfo.RoomNID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var stateEntries []types.StateEntry
|
||||
if len(request.StateToFetch) == 0 {
|
||||
// Look up all room state.
|
||||
stateEntries, err = roomState.LoadStateAtSnapshot(
|
||||
ctx, currentStateSnapshotNID,
|
||||
)
|
||||
} else {
|
||||
// Look up the current state for the requested tuples.
|
||||
stateEntries, err = roomState.LoadStateAtSnapshotForStringTuples(
|
||||
ctx, currentStateSnapshotNID, request.StateToFetch,
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
stateEvents, err := LoadStateEvents(ctx, db, stateEntries)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, event := range stateEvents {
|
||||
response.StateEvents = append(response.StateEvents, event.Headered(roomInfo.RoomVersion))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue