removeEvents method

  1. @override
Future<void> removeEvents({
  1. List<String>? ids,
  2. List<String>? pubKeys,
  3. List<int>? kinds,
  4. Map<String, List<String>>? tags,
  5. int? since,
  6. int? until,
})
override

Remove events from cache with flexible filtering
ids - list of event ids
pubKeys - list of authors pubKeys
kinds - list of kinds
tags - map of tags (e.g. {'p': 'pubkey1', 'e': 'eventid1'})
since - timestamp
until - timestamp
If all parameters are empty, returns early (doesn't delete everything)

Implementation

@override
Future<void> removeEvents({
  List<String>? ids,
  List<String>? pubKeys,
  List<int>? kinds,
  Map<String, List<String>>? tags,
  int? since,
  int? until,
}) async {
  // If all parameters are empty, return early (don't delete everything)
  if ((ids == null || ids.isEmpty) &&
      (pubKeys == null || pubKeys.isEmpty) &&
      (kinds == null || kinds.isEmpty) &&
      (tags == null || tags.isEmpty) &&
      since == null &&
      until == null) {
    return;
  }

  final eventsToRemove = await loadEvents(
    ids: ids,
    pubKeys: pubKeys,
    kinds: kinds,
    tags: tags,
    since: since,
    until: until,
  );
  for (final event in eventsToRemove) {
    events.remove(event.id);
  }
}