mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Convert DC_*_ID_* constants to u32
This commit is contained in:
57
src/chat.rs
57
src/chat.rs
@@ -468,7 +468,7 @@ impl<'a> Chat<'a> {
|
|||||||
VALUES (?,?,?, ?,?,1);",
|
VALUES (?,?,?, ?,?,1);",
|
||||||
params![
|
params![
|
||||||
timestamp,
|
timestamp,
|
||||||
DC_CONTACT_ID_SELF as i32,
|
DC_CONTACT_ID_SELF,
|
||||||
self.id as i32,
|
self.id as i32,
|
||||||
msg.param.get_float(Param::SetLatitude).unwrap_or_default(),
|
msg.param.get_float(Param::SetLatitude).unwrap_or_default(),
|
||||||
msg.param.get_float(Param::SetLongitude).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<u32, Error> {
|
|||||||
|
|
||||||
if let Ok(msg) = dc_msg_load_from_db(context, msg_id) {
|
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 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;
|
chat_id = chat.id;
|
||||||
if chat.blocked != Blocked::Not {
|
if chat.blocked != Blocked::Not {
|
||||||
unblock(context, chat.id);
|
unblock(context, chat.id);
|
||||||
@@ -602,8 +602,7 @@ pub fn create_by_contact_id(context: &Context, contact_id: u32) -> Result<u32, E
|
|||||||
chat_id
|
chat_id
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if !Contact::real_exists_by_id(context, contact_id)
|
if !Contact::real_exists_by_id(context, contact_id) && contact_id != DC_CONTACT_ID_SELF
|
||||||
&& contact_id != DC_CONTACT_ID_SELF as u32
|
|
||||||
{
|
{
|
||||||
warn!(
|
warn!(
|
||||||
context,
|
context,
|
||||||
@@ -706,7 +705,7 @@ pub fn prepare_msg<'a>(
|
|||||||
msg: &mut Message<'a>,
|
msg: &mut Message<'a>,
|
||||||
) -> Result<u32, Error> {
|
) -> Result<u32, Error> {
|
||||||
ensure!(
|
ensure!(
|
||||||
chat_id > DC_CHAT_ID_LAST_SPECIAL as u32,
|
chat_id > DC_CHAT_ID_LAST_SPECIAL,
|
||||||
"Cannot prepare message for special chat"
|
"Cannot prepare message for special chat"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -884,7 +883,7 @@ pub unsafe fn send_msg<'a>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if msg.param.exists(Param::SetLatitude) {
|
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 {
|
if 0 == chat_id {
|
||||||
@@ -916,7 +915,7 @@ pub unsafe fn send_text_msg(
|
|||||||
text_to_send: String,
|
text_to_send: String,
|
||||||
) -> Result<u32, Error> {
|
) -> Result<u32, Error> {
|
||||||
ensure!(
|
ensure!(
|
||||||
chat_id > DC_CHAT_ID_LAST_SPECIAL as u32,
|
chat_id > DC_CHAT_ID_LAST_SPECIAL,
|
||||||
"bad chat_id = {} <= 9",
|
"bad chat_id = {} <= 9",
|
||||||
chat_id
|
chat_id
|
||||||
);
|
);
|
||||||
@@ -928,7 +927,7 @@ pub unsafe fn send_text_msg(
|
|||||||
|
|
||||||
// passing `None` as message jsut deletes the draft
|
// passing `None` as message jsut deletes the draft
|
||||||
pub unsafe fn set_draft(context: &Context, chat_id: u32, msg: Option<&mut Message>) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if set_draft_raw(context, chat_id, msg) {
|
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<Message, Error> {
|
pub unsafe fn get_draft(context: &Context, chat_id: u32) -> Result<Message, 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 draft_msg_id = get_draft_msg_id(context, chat_id);
|
let draft_msg_id = get_draft_msg_id(context, chat_id);
|
||||||
ensure!(draft_msg_id != 0, "Invalid draft message 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 {
|
for row in rows {
|
||||||
let (curr_id, ts) = row?;
|
let (curr_id, ts) = row?;
|
||||||
if curr_id as u32 == marker1before {
|
if curr_id as u32 == marker1before {
|
||||||
ret.push(DC_MSG_ID_MARKER1 as u32);
|
ret.push(DC_MSG_ID_MARKER1);
|
||||||
}
|
}
|
||||||
if 0 != flags & 0x1 {
|
if 0 != flags & 0x1 {
|
||||||
let curr_local_timestamp = ts + cnv_to_local;
|
let curr_local_timestamp = ts + cnv_to_local;
|
||||||
let curr_day = (curr_local_timestamp / 86400) as libc::c_int;
|
let curr_day = (curr_local_timestamp / 86400) as libc::c_int;
|
||||||
if curr_day != last_day {
|
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;
|
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> {
|
pub fn archive(context: &Context, chat_id: u32, archive: bool) -> Result<(), Error> {
|
||||||
ensure!(
|
ensure!(
|
||||||
chat_id > DC_CHAT_ID_LAST_SPECIAL as u32,
|
chat_id > DC_CHAT_ID_LAST_SPECIAL,
|
||||||
"bad chat_id = {} <= 9",
|
"bad chat_id = {} <= 9",
|
||||||
chat_id
|
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> {
|
pub fn delete(context: &Context, chat_id: u32) -> Result<(), Error> {
|
||||||
ensure!(
|
ensure!(
|
||||||
chat_id > DC_CHAT_ID_LAST_SPECIAL as u32,
|
chat_id > DC_CHAT_ID_LAST_SPECIAL,
|
||||||
"bad chat_id = {} <= 9",
|
"bad chat_id = {} <= 9",
|
||||||
chat_id
|
chat_id
|
||||||
);
|
);
|
||||||
@@ -1405,7 +1404,7 @@ pub unsafe fn add_contact_to_chat_ex(
|
|||||||
let mut success: libc::c_int = 0;
|
let mut success: libc::c_int = 0;
|
||||||
let contact = Contact::get_by_id(context, contact_id);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
let mut msg = dc_msg_new_untyped(context);
|
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*/
|
/*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 let Ok(mut chat) = Chat::load_from_db(context, chat_id) {
|
||||||
if !(!real_group_exists(context, chat_id)
|
if !(!real_group_exists(context, chat_id)
|
||||||
|| !Contact::real_exists_by_id(context, contact_id)
|
|| !Contact::real_exists_by_id(context, contact_id) && contact_id != DC_CONTACT_ID_SELF)
|
||||||
&& contact_id != DC_CONTACT_ID_SELF as u32)
|
|
||||||
{
|
{
|
||||||
if !(is_contact_in_chat(context, chat_id, 1 as u32) == 1) {
|
if !(is_contact_in_chat(context, chat_id, 1 as u32) == 1) {
|
||||||
log_event!(
|
log_event!(
|
||||||
@@ -1496,7 +1494,7 @@ pub unsafe fn add_contact_to_chat_ex(
|
|||||||
|
|
||||||
fn real_group_exists(context: &Context, chat_id: u32) -> bool {
|
fn real_group_exists(context: &Context, chat_id: u32) -> bool {
|
||||||
// check if a group or a verified group exists under the given ID
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1549,14 +1547,11 @@ pub unsafe fn remove_contact_from_chat(
|
|||||||
contact_id: u32,
|
contact_id: u32,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
ensure!(
|
ensure!(
|
||||||
chat_id > DC_CHAT_ID_LAST_SPECIAL as u32,
|
chat_id > DC_CHAT_ID_LAST_SPECIAL,
|
||||||
"bad chat_id = {} <= 9",
|
"bad chat_id = {} <= 9",
|
||||||
chat_id
|
chat_id
|
||||||
);
|
);
|
||||||
ensure!(
|
ensure!(contact_id != DC_CONTACT_ID_SELF, "Cannot remove self");
|
||||||
contact_id != DC_CONTACT_ID_SELF as u32,
|
|
||||||
"Cannot remove self"
|
|
||||||
);
|
|
||||||
|
|
||||||
let mut msg = dc_msg_new_untyped(context);
|
let mut msg = dc_msg_new_untyped(context);
|
||||||
let mut success = false;
|
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 let Ok(contact) = Contact::get_by_id(context, contact_id) {
|
||||||
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
||||||
msg.type_0 = Viewtype::Text;
|
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();
|
set_group_explicitly_left(context, chat.grpid).unwrap();
|
||||||
msg.text = Some(context.stock_system_msg(
|
msg.text = Some(context.stock_system_msg(
|
||||||
StockMessage::MsgGroupLeft,
|
StockMessage::MsgGroupLeft,
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
DC_CONTACT_ID_SELF as u32,
|
DC_CONTACT_ID_SELF,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
msg.text = Some(context.stock_system_msg(
|
msg.text = Some(context.stock_system_msg(
|
||||||
StockMessage::MsgDelMember,
|
StockMessage::MsgDelMember,
|
||||||
contact.get_addr(),
|
contact.get_addr(),
|
||||||
"",
|
"",
|
||||||
DC_CONTACT_ID_SELF as u32,
|
DC_CONTACT_ID_SELF,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
msg.param.set_int(Param::Cmd, 5);
|
msg.param.set_int(Param::Cmd, 5);
|
||||||
@@ -1654,7 +1649,7 @@ pub unsafe fn set_chat_name(
|
|||||||
let mut success = false;
|
let mut success = false;
|
||||||
|
|
||||||
ensure!(!new_name.as_ref().is_empty(), "Invalid name");
|
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 chat = Chat::load_from_db(context, chat_id)?;
|
||||||
let mut msg = dc_msg_new_untyped(context);
|
let mut msg = dc_msg_new_untyped(context);
|
||||||
@@ -1689,7 +1684,7 @@ pub unsafe fn set_chat_name(
|
|||||||
StockMessage::MsgGrpName,
|
StockMessage::MsgGrpName,
|
||||||
&chat.name,
|
&chat.name,
|
||||||
new_name.as_ref(),
|
new_name.as_ref(),
|
||||||
DC_CONTACT_ID_SELF as u32,
|
DC_CONTACT_ID_SELF,
|
||||||
));
|
));
|
||||||
msg.param.set_int(Param::Cmd, 2);
|
msg.param.set_int(Param::Cmd, 2);
|
||||||
if !chat.name.is_empty() {
|
if !chat.name.is_empty() {
|
||||||
@@ -1725,7 +1720,7 @@ pub unsafe fn set_chat_profile_image(
|
|||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
new_image: impl AsRef<str>,
|
new_image: impl AsRef<str>,
|
||||||
) -> Result<(), Error> {
|
) -> 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 OK_TO_CONTINUE = true;
|
||||||
let mut success = false;
|
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();
|
msg.id = send_msg(context, chat_id, &mut msg).unwrap_or_default();
|
||||||
context.call_cb(
|
context.call_cb(
|
||||||
@@ -1805,7 +1800,7 @@ pub unsafe fn forward_msgs(
|
|||||||
msg_cnt: libc::c_int,
|
msg_cnt: libc::c_int,
|
||||||
chat_id: u32,
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1844,7 +1839,7 @@ pub unsafe fn forward_msgs(
|
|||||||
}
|
}
|
||||||
let mut msg = msg.unwrap();
|
let mut msg = msg.unwrap();
|
||||||
let original_param = msg.param.clone();
|
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.set_int(Param::Forwarded, 1);
|
||||||
}
|
}
|
||||||
msg.param.remove(Param::GuranteeE2ee);
|
msg.param.remove(Param::GuranteeE2ee);
|
||||||
|
|||||||
@@ -195,9 +195,9 @@ impl<'a> Chatlist<'a> {
|
|||||||
|
|
||||||
if 0 != add_archived_link_item && dc_get_archived_cnt(context) > 0 {
|
if 0 != add_archived_link_item && dc_get_archived_cnt(context) > 0 {
|
||||||
if ids.is_empty() && 0 != listflags & DC_GCL_ADD_ALLDONE_HINT {
|
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 })
|
Ok(Chatlist { context, ids })
|
||||||
@@ -290,10 +290,9 @@ impl<'a> Chatlist<'a> {
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
if chat.id == DC_CHAT_ID_ARCHIVED_LINK as u32 {
|
if chat.id == DC_CHAT_ID_ARCHIVED_LINK {
|
||||||
ret.text2 = None;
|
ret.text2 = None;
|
||||||
} else if lastmsg.is_none()
|
} else if lastmsg.is_none() || lastmsg.as_ref().unwrap().from_id == DC_CONTACT_ID_UNDEFINED
|
||||||
|| lastmsg.as_ref().unwrap().from_id == DC_CONTACT_ID_UNDEFINED as u32
|
|
||||||
{
|
{
|
||||||
ret.text2 = Some(self.context.stock_str(StockMessage::NoMessages).to_string());
|
ret.text2 = Some(self.context.stock_str(StockMessage::NoMessages).to_string());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -65,19 +65,19 @@ const DC_IMEX_EXPORT_BACKUP: usize = 11;
|
|||||||
const DC_IMEX_IMPORT_BACKUP: usize = 12;
|
const DC_IMEX_IMPORT_BACKUP: usize = 12;
|
||||||
|
|
||||||
/// virtual chat showing all messages belonging to chats flagged with chats.blocked=2
|
/// 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)
|
/// 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)
|
/// 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
|
/// 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
|
/// 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
|
/// 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.
|
/// 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(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
@@ -106,19 +106,19 @@ impl Default for Chattype {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const DC_MSG_ID_MARKER1: usize = 1;
|
pub const DC_MSG_ID_MARKER1: u32 = 1;
|
||||||
const DC_MSG_ID_DAYMARKER: usize = 9;
|
const DC_MSG_ID_DAYMARKER: u32 = 9;
|
||||||
pub const DC_MSG_ID_LAST_SPECIAL: usize = 9;
|
pub const DC_MSG_ID_LAST_SPECIAL: u32 = 9;
|
||||||
|
|
||||||
/// approx. max. length returned by dc_msg_get_text()
|
/// approx. max. length returned by dc_msg_get_text()
|
||||||
const DC_MAX_GET_TEXT_LEN: usize = 30000;
|
const DC_MAX_GET_TEXT_LEN: usize = 30000;
|
||||||
/// approx. max. length returned by dc_get_msg_info()
|
/// approx. max. length returned by dc_get_msg_info()
|
||||||
const DC_MAX_GET_INFO_LEN: usize = 100000;
|
const DC_MAX_GET_INFO_LEN: usize = 100000;
|
||||||
|
|
||||||
pub const DC_CONTACT_ID_UNDEFINED: usize = 0;
|
pub const DC_CONTACT_ID_UNDEFINED: u32 = 0;
|
||||||
pub const DC_CONTACT_ID_SELF: usize = 1;
|
pub const DC_CONTACT_ID_SELF: u32 = 1;
|
||||||
const DC_CONTACT_ID_DEVICE: usize = 2;
|
const DC_CONTACT_ID_DEVICE: u32 = 2;
|
||||||
pub const DC_CONTACT_ID_LAST_SPECIAL: usize = 9;
|
pub const DC_CONTACT_ID_LAST_SPECIAL: u32 = 9;
|
||||||
|
|
||||||
pub const DC_CREATE_MVBOX: usize = 1;
|
pub const DC_CREATE_MVBOX: usize = 1;
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ pub enum VerifiedStatus {
|
|||||||
|
|
||||||
impl<'a> Contact<'a> {
|
impl<'a> Contact<'a> {
|
||||||
pub fn load_from_db(context: &'a Context, contact_id: u32) -> Result<Self> {
|
pub fn load_from_db(context: &'a Context, contact_id: u32) -> Result<Self> {
|
||||||
if contact_id == DC_CONTACT_ID_SELF as u32 {
|
if contact_id == DC_CONTACT_ID_SELF {
|
||||||
let contact = Contact {
|
let contact = Contact {
|
||||||
context,
|
context,
|
||||||
id: contact_id,
|
id: contact_id,
|
||||||
@@ -545,7 +545,7 @@ impl<'a> Contact<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if 0 != listflags & DC_GCL_ADD_SELF as u32 && add_self {
|
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)
|
Ok(ret)
|
||||||
@@ -655,7 +655,7 @@ impl<'a> Contact<'a> {
|
|||||||
/// May result in a `#DC_EVENT_CONTACTS_CHANGED` event.
|
/// May result in a `#DC_EVENT_CONTACTS_CHANGED` event.
|
||||||
pub fn delete(context: &Context, contact_id: u32) -> Result<()> {
|
pub fn delete(context: &Context, contact_id: u32) -> Result<()> {
|
||||||
ensure!(
|
ensure!(
|
||||||
contact_id > DC_CONTACT_ID_LAST_SPECIAL as u32,
|
contact_id > DC_CONTACT_ID_LAST_SPECIAL,
|
||||||
"Can not delete special contact"
|
"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
|
/// This is the image set by each remote user on their own
|
||||||
/// using dc_set_config(context, "selfavatar", image).
|
/// using dc_set_config(context, "selfavatar", image).
|
||||||
pub fn get_profile_image(&self) -> Option<String> {
|
pub fn get_profile_image(&self) -> Option<String> {
|
||||||
if self.id == DC_CONTACT_ID_SELF as u32 {
|
if self.id == DC_CONTACT_ID_SELF {
|
||||||
return self.context.get_config(Config::Selfavatar);
|
return self.context.get_config(Config::Selfavatar);
|
||||||
}
|
}
|
||||||
// TODO: else get image_abs from contact param
|
// 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 {
|
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
|
// We're always sort of secured-verified as we could verify the key on this device any time with the key
|
||||||
// on this device
|
// on this device
|
||||||
if self.id == DC_CONTACT_ID_SELF as u32 {
|
if self.id == DC_CONTACT_ID_SELF {
|
||||||
return VerifiedStatus::BidirectVerified;
|
return VerifiedStatus::BidirectVerified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ pub unsafe fn dc_mimefactory_load_msg(
|
|||||||
context: &Context,
|
context: &Context,
|
||||||
msg_id: u32,
|
msg_id: u32,
|
||||||
) -> Result<dc_mimefactory_t, Error> {
|
) -> Result<dc_mimefactory_t, Error> {
|
||||||
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 msg = dc_msg_load_from_db(context, msg_id)?;
|
||||||
let chat = Chat::load_from_db(context, msg.chat_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()
|
// in dc_markseen_msgs()
|
||||||
ensure!(!contact.is_blocked(), "Contact blocked");
|
ensure!(!contact.is_blocked(), "Contact blocked");
|
||||||
ensure!(
|
ensure!(
|
||||||
factory.msg.chat_id > DC_CHAT_ID_LAST_SPECIAL as u32,
|
factory.msg.chat_id > DC_CHAT_ID_LAST_SPECIAL,
|
||||||
"Invalid chat id"
|
"Invalid chat id"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ pub unsafe fn dc_receive_imf(
|
|||||||
if 0 != check_self {
|
if 0 != check_self {
|
||||||
incoming = 0;
|
incoming = 0;
|
||||||
if 0 != dc_mimeparser_sender_equals_recipient(&mime_parser) {
|
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 {
|
} else if from_list.len() >= 1 {
|
||||||
// if there is no from given, from_id stays 0 which is just fine. These messages
|
// 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(
|
save_locations(
|
||||||
context,
|
context,
|
||||||
&mime_parser,
|
&mime_parser,
|
||||||
@@ -492,7 +492,7 @@ unsafe fn add_parts(
|
|||||||
}
|
}
|
||||||
if *chat_id == 0 {
|
if *chat_id == 0 {
|
||||||
// maybe from_id is null or sth. else is suspicious, move message to trash
|
// 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,
|
// 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.
|
// the mail is on the IMAP server, probably it is also delivered.
|
||||||
// We cannot recreate other states (read, error).
|
// We cannot recreate other states (read, error).
|
||||||
state = MessageState::OutDelivered;
|
state = MessageState::OutDelivered;
|
||||||
*from_id = DC_CONTACT_ID_SELF as u32;
|
*from_id = DC_CONTACT_ID_SELF;
|
||||||
if !to_ids.is_empty() {
|
if !to_ids.is_empty() {
|
||||||
*to_id = to_ids[0];
|
*to_id = to_ids[0];
|
||||||
if *chat_id == 0 {
|
if *chat_id == 0 {
|
||||||
@@ -565,7 +565,7 @@ unsafe fn add_parts(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if *chat_id == 0 {
|
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,
|
// correct message_timestamp, it should not be used before,
|
||||||
@@ -723,7 +723,7 @@ unsafe fn add_parts(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// check event to send
|
// 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;
|
*create_event_to_send = None;
|
||||||
} else if 0 != incoming && state == MessageState::InFresh {
|
} else if 0 != incoming && state == MessageState::InFresh {
|
||||||
if 0 != from_id_blocked {
|
if 0 != from_id_blocked {
|
||||||
@@ -1290,10 +1290,10 @@ unsafe fn create_or_lookup_group(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// again, check chat_id
|
// 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;
|
chat_id = 0;
|
||||||
if group_explicitly_left {
|
if group_explicitly_left {
|
||||||
chat_id = DC_CHAT_ID_TRASH as u32;
|
chat_id = DC_CHAT_ID_TRASH;
|
||||||
} else {
|
} else {
|
||||||
create_or_lookup_adhoc_group(
|
create_or_lookup_adhoc_group(
|
||||||
context,
|
context,
|
||||||
@@ -1398,9 +1398,9 @@ unsafe fn create_or_lookup_group(
|
|||||||
)
|
)
|
||||||
.ok();
|
.ok();
|
||||||
if skip.is_null() || !addr_cmp(&self_addr, as_str(skip)) {
|
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)
|
if !Contact::addr_equals_contact(context, &self_addr, from_id as u32)
|
||||||
&& (skip.is_null()
|
&& (skip.is_null()
|
||||||
|| !Contact::addr_equals_contact(context, to_string(skip), from_id as u32))
|
|| !Contact::addr_equals_contact(context, to_string(skip), from_id as u32))
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ impl Lot {
|
|||||||
if msg.state == MessageState::OutDraft {
|
if msg.state == MessageState::OutDraft {
|
||||||
self.text1 = Some(context.stock_str(StockMessage::Draft).to_owned().into());
|
self.text1 = Some(context.stock_str(StockMessage::Draft).to_owned().into());
|
||||||
self.text1_meaning = Meaning::Text1Draft;
|
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() {
|
if 0 != dc_msg_is_info(msg) || chat.is_self_talk() {
|
||||||
self.text1 = None;
|
self.text1 = None;
|
||||||
self.text1_meaning = Meaning::None;
|
self.text1_meaning = Meaning::None;
|
||||||
@@ -93,7 +93,7 @@ impl Lot {
|
|||||||
self.text1 = None;
|
self.text1 = None;
|
||||||
self.text1_meaning = Meaning::None;
|
self.text1_meaning = Meaning::None;
|
||||||
} else {
|
} else {
|
||||||
if chat.id == DC_CHAT_ID_DEADDROP as u32 {
|
if chat.id == DC_CHAT_ID_DEADDROP {
|
||||||
if let Some(contact) = contact {
|
if let Some(contact) = contact {
|
||||||
self.text1 = Some(contact.get_display_name().into());
|
self.text1 = Some(contact.get_display_name().into());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ mod tests {
|
|||||||
StockMessage::MsgAddMember,
|
StockMessage::MsgAddMember,
|
||||||
"alice@example.com",
|
"alice@example.com",
|
||||||
"",
|
"",
|
||||||
DC_CONTACT_ID_SELF as u32
|
DC_CONTACT_ID_SELF
|
||||||
),
|
),
|
||||||
"Member alice@example.com added by me."
|
"Member alice@example.com added by me."
|
||||||
)
|
)
|
||||||
@@ -338,7 +338,7 @@ mod tests {
|
|||||||
StockMessage::MsgAddMember,
|
StockMessage::MsgAddMember,
|
||||||
"alice@example.com",
|
"alice@example.com",
|
||||||
"",
|
"",
|
||||||
DC_CONTACT_ID_SELF as u32
|
DC_CONTACT_ID_SELF
|
||||||
),
|
),
|
||||||
"Member Alice (alice@example.com) added by me."
|
"Member Alice (alice@example.com) added by me."
|
||||||
);
|
);
|
||||||
@@ -373,7 +373,7 @@ mod tests {
|
|||||||
StockMessage::MsgGrpName,
|
StockMessage::MsgGrpName,
|
||||||
"Some chat",
|
"Some chat",
|
||||||
"Other chat",
|
"Other chat",
|
||||||
DC_CONTACT_ID_SELF as u32
|
DC_CONTACT_ID_SELF
|
||||||
),
|
),
|
||||||
"Group name changed from \"Some chat\" to \"Other chat\" by me."
|
"Group name changed from \"Some chat\" to \"Other chat\" by me."
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user