MCPcopy Create free account
hub / github.com/daodst/chat / QueryLatestEventsAndState

Function QueryLatestEventsAndState

roomserver/internal/helpers/helpers.go:403–456  ·  view source on GitHub ↗
(
	ctx context.Context, db storage.Database,
	request *api.QueryLatestEventsAndStateRequest,
	response *api.QueryLatestEventsAndStateResponse,
)

Source from the content-addressed store, hash-verified

401}
402
403func QueryLatestEventsAndState(
404 ctx context.Context, db storage.Database,
405 request *api.QueryLatestEventsAndStateRequest,
406 response *api.QueryLatestEventsAndStateResponse,
407) error {
408 //util.GetLogger(ctx).WithField("request.RoomID", request.RoomID).Info("QueryLatestEventsAndState 111111")
409 roomInfo, err := db.RoomInfo(ctx, request.RoomID)
410 if err != nil {
411 return err
412 }
413 //util.GetLogger(ctx).WithField("roomInfo", roomInfo).Info("QueryLatestEventsAndState 222222")
414 if roomInfo == nil || roomInfo.IsStub() {
415 response.RoomExists = false
416 return nil
417 }
418 //util.GetLogger(ctx).Info("QueryLatestEventsAndState 333333")
419 roomState := state.NewStateResolution(db, roomInfo)
420 response.RoomExists = true
421 response.RoomVersion = roomInfo.RoomVersion
422 //util.GetLogger(ctx).Info("QueryLatestEventsAndState 444444")
423 var currentStateSnapshotNID types.StateSnapshotNID
424 response.LatestEvents, currentStateSnapshotNID, response.Depth, err =
425 db.LatestEventIDs(ctx, roomInfo.RoomNID)
426 if err != nil {
427 return err
428 }
429 //util.GetLogger(ctx).Info("QueryLatestEventsAndState 555555")
430 var stateEntries []types.StateEntry
431 if len(request.StateToFetch) == 0 {
432 // Look up all room state.
433 stateEntries, err = roomState.LoadStateAtSnapshot(
434 ctx, currentStateSnapshotNID,
435 )
436 } else {
437 // Look up the current state for the requested tuples.
438 stateEntries, err = roomState.LoadStateAtSnapshotForStringTuples(
439 ctx, currentStateSnapshotNID, request.StateToFetch,
440 )
441 }
442 if err != nil {
443 return err
444 }
445 //util.GetLogger(ctx).Info("QueryLatestEventsAndState 666666")
446 stateEvents, err := LoadStateEvents(ctx, db, stateEntries)
447 if err != nil {
448 return err
449 }
450 //util.GetLogger(ctx).Info("QueryLatestEventsAndState 777777")
451 for _, event := range stateEvents {
452 response.StateEvents = append(response.StateEvents, event.Headered(roomInfo.RoomVersion))
453 }
454
455 return nil
456}

Callers

nothing calls this directly

Calls 6

LoadStateAtSnapshotMethod · 0.95
LoadStateEventsFunction · 0.85
IsStubMethod · 0.80
RoomInfoMethod · 0.65
LatestEventIDsMethod · 0.65

Tested by

no test coverage detected