fix: Make joining a channel work with multi-device, fix test_leave_broadcast_multidevice

This commit is contained in:
Hocuri
2025-08-01 23:00:06 +02:00
parent 37f6da1cc9
commit 7e191f6cf9
3 changed files with 47 additions and 14 deletions

View File

@@ -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<bool> {
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`

View File

@@ -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?;

View File

@@ -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();
}