Sends out a self-sent message with items to be synchronized, if any. Mustn't be called from multiple tasks in parallel to avoid sending the same sync items twice because sync items are removed from the db only after successful sending. We guarantee this by calling `send_sync_msg()` only from the inbox loop.
(&self)
| 222 | /// because sync items are removed from the db only after successful sending. We guarantee this |
| 223 | /// by calling `send_sync_msg()` only from the inbox loop. |
| 224 | pub async fn send_sync_msg(&self) -> Result<Option<MsgId>> { |
| 225 | if let Some((json, ids)) = self.build_sync_json().await? { |
| 226 | let chat_id = |
| 227 | ChatId::create_for_contact_with_blocked(self, ContactId::SELF, Blocked::Yes) |
| 228 | .await?; |
| 229 | let mut msg = Message { |
| 230 | chat_id, |
| 231 | viewtype: Viewtype::Text, |
| 232 | text: stock_str::sync_msg_body(self), |
| 233 | hidden: true, |
| 234 | subject: stock_str::sync_msg_subject(self), |
| 235 | ..Default::default() |
| 236 | }; |
| 237 | msg.param.set_cmd(SystemMessage::MultiDeviceSync); |
| 238 | msg.param.set(Param::Arg, json); |
| 239 | msg.param.set(Param::Arg2, ids); |
| 240 | msg.param.set_int(Param::GuaranteeE2ee, 1); |
| 241 | Ok(Some(chat::send_msg(self, chat_id, &mut msg).await?)) |
| 242 | } else { |
| 243 | Ok(None) |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /// Copies all sync items to a JSON string and clears the sync-table. |
| 248 | /// Returns the JSON string and a comma-separated string of the IDs used. |