Returns chat id for the purpose of synchronisation across devices.
(&self, context: &Context)
| 2070 | |
| 2071 | /// Returns chat id for the purpose of synchronisation across devices. |
| 2072 | async fn get_sync_id(&self, context: &Context) -> Result<Option<SyncId>> { |
| 2073 | match self.typ { |
| 2074 | Chattype::Single => { |
| 2075 | if self.is_device_talk() { |
| 2076 | return Ok(Some(SyncId::Device)); |
| 2077 | } |
| 2078 | |
| 2079 | let mut r = None; |
| 2080 | for contact_id in get_chat_contacts(context, self.id).await? { |
| 2081 | if contact_id == ContactId::SELF && !self.is_self_talk() { |
| 2082 | continue; |
| 2083 | } |
| 2084 | if r.is_some() { |
| 2085 | return Ok(None); |
| 2086 | } |
| 2087 | let contact = Contact::get_by_id(context, contact_id).await?; |
| 2088 | if let Some(fingerprint) = contact.fingerprint() { |
| 2089 | r = Some(SyncId::ContactFingerprint(fingerprint.hex())); |
| 2090 | } else { |
| 2091 | r = Some(SyncId::ContactAddr(contact.get_addr().to_string())); |
| 2092 | } |
| 2093 | } |
| 2094 | Ok(r) |
| 2095 | } |
| 2096 | Chattype::OutBroadcast |
| 2097 | | Chattype::InBroadcast |
| 2098 | | Chattype::Group |
| 2099 | | Chattype::Mailinglist => { |
| 2100 | if !self.grpid.is_empty() { |
| 2101 | return Ok(Some(SyncId::Grpid(self.grpid.clone()))); |
| 2102 | } |
| 2103 | |
| 2104 | let Some((parent_rfc724_mid, parent_in_reply_to, _)) = self |
| 2105 | .id |
| 2106 | .get_parent_mime_headers(context, MessageState::OutDelivered) |
| 2107 | .await? |
| 2108 | else { |
| 2109 | warn!( |
| 2110 | context, |
| 2111 | "Chat::get_sync_id({}): No good message identifying the chat found.", |
| 2112 | self.id |
| 2113 | ); |
| 2114 | return Ok(None); |
| 2115 | }; |
| 2116 | Ok(Some(SyncId::Msgids(vec![ |
| 2117 | parent_in_reply_to, |
| 2118 | parent_rfc724_mid, |
| 2119 | ]))) |
| 2120 | } |
| 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | /// Synchronises a chat action to other devices. |
| 2125 | pub(crate) async fn sync(&self, context: &Context, action: SyncAction) -> Result<()> { |
no test coverage detected