Skip to content

Commit

Permalink
database: add support to event deletion by coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Dec 4, 2023
1 parent 3985caa commit d119dd1
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions crates/nostr-database/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,34 @@ impl DatabaseIndexes {
}
} else if event.kind == Kind::EventDeletion {
let mut deleted = self.deleted.write().await;
let ids = event.event_ids().copied();
let filter = Filter::new().ids(ids);
let pubkey_prefix: PublicKeyPrefix = PublicKeyPrefix::from(event.pubkey);

// Check `e` tags
let ids = event.event_ids().copied();
let filter: Filter = Filter::new().ids(ids);
for ev in self.internal_query(&index, filter).await {
if ev.pubkey == pubkey_prefix {
to_discard.insert(ev.event_id);
deleted.insert(ev.event_id);
}
}
// TODO: support event deletion by coordinate (`a` tag)

// Check `a` tags
for coordinate in event.coordinates() {
let coordinate_pubkey_prefix: PublicKeyPrefix =
PublicKeyPrefix::from(coordinate.pubkey);
if coordinate_pubkey_prefix == pubkey_prefix {
let filter: Filter = Filter::new()
.author(coordinate.pubkey)
.kind(coordinate.kind)
.identifier(coordinate.identifier)
.limit(1);
for ev in self.internal_query(&index, filter).await {
to_discard.insert(ev.event_id);
deleted.insert(ev.event_id);
}
}
}
}

// Remove events
Expand Down

0 comments on commit d119dd1

Please sign in to comment.