From 13334a88ca85155f762845769c99744033c389c8 Mon Sep 17 00:00:00 2001 From: morguldir Date: Sat, 24 Aug 2024 06:45:33 +0200 Subject: [PATCH] syncv3: handle empty conn_id by mapping it to a predefined string --- src/api/client/sync.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/api/client/sync.rs b/src/api/client/sync.rs index f41321ac..9b0facc0 100644 --- a/src/api/client/sync.rs +++ b/src/api/client/sync.rs @@ -7,7 +7,9 @@ use std::{ use axum::extract::State; use conduit::{ - error, utils::math::{ruma_from_u64, ruma_from_usize, usize_from_ruma, usize_from_u64_truncated}, warn, Err, PduCount + error, + utils::math::{ruma_from_u64, ruma_from_usize, usize_from_ruma, usize_from_u64_truncated}, + warn, Err, PduCount, }; use ruma::{ api::client::{ @@ -27,7 +29,10 @@ use ruma::{ presence::PresenceEvent, room::member::{MembershipState, RoomMemberEventContent}, StateEventType, TimelineEventType, - }, room::RoomType, serde::Raw, uint, DeviceId, EventId, OwnedRoomId, OwnedUserId, RoomId, UInt, UserId + }, + room::RoomType, + serde::Raw, + uint, DeviceId, EventId, OwnedRoomId, OwnedUserId, RoomId, UInt, UserId, }; use tracing::{Instrument as _, Span}; @@ -36,6 +41,8 @@ use crate::{ utils, Error, PduEvent, Result, Ruma, RumaResponse, }; +const SINGLE_CONNECTION_SYNC: &str = "single_connection_sync"; + /// # `GET /_matrix/client/r0/sync` /// /// Synchronize the client's state with the latest state on the server. @@ -1083,6 +1090,11 @@ pub(crate) async fn sync_events_v4_route( let next_batch = services.globals.next_count()?; + let conn_id = body + .conn_id + .clone() + .unwrap_or_else(|| SINGLE_CONNECTION_SYNC.to_owned()); + let globalsince = body .pos .as_ref() @@ -1090,11 +1102,9 @@ pub(crate) async fn sync_events_v4_route( .unwrap_or(0); if globalsince == 0 { - if let Some(conn_id) = &body.conn_id { - services - .users - .forget_sync_request_connection(sender_user.clone(), sender_device.clone(), conn_id.clone()); - } + services + .users + .forget_sync_request_connection(sender_user.clone(), sender_device.clone(), conn_id.clone()); } // Get sticky parameters from cache