annotateBoundaryWithPreservedSegment function

CompactMessage annotateBoundaryWithPreservedSegment(
  1. CompactMessage boundary,
  2. String anchorUuid,
  3. List<CompactMessage>? messagesToKeep
)

Annotate a compact boundary with relink metadata for messagesToKeep.

Implementation

CompactMessage annotateBoundaryWithPreservedSegment(
  CompactMessage boundary,
  String anchorUuid,
  List<CompactMessage>? messagesToKeep,
) {
  final keep = messagesToKeep ?? [];
  if (keep.isEmpty) return boundary;

  final metadata = Map<String, dynamic>.from(boundary.compactMetadata ?? {});
  metadata['preservedSegment'] = {
    'headUuid': keep.first.uuid,
    'anchorUuid': anchorUuid,
    'tailUuid': keep.last.uuid,
  };

  return boundary.copyWith(compactMetadata: metadata);
}