further simplify get_missing_events; various log calls
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
94b107b42b
commit
b7109131e2
3 changed files with 29 additions and 40 deletions
|
@ -1,9 +1,5 @@
|
|||
use axum::extract::State;
|
||||
use conduwuit::{
|
||||
Result, debug, debug_info, debug_warn,
|
||||
utils::{self},
|
||||
warn,
|
||||
};
|
||||
use conduwuit::{Result, debug, debug_error, utils::to_canonical_object};
|
||||
use ruma::api::federation::event::get_missing_events;
|
||||
|
||||
use super::AccessCheck;
|
||||
|
@ -43,19 +39,13 @@ pub(crate) async fn get_missing_events_route(
|
|||
let mut i: usize = 0;
|
||||
while i < queued_events.len() && events.len() < limit {
|
||||
let Ok(pdu) = services.rooms.timeline.get_pdu(&queued_events[i]).await else {
|
||||
debug_info!(?body.origin, "Event {} does not exist locally, skipping", &queued_events[i]);
|
||||
i = i.saturating_add(1);
|
||||
continue;
|
||||
};
|
||||
|
||||
if pdu.room_id != body.room_id {
|
||||
warn!(?body.origin,
|
||||
"Got an event for the wrong room in database. Found {:?} in {:?}, server requested events in {:?}. Skipping.",
|
||||
pdu.event_id, pdu.room_id, body.room_id
|
||||
debug!(
|
||||
?body.origin,
|
||||
"Event {} does not exist locally, skipping", &queued_events[i]
|
||||
);
|
||||
i = i.saturating_add(1);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
if body.earliest_events.contains(&queued_events[i]) {
|
||||
i = i.saturating_add(1);
|
||||
|
@ -68,25 +58,32 @@ pub(crate) async fn get_missing_events_route(
|
|||
.server_can_see_event(body.origin(), &body.room_id, &queued_events[i])
|
||||
.await
|
||||
{
|
||||
debug!(?body.origin, "Server cannot see {:?} in {:?}, skipping", pdu.event_id, pdu.room_id);
|
||||
debug!(
|
||||
?body.origin,
|
||||
"Server cannot see {:?} in {:?}, skipping", pdu.event_id, pdu.room_id
|
||||
);
|
||||
i = i.saturating_add(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
let Ok(pdu_json) = utils::to_canonical_object(&pdu) else {
|
||||
debug_warn!(?body.origin, "Failed to convert PDU in database to canonical JSON: {pdu:?}");
|
||||
let Ok(event) = to_canonical_object(&pdu) else {
|
||||
debug_error!(
|
||||
?body.origin,
|
||||
"Failed to convert PDU in database to canonical JSON: {pdu:?}"
|
||||
);
|
||||
i = i.saturating_add(1);
|
||||
continue;
|
||||
};
|
||||
|
||||
queued_events.extend(pdu.prev_events.iter().map(ToOwned::to_owned));
|
||||
let prev_events = pdu.prev_events.iter().map(ToOwned::to_owned);
|
||||
|
||||
events.push(
|
||||
services
|
||||
.sending
|
||||
.convert_to_outgoing_federation_event(pdu_json)
|
||||
.await,
|
||||
);
|
||||
let event = services
|
||||
.sending
|
||||
.convert_to_outgoing_federation_event(event)
|
||||
.await;
|
||||
|
||||
queued_events.extend(prev_events);
|
||||
events.push(event);
|
||||
}
|
||||
|
||||
Ok(get_missing_events::v1::Response { events })
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use conduwuit::{debug_info, implement, utils::stream::ReadyExt};
|
||||
use conduwuit::{implement, utils::stream::ReadyExt};
|
||||
use futures::StreamExt;
|
||||
use ruma::{
|
||||
EventId, RoomId, ServerName,
|
||||
|
@ -36,7 +36,6 @@ pub async fn server_can_see_event(
|
|||
.ready_filter(|member| member.server_name() == origin);
|
||||
|
||||
match history_visibility {
|
||||
| HistoryVisibility::WorldReadable | HistoryVisibility::Shared => true,
|
||||
| HistoryVisibility::Invited => {
|
||||
// Allow if any member on requesting server was AT LEAST invited, else deny
|
||||
current_server_members
|
||||
|
@ -49,9 +48,6 @@ pub async fn server_can_see_event(
|
|||
.any(|member| self.user_was_joined(shortstatehash, member))
|
||||
.await
|
||||
},
|
||||
| _ => {
|
||||
debug_info!(%room_id, "Unknown history visibility, defaulting to shared: {history_visibility:?}");
|
||||
true
|
||||
},
|
||||
| HistoryVisibility::WorldReadable | HistoryVisibility::Shared | _ => true,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use conduwuit::{Err, Error, Result, debug_info, implement, pdu::PduBuilder};
|
||||
use conduwuit::{Err, Result, implement, pdu::PduBuilder};
|
||||
use ruma::{
|
||||
EventId, RoomId, UserId,
|
||||
events::{
|
||||
|
@ -76,8 +76,8 @@ pub async fn user_can_redact(
|
|||
|| redacting_event
|
||||
.as_ref()
|
||||
.is_ok_and(|redacting_event| redacting_event.sender == sender)),
|
||||
| _ => Err(Error::bad_database(
|
||||
"No m.room.power_levels or m.room.create events in database for room",
|
||||
| _ => Err!(Database(
|
||||
"No m.room.power_levels or m.room.create events in database for room"
|
||||
)),
|
||||
}
|
||||
},
|
||||
|
@ -108,8 +108,6 @@ pub async fn user_can_see_event(
|
|||
});
|
||||
|
||||
match history_visibility {
|
||||
| HistoryVisibility::WorldReadable => true,
|
||||
| HistoryVisibility::Shared => currently_member,
|
||||
| HistoryVisibility::Invited => {
|
||||
// Allow if any member on requesting server was AT LEAST invited, else deny
|
||||
self.user_was_invited(shortstatehash, user_id).await
|
||||
|
@ -118,10 +116,8 @@ pub async fn user_can_see_event(
|
|||
// Allow if any member on requested server was joined, else deny
|
||||
self.user_was_joined(shortstatehash, user_id).await
|
||||
},
|
||||
| _ => {
|
||||
debug_info!(%room_id, "Unknown history visibility, defaulting to shared: {history_visibility:?}");
|
||||
currently_member
|
||||
},
|
||||
| HistoryVisibility::WorldReadable => true,
|
||||
| HistoryVisibility::Shared | _ => currently_member,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue