fix: sometimes most recent contacts list wasn't used

`ndb::poll_for_notes` appears to give notes as they arrive. We
need to make sure we only use the most recent for contacts

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-07-17 18:16:06 -04:00
parent 030e4226f8
commit fdef74c353
3 changed files with 24 additions and 1 deletions

View File

@@ -13,6 +13,7 @@ pub enum ContactState {
Received {
contacts: HashSet<Pubkey>,
note_key: NoteKey,
timestamp: u64,
},
}
@@ -55,6 +56,7 @@ impl Contacts {
ContactState::Received {
contacts,
note_key: _,
timestamp: _,
} => {
if contacts.contains(other_pubkey) {
IsFollowing::Yes
@@ -80,6 +82,18 @@ impl Contacts {
}
};
if let ContactState::Received {
contacts: _,
note_key: _,
timestamp,
} = self.get_state()
{
if *timestamp > note.created_at() {
// the current contact list is more up to date than the one we just received. ignore it.
return;
}
}
update_state(&mut self.state, &note, *key);
}
@@ -94,11 +108,17 @@ fn update_state(state: &mut ContactState, note: &Note, key: NoteKey) {
*state = ContactState::Received {
contacts: get_contacts_owned(note),
note_key: key,
timestamp: note.created_at(),
};
}
ContactState::Received { contacts, note_key } => {
ContactState::Received {
contacts,
note_key,
timestamp,
} => {
update_contacts(contacts, note);
*note_key = key;
*timestamp = note.created_at();
}
};
}

View File

@@ -144,6 +144,7 @@ fn send_kind_3_event(ndb: &Ndb, pool: &mut RelayPool, accounts: &Accounts, actio
let ContactState::Received {
contacts: _,
note_key,
timestamp: _,
} = accounts.get_selected_account().data.contacts.get_state()
else {
return;

View File

@@ -601,6 +601,7 @@ pub fn fetch_contact_list(
ContactState::Received {
contacts: _,
note_key: _,
timestamp: _,
} => FilterState::GotRemote(filter::GotRemoteType::Contact),
};
@@ -718,6 +719,7 @@ pub fn is_timeline_ready(
let ContactState::Received {
contacts: _,
note_key,
timestamp: _,
} = accounts.get_selected_account().data.contacts.get_state()
else {
return false;