mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Events::get_highest_local_parent()
This commit is contained in:
parent
fce496ac2d
commit
77da80b261
@ -1,5 +1,6 @@
|
||||
use crate::error::Error;
|
||||
use crate::globals::GLOBALS;
|
||||
use async_recursion::async_recursion;
|
||||
use dashmap::{DashMap, DashSet};
|
||||
use nostr_types::{Event, Id};
|
||||
use tokio::task;
|
||||
@ -22,6 +23,7 @@ impl Events {
|
||||
let _ = self.events.insert(event.id, event);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn contains_key(&self, id: &Id) -> bool {
|
||||
self.events.contains_key(id)
|
||||
}
|
||||
@ -59,6 +61,23 @@ impl Events {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[async_recursion]
|
||||
pub async fn get_highest_local_parent(&self, id: &Id) -> Result<Option<Id>, Error> {
|
||||
if let Some(event) = self.get_local(*id).await? {
|
||||
if let Some((parent_id, _opturl)) = event.replies_to() {
|
||||
match self.get_highest_local_parent(&parent_id).await? {
|
||||
Some(top_id) => Ok(Some(top_id)), // went higher
|
||||
None => Ok(Some(*id)), // couldn't go higher, stay here
|
||||
}
|
||||
} else {
|
||||
Ok(Some(*id)) // is a root
|
||||
}
|
||||
} else {
|
||||
Ok(None) // not present locally
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_new(&self, id: &Id) -> bool {
|
||||
self.new_events.contains(id)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user