diff --git a/src/chat.rs b/src/chat.rs index 3e0b0958a..c88e9f984 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -468,7 +468,7 @@ impl<'a> Chat<'a> { VALUES (?,?,?, ?,?,1);", params![ timestamp, - DC_CONTACT_ID_SELF as i32, + DC_CONTACT_ID_SELF, self.id as i32, msg.param.get_float(Param::SetLatitude).unwrap_or_default(), msg.param.get_float(Param::SetLongitude).unwrap_or_default(), @@ -566,7 +566,7 @@ pub fn create_by_msg_id(context: &Context, msg_id: u32) -> Result { if let Ok(msg) = dc_msg_load_from_db(context, msg_id) { if let Ok(chat) = Chat::load_from_db(context, msg.chat_id) { - if chat.id > DC_CHAT_ID_LAST_SPECIAL as u32 { + if chat.id > DC_CHAT_ID_LAST_SPECIAL { chat_id = chat.id; if chat.blocked != Blocked::Not { unblock(context, chat.id); @@ -602,8 +602,7 @@ pub fn create_by_contact_id(context: &Context, contact_id: u32) -> Result { - if !Contact::real_exists_by_id(context, contact_id) - && contact_id != DC_CONTACT_ID_SELF as u32 + if !Contact::real_exists_by_id(context, contact_id) && contact_id != DC_CONTACT_ID_SELF { warn!( context, @@ -706,7 +705,7 @@ pub fn prepare_msg<'a>( msg: &mut Message<'a>, ) -> Result { ensure!( - chat_id > DC_CHAT_ID_LAST_SPECIAL as u32, + chat_id > DC_CHAT_ID_LAST_SPECIAL, "Cannot prepare message for special chat" ); @@ -884,7 +883,7 @@ pub unsafe fn send_msg<'a>( ); if msg.param.exists(Param::SetLatitude) { - context.call_cb(Event::LOCATION_CHANGED, DC_CONTACT_ID_SELF, 0); + context.call_cb(Event::LOCATION_CHANGED, DC_CONTACT_ID_SELF as usize, 0); } if 0 == chat_id { @@ -916,7 +915,7 @@ pub unsafe fn send_text_msg( text_to_send: String, ) -> Result { ensure!( - chat_id > DC_CHAT_ID_LAST_SPECIAL as u32, + chat_id > DC_CHAT_ID_LAST_SPECIAL, "bad chat_id = {} <= 9", chat_id ); @@ -928,7 +927,7 @@ pub unsafe fn send_text_msg( // passing `None` as message jsut deletes the draft pub unsafe fn set_draft(context: &Context, chat_id: u32, msg: Option<&mut Message>) { - if chat_id <= DC_CHAT_ID_LAST_SPECIAL as u32 { + if chat_id <= DC_CHAT_ID_LAST_SPECIAL { return; } if set_draft_raw(context, chat_id, msg) { @@ -1006,7 +1005,7 @@ fn get_draft_msg_id(context: &Context, chat_id: u32) -> u32 { } pub unsafe fn get_draft(context: &Context, chat_id: u32) -> Result { - ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL as u32, "Invalid chat ID"); + ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat ID"); let draft_msg_id = get_draft_msg_id(context, chat_id); ensure!(draft_msg_id != 0, "Invalid draft message ID"); @@ -1024,13 +1023,13 @@ pub fn get_chat_msgs(context: &Context, chat_id: u32, flags: u32, marker1before: for row in rows { let (curr_id, ts) = row?; if curr_id as u32 == marker1before { - ret.push(DC_MSG_ID_MARKER1 as u32); + ret.push(DC_MSG_ID_MARKER1); } if 0 != flags & 0x1 { let curr_local_timestamp = ts + cnv_to_local; let curr_day = (curr_local_timestamp / 86400) as libc::c_int; if curr_day != last_day { - ret.push(DC_MSG_ID_LAST_SPECIAL as u32); + ret.push(DC_MSG_ID_LAST_SPECIAL); last_day = curr_day; } } @@ -1233,7 +1232,7 @@ pub unsafe fn get_next_media( pub fn archive(context: &Context, chat_id: u32, archive: bool) -> Result<(), Error> { ensure!( - chat_id > DC_CHAT_ID_LAST_SPECIAL as u32, + chat_id > DC_CHAT_ID_LAST_SPECIAL, "bad chat_id = {} <= 9", chat_id ); @@ -1265,7 +1264,7 @@ pub fn archive(context: &Context, chat_id: u32, archive: bool) -> Result<(), Err pub fn delete(context: &Context, chat_id: u32) -> Result<(), Error> { ensure!( - chat_id > DC_CHAT_ID_LAST_SPECIAL as u32, + chat_id > DC_CHAT_ID_LAST_SPECIAL, "bad chat_id = {} <= 9", chat_id ); @@ -1405,7 +1404,7 @@ pub unsafe fn add_contact_to_chat_ex( let mut success: libc::c_int = 0; let contact = Contact::get_by_id(context, contact_id); - if contact.is_err() || chat_id <= DC_CHAT_ID_LAST_SPECIAL as u32 { + if contact.is_err() || chat_id <= DC_CHAT_ID_LAST_SPECIAL { return 0; } let mut msg = dc_msg_new_untyped(context); @@ -1416,8 +1415,7 @@ pub unsafe fn add_contact_to_chat_ex( /*this also makes sure, not contacts are added to special or normal chats*/ if let Ok(mut chat) = Chat::load_from_db(context, chat_id) { if !(!real_group_exists(context, chat_id) - || !Contact::real_exists_by_id(context, contact_id) - && contact_id != DC_CONTACT_ID_SELF as u32) + || !Contact::real_exists_by_id(context, contact_id) && contact_id != DC_CONTACT_ID_SELF) { if !(is_contact_in_chat(context, chat_id, 1 as u32) == 1) { log_event!( @@ -1496,7 +1494,7 @@ pub unsafe fn add_contact_to_chat_ex( fn real_group_exists(context: &Context, chat_id: u32) -> bool { // check if a group or a verified group exists under the given ID - if !context.sql.is_open() || chat_id <= DC_CHAT_ID_LAST_SPECIAL as u32 { + if !context.sql.is_open() || chat_id <= DC_CHAT_ID_LAST_SPECIAL { return false; } @@ -1549,14 +1547,11 @@ pub unsafe fn remove_contact_from_chat( contact_id: u32, ) -> Result<(), Error> { ensure!( - chat_id > DC_CHAT_ID_LAST_SPECIAL as u32, + chat_id > DC_CHAT_ID_LAST_SPECIAL, "bad chat_id = {} <= 9", chat_id ); - ensure!( - contact_id != DC_CONTACT_ID_SELF as u32, - "Cannot remove self" - ); + ensure!(contact_id != DC_CONTACT_ID_SELF, "Cannot remove self"); let mut msg = dc_msg_new_untyped(context); let mut success = false; @@ -1577,20 +1572,20 @@ pub unsafe fn remove_contact_from_chat( if let Ok(contact) = Contact::get_by_id(context, contact_id) { if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 { msg.type_0 = Viewtype::Text; - if contact.id == DC_CONTACT_ID_SELF as u32 { + if contact.id == DC_CONTACT_ID_SELF { set_group_explicitly_left(context, chat.grpid).unwrap(); msg.text = Some(context.stock_system_msg( StockMessage::MsgGroupLeft, "", "", - DC_CONTACT_ID_SELF as u32, + DC_CONTACT_ID_SELF, )); } else { msg.text = Some(context.stock_system_msg( StockMessage::MsgDelMember, contact.get_addr(), "", - DC_CONTACT_ID_SELF as u32, + DC_CONTACT_ID_SELF, )); } msg.param.set_int(Param::Cmd, 5); @@ -1654,7 +1649,7 @@ pub unsafe fn set_chat_name( let mut success = false; ensure!(!new_name.as_ref().is_empty(), "Invalid name"); - ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL as u32, "Invalid chat ID"); + ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat ID"); let chat = Chat::load_from_db(context, chat_id)?; let mut msg = dc_msg_new_untyped(context); @@ -1689,7 +1684,7 @@ pub unsafe fn set_chat_name( StockMessage::MsgGrpName, &chat.name, new_name.as_ref(), - DC_CONTACT_ID_SELF as u32, + DC_CONTACT_ID_SELF, )); msg.param.set_int(Param::Cmd, 2); if !chat.name.is_empty() { @@ -1725,7 +1720,7 @@ pub unsafe fn set_chat_profile_image( chat_id: u32, new_image: impl AsRef, ) -> Result<(), Error> { - ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL as u32, "Invalid chat ID"); + ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat ID"); let mut OK_TO_CONTINUE = true; let mut success = false; @@ -1773,7 +1768,7 @@ pub unsafe fn set_chat_profile_image( }, "", "", - DC_CONTACT_ID_SELF as u32, + DC_CONTACT_ID_SELF, )); msg.id = send_msg(context, chat_id, &mut msg).unwrap_or_default(); context.call_cb( @@ -1805,7 +1800,7 @@ pub unsafe fn forward_msgs( msg_cnt: libc::c_int, chat_id: u32, ) { - if msg_ids.is_null() || msg_cnt <= 0 || chat_id <= DC_CHAT_ID_LAST_SPECIAL as u32 { + if msg_ids.is_null() || msg_cnt <= 0 || chat_id <= DC_CHAT_ID_LAST_SPECIAL { return; } @@ -1844,7 +1839,7 @@ pub unsafe fn forward_msgs( } let mut msg = msg.unwrap(); let original_param = msg.param.clone(); - if msg.from_id != DC_CONTACT_ID_SELF as u32 { + if msg.from_id != DC_CONTACT_ID_SELF { msg.param.set_int(Param::Forwarded, 1); } msg.param.remove(Param::GuranteeE2ee); diff --git a/src/chatlist.rs b/src/chatlist.rs index 0190b7de4..a3a130292 100644 --- a/src/chatlist.rs +++ b/src/chatlist.rs @@ -195,9 +195,9 @@ impl<'a> Chatlist<'a> { if 0 != add_archived_link_item && dc_get_archived_cnt(context) > 0 { if ids.is_empty() && 0 != listflags & DC_GCL_ADD_ALLDONE_HINT { - ids.push((DC_CHAT_ID_ALLDONE_HINT as u32, 0)); + ids.push((DC_CHAT_ID_ALLDONE_HINT, 0)); } - ids.push((DC_CHAT_ID_ARCHIVED_LINK as u32, 0)); + ids.push((DC_CHAT_ID_ARCHIVED_LINK, 0)); } Ok(Chatlist { context, ids }) @@ -290,10 +290,9 @@ impl<'a> Chatlist<'a> { None }; - if chat.id == DC_CHAT_ID_ARCHIVED_LINK as u32 { + if chat.id == DC_CHAT_ID_ARCHIVED_LINK { ret.text2 = None; - } else if lastmsg.is_none() - || lastmsg.as_ref().unwrap().from_id == DC_CONTACT_ID_UNDEFINED as u32 + } else if lastmsg.is_none() || lastmsg.as_ref().unwrap().from_id == DC_CONTACT_ID_UNDEFINED { ret.text2 = Some(self.context.stock_str(StockMessage::NoMessages).to_string()); } else { diff --git a/src/constants.rs b/src/constants.rs index 8089fcb33..a4015d562 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -65,19 +65,19 @@ const DC_IMEX_EXPORT_BACKUP: usize = 11; const DC_IMEX_IMPORT_BACKUP: usize = 12; /// virtual chat showing all messages belonging to chats flagged with chats.blocked=2 -pub(crate) const DC_CHAT_ID_DEADDROP: usize = 1; +pub(crate) const DC_CHAT_ID_DEADDROP: u32 = 1; /// messages that should be deleted get this chat_id; the messages are deleted from the working thread later then. This is also needed as rfc724_mid should be preset as long as the message is not deleted on the server (otherwise it is downloaded again) -pub const DC_CHAT_ID_TRASH: usize = 3; +pub const DC_CHAT_ID_TRASH: u32 = 3; /// a message is just in creation but not yet assigned to a chat (eg. we may need the message ID to set up blobs; this avoids unready message to be sent and shown) -const DC_CHAT_ID_MSGS_IN_CREATION: usize = 4; +const DC_CHAT_ID_MSGS_IN_CREATION: u32 = 4; /// virtual chat showing all messages flagged with msgs.starred=2 -const DC_CHAT_ID_STARRED: usize = 5; +const DC_CHAT_ID_STARRED: u32 = 5; /// only an indicator in a chatlist -pub const DC_CHAT_ID_ARCHIVED_LINK: usize = 6; +pub const DC_CHAT_ID_ARCHIVED_LINK: u32 = 6; /// only an indicator in a chatlist -pub const DC_CHAT_ID_ALLDONE_HINT: usize = 7; +pub const DC_CHAT_ID_ALLDONE_HINT: u32 = 7; /// larger chat IDs are "real" chats, their messages are "real" messages. -pub const DC_CHAT_ID_LAST_SPECIAL: usize = 9; +pub const DC_CHAT_ID_LAST_SPECIAL: u32 = 9; #[derive( Debug, @@ -106,19 +106,19 @@ impl Default for Chattype { } } -pub const DC_MSG_ID_MARKER1: usize = 1; -const DC_MSG_ID_DAYMARKER: usize = 9; -pub const DC_MSG_ID_LAST_SPECIAL: usize = 9; +pub const DC_MSG_ID_MARKER1: u32 = 1; +const DC_MSG_ID_DAYMARKER: u32 = 9; +pub const DC_MSG_ID_LAST_SPECIAL: u32 = 9; /// approx. max. length returned by dc_msg_get_text() const DC_MAX_GET_TEXT_LEN: usize = 30000; /// approx. max. length returned by dc_get_msg_info() const DC_MAX_GET_INFO_LEN: usize = 100000; -pub const DC_CONTACT_ID_UNDEFINED: usize = 0; -pub const DC_CONTACT_ID_SELF: usize = 1; -const DC_CONTACT_ID_DEVICE: usize = 2; -pub const DC_CONTACT_ID_LAST_SPECIAL: usize = 9; +pub const DC_CONTACT_ID_UNDEFINED: u32 = 0; +pub const DC_CONTACT_ID_SELF: u32 = 1; +const DC_CONTACT_ID_DEVICE: u32 = 2; +pub const DC_CONTACT_ID_LAST_SPECIAL: u32 = 9; pub const DC_CREATE_MVBOX: usize = 1; diff --git a/src/contact.rs b/src/contact.rs index 6e3bcfd45..e8e20c0cd 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -152,7 +152,7 @@ pub enum VerifiedStatus { impl<'a> Contact<'a> { pub fn load_from_db(context: &'a Context, contact_id: u32) -> Result { - if contact_id == DC_CONTACT_ID_SELF as u32 { + if contact_id == DC_CONTACT_ID_SELF { let contact = Contact { context, id: contact_id, @@ -545,7 +545,7 @@ impl<'a> Contact<'a> { } if 0 != listflags & DC_GCL_ADD_SELF as u32 && add_self { - ret.push(DC_CONTACT_ID_SELF as u32); + ret.push(DC_CONTACT_ID_SELF); } Ok(ret) @@ -655,7 +655,7 @@ impl<'a> Contact<'a> { /// May result in a `#DC_EVENT_CONTACTS_CHANGED` event. pub fn delete(context: &Context, contact_id: u32) -> Result<()> { ensure!( - contact_id > DC_CONTACT_ID_LAST_SPECIAL as u32, + contact_id > DC_CONTACT_ID_LAST_SPECIAL, "Can not delete special contact" ); @@ -780,7 +780,7 @@ impl<'a> Contact<'a> { /// This is the image set by each remote user on their own /// using dc_set_config(context, "selfavatar", image). pub fn get_profile_image(&self) -> Option { - if self.id == DC_CONTACT_ID_SELF as u32 { + if self.id == DC_CONTACT_ID_SELF { return self.context.get_config(Config::Selfavatar); } // TODO: else get image_abs from contact param @@ -810,7 +810,7 @@ impl<'a> Contact<'a> { pub fn is_verified_ex(&self, peerstate: Option<&Peerstate<'a>>) -> VerifiedStatus { // We're always sort of secured-verified as we could verify the key on this device any time with the key // on this device - if self.id == DC_CONTACT_ID_SELF as u32 { + if self.id == DC_CONTACT_ID_SELF { return VerifiedStatus::BidirectVerified; } diff --git a/src/dc_mimefactory.rs b/src/dc_mimefactory.rs index a55a8cb1a..9555bdc00 100644 --- a/src/dc_mimefactory.rs +++ b/src/dc_mimefactory.rs @@ -87,7 +87,7 @@ pub unsafe fn dc_mimefactory_load_msg( context: &Context, msg_id: u32, ) -> Result { - ensure!(msg_id > DC_CHAT_ID_LAST_SPECIAL as u32, "Invalid chat id"); + ensure!(msg_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat id"); let msg = dc_msg_load_from_db(context, msg_id)?; let chat = Chat::load_from_db(context, msg.chat_id)?; @@ -308,7 +308,7 @@ pub unsafe fn dc_mimefactory_load_mdn<'a>( // in dc_markseen_msgs() ensure!(!contact.is_blocked(), "Contact blocked"); ensure!( - factory.msg.chat_id > DC_CHAT_ID_LAST_SPECIAL as u32, + factory.msg.chat_id > DC_CHAT_ID_LAST_SPECIAL, "Invalid chat id" ); diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 96056699e..1871a226c 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -131,7 +131,7 @@ pub unsafe fn dc_receive_imf( if 0 != check_self { incoming = 0; if 0 != dc_mimeparser_sender_equals_recipient(&mime_parser) { - from_id = DC_CONTACT_ID_SELF as u32; + from_id = DC_CONTACT_ID_SELF; } } else if from_list.len() >= 1 { // if there is no from given, from_id stays 0 which is just fine. These messages @@ -220,7 +220,7 @@ pub unsafe fn dc_receive_imf( ); } - if !mime_parser.message_kml.is_none() && chat_id > DC_CHAT_ID_LAST_SPECIAL as u32 { + if !mime_parser.message_kml.is_none() && chat_id > DC_CHAT_ID_LAST_SPECIAL { save_locations( context, &mime_parser, @@ -492,7 +492,7 @@ unsafe fn add_parts( } if *chat_id == 0 { // maybe from_id is null or sth. else is suspicious, move message to trash - *chat_id = DC_CHAT_ID_TRASH as u32; + *chat_id = DC_CHAT_ID_TRASH; } // if the chat_id is blocked, @@ -509,7 +509,7 @@ unsafe fn add_parts( // the mail is on the IMAP server, probably it is also delivered. // We cannot recreate other states (read, error). state = MessageState::OutDelivered; - *from_id = DC_CONTACT_ID_SELF as u32; + *from_id = DC_CONTACT_ID_SELF; if !to_ids.is_empty() { *to_id = to_ids[0]; if *chat_id == 0 { @@ -565,7 +565,7 @@ unsafe fn add_parts( } } if *chat_id == 0 { - *chat_id = DC_CHAT_ID_TRASH as u32; + *chat_id = DC_CHAT_ID_TRASH; } } // correct message_timestamp, it should not be used before, @@ -723,7 +723,7 @@ unsafe fn add_parts( ); // check event to send - if *chat_id == DC_CHAT_ID_TRASH as u32 { + if *chat_id == DC_CHAT_ID_TRASH { *create_event_to_send = None; } else if 0 != incoming && state == MessageState::InFresh { if 0 != from_id_blocked { @@ -1290,10 +1290,10 @@ unsafe fn create_or_lookup_group( } // again, check chat_id - if chat_id <= DC_CHAT_ID_LAST_SPECIAL as u32 { + if chat_id <= DC_CHAT_ID_LAST_SPECIAL { chat_id = 0; if group_explicitly_left { - chat_id = DC_CHAT_ID_TRASH as u32; + chat_id = DC_CHAT_ID_TRASH; } else { create_or_lookup_adhoc_group( context, @@ -1398,9 +1398,9 @@ unsafe fn create_or_lookup_group( ) .ok(); if skip.is_null() || !addr_cmp(&self_addr, as_str(skip)) { - chat::add_to_chat_contacts_table(context, chat_id, DC_CONTACT_ID_SELF as u32); + chat::add_to_chat_contacts_table(context, chat_id, DC_CONTACT_ID_SELF); } - if from_id > DC_CHAT_ID_LAST_SPECIAL as u32 { + if from_id > DC_CHAT_ID_LAST_SPECIAL { if !Contact::addr_equals_contact(context, &self_addr, from_id as u32) && (skip.is_null() || !Contact::addr_equals_contact(context, to_string(skip), from_id as u32)) diff --git a/src/message.rs b/src/message.rs index 18005fd99..89ecd00b3 100644 --- a/src/message.rs +++ b/src/message.rs @@ -80,7 +80,7 @@ impl Lot { if msg.state == MessageState::OutDraft { self.text1 = Some(context.stock_str(StockMessage::Draft).to_owned().into()); self.text1_meaning = Meaning::Text1Draft; - } else if msg.from_id == DC_CONTACT_ID_SELF as u32 { + } else if msg.from_id == DC_CONTACT_ID_SELF { if 0 != dc_msg_is_info(msg) || chat.is_self_talk() { self.text1 = None; self.text1_meaning = Meaning::None; @@ -93,7 +93,7 @@ impl Lot { self.text1 = None; self.text1_meaning = Meaning::None; } else { - if chat.id == DC_CHAT_ID_DEADDROP as u32 { + if chat.id == DC_CHAT_ID_DEADDROP { if let Some(contact) = contact { self.text1 = Some(contact.get_display_name().into()); } else { diff --git a/src/stock.rs b/src/stock.rs index 20231712b..7936ac0a5 100644 --- a/src/stock.rs +++ b/src/stock.rs @@ -323,7 +323,7 @@ mod tests { StockMessage::MsgAddMember, "alice@example.com", "", - DC_CONTACT_ID_SELF as u32 + DC_CONTACT_ID_SELF ), "Member alice@example.com added by me." ) @@ -338,7 +338,7 @@ mod tests { StockMessage::MsgAddMember, "alice@example.com", "", - DC_CONTACT_ID_SELF as u32 + DC_CONTACT_ID_SELF ), "Member Alice (alice@example.com) added by me." ); @@ -373,7 +373,7 @@ mod tests { StockMessage::MsgGrpName, "Some chat", "Other chat", - DC_CONTACT_ID_SELF as u32 + DC_CONTACT_ID_SELF ), "Group name changed from \"Some chat\" to \"Other chat\" by me." )