add support for jumping to out-of-context events (#95)

Fixes #84.

Reviewed-on: #95
This commit is contained in:
Henry Hiles 2026-09-26 13:03:16 -04:00 • committed by Henry Hiles
commit 389b65ae61
16 changed files with 463 additions and 132 deletions

View file

@ -0,0 +1,8 @@
import "package:freezed_annotation/freezed_annotation.dart";
enum Direction {
@JsonValue("f")
forward,
@JsonValue("b")
backward,
}

View file

@ -0,0 +1,22 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/event.dart";
part "event_context.freezed.dart";
part "event_context.g.dart";
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const EventContext({
required final Event event,
required final IList<Event> before,
required final IList<Event> after,
required final String start,
required final String end,
final IList<Event> relatedEvents = const IList.empty(),
}) with _$EventContext {
Map<String, Object?> toJson() => _$EventContextToJson(this);
factory EventContext.fromJson(Map<String, Object?> json) =>
_$EventContextFromJson(json);
}

View file

@ -0,0 +1,19 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/event.dart";
part "paginate_manual.freezed.dart";
part "paginate_manual.g.dart";
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const PaginateManual({
required final IList<Event> events,
final IList<Event> relatedEvents = const IList.empty(),
required final String? nextBatch,
}) with _$PaginateManual {
Map<String, Object?> toJson() => _$PaginateManualToJson(this);
factory PaginateManual.fromJson(Map<String, Object?> json) =>
_$PaginateManualFromJson(json);
}

View file

@ -0,0 +1,17 @@
import "package:freezed_annotation/freezed_annotation.dart";
part "get_event_context.freezed.dart";
part "get_event_context.g.dart";
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const GetEventContextRequest({
required final String roomId,
required final String eventId,
final int limit = 20,
}) with _$GetEventContextRequest {
Map<String, Object?> toJson() => _$GetEventContextRequestToJson(this);
factory GetEventContextRequest.fromJson(Map<String, Object?> json) =>
_$GetEventContextRequestFromJson(json);
}

View file

@ -9,7 +9,7 @@ part "get_mentions.g.dart";
class GetMentionsRequest({
@EpochDateTimeConverter() required final DateTime maxTimestamp,
@JsonKey(name: "type") required final UnreadType unreadType,
required final int limit,
final int limit = 20,
final String? roomId,
}) with _$GetMentionsRequest {
Map<String, Object?> toJson() => _$GetMentionsRequestToJson(this);

View file

@ -0,0 +1,22 @@
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/direction.dart";
part "paginate_manual.freezed.dart";
part "paginate_manual.g.dart";
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const PaginateManualRequest({
required final String roomId,
// Root event ID of a thread to paginate
final String? threadRoot,
// Can be null for starting pagination of a thread
final String? since,
required final Direction direction,
final int limit = 20,
}) with _$PaginateManualRequest {
Map<String, Object?> toJson() => _$PaginateManualRequestToJson(this);
factory PaginateManualRequest.fromJson(Map<String, Object?> json) =>
_$PaginateManualRequestFromJson(json);
}

View file

@ -12,17 +12,26 @@ part "room.g.dart";
class const Room({
@JsonKey(name: "meta") final RoomMetadata? metadata,
/// [timeline] is an IMap of timelineRowId to eventRowId
@JsonKey(fromJson: Room.timelineTupleJsonToIMap)
final IMap<int, int?> timeline = const IMap.empty(),
/// [clientSticky] is an ISet of eventRowId
@JsonKey(includeFromJson: false, includeToJson: false)
final ISet<int> clientSticky = const ISet.empty(),
/// [events] is an IMap of eventRowId to event
@JsonKey(fromJson: Room.eventsJsonToIMap)
final IMap<int, Event> events = const IMap.empty(),
final bool reset = false,
@JsonKey(includeFromJson: false, includeToJson: false)
final bool hasFetchedState = false,
@JsonKey(includeFromJson: false, includeToJson: false)
final bool hasFetchedMembers = false,
final IMap<String, IMap<String, int>> state = const IMap.empty(),
final IMap<String, IList<ReadReceipt>> receipts = const IMap.empty(),
@ -32,9 +41,6 @@ class const Room({
// IMap<String, AccountData> accountData,
// IList<Notification> notifications,
}) with _$Room {
/// [timeline] is an IMap of timelineRowId to eventRowId
/// [events] is an IMap of eventRowId to event
/// [clientSticky] is an ISet of eventRowId
static IMap<int, int?> timelineTupleJsonToIMap(List<dynamic> json) =>
IMap.fromEntries(
json.map(

32
lib/models/room_chat.dart Normal file
View file

@ -0,0 +1,32 @@
import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:freezed_annotation/freezed_annotation.dart";
import "package:nexus/models/event.dart";
part "room_chat.freezed.dart";
part "room_chat.g.dart";
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const RoomChat({
required final IList<Event> timeline,
required final bool hasMoreForward,
required final bool hasMoreBackward,
final HistoricalData? historicalData,
}) with _$RoomChat {
Map<String, Object?> toJson() => _$RoomChatToJson(this);
factory RoomChat.fromJson(Map<String, Object?> json) =>
_$RoomChatFromJson(json);
}
@Freezed(toJson: false, fromJson: false)
@JsonSerializable()
class const HistoricalData({
required final String start,
required final String end,
}) with _$HistoricalData {
Map<String, Object?> toJson() => _$HistoricalDataToJson(this);
factory HistoricalData.fromJson(Map<String, Object?> json) =>
_$HistoricalDataFromJson(json);
}