|
|
@ -653,6 +653,11 @@ async fn load_joined_room(
|
|
|
|
.user
|
|
|
|
.user
|
|
|
|
.get_token_shortstatehash(&room_id, since)?;
|
|
|
|
.get_token_shortstatehash(&room_id, since)?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let (heroes, joined_member_count, invited_member_count, joined_since_last_sync, state_events) =
|
|
|
|
|
|
|
|
if timeline_pdus.is_empty() && since_shortstatehash == Some(current_shortstatehash) {
|
|
|
|
|
|
|
|
// No state changes
|
|
|
|
|
|
|
|
(Vec::new(), None, None, false, Vec::new())
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Calculates joined_member_count, invited_member_count and heroes
|
|
|
|
// Calculates joined_member_count, invited_member_count and heroes
|
|
|
|
let calculate_counts = || {
|
|
|
|
let calculate_counts = || {
|
|
|
|
let joined_member_count = services()
|
|
|
|
let joined_member_count = services()
|
|
|
@ -680,20 +685,24 @@ async fn load_joined_room(
|
|
|
|
.filter_map(|pdu| pdu.ok()) // Ignore all broken pdus
|
|
|
|
.filter_map(|pdu| pdu.ok()) // Ignore all broken pdus
|
|
|
|
.filter(|(_, pdu)| pdu.kind == TimelineEventType::RoomMember)
|
|
|
|
.filter(|(_, pdu)| pdu.kind == TimelineEventType::RoomMember)
|
|
|
|
.map(|(_, pdu)| {
|
|
|
|
.map(|(_, pdu)| {
|
|
|
|
let content: RoomMemberEventContent = serde_json::from_str(pdu.content.get())
|
|
|
|
let content: RoomMemberEventContent =
|
|
|
|
.map_err(|_| {
|
|
|
|
serde_json::from_str(pdu.content.get()).map_err(|_| {
|
|
|
|
Error::bad_database("Invalid member event in database.")
|
|
|
|
Error::bad_database("Invalid member event in database.")
|
|
|
|
})?;
|
|
|
|
})?;
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(state_key) = &pdu.state_key {
|
|
|
|
if let Some(state_key) = &pdu.state_key {
|
|
|
|
let user_id = UserId::parse(state_key.clone())
|
|
|
|
let user_id = UserId::parse(state_key.clone()).map_err(|_| {
|
|
|
|
.map_err(|_| Error::bad_database("Invalid UserId in member PDU."))?;
|
|
|
|
Error::bad_database("Invalid UserId in member PDU.")
|
|
|
|
|
|
|
|
})?;
|
|
|
|
|
|
|
|
|
|
|
|
// The membership was and still is invite or join
|
|
|
|
// The membership was and still is invite or join
|
|
|
|
if matches!(
|
|
|
|
if matches!(
|
|
|
|
content.membership,
|
|
|
|
content.membership,
|
|
|
|
MembershipState::Join | MembershipState::Invite
|
|
|
|
MembershipState::Join | MembershipState::Invite
|
|
|
|
) && (services().rooms.state_cache.is_joined(&user_id, &room_id)?
|
|
|
|
) && (services()
|
|
|
|
|
|
|
|
.rooms
|
|
|
|
|
|
|
|
.state_cache
|
|
|
|
|
|
|
|
.is_joined(&user_id, &room_id)?
|
|
|
|
|| services()
|
|
|
|
|| services()
|
|
|
|
.rooms
|
|
|
|
.rooms
|
|
|
|
.state_cache
|
|
|
|
.state_cache
|
|
|
@ -746,10 +755,9 @@ async fn load_joined_room(
|
|
|
|
.ok()
|
|
|
|
.ok()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let joined_since_last_sync =
|
|
|
|
let joined_since_last_sync = since_sender_member
|
|
|
|
since_sender_member.map_or(true, |member| member.membership != MembershipState::Join);
|
|
|
|
.map_or(true, |member| member.membership != MembershipState::Join);
|
|
|
|
|
|
|
|
|
|
|
|
let (heroes, joined_member_count, invited_member_count, joined_since_last_sync, state_events) =
|
|
|
|
|
|
|
|
if since_shortstatehash.is_none() || joined_since_last_sync {
|
|
|
|
if since_shortstatehash.is_none() || joined_since_last_sync {
|
|
|
|
// Probably since = 0, we will do an initial sync
|
|
|
|
// Probably since = 0, we will do an initial sync
|
|
|
|
|
|
|
|
|
|
|
@ -836,9 +844,6 @@ async fn load_joined_room(
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
state_events,
|
|
|
|
state_events,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
} else if timeline_pdus.is_empty() && since_shortstatehash == Some(current_shortstatehash) {
|
|
|
|
|
|
|
|
// No state changes
|
|
|
|
|
|
|
|
(Vec::new(), None, None, false, Vec::new())
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Incremental /sync
|
|
|
|
// Incremental /sync
|
|
|
|
let since_shortstatehash = since_shortstatehash.unwrap();
|
|
|
|
let since_shortstatehash = since_shortstatehash.unwrap();
|
|
|
@ -945,8 +950,9 @@ async fn load_joined_room(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(state_key) = &state_event.state_key {
|
|
|
|
if let Some(state_key) = &state_event.state_key {
|
|
|
|
let user_id = UserId::parse(state_key.clone())
|
|
|
|
let user_id = UserId::parse(state_key.clone()).map_err(|_| {
|
|
|
|
.map_err(|_| Error::bad_database("Invalid UserId in member PDU."))?;
|
|
|
|
Error::bad_database("Invalid UserId in member PDU.")
|
|
|
|
|
|
|
|
})?;
|
|
|
|
|
|
|
|
|
|
|
|
if user_id == sender_user {
|
|
|
|
if user_id == sender_user {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
@ -989,7 +995,8 @@ async fn load_joined_room(
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.filter(|user_id| {
|
|
|
|
.filter(|user_id| {
|
|
|
|
// Only send keys if the sender doesn't share an encrypted room with the target already
|
|
|
|
// Only send keys if the sender doesn't share an encrypted room with the target already
|
|
|
|
!share_encrypted_room(&sender_user, user_id, &room_id).unwrap_or(false)
|
|
|
|
!share_encrypted_room(&sender_user, user_id, &room_id)
|
|
|
|
|
|
|
|
.unwrap_or(false)
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1007,6 +1014,7 @@ async fn load_joined_room(
|
|
|
|
joined_since_last_sync,
|
|
|
|
joined_since_last_sync,
|
|
|
|
state_events,
|
|
|
|
state_events,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Look for device list updates in this room
|
|
|
|
// Look for device list updates in this room
|
|
|
|