getDocumentHistory method

Future<List<DocumentVersionInfo>?> getDocumentHistory({
  1. required PeerId ownerPeerId,
  2. required String path,
  3. int? maxVersions,
  4. PeerId? fromServer,
})

The kept versions of a document, newest first, with sizes but not bodies. Empty when history is off; null if the document does not exist or the request failed.

Implementation

Future<List<DocumentVersionInfo>?> getDocumentHistory({
  required PeerId ownerPeerId,
  required String path,
  int? maxVersions,
  PeerId? fromServer,
}) async {
  final response = await _documentCall(
    fromServer,
    'HISTORY',
    (stream) => DocumentHandler.getDocumentHistory(stream,
        ownerPeerId: ownerPeerId, path: path, maxVersions: maxVersions),
  );
  if (response == null || response.status != 200) return null;
  final body = response.body;
  if (body == null || body.isEmpty) return const [];
  final entries = jsonDecode(utf8.decode(body)) as List<dynamic>? ?? const [];
  return [for (final e in entries) DocumentVersionInfo.fromJson(e as Map<String, dynamic>)];
}