diff --git a/src/chat.rs b/src/chat.rs index 4d245b88d..87482c2d3 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -5161,19 +5161,8 @@ impl Context { .id } SyncId::Grpid(grpid) => { - if let SyncAction::CreateOutBroadcast { - chat_name, - shared_secret: secret, - } = action - { - create_broadcast_ex( - self, - Nosync, - grpid.clone(), - chat_name.clone(), - secret.to_string(), - ) - .await?; + let handled = self.handle_sync_create_chat(action, grpid).await?; + if handled { return Ok(()); } get_chat_id_by_grpid(self, grpid) @@ -5197,6 +5186,7 @@ impl Context { SyncAction::SetVisibility(v) => chat_id.set_visibility_ex(self, Nosync, *v).await, SyncAction::SetMuted(duration) => set_muted_ex(self, Nosync, chat_id, *duration).await, SyncAction::CreateOutBroadcast { .. } | SyncAction::CreateInBroadcast { .. } => { + // Create action should have been handled by handle_sync_create_chat() already Err(anyhow!("sync_alter_chat({id:?}, {action:?}): Bad request.")) } SyncAction::Rename(to) => rename_ex(self, Nosync, chat_id, to).await, @@ -5208,6 +5198,45 @@ impl Context { } } + async fn handle_sync_create_chat(&self, action: &SyncAction, grpid: &String) -> Result { + Ok(match action { + SyncAction::CreateOutBroadcast { + chat_name, + shared_secret, + } => { + create_broadcast_ex( + self, + Nosync, + grpid.clone(), + chat_name.clone(), + shared_secret.to_string(), + ) + .await?; + return Ok(true); + } + SyncAction::CreateInBroadcast { + chat_name, + shared_secret, + } => { + let chat_id = ChatId::create_multiuser_record( + self, + Chattype::InBroadcast, + grpid, + chat_name, + Blocked::Not, + ProtectionStatus::Unprotected, + None, + create_smeared_timestamp(self), + ) + .await?; + save_broadcast_shared_secret(self, chat_id, shared_secret).await?; + + return Ok(true); + } + _ => false, + }) + } + /// Emits the appropriate `MsgsChanged` event. Should be called if the number of unnoticed /// archived chats could decrease. In general we don't want to make an extra db query to know if /// a noticed chat is archived. Emitting events should be cheap, a false-positive `MsgsChanged` diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index 4d0fbba0e..3f0831d36 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -3058,6 +3058,9 @@ async fn test_leave_broadcast_multidevice() -> Result<()> { let alice = &tcm.alice().await; let bob0 = &tcm.bob().await; let bob1 = &tcm.bob().await; + for b in [bob0, bob1] { + b.set_config_bool(Config::SyncMsgs, true).await?; + } tcm.section("Alice creates broadcast channel with Bob."); let alice_chat_id = create_broadcast(alice, "foo".to_string()).await?; diff --git a/src/sync.rs b/src/sync.rs index b5a42130b..3e3b83c58 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -1,6 +1,6 @@ //! # Synchronize items between devices. -use anyhow::Result; +use anyhow::{Context as _, Result}; use mail_builder::mime::MimePart; use serde::{Deserialize, Serialize}; @@ -274,6 +274,7 @@ impl Context { Ok(()) } } + .with_context(|| format!("Sync data {:?}", item.data)) .log_err(self) .ok(); }