431 errors left
This commit is contained in:
parent
bd8b616ca0
commit
8708cd3b63
32 changed files with 640 additions and 973 deletions
|
@ -172,7 +172,7 @@ async fn sync_helper(
|
|||
};
|
||||
|
||||
// TODO: match body.set_presence {
|
||||
services().rooms.edus.ping_presence(&sender_user)?;
|
||||
services().rooms.edus.presence.ping_presence(&sender_user)?;
|
||||
|
||||
// Setup watchers, so if there's no response, we can wait for them
|
||||
let watcher = services().watch(&sender_user, &sender_device);
|
||||
|
@ -216,7 +216,7 @@ async fn sync_helper(
|
|||
.filter_map(|r| r.ok()),
|
||||
);
|
||||
|
||||
let all_joined_rooms = services().rooms.rooms_joined(&sender_user).collect::<Vec<_>>();
|
||||
let all_joined_rooms = services().rooms.state_cache.rooms_joined(&sender_user).collect::<Vec<_>>();
|
||||
for room_id in all_joined_rooms {
|
||||
let room_id = room_id?;
|
||||
|
||||
|
@ -237,9 +237,10 @@ async fn sync_helper(
|
|||
|
||||
let timeline_pdus;
|
||||
let limited;
|
||||
if services().rooms.last_timeline_count(&sender_user, &room_id)? > since {
|
||||
if services().rooms.timeline.last_timeline_count(&sender_user, &room_id)? > since {
|
||||
let mut non_timeline_pdus = services()
|
||||
.rooms
|
||||
.timeline
|
||||
.pdus_until(&sender_user, &room_id, u64::MAX)?
|
||||
.filter_map(|r| {
|
||||
// Filter out buggy events
|
||||
|
@ -250,6 +251,7 @@ async fn sync_helper(
|
|||
})
|
||||
.take_while(|(pduid, _)| {
|
||||
services().rooms
|
||||
.timeline
|
||||
.pdu_count(pduid)
|
||||
.map_or(false, |count| count > since)
|
||||
});
|
||||
|
@ -275,6 +277,7 @@ async fn sync_helper(
|
|||
|| services()
|
||||
.rooms
|
||||
.edus
|
||||
.read_receipt
|
||||
.last_privateread_update(&sender_user, &room_id)?
|
||||
> since;
|
||||
|
||||
|
@ -283,24 +286,24 @@ async fn sync_helper(
|
|||
timeline_users.insert(event.sender.as_str().to_owned());
|
||||
}
|
||||
|
||||
services().rooms
|
||||
services().rooms.lazy_loading
|
||||
.lazy_load_confirm_delivery(&sender_user, &sender_device, &room_id, since)?;
|
||||
|
||||
// Database queries:
|
||||
|
||||
let current_shortstatehash = if let Some(s) = services().rooms.current_shortstatehash(&room_id)? {
|
||||
let current_shortstatehash = if let Some(s) = services().rooms.state.get_room_shortstatehash(&room_id)? {
|
||||
s
|
||||
} else {
|
||||
error!("Room {} has no state", room_id);
|
||||
continue;
|
||||
};
|
||||
|
||||
let since_shortstatehash = services().rooms.get_token_shortstatehash(&room_id, since)?;
|
||||
let since_shortstatehash = services().rooms.user.get_token_shortstatehash(&room_id, since)?;
|
||||
|
||||
// Calculates joined_member_count, invited_member_count and heroes
|
||||
let calculate_counts = || {
|
||||
let joined_member_count = services().rooms.room_joined_count(&room_id)?.unwrap_or(0);
|
||||
let invited_member_count = services().rooms.room_invited_count(&room_id)?.unwrap_or(0);
|
||||
let joined_member_count = services().rooms.state_cache.room_joined_count(&room_id)?.unwrap_or(0);
|
||||
let invited_member_count = services().rooms.state_cache.room_invited_count(&room_id)?.unwrap_or(0);
|
||||
|
||||
// Recalculate heroes (first 5 members)
|
||||
let mut heroes = Vec::new();
|
||||
|
@ -311,7 +314,7 @@ async fn sync_helper(
|
|||
|
||||
for hero in services()
|
||||
.rooms
|
||||
.all_pdus(&sender_user, &room_id)?
|
||||
.timeline.all_pdus(&sender_user, &room_id)?
|
||||
.filter_map(|pdu| pdu.ok()) // Ignore all broken pdus
|
||||
.filter(|(_, pdu)| pdu.kind == RoomEventType::RoomMember)
|
||||
.map(|(_, pdu)| {
|
||||
|
@ -329,8 +332,8 @@ async fn sync_helper(
|
|||
if matches!(
|
||||
content.membership,
|
||||
MembershipState::Join | MembershipState::Invite
|
||||
) && (services().rooms.is_joined(&user_id, &room_id)?
|
||||
|| services().rooms.is_invited(&user_id, &room_id)?)
|
||||
) && (services().rooms.state_cache.is_joined(&user_id, &room_id)?
|
||||
|| services().rooms.state_cache.is_invited(&user_id, &room_id)?)
|
||||
{
|
||||
Ok::<_, Error>(Some(state_key.clone()))
|
||||
} else {
|
||||
|
@ -371,17 +374,17 @@ async fn sync_helper(
|
|||
|
||||
let (joined_member_count, invited_member_count, heroes) = calculate_counts()?;
|
||||
|
||||
let current_state_ids = services().rooms.state_full_ids(current_shortstatehash).await?;
|
||||
let current_state_ids = services().rooms.state_accessor.state_full_ids(current_shortstatehash).await?;
|
||||
|
||||
let mut state_events = Vec::new();
|
||||
let mut lazy_loaded = HashSet::new();
|
||||
|
||||
let mut i = 0;
|
||||
for (shortstatekey, id) in current_state_ids {
|
||||
let (event_type, state_key) = services().rooms.get_statekey_from_short(shortstatekey)?;
|
||||
let (event_type, state_key) = services().rooms.short.get_statekey_from_short(shortstatekey)?;
|
||||
|
||||
if event_type != StateEventType::RoomMember {
|
||||
let pdu = match services().rooms.get_pdu(&id)? {
|
||||
let pdu = match services().rooms.timeline.get_pdu(&id)? {
|
||||
Some(pdu) => pdu,
|
||||
None => {
|
||||
error!("Pdu in state not found: {}", id);
|
||||
|
@ -398,7 +401,7 @@ async fn sync_helper(
|
|||
|| body.full_state
|
||||
|| timeline_users.contains(&state_key)
|
||||
{
|
||||
let pdu = match services().rooms.get_pdu(&id)? {
|
||||
let pdu = match services().rooms.timeline.get_pdu(&id)? {
|
||||
Some(pdu) => pdu,
|
||||
None => {
|
||||
error!("Pdu in state not found: {}", id);
|
||||
|
@ -420,12 +423,12 @@ async fn sync_helper(
|
|||
}
|
||||
|
||||
// Reset lazy loading because this is an initial sync
|
||||
services().rooms
|
||||
services().rooms.lazy_loading
|
||||
.lazy_load_reset(&sender_user, &sender_device, &room_id)?;
|
||||
|
||||
// The state_events above should contain all timeline_users, let's mark them as lazy
|
||||
// loaded.
|
||||
services().rooms.lazy_load_mark_sent(
|
||||
services().rooms.lazy_loading.lazy_load_mark_sent(
|
||||
&sender_user,
|
||||
&sender_device,
|
||||
&room_id,
|
||||
|
@ -449,6 +452,7 @@ async fn sync_helper(
|
|||
|
||||
let since_sender_member: Option<RoomMemberEventContent> = services()
|
||||
.rooms
|
||||
.state_accessor
|
||||
.state_get(
|
||||
since_shortstatehash,
|
||||
&StateEventType::RoomMember,
|
||||
|
@ -467,12 +471,12 @@ async fn sync_helper(
|
|||
let mut lazy_loaded = HashSet::new();
|
||||
|
||||
if since_shortstatehash != current_shortstatehash {
|
||||
let current_state_ids = services().rooms.state_full_ids(current_shortstatehash).await?;
|
||||
let since_state_ids = services().rooms.state_full_ids(since_shortstatehash).await?;
|
||||
let current_state_ids = services().rooms.state_accessor.state_full_ids(current_shortstatehash).await?;
|
||||
let since_state_ids = services().rooms.state_accessor.state_full_ids(since_shortstatehash).await?;
|
||||
|
||||
for (key, id) in current_state_ids {
|
||||
if body.full_state || since_state_ids.get(&key) != Some(&id) {
|
||||
let pdu = match services().rooms.get_pdu(&id)? {
|
||||
let pdu = match services().rooms.timeline.get_pdu(&id)? {
|
||||
Some(pdu) => pdu,
|
||||
None => {
|
||||
error!("Pdu in state not found: {}", id);
|
||||
|
@ -505,14 +509,14 @@ async fn sync_helper(
|
|||
continue;
|
||||
}
|
||||
|
||||
if !services().rooms.lazy_load_was_sent_before(
|
||||
if !services().rooms.lazy_loading.lazy_load_was_sent_before(
|
||||
&sender_user,
|
||||
&sender_device,
|
||||
&room_id,
|
||||
&event.sender,
|
||||
)? || lazy_load_send_redundant
|
||||
{
|
||||
if let Some(member_event) = services().rooms.room_state_get(
|
||||
if let Some(member_event) = services().rooms.state_accessor.room_state_get(
|
||||
&room_id,
|
||||
&StateEventType::RoomMember,
|
||||
event.sender.as_str(),
|
||||
|
@ -523,7 +527,7 @@ async fn sync_helper(
|
|||
}
|
||||
}
|
||||
|
||||
services().rooms.lazy_load_mark_sent(
|
||||
services().rooms.lazy_loading.lazy_load_mark_sent(
|
||||
&sender_user,
|
||||
&sender_device,
|
||||
&room_id,
|
||||
|
@ -533,11 +537,12 @@ async fn sync_helper(
|
|||
|
||||
let encrypted_room = services()
|
||||
.rooms
|
||||
.state_get(current_shortstatehash, &StateEventType::RoomEncryption, "")?
|
||||
.state_accessor.state_get(current_shortstatehash, &StateEventType::RoomEncryption, "")?
|
||||
.is_some();
|
||||
|
||||
let since_encryption =
|
||||
services().rooms
|
||||
.state_accessor
|
||||
.state_get(since_shortstatehash, &StateEventType::RoomEncryption, "")?;
|
||||
|
||||
// Calculations:
|
||||
|
@ -588,6 +593,7 @@ async fn sync_helper(
|
|||
// If the user is in a new encrypted room, give them all joined users
|
||||
device_list_updates.extend(
|
||||
services().rooms
|
||||
.state_cache
|
||||
.room_members(&room_id)
|
||||
.flatten()
|
||||
.filter(|user_id| {
|
||||
|
@ -627,6 +633,7 @@ async fn sync_helper(
|
|||
let notification_count = if send_notification_counts {
|
||||
Some(
|
||||
services().rooms
|
||||
.user
|
||||
.notification_count(&sender_user, &room_id)?
|
||||
.try_into()
|
||||
.expect("notification count can't go that high"),
|
||||
|
@ -638,6 +645,7 @@ async fn sync_helper(
|
|||
let highlight_count = if send_notification_counts {
|
||||
Some(
|
||||
services().rooms
|
||||
.user
|
||||
.highlight_count(&sender_user, &room_id)?
|
||||
.try_into()
|
||||
.expect("highlight count can't go that high"),
|
||||
|
@ -649,7 +657,7 @@ async fn sync_helper(
|
|||
let prev_batch = timeline_pdus
|
||||
.first()
|
||||
.map_or(Ok::<_, Error>(None), |(pdu_id, _)| {
|
||||
Ok(Some(services().rooms.pdu_count(pdu_id)?.to_string()))
|
||||
Ok(Some(services().rooms.timeline.pdu_count(pdu_id)?.to_string()))
|
||||
})?;
|
||||
|
||||
let room_events: Vec<_> = timeline_pdus
|
||||
|
@ -660,15 +668,16 @@ async fn sync_helper(
|
|||
let mut edus: Vec<_> = services()
|
||||
.rooms
|
||||
.edus
|
||||
.read_receipt
|
||||
.readreceipts_since(&room_id, since)
|
||||
.filter_map(|r| r.ok()) // Filter out buggy events
|
||||
.map(|(_, _, v)| v)
|
||||
.collect();
|
||||
|
||||
if services().rooms.edus.last_typing_update(&room_id, &services().globals)? > since {
|
||||
if services().rooms.edus.typing.last_typing_update(&room_id)? > since {
|
||||
edus.push(
|
||||
serde_json::from_str(
|
||||
&serde_json::to_string(&services().rooms.edus.typings_all(&room_id)?)
|
||||
&serde_json::to_string(&services().rooms.edus.typing.typings_all(&room_id)?)
|
||||
.expect("event is valid, we just created it"),
|
||||
)
|
||||
.expect("event is valid, we just created it"),
|
||||
|
@ -676,7 +685,7 @@ async fn sync_helper(
|
|||
}
|
||||
|
||||
// Save the state after this sync so we can send the correct state diff next sync
|
||||
services().rooms
|
||||
services().rooms.user
|
||||
.associate_token_shortstatehash(&room_id, next_batch, current_shortstatehash)?;
|
||||
|
||||
let joined_room = JoinedRoom {
|
||||
|
@ -723,6 +732,7 @@ async fn sync_helper(
|
|||
for (user_id, presence) in
|
||||
services().rooms
|
||||
.edus
|
||||
.presence
|
||||
.presence_since(&room_id, since)?
|
||||
{
|
||||
match presence_updates.entry(user_id) {
|
||||
|
@ -755,7 +765,7 @@ async fn sync_helper(
|
|||
}
|
||||
|
||||
let mut left_rooms = BTreeMap::new();
|
||||
let all_left_rooms: Vec<_> = services().rooms.rooms_left(&sender_user).collect();
|
||||
let all_left_rooms: Vec<_> = services().rooms.state_cache.rooms_left(&sender_user).collect();
|
||||
for result in all_left_rooms {
|
||||
let (room_id, left_state_events) = result?;
|
||||
|
||||
|
@ -773,7 +783,7 @@ async fn sync_helper(
|
|||
drop(insert_lock);
|
||||
}
|
||||
|
||||
let left_count = services().rooms.get_left_count(&room_id, &sender_user)?;
|
||||
let left_count = services().rooms.state_cache.get_left_count(&room_id, &sender_user)?;
|
||||
|
||||
// Left before last sync
|
||||
if Some(since) >= left_count {
|
||||
|
@ -797,7 +807,7 @@ async fn sync_helper(
|
|||
}
|
||||
|
||||
let mut invited_rooms = BTreeMap::new();
|
||||
let all_invited_rooms: Vec<_> = services().rooms.rooms_invited(&sender_user).collect();
|
||||
let all_invited_rooms: Vec<_> = services().rooms.state_cache.rooms_invited(&sender_user).collect();
|
||||
for result in all_invited_rooms {
|
||||
let (room_id, invite_state_events) = result?;
|
||||
|
||||
|
@ -815,7 +825,7 @@ async fn sync_helper(
|
|||
drop(insert_lock);
|
||||
}
|
||||
|
||||
let invite_count = services().rooms.get_invite_count(&room_id, &sender_user)?;
|
||||
let invite_count = services().rooms.state_cache.get_invite_count(&room_id, &sender_user)?;
|
||||
|
||||
// Invited before last sync
|
||||
if Some(since) >= invite_count {
|
||||
|
@ -835,12 +845,13 @@ async fn sync_helper(
|
|||
for user_id in left_encrypted_users {
|
||||
let still_share_encrypted_room = services()
|
||||
.rooms
|
||||
.user
|
||||
.get_shared_rooms(vec![sender_user.clone(), user_id.clone()])?
|
||||
.filter_map(|r| r.ok())
|
||||
.filter_map(|other_room_id| {
|
||||
Some(
|
||||
services().rooms
|
||||
.room_state_get(&other_room_id, &StateEventType::RoomEncryption, "")
|
||||
.state_accessor.room_state_get(&other_room_id, &StateEventType::RoomEncryption, "")
|
||||
.ok()?
|
||||
.is_some(),
|
||||
)
|
||||
|
@ -925,12 +936,14 @@ fn share_encrypted_room(
|
|||
) -> Result<bool> {
|
||||
Ok(services()
|
||||
.rooms
|
||||
.user
|
||||
.get_shared_rooms(vec![sender_user.to_owned(), user_id.to_owned()])?
|
||||
.filter_map(|r| r.ok())
|
||||
.filter(|room_id| room_id != ignore_room)
|
||||
.filter_map(|other_room_id| {
|
||||
Some(
|
||||
services().rooms
|
||||
.state_accessor
|
||||
.room_state_get(&other_room_id, &StateEventType::RoomEncryption, "")
|
||||
.ok()?
|
||||
.is_some(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue