diff --git a/src/chat.rs b/src/chat.rs
index 4fba6b61f..f973b8bd3 100644
--- a/src/chat.rs
+++ b/src/chat.rs
@@ -38,6 +38,7 @@ use crate::scheduler::InterruptInfo;
use crate::smtp::send_msg_to_smtp;
use crate::sql;
use crate::stock_str;
+use crate::sync::{self, ChatAction, SyncData};
use crate::tools::{
buf_compress, create_id, create_outgoing_rfc724_mid, create_smeared_timestamp,
create_smeared_timestamps, get_abs_path, gm2local_offset, improve_single_line_input,
@@ -250,7 +251,7 @@ impl ChatId {
let chat_id = match ChatIdBlocked::lookup_by_contact(context, contact_id).await? {
Some(chat) => {
if create_blocked == Blocked::Not && chat.blocked != Blocked::Not {
- chat.id.unblock(context).await?;
+ chat.id.unblock(&context.nosync()).await?;
}
chat.id
}
@@ -356,6 +357,7 @@ impl ChatId {
/// Blocks the chat as a result of explicit user action.
pub async fn block(self, context: &Context) -> Result<()> {
+ let (context, nosync) = &context.unwrap_nosync();
let chat = Chat::load_from_db(context, self).await?;
match chat.typ {
@@ -384,12 +386,22 @@ impl ChatId {
}
}
+ if !nosync {
+ chat.add_sync_item(context, ChatAction::Block).await?;
+ }
Ok(())
}
/// Unblocks the chat.
pub async fn unblock(self, context: &Context) -> Result<()> {
+ let (context, nosync) = &context.unwrap_nosync();
+
self.set_blocked(context, Blocked::Not).await?;
+
+ if !nosync {
+ let chat = Chat::load_from_db(context, self).await?;
+ chat.add_sync_item(context, ChatAction::Unblock).await?;
+ }
Ok(())
}
@@ -397,6 +409,7 @@ impl ChatId {
///
/// Unblocks the chat and scales up origin of contacts.
pub async fn accept(self, context: &Context) -> Result<()> {
+ let (context, nosync) = &context.unwrap_nosync();
let chat = Chat::load_from_db(context, self).await?;
match chat.typ {
@@ -431,6 +444,9 @@ impl ChatId {
context.emit_event(EventType::ChatModified(self));
}
+ if !nosync {
+ chat.add_sync_item(context, ChatAction::Accept).await?;
+ }
Ok(())
}
@@ -1269,7 +1285,8 @@ pub struct Chat {
/// Whether the chat is archived or pinned.
pub visibility: ChatVisibility,
- /// Group ID.
+ /// Group ID. For [`Chattype::Mailinglist`] -- mailing list address. Empty for 1:1 chats and
+ /// ad-hoc groups.
pub grpid: String,
/// Whether the chat is blocked, unblocked or a contact request.
@@ -1826,6 +1843,42 @@ impl Chat {
context.scheduler.interrupt_ephemeral_task().await;
Ok(msg.id)
}
+
+ /// Returns chat id for the purpose of synchronisation across devices.
+ async fn get_sync_id(&self, context: &Context) -> Result