Executes [`SyncData::AlterChat`] item sent by other device.
(&self, id: &SyncId, action: &SyncAction)
| 5208 | impl 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(), |
no test coverage detected