(self, context: &Context, sync: sync::Sync)
| 362 | } |
| 363 | |
| 364 | pub(crate) async fn block_ex(self, context: &Context, sync: sync::Sync) -> Result<()> { |
| 365 | let chat = Chat::load_from_db(context, self).await?; |
| 366 | let mut delete = false; |
| 367 | |
| 368 | match chat.typ { |
| 369 | Chattype::OutBroadcast => { |
| 370 | bail!("Can't block chat of type {:?}", chat.typ) |
| 371 | } |
| 372 | Chattype::Single => { |
| 373 | for contact_id in get_chat_contacts(context, self).await? { |
| 374 | if contact_id != ContactId::SELF { |
| 375 | info!( |
| 376 | context, |
| 377 | "Blocking the contact {contact_id} to block 1:1 chat." |
| 378 | ); |
| 379 | contact::set_blocked(context, Nosync, contact_id, true).await?; |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | Chattype::Group => { |
| 384 | info!(context, "Can't block groups yet, deleting the chat."); |
| 385 | delete = true; |
| 386 | } |
| 387 | Chattype::Mailinglist | Chattype::InBroadcast => { |
| 388 | if self.set_blocked(context, Blocked::Yes).await? { |
| 389 | context.emit_event(EventType::ChatModified(self)); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | chatlist_events::emit_chatlist_changed(context); |
| 394 | |
| 395 | if sync.into() { |
| 396 | // NB: For a 1:1 chat this currently triggers `Contact::block()` on other devices. |
| 397 | chat.sync(context, SyncAction::Block) |
| 398 | .await |
| 399 | .log_err(context) |
| 400 | .ok(); |
| 401 | } |
| 402 | if delete { |
| 403 | self.delete_ex(context, Nosync).await?; |
| 404 | } |
| 405 | Ok(()) |
| 406 | } |
| 407 | |
| 408 | /// Unblocks the chat. |
| 409 | pub async fn unblock(self, context: &Context) -> Result<()> { |
no test coverage detected