uploadSnapshot method

Future<void> uploadSnapshot(
  1. int requestedSeq
)

Uploads a snapshot to compact the room log.

requestedSeq is the log position the relay asked to compact. The upload covers at most lastKnownSeq: covering log entries this client has not imported would lose them for future joiners once the relay truncates the log.

Implementation

Future<void> uploadSnapshot(int requestedSeq) async {
  final upToSeq = requestedSeq < lastKnownSeq ? requestedSeq : lastKnownSeq;
  if (upToSeq <= 0) {
    return;
  }

  await tryCatchIgnore(() async {
    final snapshot = document.takeSnapshot(pruneHistory: false);
    await client.sendMessage(
      RelaySnapshotUploadMessage(
        documentId: document.documentId,
        snapshot: base64Encode(snapshot.toBytes()),
        upToSeq: upToSeq,
      ),
    );
  });
}