handling incoming protection-changes messages, always add info-msg

This commit is contained in:
B. Petersen
2020-10-04 17:28:21 +02:00
parent d240bbcd07
commit 12cf89735c
3 changed files with 45 additions and 15 deletions

View File

@@ -181,7 +181,6 @@ impl ChatId {
self,
context: &Context,
protect: ProtectionStatus,
send_to_others: bool,
) -> Result<(), Error> {
ensure!(!self.is_special(), "set protection: invalid chat-id.");
@@ -224,7 +223,16 @@ impl ChatId {
// make sure, the receivers will get all keys
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
.stock_system_msg(
match protect {
@@ -236,7 +244,8 @@ impl ChatId {
DC_CONTACT_ID_SELF as u32,
)
.await;
if send_to_others {
if promote {
let mut msg = Message::default();
msg.viewtype = Viewtype::Text;
msg.text = Some(msg_text);
@@ -261,16 +270,12 @@ impl ChatId {
let chat = Chat::load_from_db(context, self).await?;
match self
.inner_set_protection(context, protect, chat.is_promoted())
.await
{
Ok(()) => Ok(()),
Err(err) => {
error!(context, "{}", err); // make error user-visible
Err(err)
}
if let Err(e) = self.inner_set_protection(context, protect).await {
error!(context, "{}", e); // make error user-visible
return Err(e);
}
self.add_protection_msg(context, protect, chat.is_promoted()).await
}
/// Archives or unarchives a chat.
@@ -2030,9 +2035,7 @@ pub async fn create_group_chat(
});
if protect == ProtectionStatus::Protected {
chat_id
.inner_set_protection(context, protect, false)
.await?;
chat_id.set_protection(context, protect).await?;
}
Ok(chat_id)

View File

@@ -714,6 +714,17 @@ async fn add_parts(
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,
// however, we cannot do this earlier as we need from_id to be set
let in_fresh = state == MessageState::InFresh;
@@ -1227,6 +1238,10 @@ async fn create_or_lookup_group(
.await;
chat_id_blocked = create_blocked;
recreate_member_list = true;
if create_protected == ProtectionStatus::Protected {
chat_id.add_protection_msg(context, ProtectionStatus::Protected, false).await?;
}
}
// 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 {
info!(context, "group-avatar change for {}", chat_id);
if let Ok(mut chat) = Chat::load_from_db(context, chat_id).await {

View File

@@ -257,6 +257,10 @@ impl MimeMessage {
self.is_system_message = SystemMessage::LocationStreamingEnabled;
} else if value == "ephemeral-timer-changed" {
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(())