mirror of
https://github.com/scsibug/nostr-rs-relay.git
synced 2024-11-09 21:29:06 -05:00
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
This commit is contained in:
parent
d72e7a57b6
commit
c60519de23
15
src/db.rs
15
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
|
// 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 {
|
if e.kind == 0 {
|
||||||
let update_count = tx.execute(
|
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],
|
params![ev_id, hex::decode(&e.pubkey).ok(), e.created_at],
|
||||||
)?;
|
)?;
|
||||||
if update_count > 0 {
|
if update_count > 0 {
|
||||||
info!("hid {} older metadata events", update_count);
|
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()?;
|
tx.commit()?;
|
||||||
Ok(ins_count)
|
Ok(ins_count)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user