use bincode::{Decode, Encode};
use rostra_core::event::{PersonaSelector, PersonaTag, PersonasTagsSelector};
use rostra_core::{ShortEventId, Timestamp};
#[derive(Debug, Encode, Decode, Clone)]
pub struct IdsFolloweesRecord {
pub latest_ts: Timestamp,
pub latest_event_id: ShortEventId,
pub first_ts: Timestamp,
selector: Option<PersonaSelector>,
tags_selector: Option<PersonasTagsSelector>,
}
impl IdsFolloweesRecord {
pub fn new(
latest_ts: Timestamp,
latest_event_id: ShortEventId,
first_ts: Timestamp,
selector: Option<PersonaSelector>,
tags_selector: Option<PersonasTagsSelector>,
) -> Self {
Self {
latest_ts,
latest_event_id,
first_ts,
selector,
tags_selector,
}
}
pub fn effective_tags_selector(&self) -> PersonasTagsSelector {
if let Some(ref ts) = self.tags_selector {
return ts.clone();
}
if let Some(ref s) = self.selector {
return match s {
PersonaSelector::Only { ids } => PersonasTagsSelector::Only {
ids: ids
.iter()
.filter_map(|id| PersonaTag::from_persona_id(*id))
.collect(),
},
PersonaSelector::Except { ids } => PersonasTagsSelector::Except {
ids: ids
.iter()
.filter_map(|id| PersonaTag::from_persona_id(*id))
.collect(),
},
};
}
PersonasTagsSelector::default()
}
pub(crate) fn with_first_ts(mut self, first_ts: Timestamp) -> Self {
self.first_ts = first_ts;
self
}
}
#[derive(Debug, Encode, Decode, Clone)]
pub struct IdsFollowersRecord {}
#[derive(Debug, Encode, Decode, Clone)]
pub struct IdsUnfollowedRecord {
pub ts: Timestamp,
pub event_id: ShortEventId,
}
#[derive(Debug, Encode, Decode, Clone)]
pub struct IdsPersonaRecord {
pub ts: u64,
pub display_name: String,
}