mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
handling incoming protection-changes messages, always add info-msg
This commit is contained in:
33
src/chat.rs
33
src/chat.rs
@@ -181,7 +181,6 @@ impl ChatId {
|
|||||||
self,
|
self,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
protect: ProtectionStatus,
|
protect: ProtectionStatus,
|
||||||
send_to_others: bool,
|
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
ensure!(!self.is_special(), "set protection: invalid chat-id.");
|
ensure!(!self.is_special(), "set protection: invalid chat-id.");
|
||||||
|
|
||||||
@@ -224,7 +223,16 @@ impl ChatId {
|
|||||||
// make sure, the receivers will get all keys
|
// make sure, the receivers will get all keys
|
||||||
reset_gossiped_timestamp(context, self).await?;
|
reset_gossiped_timestamp(context, self).await?;
|
||||||
|
|
||||||
// add info message
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
// adds or sends out a protection-info-message
|
||||||
|
pub(crate) async fn add_protection_msg(
|
||||||
|
self,
|
||||||
|
context: &Context,
|
||||||
|
protect: ProtectionStatus,
|
||||||
|
promote: bool,
|
||||||
|
) -> Result<(), Error> {
|
||||||
let msg_text = context
|
let msg_text = context
|
||||||
.stock_system_msg(
|
.stock_system_msg(
|
||||||
match protect {
|
match protect {
|
||||||
@@ -236,7 +244,8 @@ impl ChatId {
|
|||||||
DC_CONTACT_ID_SELF as u32,
|
DC_CONTACT_ID_SELF as u32,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
if send_to_others {
|
|
||||||
|
if promote {
|
||||||
let mut msg = Message::default();
|
let mut msg = Message::default();
|
||||||
msg.viewtype = Viewtype::Text;
|
msg.viewtype = Viewtype::Text;
|
||||||
msg.text = Some(msg_text);
|
msg.text = Some(msg_text);
|
||||||
@@ -261,16 +270,12 @@ impl ChatId {
|
|||||||
|
|
||||||
let chat = Chat::load_from_db(context, self).await?;
|
let chat = Chat::load_from_db(context, self).await?;
|
||||||
|
|
||||||
match self
|
if let Err(e) = self.inner_set_protection(context, protect).await {
|
||||||
.inner_set_protection(context, protect, chat.is_promoted())
|
error!(context, "{}", e); // make error user-visible
|
||||||
.await
|
return Err(e);
|
||||||
{
|
|
||||||
Ok(()) => Ok(()),
|
|
||||||
Err(err) => {
|
|
||||||
error!(context, "{}", err); // make error user-visible
|
|
||||||
Err(err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.add_protection_msg(context, protect, chat.is_promoted()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Archives or unarchives a chat.
|
/// Archives or unarchives a chat.
|
||||||
@@ -2030,9 +2035,7 @@ pub async fn create_group_chat(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if protect == ProtectionStatus::Protected {
|
if protect == ProtectionStatus::Protected {
|
||||||
chat_id
|
chat_id.set_protection(context, protect).await?;
|
||||||
.inner_set_protection(context, protect, false)
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(chat_id)
|
Ok(chat_id)
|
||||||
|
|||||||
@@ -714,6 +714,17 @@ async fn add_parts(
|
|||||||
ephemeral_timer = EphemeralTimer::Disabled;
|
ephemeral_timer = EphemeralTimer::Disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// change chat protection
|
||||||
|
if mime_parser.is_system_message == SystemMessage::ChatProtectionEnabled {
|
||||||
|
chat_id
|
||||||
|
.inner_set_protection(context, ProtectionStatus::Protected)
|
||||||
|
.await?;
|
||||||
|
} else if mime_parser.is_system_message == SystemMessage::ChatProtectionDisabled {
|
||||||
|
chat_id
|
||||||
|
.inner_set_protection(context, ProtectionStatus::Unprotected)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
// correct message_timestamp, it should not be used before,
|
// correct message_timestamp, it should not be used before,
|
||||||
// however, we cannot do this earlier as we need from_id to be set
|
// however, we cannot do this earlier as we need from_id to be set
|
||||||
let in_fresh = state == MessageState::InFresh;
|
let in_fresh = state == MessageState::InFresh;
|
||||||
@@ -1227,6 +1238,10 @@ async fn create_or_lookup_group(
|
|||||||
.await;
|
.await;
|
||||||
chat_id_blocked = create_blocked;
|
chat_id_blocked = create_blocked;
|
||||||
recreate_member_list = true;
|
recreate_member_list = true;
|
||||||
|
|
||||||
|
if create_protected == ProtectionStatus::Protected {
|
||||||
|
chat_id.add_protection_msg(context, ProtectionStatus::Protected, false).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// again, check chat_id
|
// again, check chat_id
|
||||||
@@ -1278,7 +1293,15 @@ async fn create_or_lookup_group(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if mime_parser.is_system_message == SystemMessage::ChatProtectionEnabled {
|
||||||
|
recreate_member_list = true;
|
||||||
|
if let Err(e) = check_verified_properties(context, mime_parser, from_id, to_ids).await {
|
||||||
|
warn!(context, "checking verified properties failed: {}", e);
|
||||||
|
let s = format!("{}. See 'Info' for more details", e);
|
||||||
|
mime_parser.repl_msg_by_error(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(avatar_action) = &mime_parser.group_avatar {
|
if let Some(avatar_action) = &mime_parser.group_avatar {
|
||||||
info!(context, "group-avatar change for {}", chat_id);
|
info!(context, "group-avatar change for {}", chat_id);
|
||||||
if let Ok(mut chat) = Chat::load_from_db(context, chat_id).await {
|
if let Ok(mut chat) = Chat::load_from_db(context, chat_id).await {
|
||||||
|
|||||||
@@ -257,6 +257,10 @@ impl MimeMessage {
|
|||||||
self.is_system_message = SystemMessage::LocationStreamingEnabled;
|
self.is_system_message = SystemMessage::LocationStreamingEnabled;
|
||||||
} else if value == "ephemeral-timer-changed" {
|
} else if value == "ephemeral-timer-changed" {
|
||||||
self.is_system_message = SystemMessage::EphemeralTimerChanged;
|
self.is_system_message = SystemMessage::EphemeralTimerChanged;
|
||||||
|
} else if value == "protection-enabled" {
|
||||||
|
self.is_system_message = SystemMessage::ChatProtectionEnabled;
|
||||||
|
} else if value == "protection-disabled" {
|
||||||
|
self.is_system_message = SystemMessage::ChatProtectionDisabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user