nostr-rs-relay

My dev fork of nostr-rs-relay
git clone git://jb55.com/nostr-rs-relay
Log | Files | Refs | README | LICENSE

commit c60519de2362b1aa159c7431189ed33b9e6639c1
parent d72e7a57b64891bb25d058d6ec6ec9b2be21cc32
Author: Greg Heartsfield <scsibug@imap.cc>
Date:   Thu, 30 Dec 2021 15:45:03 -0600

feat: hide older contact update events

Type 3 (NIP-02) contact lists are hidden when newer ones are submitted
for the same author.

Fixes https://todo.sr.ht/~gheartsfield/nostr-rs-relay/4

Diffstat:
Msrc/db.rs | 15+++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/db.rs b/src/db.rs @@ -204,16 +204,27 @@ pub fn write_event(conn: &mut Connection, e: &Event) -> Result<usize> { } } // if this event is for a metadata update, hide every other kind=0 - // event from the same author that was issued earlier + // event from the same author that was issued earlier than this. if e.kind == 0 { let update_count = tx.execute( - "UPDATE event SET hidden=TRUE WHERE id!=? AND kind=0 AND author=? AND created_at <= ?", + "UPDATE event SET hidden=TRUE WHERE id!=? AND kind=0 AND author=? AND created_at <= ? and hidden!=TRUE", params![ev_id, hex::decode(&e.pubkey).ok(), e.created_at], )?; if update_count > 0 { info!("hid {} older metadata events", update_count); } } + // if this event is for a contact update, hide every other kind=3 + // event from the same author that was issued earlier than this. + if e.kind == 3 { + let update_count = tx.execute( + "UPDATE event SET hidden=TRUE WHERE id!=? AND kind=3 AND author=? AND created_at <= ? and hidden!=TRUE", + params![ev_id, hex::decode(&e.pubkey).ok(), e.created_at], + )?; + if update_count > 0 { + info!("hid {} older contact events", update_count); + } + } tx.commit()?; Ok(ins_count) }