1
0
Fork 0
mirror of https://gitlab.com/famedly/conduit.git synced 2024-12-27 13:04:31 +01:00

fix: not sending enough state on join

This commit is contained in:
Timo Kösters 2022-10-30 21:23:10 +01:00
parent 5d691f405e
commit 0cf6545116
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
3 changed files with 29 additions and 28 deletions

View file

@ -388,13 +388,35 @@ async fn sync_helper(
))
};
let since_sender_member: Option<RoomMemberEventContent> = since_shortstatehash
.and_then(|shortstatehash| {
services()
.rooms
.state_accessor
.state_get(
shortstatehash,
&StateEventType::RoomMember,
sender_user.as_str(),
)
.transpose()
})
.transpose()?
.and_then(|pdu| {
serde_json::from_str(pdu.content.get())
.map_err(|_| Error::bad_database("Invalid PDU in database."))
.ok()
});
let joined_since_last_sync =
since_sender_member.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() {
) = if since_shortstatehash.is_none() || joined_since_last_sync {
// Probably since = 0, we will do an initial sync
let (joined_member_count, invited_member_count, heroes) = calculate_counts()?;
@ -487,23 +509,6 @@ async fn sync_helper(
// Incremental /sync
let since_shortstatehash = since_shortstatehash.unwrap();
let since_sender_member: Option<RoomMemberEventContent> = services()
.rooms
.state_accessor
.state_get(
since_shortstatehash,
&StateEventType::RoomMember,
sender_user.as_str(),
)?
.and_then(|pdu| {
serde_json::from_str(pdu.content.get())
.map_err(|_| Error::bad_database("Invalid PDU in database."))
.ok()
});
let joined_since_last_sync = since_sender_member
.map_or(true, |member| member.membership != MembershipState::Join);
let mut state_events = Vec::new();
let mut lazy_loaded = HashSet::new();

View file

@ -54,10 +54,7 @@ impl service::rooms::edus::typing::Data for KeyValueDatabase {
Ok(())
}
fn typings_maintain(
&self,
room_id: &RoomId,
) -> Result<()> {
fn typings_maintain(&self, room_id: &RoomId) -> Result<()> {
let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff);
@ -89,8 +86,10 @@ impl service::rooms::edus::typing::Data for KeyValueDatabase {
}
if found_outdated {
self.roomid_lasttypingupdate
.insert(room_id.as_bytes(), &services().globals.next_count()?.to_be_bytes())?;
self.roomid_lasttypingupdate.insert(
room_id.as_bytes(),
&services().globals.next_count()?.to_be_bytes(),
)?;
}
Ok(())

View file

@ -22,10 +22,7 @@ impl Service {
}
/// Makes sure that typing events with old timestamps get removed.
fn typings_maintain(
&self,
room_id: &RoomId,
) -> Result<()> {
fn typings_maintain(&self, room_id: &RoomId) -> Result<()> {
self.db.typings_maintain(room_id)
}