From 41b8c14d6e1a10423fc08e0a668ffe909ac3107f Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Thu, 29 Apr 2021 13:11:47 -0400 Subject: [PATCH] Remove state_store module --- src/state_store.rs | 76 ---------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 src/state_store.rs diff --git a/src/state_store.rs b/src/state_store.rs deleted file mode 100644 index b8a1ea88..00000000 --- a/src/state_store.rs +++ /dev/null @@ -1,76 +0,0 @@ -use std::{collections::BTreeSet, sync::Arc}; - -use ruma::{EventId, RoomId}; - -use crate::{Event, Result}; - -/// TODO: this is only used in testing on this branch now REMOVE -pub trait StateStore { - /// Return a single event based on the EventId. - fn get_event(&self, room_id: &RoomId, event_id: &EventId) -> Result>; - - /// Returns the events that correspond to the `event_ids` sorted in the same order. - fn get_events(&self, room_id: &RoomId, event_ids: &[EventId]) -> Result>> { - let mut events = vec![]; - for id in event_ids { - events.push(self.get_event(room_id, id)?); - } - Ok(events) - } - - /// Returns a Vec of the related auth events to the given `event`. - fn auth_event_ids(&self, room_id: &RoomId, event_ids: &[EventId]) -> Result> { - let mut result = vec![]; - let mut stack = event_ids.to_vec(); - - // DFS for auth event chain - while !stack.is_empty() { - let ev_id = stack.pop().unwrap(); - if result.contains(&ev_id) { - continue; - } - - result.push(ev_id.clone()); - - let event = self.get_event(room_id, &ev_id)?; - - stack.extend(event.auth_events().clone()); - } - - Ok(result) - } - - /// Returns a Vec representing the difference in auth chains of the given `events`. - fn auth_chain_diff( - &self, - room_id: &RoomId, - event_ids: Vec>, - ) -> Result> { - let mut chains = vec![]; - for ids in event_ids { - // TODO state store `auth_event_ids` returns self in the event ids list - // when an event returns `auth_event_ids` self is not contained - let chain = self - .auth_event_ids(room_id, &ids)? - .into_iter() - .collect::>(); - chains.push(chain); - } - - if let Some(chain) = chains.first() { - let rest = chains.iter().skip(1).flatten().cloned().collect(); - let common = chain.intersection(&rest).collect::>(); - - Ok(chains - .iter() - .flatten() - .filter(|id| !common.contains(&id)) - .cloned() - .collect::>() - .into_iter() - .collect()) - } else { - Ok(vec![]) - } - } -}