clear method

Future<int> clear()

Deletes the conversation; returns how many messages were removed.

Implementation

Future<int> clear() async {
  final docs = await store.list(filter: _scope);
  if (docs.isEmpty) {
    length = 0;
    return 0;
  }
  final removed = await store.delete([for (final d in docs) d.id]);
  // Only after the delete succeeded: believing the conversation empty while
  // its messages survive is how a later append overwrites them.
  length = 0;
  return removed;
}