From c60519de2362b1aa159c7431189ed33b9e6639c1 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Thu, 30 Dec 2021 15:45:03 -0600 Subject: [PATCH] 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 --- src/db.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/db.rs b/src/db.rs index cd74df2..aca05cd 100644 --- a/src/db.rs +++ b/src/db.rs @@ -204,16 +204,27 @@ pub fn write_event(conn: &mut Connection, e: &Event) -> Result { } } // 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) }