mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 23:06:32 +03:00
move get_protection_msg() to stock.rs as stock_protection_msg()
This commit is contained in:
22
src/chat.rs
22
src/chat.rs
@@ -224,26 +224,6 @@ impl ChatId {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a stock message saying that protection status has changed.
|
|
||||||
pub(crate) async fn get_protection_msg(
|
|
||||||
self,
|
|
||||||
context: &Context,
|
|
||||||
protect: ProtectionStatus,
|
|
||||||
from_id: u32,
|
|
||||||
) -> String {
|
|
||||||
context
|
|
||||||
.stock_system_msg(
|
|
||||||
match protect {
|
|
||||||
ProtectionStatus::Protected => StockMessage::ProtectionEnabled,
|
|
||||||
ProtectionStatus::Unprotected => StockMessage::ProtectionDisabled,
|
|
||||||
},
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
from_id,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Send protected status message to the chat.
|
/// Send protected status message to the chat.
|
||||||
///
|
///
|
||||||
/// This sends the message with the protected status change to the chat,
|
/// This sends the message with the protected status change to the chat,
|
||||||
@@ -258,7 +238,7 @@ impl ChatId {
|
|||||||
promoted: bool,
|
promoted: bool,
|
||||||
from_id: u32,
|
from_id: u32,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let msg_text = self.get_protection_msg(context, protect, from_id).await;
|
let msg_text = context.stock_protection_msg(protect, from_id).await;
|
||||||
|
|
||||||
if promoted {
|
if promoted {
|
||||||
let mut msg = Message::default();
|
let mut msg = Message::default();
|
||||||
|
|||||||
@@ -721,8 +721,8 @@ async fn add_parts(
|
|||||||
.await?;
|
.await?;
|
||||||
set_better_msg(
|
set_better_msg(
|
||||||
mime_parser,
|
mime_parser,
|
||||||
chat_id
|
context
|
||||||
.get_protection_msg(context, ProtectionStatus::Protected, from_id)
|
.stock_protection_msg(ProtectionStatus::Protected, from_id)
|
||||||
.await,
|
.await,
|
||||||
);
|
);
|
||||||
} else if mime_parser.is_system_message == SystemMessage::ChatProtectionDisabled {
|
} else if mime_parser.is_system_message == SystemMessage::ChatProtectionDisabled {
|
||||||
@@ -731,8 +731,8 @@ async fn add_parts(
|
|||||||
.await?;
|
.await?;
|
||||||
set_better_msg(
|
set_better_msg(
|
||||||
mime_parser,
|
mime_parser,
|
||||||
chat_id
|
context
|
||||||
.get_protection_msg(context, ProtectionStatus::Unprotected, from_id)
|
.stock_protection_msg(ProtectionStatus::Unprotected, from_id)
|
||||||
.await,
|
.await,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/stock.rs
15
src/stock.rs
@@ -7,6 +7,7 @@ use strum_macros::EnumProperty;
|
|||||||
|
|
||||||
use crate::blob::BlobObject;
|
use crate::blob::BlobObject;
|
||||||
use crate::chat;
|
use crate::chat;
|
||||||
|
use crate::chat::ProtectionStatus;
|
||||||
use crate::constants::{Viewtype, DC_CONTACT_ID_SELF};
|
use crate::constants::{Viewtype, DC_CONTACT_ID_SELF};
|
||||||
use crate::contact::*;
|
use crate::contact::*;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
@@ -404,6 +405,20 @@ impl Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a stock message saying that protection status has changed.
|
||||||
|
pub async fn stock_protection_msg(&self, protect: ProtectionStatus, from_id: u32) -> String {
|
||||||
|
self.stock_system_msg(
|
||||||
|
match protect {
|
||||||
|
ProtectionStatus::Protected => StockMessage::ProtectionEnabled,
|
||||||
|
ProtectionStatus::Unprotected => StockMessage::ProtectionDisabled,
|
||||||
|
},
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
from_id,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update_device_chats(&self) -> Result<(), Error> {
|
pub async fn update_device_chats(&self) -> Result<(), Error> {
|
||||||
// check for the LAST added device message - if it is present, we can skip message creation.
|
// check for the LAST added device message - if it is present, we can skip message creation.
|
||||||
// this is worthwhile as this function is typically called
|
// this is worthwhile as this function is typically called
|
||||||
|
|||||||
Reference in New Issue
Block a user