locateRoom method
- CampusMapRoom result
Fetches the owning floor if needed and resolves a search result's geometry.
Returns null if the space disappeared upstream or has no drawable outline.
Implementation
Future<CampusMapRoom?> locateRoom(CampusMapRoom result) async {
Future<CampusMapRoom?> cachedRoom() async {
final row =
await (_roomQuery()..where(_db.campusMapRooms.id.equals(result.id)))
.getSingleOrNull();
if (row == null) return null;
final room = _room(row);
return room.polygons.isEmpty ? null : room;
}
final cached = await cachedRoom();
final floor =
await (_db.select(
_db.campusMapFloors,
)..where((floor) => floor.layerName.equals(result.floor.layerName)))
.getSingleOrNull();
final stamp = floor?.fetchedAt;
if (cached == null ||
stamp == null ||
_now().difference(stamp) >= _cacheTtl) {
try {
await refreshFloor(result.floor.layerName);
} catch (_) {
if (cached == null) rethrow;
return cached;
}
}
return cachedRoom();
}