Sends a `SyncAction` synchronising chat contacts to other devices.
(&self, context: &Context)
| 2026 | |
| 2027 | /// Sends a `SyncAction` synchronising chat contacts to other devices. |
| 2028 | pub(crate) async fn sync_contacts(&self, context: &Context) -> Result<()> { |
| 2029 | if self.is_encrypted(context).await? { |
| 2030 | let self_fp = self_fingerprint(context).await?; |
| 2031 | let fingerprint_addrs = context |
| 2032 | .sql |
| 2033 | .query_map_vec( |
| 2034 | "SELECT c.id, c.fingerprint, c.addr |
| 2035 | FROM contacts c INNER JOIN chats_contacts cc |
| 2036 | ON c.id=cc.contact_id |
| 2037 | WHERE cc.chat_id=? AND cc.add_timestamp >= cc.remove_timestamp", |
| 2038 | (self.id,), |
| 2039 | |row| { |
| 2040 | if row.get::<_, ContactId>(0)? == ContactId::SELF { |
| 2041 | return Ok((self_fp.to_string(), String::new())); |
| 2042 | } |
| 2043 | let fingerprint = row.get(1)?; |
| 2044 | let addr = row.get(2)?; |
| 2045 | Ok((fingerprint, addr)) |
| 2046 | }, |
| 2047 | ) |
| 2048 | .await?; |
| 2049 | self.sync(context, SyncAction::SetPgpContacts(fingerprint_addrs)) |
| 2050 | .await?; |
| 2051 | } else { |
| 2052 | let addrs = context |
| 2053 | .sql |
| 2054 | .query_map_vec( |
| 2055 | "SELECT c.addr \ |
| 2056 | FROM contacts c INNER JOIN chats_contacts cc \ |
| 2057 | ON c.id=cc.contact_id \ |
| 2058 | WHERE cc.chat_id=? AND cc.add_timestamp >= cc.remove_timestamp", |
| 2059 | (self.id,), |
| 2060 | |row| { |
| 2061 | let addr: String = row.get(0)?; |
| 2062 | Ok(addr) |
| 2063 | }, |
| 2064 | ) |
| 2065 | .await?; |
| 2066 | self.sync(context, SyncAction::SetContacts(addrs)).await?; |
| 2067 | } |
| 2068 | Ok(()) |
| 2069 | } |
| 2070 | |
| 2071 | /// Returns chat id for the purpose of synchronisation across devices. |
| 2072 | async fn get_sync_id(&self, context: &Context) -> Result<Option<SyncId>> { |
no test coverage detected