MCPcopy Create free account
hub / github.com/chatmail/core / block_ex

Method block_ex

src/chat.rs:364–406  ·  view source on GitHub ↗
(self, context: &Context, sync: sync::Sync)

Source from the content-addressed store, hash-verified

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<()> {

Callers 2

blockMethod · 0.80
sync_alter_chatMethod · 0.80

Calls 8

get_chat_contactsFunction · 0.85
set_blockedFunction · 0.85
emit_chatlist_changedFunction · 0.85
log_errMethod · 0.80
delete_exMethod · 0.80
set_blockedMethod · 0.45
emit_eventMethod · 0.45
syncMethod · 0.45

Tested by

no test coverage detected