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

Method send_sync_msg

src/sync.rs:224–245  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 10

cmdlineFunction · 0.80
send_smtp_messagesFunction · 0.80
syncFunction · 0.80
test_send_sync_msgFunction · 0.80
test_bot_no_sync_msgsFunction · 0.80

Calls 7

sync_msg_bodyFunction · 0.85
sync_msg_subjectFunction · 0.85
send_msgFunction · 0.85
build_sync_jsonMethod · 0.80
set_cmdMethod · 0.80
set_intMethod · 0.80
setMethod · 0.45

Tested by 8

syncFunction · 0.64
test_send_sync_msgFunction · 0.64
test_bot_no_sync_msgsFunction · 0.64