EventSet: event2 -> target

This commit is contained in:
Alex Gleason 2024-01-03 22:15:20 -06:00
parent 96dd635661
commit b71124cc30
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 7 additions and 7 deletions

View File

@ -57,18 +57,18 @@ class EventSet<E extends Event = Event> implements Set<E> {
[Symbol.toStringTag]: string = 'EventSet';
/** Returns true if both events are replaceable, belong to the same pubkey (and `d` tag, for parameterized events), and the first event is newer than the second one. */
static eventReplaces(event: Event, event2: Event): boolean {
/** Returns true if both events are replaceable, belong to the same kind and pubkey (and `d` tag, for parameterized events), and the first event is newer than the second one. */
static eventReplaces(event: Event, target: Event): boolean {
if (isReplaceableKind(event.kind)) {
return event.kind === event2.kind && event.pubkey === event2.pubkey && event.created_at > event2.created_at;
return event.kind === target.kind && event.pubkey === target.pubkey && event.created_at > target.created_at;
} else if (isParameterizedReplaceableKind(event.kind)) {
const d = event.tags.find(([name]) => name === 'd')?.[1] || '';
const d2 = event2.tags.find(([name]) => name === 'd')?.[1] || '';
const d2 = target.tags.find(([name]) => name === 'd')?.[1] || '';
return event.kind === event2.kind &&
event.pubkey === event2.pubkey &&
return event.kind === target.kind &&
event.pubkey === target.pubkey &&
d === d2 &&
event.created_at > event2.created_at;
event.created_at > target.created_at;
}
return false;
}