mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 06:46:32 +03:00
add multi-device sync (#2669)
* add basic multi-device-sync functions * generate json * add context.parse_sync_items() * add context.execute_sync_items() * piggyback sync-commands message, add body for human-readable part * avoid double json renderings * mimeparser parses incoming .json sync-files * do not piggyback sync-files * execute sync items * return status of send_sync_msg() * send sync messages as multipart/report * add a per-item-timestamp and also allow adding other per-item-fields in the future * if the self-chat does not exist, create it blocked/hidden * create tokens closer to real qr-code needs * respect bcc_self setting, add test for that * sync qr code tokens after promoting groups * send sync-messages only if an experimental switch is set * trigger send_sync_msg() after sending messages and after creating/redraw/revive qr-code * add DC_STR_* constants to deltachat.h * adapt to refactored qr module as of #2729 * tweak test * use SendSyncMsgs config name instead of SendExperimentalSyncMsgs - we can remove or rename the config nevertheless, but have the option to keep it without renaming * tweak docs * remove currently unused effective timestamp calculation * clarify when send_sync_msg() is called * make sure, sync-messages are encrypted and are sent by SELF * tweak docs, fix typos
This commit is contained in:
@@ -233,6 +233,20 @@ pub(crate) async fn dc_receive_imf_inner(
|
||||
.await;
|
||||
}
|
||||
|
||||
if let Some(ref sync_items) = mime_parser.sync_items {
|
||||
if from_id == DC_CONTACT_ID_SELF {
|
||||
if mime_parser.was_encrypted() {
|
||||
if let Err(err) = context.execute_sync_items(sync_items).await {
|
||||
warn!(context, "receive_imf cannot execute sync items: {}", err);
|
||||
}
|
||||
} else {
|
||||
warn!(context, "sync items are not encrypted.");
|
||||
}
|
||||
} else {
|
||||
warn!(context, "sync items not sent by self.");
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(avatar_action) = &mime_parser.user_avatar {
|
||||
if from_id != 0
|
||||
&& context
|
||||
@@ -692,6 +706,10 @@ async fn add_parts(
|
||||
state = MessageState::OutDelivered;
|
||||
to_id = to_ids.get_index(0).cloned().unwrap_or_default();
|
||||
|
||||
let self_sent = from_id == DC_CONTACT_ID_SELF
|
||||
&& to_ids.len() == 1
|
||||
&& to_ids.contains(&DC_CONTACT_ID_SELF);
|
||||
|
||||
// handshake may mark contacts as verified and must be processed before chats are created
|
||||
if mime_parser.get_header(HeaderDef::SecureJoin).is_some() {
|
||||
is_dc_message = MessengerMessage::Yes; // avoid discarding by show_emails setting
|
||||
@@ -710,6 +728,10 @@ async fn add_parts(
|
||||
return Ok(DC_CHAT_ID_TRASH);
|
||||
}
|
||||
}
|
||||
} else if mime_parser.sync_items.is_some() && self_sent {
|
||||
is_dc_message = MessengerMessage::Yes;
|
||||
allow_creation = true;
|
||||
*hidden = true;
|
||||
}
|
||||
|
||||
// If the message is outgoing AND there is no Received header AND it's not in the sentbox,
|
||||
@@ -775,7 +797,11 @@ async fn add_parts(
|
||||
}
|
||||
if chat_id.is_none() && allow_creation {
|
||||
let create_blocked = if !Contact::is_blocked_load(context, to_id).await? {
|
||||
Blocked::Not
|
||||
if self_sent && *hidden {
|
||||
Blocked::Manually
|
||||
} else {
|
||||
Blocked::Not
|
||||
}
|
||||
} else {
|
||||
Blocked::Request
|
||||
};
|
||||
@@ -794,9 +820,6 @@ async fn add_parts(
|
||||
}
|
||||
}
|
||||
}
|
||||
let self_sent = from_id == DC_CONTACT_ID_SELF
|
||||
&& to_ids.len() == 1
|
||||
&& to_ids.contains(&DC_CONTACT_ID_SELF);
|
||||
|
||||
if chat_id.is_none() && self_sent {
|
||||
// from_id==to_id==DC_CONTACT_ID_SELF - this is a self-sent messages,
|
||||
|
||||
Reference in New Issue
Block a user