Show space hierarchies

Fixes #83
This commit is contained in:
Henry Hiles 2026-10-15 22:34:27 -04:00
commit b71a7f0bd6
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
10 changed files with 519 additions and 98 deletions

View file

@ -0,0 +1,19 @@
import "package:freezed_annotation/freezed_annotation.dart";
part "get_space_hierarchy.freezed.dart";
part "get_space_hierarchy.g.dart";
@Freezed(toJson: false, fromJson: false)
@JsonSerializable(includeIfNull: false)
class const GetSpaceHierarchyRequest({
required final String roomId,
final String? from,
final int limit = 50,
final int? maxDepth,
final bool? suggestedOnly,
}) with _$GetSpaceHierarchyRequest {
Map<String, Object?> toJson() => _$GetSpaceHierarchyRequestToJson(this);
factory GetSpaceHierarchyRequest.fromJson(Map<String, Object?> json) =>
_$GetSpaceHierarchyRequestFromJson(json);
}

View file

@ -0,0 +1,45 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/room_summary.dart";
part "space_hierarchy.freezed.dart";
part "space_hierarchy.g.dart";
@Freezed(toJson: false, fromJson: false)
@JsonSerializable(createToJson: false)
class const SpaceHierarchy({
final IList<SpaceHierarchyRoom> rooms = const .empty(),
final String? nextBatch,
}) with _$SpaceHierarchy {
factory SpaceHierarchy.fromJson(Map<String, Object?> json) =>
_$SpaceHierarchyFromJson(json);
}
@Freezed(toJson: false, fromJson: false)
@JsonSerializable(createToJson: false)
class const SpaceHierarchyRoom({
@JsonKey(readValue: SpaceHierarchyRoom.readEntry)
required final RoomSummary summary,
@JsonKey(name: "children_state")
final IList<SpaceHierarchyChild> children = const .empty(),
}) with _$SpaceHierarchyRoom {
static Object? readEntry(Map json, String _) => json;
factory SpaceHierarchyRoom.fromJson(Map<String, Object?> json) =>
_$SpaceHierarchyRoomFromJson(json);
}
@Freezed(toJson: false, fromJson: false)
@JsonSerializable(createToJson: false)
class const SpaceHierarchyChild({
@JsonKey(name: "state_key") required final String roomId,
@JsonKey(readValue: SpaceHierarchyChild.readContent)
final IList<String> via = const .empty(),
@JsonKey(readValue: SpaceHierarchyChild.readContent)
final bool suggested = false,
}) with _$SpaceHierarchyChild {
static Object? readContent(Map json, String key) => json["content"]?[key];
factory SpaceHierarchyChild.fromJson(Map<String, Object?> json) =>
_$SpaceHierarchyChildFromJson(json);
}