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

Method sync_alter_chat

src/chat.rs:5210–5312  ·  view source on GitHub ↗

Executes [`SyncData::AlterChat`] item sent by other device.

(&self, id: &SyncId, action: &SyncAction)

Source from the content-addressed store, hash-verified

5208impl Context {
5209 /// Executes [`SyncData::AlterChat`] item sent by other device.
5210 pub(crate) async fn sync_alter_chat(&self, id: &SyncId, action: &SyncAction) -> Result<()> {
5211 let chat_id = match id {
5212 SyncId::ContactAddr(addr) => {
5213 if let SyncAction::Rename(to) = action {
5214 Contact::create_ex(self, Nosync, to, addr).await?;
5215 return Ok(());
5216 }
5217 let addr = ContactAddress::new(addr).context("Invalid address")?;
5218 let (contact_id, _) =
5219 Contact::add_or_lookup(self, "", &addr, Origin::Hidden).await?;
5220 match action {
5221 SyncAction::Block => {
5222 return contact::set_blocked(self, Nosync, contact_id, true).await;
5223 }
5224 SyncAction::Unblock => {
5225 return contact::set_blocked(self, Nosync, contact_id, false).await;
5226 }
5227 _ => (),
5228 }
5229 // Use `Request` so that even if the program crashes, the user doesn't have to look
5230 // into the blocked contacts.
5231 ChatIdBlocked::get_for_contact(self, contact_id, Blocked::Request)
5232 .await?
5233 .id
5234 }
5235 SyncId::ContactFingerprint(fingerprint) => {
5236 let name = "";
5237 let addr = "";
5238 let (contact_id, _) =
5239 Contact::add_or_lookup_ex(self, name, addr, fingerprint, Origin::Hidden)
5240 .await?;
5241 match action {
5242 SyncAction::Rename(to) => {
5243 contact_id.set_name_ex(self, Nosync, to).await?;
5244 self.emit_event(EventType::ContactsChanged(Some(contact_id)));
5245 return Ok(());
5246 }
5247 SyncAction::Block => {
5248 return contact::set_blocked(self, Nosync, contact_id, true).await;
5249 }
5250 SyncAction::Unblock => {
5251 return contact::set_blocked(self, Nosync, contact_id, false).await;
5252 }
5253 _ => (),
5254 }
5255 ChatIdBlocked::get_for_contact(self, contact_id, Blocked::Request)
5256 .await?
5257 .id
5258 }
5259 SyncId::Grpid(grpid) => {
5260 match action {
5261 SyncAction::CreateOutBroadcast { chat_name, secret } => {
5262 create_out_broadcast_ex(
5263 self,
5264 Nosync,
5265 grpid.to_string(),
5266 chat_name.clone(),
5267 secret.to_string(),

Callers 1

execute_sync_itemsMethod · 0.80

Calls 15

set_blockedFunction · 0.85
create_out_broadcast_exFunction · 0.85
create_group_exFunction · 0.85
get_chat_id_by_grpidFunction · 0.85
get_by_rfc724_midsFunction · 0.85
set_muted_exFunction · 0.85
rename_exFunction · 0.85
set_chat_description_exFunction · 0.85
set_contacts_by_addrsFunction · 0.85
set_name_exMethod · 0.80
cloneMethod · 0.80

Tested by

no test coverage detected