mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-08-02 05:08:31 +00:00
refactor various Arc<EventId> to OwnedEventId
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
5a335933b8
commit
6458f4b195
29 changed files with 142 additions and 152 deletions
|
@ -1,15 +1,14 @@
|
|||
use std::{
|
||||
collections::{hash_map, HashMap},
|
||||
sync::Arc,
|
||||
};
|
||||
use std::collections::{hash_map, HashMap};
|
||||
|
||||
use conduwuit::{debug, implement, warn, Err, Error, PduEvent, Result};
|
||||
use futures::FutureExt;
|
||||
use ruma::{
|
||||
api::federation::event::get_room_state_ids, events::StateEventType, EventId, RoomId,
|
||||
RoomVersionId, ServerName,
|
||||
api::federation::event::get_room_state_ids, events::StateEventType, EventId, OwnedEventId,
|
||||
RoomId, RoomVersionId, ServerName,
|
||||
};
|
||||
|
||||
use crate::rooms::short::ShortStateKey;
|
||||
|
||||
/// Call /state_ids to find out what the state at this pdu is. We trust the
|
||||
/// server's response to some extend (sic), but we still do a lot of checks
|
||||
/// on the events
|
||||
|
@ -22,31 +21,25 @@ pub(super) async fn fetch_state(
|
|||
room_id: &RoomId,
|
||||
room_version_id: &RoomVersionId,
|
||||
event_id: &EventId,
|
||||
) -> Result<Option<HashMap<u64, Arc<EventId>>>> {
|
||||
) -> Result<Option<HashMap<u64, OwnedEventId>>> {
|
||||
debug!("Fetching state ids");
|
||||
let res = self
|
||||
.services
|
||||
.sending
|
||||
.send_federation_request(origin, get_room_state_ids::v1::Request {
|
||||
room_id: room_id.to_owned(),
|
||||
event_id: (*event_id).to_owned(),
|
||||
event_id: event_id.to_owned(),
|
||||
})
|
||||
.await
|
||||
.inspect_err(|e| warn!("Fetching state for event failed: {e}"))?;
|
||||
|
||||
debug!("Fetching state events");
|
||||
let collect = res
|
||||
.pdu_ids
|
||||
.iter()
|
||||
.map(|x| Arc::from(&**x))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let state_vec = self
|
||||
.fetch_and_handle_outliers(origin, &collect, create_event, room_id, room_version_id)
|
||||
.fetch_and_handle_outliers(origin, &res.pdu_ids, create_event, room_id, room_version_id)
|
||||
.boxed()
|
||||
.await;
|
||||
|
||||
let mut state: HashMap<_, Arc<EventId>> = HashMap::with_capacity(state_vec.len());
|
||||
let mut state: HashMap<ShortStateKey, OwnedEventId> = HashMap::with_capacity(state_vec.len());
|
||||
for (pdu, _) in state_vec {
|
||||
let state_key = pdu
|
||||
.state_key
|
||||
|
@ -61,10 +54,10 @@ pub(super) async fn fetch_state(
|
|||
|
||||
match state.entry(shortstatekey) {
|
||||
| hash_map::Entry::Vacant(v) => {
|
||||
v.insert(Arc::from(&*pdu.event_id));
|
||||
v.insert(pdu.event_id.clone());
|
||||
},
|
||||
| hash_map::Entry::Occupied(_) =>
|
||||
return Err(Error::bad_database(
|
||||
return Err!(Database(
|
||||
"State event's type and state_key combination exists multiple times.",
|
||||
)),
|
||||
}
|
||||
|
@ -77,7 +70,7 @@ pub(super) async fn fetch_state(
|
|||
.get_shortstatekey(&StateEventType::RoomCreate, "")
|
||||
.await?;
|
||||
|
||||
if state.get(&create_shortstatekey).map(AsRef::as_ref) != Some(&create_event.event_id) {
|
||||
if state.get(&create_shortstatekey) != Some(&create_event.event_id) {
|
||||
return Err!(Database("Incoming event refers to wrong create event."));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue