Allow client to load history on newly joined rooms

On /sync, check if a room is a new join between `since` parameter and
now. If it's a newly joined room, set the limited flag to true, which will force
the client to load room messages via the `/messages` endpoint.

On `master`, I could not reproduce the messages not showing to others
when joining after being invited.

Fixes #39
This commit is contained in:
Guillem Nieto 2020-06-06 17:23:14 +02:00
parent 8f6b446193
commit 9269f009db

View file

@ -2149,13 +2149,13 @@ pub fn sync_route(
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let mut send_member_count = false; let mut send_member_count = false;
let mut send_full_state = false; let mut joined_since_last_sync = false;
let mut send_notification_counts = false; let mut send_notification_counts = false;
for pdu in &pdus { for pdu in &pdus {
send_notification_counts = true; send_notification_counts = true;
if pdu.kind == EventType::RoomMember { if pdu.kind == EventType::RoomMember {
send_member_count = true; send_member_count = true;
if !send_full_state && pdu.state_key == Some(user_id.to_string()) { if !joined_since_last_sync && pdu.state_key == Some(user_id.to_string()) {
let content = serde_json::from_value::< let content = serde_json::from_value::<
EventJson<ruma::events::room::member::MemberEventContent>, EventJson<ruma::events::room::member::MemberEventContent>,
>(pdu.content.clone()) >(pdu.content.clone())
@ -2163,8 +2163,8 @@ pub fn sync_route(
.deserialize() .deserialize()
.unwrap(); .unwrap();
if content.membership == ruma::events::room::member::MembershipState::Join { if content.membership == ruma::events::room::member::MembershipState::Join {
send_full_state = true; joined_since_last_sync = true;
// Both send_member_count and send_full_state are set. There's nothing more // Both send_member_count and joined_since_last_sync are set. There's nothing more
// to do // to do
break; break;
} }
@ -2338,13 +2338,13 @@ pub fn sync_route(
notification_count, notification_count,
}, },
timeline: sync_events::Timeline { timeline: sync_events::Timeline {
limited: if limited { Some(limited) } else { None }, limited: if limited || joined_since_last_sync { Some(true) } else { None },
prev_batch, prev_batch,
events: room_events, events: room_events,
}, },
// TODO: state before timeline // TODO: state before timeline
state: sync_events::State { state: sync_events::State {
events: if send_full_state { events: if joined_since_last_sync {
state state
.into_iter() .into_iter()
.map(|(_, pdu)| pdu.to_state_event()) .map(|(_, pdu)| pdu.to_state_event())