diff --git a/src/chat.rs b/src/chat.rs index 2101fc221..f0f3d0e6d 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1114,7 +1114,7 @@ pub fn create_by_contact_id(context: &Context, contact_id: u32) -> Result Result<(), Error> { +pub(crate) fn update_saved_messages_icon(context: &Context) -> Result<(), Error> { // if there is no saved-messages chat, there is nothing to update. this is no error. if let Ok((chat_id, _)) = lookup_by_contact_id(context, DC_CONTACT_ID_SELF) { let icon = include_bytes!("../assets/icon-saved-messages.png"); @@ -1128,7 +1128,7 @@ pub fn update_saved_messages_icon(context: &Context) -> Result<(), Error> { Ok(()) } -pub fn update_device_icon(context: &Context) -> Result<(), Error> { +pub(crate) fn update_device_icon(context: &Context) -> Result<(), Error> { // if there is no device-chat, there is nothing to update. this is no error. if let Ok((chat_id, _)) = lookup_by_contact_id(context, DC_CONTACT_ID_DEVICE) { let icon = include_bytes!("../assets/icon-device.png"); @@ -1162,13 +1162,13 @@ fn update_special_chat_name( Ok(()) } -pub fn update_special_chat_names(context: &Context) -> Result<(), Error> { +pub(crate) fn update_special_chat_names(context: &Context) -> Result<(), Error> { update_special_chat_name(context, DC_CONTACT_ID_DEVICE, StockMessage::DeviceMessages)?; update_special_chat_name(context, DC_CONTACT_ID_SELF, StockMessage::SavedMessages)?; Ok(()) } -pub fn create_or_lookup_by_contact_id( +pub(crate) fn create_or_lookup_by_contact_id( context: &Context, contact_id: u32, create_blocked: Blocked, @@ -1219,7 +1219,7 @@ pub fn create_or_lookup_by_contact_id( lookup_by_contact_id(context, contact_id) } -pub fn lookup_by_contact_id( +pub(crate) fn lookup_by_contact_id( context: &Context, contact_id: u32, ) -> Result<(ChatId, Blocked), Error> { @@ -1273,7 +1273,7 @@ pub fn prepare_msg<'a>( Ok(msg_id) } -pub fn msgtype_has_file(msgtype: Viewtype) -> bool { +pub(crate) fn msgtype_has_file(msgtype: Viewtype) -> bool { match msgtype { Viewtype::Unknown => false, Viewtype::Text => false, @@ -1750,7 +1750,11 @@ pub fn create_group_chat( Ok(chat_id) } -pub fn add_to_chat_contacts_table(context: &Context, chat_id: ChatId, contact_id: u32) -> bool { +pub(crate) fn add_to_chat_contacts_table( + context: &Context, + chat_id: ChatId, + contact_id: u32, +) -> bool { // add a contact to a chat; the function does not check the type or if any of the record exist or are already // added to the chat! sql::execute( @@ -1762,7 +1766,7 @@ pub fn add_to_chat_contacts_table(context: &Context, chat_id: ChatId, contact_id .is_ok() } -pub fn remove_from_chat_contacts_table( +pub(crate) fn remove_from_chat_contacts_table( context: &Context, chat_id: ChatId, contact_id: u32, @@ -1898,7 +1902,7 @@ fn real_group_exists(context: &Context, chat_id: ChatId) -> bool { .unwrap_or_default() } -pub fn reset_gossiped_timestamp(context: &Context, chat_id: ChatId) -> Result<(), Error> { +pub(crate) fn reset_gossiped_timestamp(context: &Context, chat_id: ChatId) -> Result<(), Error> { set_gossiped_timestamp(context, chat_id, 0) } @@ -1915,7 +1919,7 @@ pub fn get_gossiped_timestamp(context: &Context, chat_id: ChatId) -> i64 { .unwrap_or_default() } -pub fn set_gossiped_timestamp( +pub(crate) fn set_gossiped_timestamp( context: &Context, chat_id: ChatId, timestamp: i64, @@ -1935,7 +1939,7 @@ pub fn set_gossiped_timestamp( Ok(()) } -pub fn shall_attach_selfavatar(context: &Context, chat_id: ChatId) -> Result { +pub(crate) fn shall_attach_selfavatar(context: &Context, chat_id: ChatId) -> Result { // versions before 12/2019 already allowed to set selfavatar, however, it was never sent to others. // to avoid sending out previously set selfavatars unexpectedly we added this additional check. // it can be removed after some time. @@ -2117,7 +2121,10 @@ fn set_group_explicitly_left(context: &Context, grpid: impl AsRef) -> Resul Ok(()) } -pub fn is_group_explicitly_left(context: &Context, grpid: impl AsRef) -> Result { +pub(crate) fn is_group_explicitly_left( + context: &Context, + grpid: impl AsRef, +) -> Result { context .sql .exists( @@ -2339,7 +2346,7 @@ pub fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId) -> Re Ok(()) } -pub fn get_chat_contact_cnt(context: &Context, chat_id: ChatId) -> usize { +pub(crate) fn get_chat_contact_cnt(context: &Context, chat_id: ChatId) -> usize { context .sql .query_get_value::<_, isize>( @@ -2350,7 +2357,7 @@ pub fn get_chat_contact_cnt(context: &Context, chat_id: ChatId) -> usize { .unwrap_or_default() as usize } -pub fn get_chat_cnt(context: &Context) -> usize { +pub(crate) fn get_chat_cnt(context: &Context) -> usize { if context.sql.is_open() { /* no database, no chats - this is no error (needed eg. for information) */ context @@ -2465,7 +2472,7 @@ pub fn was_device_msg_ever_added(context: &Context, label: &str) -> Result Result<(), Error> { +pub(crate) fn delete_and_reset_all_device_msgs(context: &Context) -> Result<(), Error> { context.sql.execute( "DELETE FROM msgs WHERE from_id=?;", params![DC_CONTACT_ID_DEVICE], @@ -2479,7 +2486,7 @@ pub fn delete_and_reset_all_device_msgs(context: &Context) -> Result<(), Error> /// Adds an informational message to chat. /// /// For example, it can be a message showing that a member was added to a group. -pub fn add_info_msg(context: &Context, chat_id: ChatId, text: impl AsRef) { +pub(crate) fn add_info_msg(context: &Context, chat_id: ChatId, text: impl AsRef) { let rfc724_mid = dc_create_outgoing_rfc724_mid(None, "@device"); if context.sql.execute( diff --git a/src/contact.rs b/src/contact.rs index 63197ab79..a2f493f9c 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -146,7 +146,7 @@ impl Origin { } #[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub enum Modifier { +pub(crate) enum Modifier { None, Modified, Created, @@ -324,7 +324,7 @@ impl Contact { /// Depending on the origin, both, "row_name" and "row_authname" are updated from "name". /// /// Returns the contact_id and a `Modifier` value indicating if a modification occured. - pub fn add_or_lookup( + pub(crate) fn add_or_lookup( context: &Context, name: impl AsRef, addr: impl AsRef, @@ -1019,7 +1019,7 @@ fn set_block_contact(context: &Context, contact_id: u32, new_blocking: bool) { } } -pub fn set_profile_image( +pub(crate) fn set_profile_image( context: &Context, contact_id: u32, profile_image: &AvatarAction, diff --git a/src/context.rs b/src/context.rs index c7ae9b63d..a037e7a7f 100644 --- a/src/context.rs +++ b/src/context.rs @@ -51,7 +51,7 @@ pub struct Context { cb: Box, pub os_name: Option, pub cmdline_sel_chat_id: Arc>, - pub bob: Arc>, + pub(crate) bob: Arc>, pub last_smeared_timestamp: RwLock, pub running_state: Arc>, /// Mutex to avoid generating the key for the user more than once. @@ -478,14 +478,14 @@ impl Default for RunningState { } #[derive(Debug, Default)] -pub struct BobStatus { +pub(crate) struct BobStatus { pub expects: i32, pub status: i32, pub qr_scan: Option, } #[derive(Debug, PartialEq)] -pub enum PerformJobsNeeded { +pub(crate) enum PerformJobsNeeded { Not, AtOnce, AvoidDos, @@ -502,7 +502,7 @@ pub struct SmtpState { pub idle: bool, pub suspended: bool, pub doing_jobs: bool, - pub perform_jobs_needed: PerformJobsNeeded, + pub(crate) perform_jobs_needed: PerformJobsNeeded, pub probe_network: bool, } diff --git a/src/lib.rs b/src/lib.rs index dff1c8fcb..3bd459ad9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,7 @@ pub(crate) mod events; pub use events::*; mod aheader; -pub mod blob; +mod blob; pub mod chat; pub mod chatlist; pub mod config; @@ -42,7 +42,7 @@ pub mod imex; pub mod job; mod job_thread; pub mod key; -pub mod keyring; +mod keyring; pub mod location; mod login_param; pub mod lot; diff --git a/src/location.rs b/src/location.rs index 6bde075c4..4f8072278 100644 --- a/src/location.rs +++ b/src/location.rs @@ -364,6 +364,7 @@ fn is_marker(txt: &str) -> bool { txt.len() == 1 && !txt.starts_with(' ') } +/// Deletes all locations from the database. pub fn delete_all(context: &Context) -> Result<(), Error> { sql::execute(context, &context.sql, "DELETE FROM locations;", params![])?; context.call_cb(Event::LocationChanged(None)); @@ -547,7 +548,7 @@ pub fn save( } #[allow(non_snake_case)] -pub fn JobMaybeSendLocations(context: &Context, _job: &Job) -> job::Status { +pub(crate) fn JobMaybeSendLocations(context: &Context, _job: &Job) -> job::Status { let now = time(); let mut continue_streaming = false; info!( @@ -638,7 +639,7 @@ pub fn JobMaybeSendLocations(context: &Context, _job: &Job) -> job::Status { } #[allow(non_snake_case)] -pub fn JobMaybeSendLocationsEnded(context: &Context, job: &mut Job) -> job::Status { +pub(crate) fn JobMaybeSendLocationsEnded(context: &Context, job: &mut Job) -> job::Status { // this function is called when location-streaming _might_ have ended for a chat. // the function checks, if location-streaming is really ended; // if so, a device-message is added if not yet done. diff --git a/src/message.rs b/src/message.rs index 7ad619570..aba9b094c 100644 --- a/src/message.rs +++ b/src/message.rs @@ -161,7 +161,7 @@ pub struct InvalidMsgId; Deserialize, )] #[repr(u8)] -pub enum MessengerMessage { +pub(crate) enum MessengerMessage { No = 0, Yes = 1, diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 817360879..0a4e1bac7 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -46,26 +46,17 @@ pub struct MimeMessage { pub is_system_message: SystemMessage, pub location_kml: Option, pub message_kml: Option, - pub user_avatar: Option, - pub group_avatar: Option, + pub(crate) user_avatar: Option, + pub(crate) group_avatar: Option, pub(crate) reports: Vec, } #[derive(Debug, PartialEq)] -pub enum AvatarAction { +pub(crate) enum AvatarAction { Delete, Change(String), } -impl AvatarAction { - pub fn is_change(&self) -> bool { - match self { - AvatarAction::Delete => false, - AvatarAction::Change(_) => true, - } - } -} - #[derive(Debug, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, ToSql, FromSql)] #[repr(i32)] pub enum SystemMessage { @@ -1094,6 +1085,15 @@ mod tests { use super::*; use crate::test_utils::*; + impl AvatarAction { + pub fn is_change(&self) -> bool { + match self { + AvatarAction::Delete => false, + AvatarAction::Change(_) => true, + } + } + } + #[test] fn test_dc_mimeparser_crash() { let context = dummy_context(); diff --git a/src/provider/mod.rs b/src/provider/mod.rs index a52a41905..7f7174774 100644 --- a/src/provider/mod.rs +++ b/src/provider/mod.rs @@ -1,3 +1,5 @@ +//! [Provider database](https://providers.delta.chat/) module + mod data; use crate::dc_tools::EmailAddress;