refactor(chat): improve field types by using enums and bools

This commit is contained in:
dignifiedquire
2019-08-14 20:37:36 +02:00
parent 4878192a25
commit c8ce099f22
12 changed files with 272 additions and 266 deletions

View File

@@ -1276,7 +1276,7 @@ pub unsafe extern "C" fn dc_chat_get_id(chat: *mut dc_chat_t) -> u32 {
pub unsafe extern "C" fn dc_chat_get_type(chat: *mut dc_chat_t) -> libc::c_int { pub unsafe extern "C" fn dc_chat_get_type(chat: *mut dc_chat_t) -> libc::c_int {
assert!(!chat.is_null()); assert!(!chat.is_null());
dc_chat::dc_chat_get_type(chat) dc_chat::dc_chat_get_type(chat) as libc::c_int
} }
#[no_mangle] #[no_mangle]
@@ -1311,7 +1311,7 @@ pub unsafe extern "C" fn dc_chat_get_color(chat: *mut dc_chat_t) -> u32 {
pub unsafe extern "C" fn dc_chat_get_archived(chat: *mut dc_chat_t) -> libc::c_int { pub unsafe extern "C" fn dc_chat_get_archived(chat: *mut dc_chat_t) -> libc::c_int {
assert!(!chat.is_null()); assert!(!chat.is_null());
dc_chat::dc_chat_get_archived(chat) dc_chat::dc_chat_get_archived(chat) as libc::c_int
} }
#[no_mangle] #[no_mangle]
@@ -1339,7 +1339,7 @@ pub unsafe extern "C" fn dc_chat_is_verified(chat: *mut dc_chat_t) -> libc::c_in
pub unsafe extern "C" fn dc_chat_is_sending_locations(chat: *mut dc_chat_t) -> libc::c_int { pub unsafe extern "C" fn dc_chat_is_sending_locations(chat: *mut dc_chat_t) -> libc::c_int {
assert!(!chat.is_null()); assert!(!chat.is_null());
dc_chat::dc_chat_is_sending_locations(chat) dc_chat::dc_chat_is_sending_locations(chat) as libc::c_int
} }
// dc_msg_t // dc_msg_t

View File

@@ -20,7 +20,6 @@ pub fn to_sql_derive(input: TokenStream) -> TokenStream {
let num = *self as i64; let num = *self as i64;
let value = rusqlite::types::Value::Integer(num); let value = rusqlite::types::Value::Integer(num);
let output = rusqlite::types::ToSqlOutput::Owned(value); let output = rusqlite::types::ToSqlOutput::Owned(value);
std::result::Result::Ok(output) std::result::Result::Ok(output)
} }
} }

View File

@@ -350,13 +350,7 @@ pub unsafe fn dc_cmdline_skip_auth() {
} }
unsafe fn chat_prefix(chat: *const Chat) -> &'static str { unsafe fn chat_prefix(chat: *const Chat) -> &'static str {
if (*chat).type_0 == 120 { (*chat).typ.into()
"Group"
} else if (*chat).type_0 == 130 {
"VerifiedGroup"
} else {
"Single"
}
} }
pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> { pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::Error> {
@@ -628,7 +622,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
free(temp_subtitle as *mut libc::c_void); free(temp_subtitle as *mut libc::c_void);
free(temp_name as *mut libc::c_void); free(temp_name as *mut libc::c_void);
let lot = chatlist.get_summary(i, chat); let lot = chatlist.get_summary(i, chat);
let statestr = if 0 != dc_chat_get_archived(chat) { let statestr = if dc_chat_get_archived(chat) {
" [Archived]" " [Archived]"
} else { } else {
match dc_lot_get_state(lot) { match dc_lot_get_state(lot) {
@@ -651,7 +645,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
to_string(text2), to_string(text2),
statestr, statestr,
&timestr, &timestr,
if 0 != dc_chat_is_sending_locations(chat) { if dc_chat_is_sending_locations(chat) {
"📍" "📍"
} else { } else {
"" ""
@@ -699,7 +693,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
dc_chat_get_id(sel_chat), dc_chat_get_id(sel_chat),
as_str(temp_name), as_str(temp_name),
as_str(temp2), as_str(temp2),
if 0 != dc_chat_is_sending_locations(sel_chat) { if dc_chat_is_sending_locations(sel_chat) {
"📍" "📍"
} else { } else {
"" ""

View File

@@ -280,8 +280,7 @@ impl<'a> Chatlist<'a> {
dc_msg_load_from_db(lastmsg, self.context, lastmsg_id); dc_msg_load_from_db(lastmsg, self.context, lastmsg_id);
if (*lastmsg).from_id != 1 as libc::c_uint if (*lastmsg).from_id != 1 as libc::c_uint
&& ((*chat).type_0 == DC_CHAT_TYPE_GROUP && ((*chat).typ == Chattype::Group || (*chat).typ == Chattype::VerifiedGroup)
|| (*chat).type_0 == DC_CHAT_TYPE_VERIFIED_GROUP)
{ {
lastcontact = Contact::load_from_db(self.context, (*lastmsg).from_id).ok(); lastcontact = Contact::load_from_db(self.context, (*lastmsg).from_id).ok();
} }

View File

@@ -26,9 +26,19 @@ const DC_SENTBOX_WATCH_DEFAULT: i32 = 1;
const DC_MVBOX_WATCH_DEFAULT: i32 = 1; const DC_MVBOX_WATCH_DEFAULT: i32 = 1;
const DC_MVBOX_MOVE_DEFAULT: i32 = 1; const DC_MVBOX_MOVE_DEFAULT: i32 = 1;
pub const DC_CHAT_NOT_BLOCKED: i32 = 0; #[derive(Debug, Display, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive, FromSql, ToSql)]
const DC_CHAT_MANUALLY_BLOCKED: i32 = 1; #[repr(u8)]
pub const DC_CHAT_DEADDROP_BLOCKED: i32 = 2; pub enum Blocked {
Not = 0,
Manually = 1,
Deaddrop = 2,
}
impl Default for Blocked {
fn default() -> Self {
Blocked::Not
}
}
pub const DC_IMAP_SEEN: u32 = 0x1; pub const DC_IMAP_SEEN: u32 = 0x1;
@@ -88,10 +98,32 @@ pub const DC_CHAT_ID_ALLDONE_HINT: usize = 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: usize = 9;
const DC_CHAT_TYPE_UNDEFINED: i32 = 0; #[derive(
pub const DC_CHAT_TYPE_SINGLE: i32 = 100; Debug,
pub const DC_CHAT_TYPE_GROUP: i32 = 120; Display,
pub const DC_CHAT_TYPE_VERIFIED_GROUP: i32 = 130; Clone,
Copy,
PartialEq,
Eq,
FromPrimitive,
ToPrimitive,
FromSql,
ToSql,
IntoStaticStr,
)]
#[repr(u32)]
pub enum Chattype {
Undefined = 0,
Single = 100,
Group = 120,
VerifiedGroup = 130,
}
impl Default for Chattype {
fn default() -> Self {
Chattype::Undefined
}
}
pub const DC_MSG_ID_MARKER1: usize = 1; pub const DC_MSG_ID_MARKER1: usize = 1;
const DC_MSG_ID_DAYMARKER: usize = 9; const DC_MSG_ID_DAYMARKER: usize = 9;

View File

@@ -15,31 +15,27 @@ use crate::types::*;
use crate::x::*; use crate::x::*;
use std::ptr; use std::ptr;
/** /// An object representing a single chat in memory.
* @class dc_chat_t /// Chat objects are created using eg. dc_get_chat()
* /// and are not updated on database changes;
* An object representing a single chat in memory. /// if you want an update, you have to recreate the object.
* Chat objects are created using eg. dc_get_chat()
* and are not updated on database changes;
* if you want an update, you have to recreate the object.
*/
#[derive(Clone)] #[derive(Clone)]
pub struct Chat<'a> { pub struct Chat<'a> {
pub id: uint32_t, pub id: u32,
pub type_0: libc::c_int, pub typ: Chattype,
pub name: *mut libc::c_char, pub name: *mut libc::c_char,
archived: libc::c_int, archived: bool,
pub context: &'a Context, pub context: &'a Context,
pub grpid: *mut libc::c_char, pub grpid: *mut libc::c_char,
blocked: libc::c_int, blocked: Blocked,
pub param: Params, pub param: Params,
pub gossiped_timestamp: i64, pub gossiped_timestamp: i64,
is_sending_locations: libc::c_int, is_sending_locations: bool,
} }
// handle chats // handle chats
pub unsafe fn dc_create_chat_by_msg_id(context: &Context, msg_id: uint32_t) -> uint32_t { pub unsafe fn dc_create_chat_by_msg_id(context: &Context, msg_id: u32) -> u32 {
let mut chat_id: uint32_t = 0i32 as uint32_t; let mut chat_id: u32 = 0i32 as u32;
let mut send_event: libc::c_int = 0i32; let mut send_event: libc::c_int = 0i32;
let msg: *mut dc_msg_t = dc_msg_new_untyped(context); let msg: *mut dc_msg_t = dc_msg_new_untyped(context);
let chat: *mut Chat = dc_chat_new(context); let chat: *mut Chat = dc_chat_new(context);
@@ -48,7 +44,7 @@ pub unsafe fn dc_create_chat_by_msg_id(context: &Context, msg_id: uint32_t) -> u
&& (*chat).id > 9i32 as libc::c_uint && (*chat).id > 9i32 as libc::c_uint
{ {
chat_id = (*chat).id; chat_id = (*chat).id;
if 0 != (*chat).blocked { if (*chat).blocked != Blocked::Not {
dc_unblock_chat(context, (*chat).id); dc_unblock_chat(context, (*chat).id);
send_event = 1i32 send_event = 1i32
} }
@@ -66,15 +62,15 @@ pub unsafe fn dc_create_chat_by_msg_id(context: &Context, msg_id: uint32_t) -> u
pub unsafe fn dc_chat_new<'a>(context: &'a Context) -> *mut Chat<'a> { pub unsafe fn dc_chat_new<'a>(context: &'a Context) -> *mut Chat<'a> {
let chat = Chat { let chat = Chat {
id: 0, id: 0,
type_0: 0, typ: Chattype::Undefined,
name: std::ptr::null_mut(), name: std::ptr::null_mut(),
archived: 0, archived: false,
context, context,
grpid: std::ptr::null_mut(), grpid: std::ptr::null_mut(),
blocked: 0, blocked: Blocked::Not,
param: Params::new(), param: Params::new(),
gossiped_timestamp: 0, gossiped_timestamp: 0,
is_sending_locations: 0, is_sending_locations: false,
}; };
Box::into_raw(Box::new(chat)) Box::into_raw(Box::new(chat))
@@ -94,16 +90,16 @@ unsafe fn dc_chat_empty(mut chat: *mut Chat) {
} }
free((*chat).name as *mut libc::c_void); free((*chat).name as *mut libc::c_void);
(*chat).name = ptr::null_mut(); (*chat).name = ptr::null_mut();
(*chat).type_0 = 0i32; (*chat).typ = Chattype::Undefined;
(*chat).id = 0i32 as uint32_t; (*chat).id = 0i32 as u32;
free((*chat).grpid as *mut libc::c_void); free((*chat).grpid as *mut libc::c_void);
(*chat).grpid = ptr::null_mut(); (*chat).grpid = ptr::null_mut();
(*chat).blocked = 0i32; (*chat).blocked = Blocked::Not;
(*chat).gossiped_timestamp = 0; (*chat).gossiped_timestamp = 0;
(*chat).param = Params::new(); (*chat).param = Params::new();
} }
pub unsafe fn dc_unblock_chat(context: &Context, chat_id: uint32_t) { pub unsafe fn dc_unblock_chat(context: &Context, chat_id: u32) {
dc_block_chat(context, chat_id, 0i32); dc_block_chat(context, chat_id, 0i32);
} }
@@ -134,13 +130,13 @@ pub fn dc_chat_load_from_db(chat: *mut Chat, chat_id: u32) -> bool {
let c = unsafe { &mut *chat }; let c = unsafe { &mut *chat };
c.id = row.get(0)?; c.id = row.get(0)?;
c.type_0 = row.get(1)?; c.typ = row.get(1)?;
c.name = unsafe { row.get::<_, String>(2)?.strdup() }; c.name = unsafe { row.get::<_, String>(2)?.strdup() };
c.grpid = unsafe { row.get::<_, String>(3)?.strdup() }; c.grpid = unsafe { row.get::<_, String>(3)?.strdup() };
c.param = row.get::<_, String>(4)?.parse().unwrap_or_default(); c.param = row.get::<_, String>(4)?.parse().unwrap_or_default();
c.archived = row.get(5)?; c.archived = row.get(5)?;
c.blocked = row.get::<_, Option<i32>>(6)?.unwrap_or_default(); c.blocked = row.get::<_, Option<_>>(6)?.unwrap_or_default();
c.gossiped_timestamp = row.get(7)?; c.gossiped_timestamp = row.get(7)?;
c.is_sending_locations = row.get(8)?; c.is_sending_locations = row.get(8)?;
@@ -181,7 +177,7 @@ pub fn dc_chat_load_from_db(chat: *mut Chat, chat_id: u32) -> bool {
}, },
_ => { _ => {
unsafe { unsafe {
if (*chat).type_0 == DC_CHAT_TYPE_SINGLE { if (*chat).typ == Chattype::Single {
free((*chat).name as *mut libc::c_void); free((*chat).name as *mut libc::c_void);
let contacts = dc_get_chat_contacts((*chat).context, (*chat).id); let contacts = dc_get_chat_contacts((*chat).context, (*chat).id);
let mut chat_name = "Err [Name not found]".to_owned(); let mut chat_name = "Err [Name not found]".to_owned();
@@ -210,15 +206,15 @@ pub fn dc_chat_load_from_db(chat: *mut Chat, chat_id: u32) -> bool {
} }
} }
pub unsafe fn dc_create_chat_by_contact_id(context: &Context, contact_id: uint32_t) -> uint32_t { pub unsafe fn dc_create_chat_by_contact_id(context: &Context, contact_id: u32) -> u32 {
let mut chat_id = 0; let mut chat_id = 0;
let mut chat_blocked = 0; let mut chat_blocked = Blocked::Not;
let mut send_event = 0; let mut send_event = 0;
dc_lookup_real_nchat_by_contact_id(context, contact_id, &mut chat_id, &mut chat_blocked); dc_lookup_real_nchat_by_contact_id(context, contact_id, &mut chat_id, &mut chat_blocked);
if 0 != chat_id { if 0 != chat_id {
if 0 != chat_blocked { if chat_blocked != Blocked::Not {
dc_unblock_chat(context, chat_id); dc_unblock_chat(context, chat_id);
send_event = 1i32 send_event = 1i32;
} }
} else if !Contact::real_exists_by_id(context, contact_id) } else if !Contact::real_exists_by_id(context, contact_id)
&& contact_id != DC_CONTACT_ID_SELF as u32 && contact_id != DC_CONTACT_ID_SELF as u32
@@ -231,9 +227,9 @@ pub unsafe fn dc_create_chat_by_contact_id(context: &Context, contact_id: uint32
dc_create_or_lookup_nchat_by_contact_id( dc_create_or_lookup_nchat_by_contact_id(
context, context,
contact_id, contact_id,
0i32, Blocked::Not,
&mut chat_id, &mut chat_id,
ptr::null_mut(), None,
); );
if 0 != chat_id { if 0 != chat_id {
send_event = 1; send_event = 1;
@@ -248,20 +244,22 @@ pub unsafe fn dc_create_chat_by_contact_id(context: &Context, contact_id: uint32
pub unsafe fn dc_create_or_lookup_nchat_by_contact_id( pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
context: &Context, context: &Context,
contact_id: uint32_t, contact_id: u32,
create_blocked: libc::c_int, create_blocked: Blocked,
ret_chat_id: *mut uint32_t, ret_chat_id: *mut u32,
ret_chat_blocked: *mut libc::c_int, mut ret_chat_blocked: Option<&mut Blocked>,
) { ) {
let mut chat_id = 0; let mut chat_id = 0;
let mut chat_blocked = 0; let mut chat_blocked = Blocked::Not;
if !ret_chat_id.is_null() { if !ret_chat_id.is_null() {
*ret_chat_id = 0; *ret_chat_id = 0;
} }
if !ret_chat_blocked.is_null() {
*ret_chat_blocked = 0; if let Some(b) = ret_chat_blocked.as_mut() {
**b = Blocked::Not;
} }
if !context.sql.is_open() { if !context.sql.is_open() {
return; return;
} }
@@ -271,17 +269,18 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
dc_lookup_real_nchat_by_contact_id(context, contact_id, &mut chat_id, &mut chat_blocked); dc_lookup_real_nchat_by_contact_id(context, contact_id, &mut chat_id, &mut chat_blocked);
if chat_id != 0 { if chat_id != 0 {
if !ret_chat_id.is_null() { if !ret_chat_id.is_null() {
*ret_chat_id = chat_id *ret_chat_id = chat_id;
} }
if !ret_chat_blocked.is_null() {
*ret_chat_blocked = chat_blocked if let Some(b) = ret_chat_blocked.as_mut() {
**b = chat_blocked;
} }
return; return;
} }
if let Ok(contact) = Contact::load_from_db(context, contact_id) { if let Ok(contact) = Contact::load_from_db(context, contact_id) {
let chat_name = contact.get_display_name(); let chat_name = contact.get_display_name();
if sql::execute( match sql::execute(
context, context,
&context.sql, &context.sql,
format!( format!(
@@ -289,11 +288,12 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
100, 100,
chat_name, chat_name,
if contact_id == DC_CONTACT_ID_SELF as u32 { "K=1" } else { "" }, if contact_id == DC_CONTACT_ID_SELF as u32 { "K=1" } else { "" },
create_blocked, create_blocked as u8,
contact.get_addr(), contact.get_addr(),
), ),
params![], params![],
).is_ok() { ) {
Ok(_) => {
chat_id = sql::get_rowid( chat_id = sql::get_rowid(
context, context,
&context.sql, &context.sql,
@@ -308,30 +308,29 @@ pub unsafe fn dc_create_or_lookup_nchat_by_contact_id(
format!("INSERT INTO chats_contacts (chat_id, contact_id) VALUES({}, {})", chat_id, contact_id), format!("INSERT INTO chats_contacts (chat_id, contact_id) VALUES({}, {})", chat_id, contact_id),
params![], params![],
).ok(); ).ok();
},
Err(err) => panic!("{:?}", err),
} }
} }
if !ret_chat_id.is_null() { if !ret_chat_id.is_null() {
*ret_chat_id = chat_id *ret_chat_id = chat_id
} }
if !ret_chat_blocked.is_null() { if let Some(b) = ret_chat_blocked.as_mut() {
*ret_chat_blocked = create_blocked **b = create_blocked;
}; }
} }
pub fn dc_lookup_real_nchat_by_contact_id( pub fn dc_lookup_real_nchat_by_contact_id(
context: &Context, context: &Context,
contact_id: uint32_t, contact_id: u32,
ret_chat_id: *mut uint32_t, ret_chat_id: *mut u32,
ret_chat_blocked: *mut libc::c_int, ret_chat_blocked: &mut Blocked,
) { ) {
/* checks for "real" chats or self-chat */ /* checks for "real" chats or self-chat */
if !ret_chat_id.is_null() { if !ret_chat_id.is_null() {
unsafe { *ret_chat_id = 0 }; unsafe { *ret_chat_id = 0 };
} }
if !ret_chat_blocked.is_null() {
unsafe { *ret_chat_blocked = 0 };
}
if !context.sql.is_open() { if !context.sql.is_open() {
return; return;
} }
@@ -339,19 +338,19 @@ pub fn dc_lookup_real_nchat_by_contact_id(
if let Ok((id, blocked)) = context.sql.query_row( if let Ok((id, blocked)) = context.sql.query_row(
"SELECT c.id, c.blocked FROM chats c INNER JOIN chats_contacts j ON c.id=j.chat_id WHERE c.type=100 AND c.id>9 AND j.contact_id=?;", "SELECT c.id, c.blocked FROM chats c INNER JOIN chats_contacts j ON c.id=j.chat_id WHERE c.type=100 AND c.id>9 AND j.contact_id=?;",
params![contact_id as i32], params![contact_id as i32],
|row| Ok((row.get(0)?, row.get::<_, Option<i32>>(1)?.unwrap_or_default())), |row| Ok((row.get(0)?, row.get::<_, Option<_>>(1)?.unwrap_or_default())),
) { ) {
unsafe { *ret_chat_id = id }; unsafe { *ret_chat_id = id };
unsafe { *ret_chat_blocked = blocked }; *ret_chat_blocked = blocked;
} }
} }
pub unsafe fn dc_get_chat_id_by_contact_id(context: &Context, contact_id: uint32_t) -> uint32_t { pub unsafe fn dc_get_chat_id_by_contact_id(context: &Context, contact_id: u32) -> u32 {
let mut chat_id: uint32_t = 0i32 as uint32_t; let mut chat_id: u32 = 0i32 as u32;
let mut chat_id_blocked: libc::c_int = 0i32; let mut chat_id_blocked = Blocked::Not;
dc_lookup_real_nchat_by_contact_id(context, contact_id, &mut chat_id, &mut chat_id_blocked); dc_lookup_real_nchat_by_contact_id(context, contact_id, &mut chat_id, &mut chat_id_blocked);
if 0 != chat_id_blocked { if chat_id_blocked != Blocked::Not {
0i32 as libc::c_uint 0
} else { } else {
chat_id chat_id
} }
@@ -359,14 +358,14 @@ pub unsafe fn dc_get_chat_id_by_contact_id(context: &Context, contact_id: uint32
pub unsafe fn dc_prepare_msg<'a>( pub unsafe fn dc_prepare_msg<'a>(
context: &'a Context, context: &'a Context,
chat_id: uint32_t, chat_id: u32,
mut msg: *mut dc_msg_t<'a>, mut msg: *mut dc_msg_t<'a>,
) -> uint32_t { ) -> u32 {
if msg.is_null() || chat_id <= 9i32 as libc::c_uint { if msg.is_null() || chat_id <= 9i32 as libc::c_uint {
return 0i32 as uint32_t; return 0i32 as u32;
} }
(*msg).state = DC_STATE_OUT_PREPARING; (*msg).state = DC_STATE_OUT_PREPARING;
let msg_id: uint32_t = prepare_msg_common(context, chat_id, msg); let msg_id: u32 = prepare_msg_common(context, chat_id, msg);
context.call_cb( context.call_cb(
Event::MSGS_CHANGED, Event::MSGS_CHANGED,
(*msg).chat_id as uintptr_t, (*msg).chat_id as uintptr_t,
@@ -390,11 +389,11 @@ pub fn msgtype_has_file(msgtype: Viewtype) -> bool {
#[allow(non_snake_case)] #[allow(non_snake_case)]
unsafe fn prepare_msg_common<'a>( unsafe fn prepare_msg_common<'a>(
context: &'a Context, context: &'a Context,
chat_id: uint32_t, chat_id: u32,
mut msg: *mut dc_msg_t<'a>, mut msg: *mut dc_msg_t<'a>,
) -> uint32_t { ) -> u32 {
let mut OK_TO_CONTINUE = true; let mut OK_TO_CONTINUE = true;
(*msg).id = 0i32 as uint32_t; (*msg).id = 0i32 as u32;
(*msg).context = context; (*msg).context = context;
if (*msg).type_0 == Viewtype::Text { if (*msg).type_0 == Viewtype::Text {
/* the caller should check if the message text is empty */ /* the caller should check if the message text is empty */
@@ -479,7 +478,7 @@ unsafe fn prepare_msg_raw(
chat: *mut Chat, chat: *mut Chat,
msg: *mut dc_msg_t, msg: *mut dc_msg_t,
timestamp: i64, timestamp: i64,
) -> uint32_t { ) -> u32 {
let mut do_guarantee_e2ee: libc::c_int; let mut do_guarantee_e2ee: libc::c_int;
let e2ee_enabled: libc::c_int; let e2ee_enabled: libc::c_int;
let mut OK_TO_CONTINUE = true; let mut OK_TO_CONTINUE = true;
@@ -493,10 +492,13 @@ unsafe fn prepare_msg_raw(
let mut to_id = 0; let mut to_id = 0;
let mut location_id = 0; let mut location_id = 0;
if !((*chat).type_0 == 100 || (*chat).type_0 == 120 || (*chat).type_0 == 130) { if !((*chat).typ == Chattype::Single
error!(context, 0, "Cannot send to chat type #{}.", (*chat).type_0,); || (*chat).typ == Chattype::Group
} else if ((*chat).type_0 == 120 || (*chat).type_0 == 130) || (*chat).typ == Chattype::VerifiedGroup)
&& 0 == dc_is_contact_in_chat(context, (*chat).id, 1 as uint32_t) {
error!(context, 0, "Cannot send to chat type #{}.", (*chat).typ,);
} else if ((*chat).typ == Chattype::Group || (*chat).typ == Chattype::VerifiedGroup)
&& 0 == dc_is_contact_in_chat(context, (*chat).id, 1 as u32)
{ {
log_event!( log_event!(
context, context,
@@ -511,7 +513,7 @@ unsafe fn prepare_msg_raw(
} else { } else {
let from_c = CString::yolo(from.unwrap()); let from_c = CString::yolo(from.unwrap());
new_rfc724_mid = dc_create_outgoing_rfc724_mid( new_rfc724_mid = dc_create_outgoing_rfc724_mid(
if (*chat).type_0 == 120 || (*chat).type_0 == 130 { if (*chat).typ == Chattype::Group || (*chat).typ == Chattype::VerifiedGroup {
(*chat).grpid (*chat).grpid
} else { } else {
ptr::null_mut() ptr::null_mut()
@@ -519,7 +521,7 @@ unsafe fn prepare_msg_raw(
from_c.as_ptr(), from_c.as_ptr(),
); );
if (*chat).type_0 == DC_CHAT_TYPE_SINGLE { if (*chat).typ == Chattype::Single {
if let Some(id) = context.sql.query_row_col( if let Some(id) = context.sql.query_row_col(
context, context,
"SELECT contact_id FROM chats_contacts WHERE chat_id=?;", "SELECT contact_id FROM chats_contacts WHERE chat_id=?;",
@@ -537,9 +539,7 @@ unsafe fn prepare_msg_raw(
OK_TO_CONTINUE = false; OK_TO_CONTINUE = false;
} }
} else { } else {
if (*chat).type_0 == DC_CHAT_TYPE_GROUP if (*chat).typ == Chattype::Group || (*chat).typ == Chattype::VerifiedGroup {
|| (*chat).type_0 == DC_CHAT_TYPE_VERIFIED_GROUP
{
if (*chat).param.get_int(Param::Unpromoted).unwrap_or_default() == 1 { if (*chat).param.get_int(Param::Unpromoted).unwrap_or_default() == 1 {
(*chat).param.remove(Param::Unpromoted); (*chat).param.remove(Param::Unpromoted);
dc_chat_update_param(chat); dc_chat_update_param(chat);
@@ -823,11 +823,7 @@ pub unsafe fn dc_chat_is_self_talk(chat: *const Chat) -> libc::c_int {
* Sending messages * Sending messages
******************************************************************************/ ******************************************************************************/
// TODO should return bool /rtn // TODO should return bool /rtn
unsafe fn last_msg_in_chat_encrypted( unsafe fn last_msg_in_chat_encrypted(context: &Context, sql: &Sql, chat_id: u32) -> libc::c_int {
context: &Context,
sql: &Sql,
chat_id: uint32_t,
) -> libc::c_int {
let packed: Option<String> = sql.query_row_col( let packed: Option<String> = sql.query_row_col(
context, context,
"SELECT param \ "SELECT param \
@@ -863,8 +859,8 @@ pub unsafe fn dc_chat_update_param(chat: *mut Chat) -> libc::c_int {
pub unsafe fn dc_is_contact_in_chat( pub unsafe fn dc_is_contact_in_chat(
context: &Context, context: &Context,
chat_id: uint32_t, chat_id: u32,
contact_id: uint32_t, contact_id: u32,
) -> libc::c_int { ) -> libc::c_int {
/* this function works for group and for normal chats, however, it is more useful for group chats. /* this function works for group and for normal chats, however, it is more useful for group chats.
DC_CONTACT_ID_SELF may be used to check, if the user itself is in a group chat (DC_CONTACT_ID_SELF is not added to normal chats) */ DC_CONTACT_ID_SELF may be used to check, if the user itself is in a group chat (DC_CONTACT_ID_SELF is not added to normal chats) */
@@ -889,11 +885,7 @@ pub fn dc_unarchive_chat(context: &Context, chat_id: u32) {
.ok(); .ok();
} }
pub unsafe fn dc_send_msg<'a>( pub unsafe fn dc_send_msg<'a>(context: &'a Context, chat_id: u32, msg: *mut dc_msg_t<'a>) -> u32 {
context: &'a Context,
chat_id: uint32_t,
msg: *mut dc_msg_t<'a>,
) -> uint32_t {
if msg.is_null() { if msg.is_null() {
return 0; return 0;
} }
@@ -944,11 +936,7 @@ pub unsafe fn dc_send_msg<'a>(
(*msg).id (*msg).id
} }
pub unsafe fn dc_send_text_msg( pub unsafe fn dc_send_text_msg(context: &Context, chat_id: u32, text_to_send: String) -> u32 {
context: &Context,
chat_id: uint32_t,
text_to_send: String,
) -> uint32_t {
if chat_id <= 9 { if chat_id <= 9 {
warn!( warn!(
context, context,
@@ -964,7 +952,7 @@ pub unsafe fn dc_send_text_msg(
ret ret
} }
pub unsafe fn dc_set_draft(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t) { pub unsafe fn dc_set_draft(context: &Context, chat_id: u32, msg: *mut dc_msg_t) {
if chat_id <= 9i32 as libc::c_uint { if chat_id <= 9i32 as libc::c_uint {
return; return;
} }
@@ -975,10 +963,10 @@ pub unsafe fn dc_set_draft(context: &Context, chat_id: uint32_t, msg: *mut dc_ms
// TODO should return bool /rtn // TODO should return bool /rtn
#[allow(non_snake_case)] #[allow(non_snake_case)]
unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t) -> libc::c_int { unsafe fn set_draft_raw(context: &Context, chat_id: u32, msg: *mut dc_msg_t) -> libc::c_int {
let mut OK_TO_CONTINUE = true; let mut OK_TO_CONTINUE = true;
// similar to as dc_set_draft() but does not emit an event // similar to as dc_set_draft() but does not emit an event
let prev_draft_msg_id: uint32_t; let prev_draft_msg_id: u32;
let mut sth_changed: libc::c_int = 0i32; let mut sth_changed: libc::c_int = 0i32;
prev_draft_msg_id = get_draft_msg_id(context, chat_id); prev_draft_msg_id = get_draft_msg_id(context, chat_id);
if 0 != prev_draft_msg_id { if 0 != prev_draft_msg_id {
@@ -1050,8 +1038,8 @@ fn get_draft_msg_id(context: &Context, chat_id: u32) -> u32 {
draft_msg_id as u32 draft_msg_id as u32
} }
pub unsafe fn dc_get_draft(context: &Context, chat_id: uint32_t) -> *mut dc_msg_t { pub unsafe fn dc_get_draft(context: &Context, chat_id: u32) -> *mut dc_msg_t {
let draft_msg_id: uint32_t; let draft_msg_id: u32;
let draft_msg: *mut dc_msg_t; let draft_msg: *mut dc_msg_t;
if chat_id <= 9i32 as libc::c_uint { if chat_id <= 9i32 as libc::c_uint {
return 0 as *mut dc_msg_t; return 0 as *mut dc_msg_t;
@@ -1071,9 +1059,9 @@ pub unsafe fn dc_get_draft(context: &Context, chat_id: uint32_t) -> *mut dc_msg_
pub fn dc_get_chat_msgs( pub fn dc_get_chat_msgs(
context: &Context, context: &Context,
chat_id: uint32_t, chat_id: u32,
flags: uint32_t, flags: u32,
marker1before: uint32_t, marker1before: u32,
) -> *mut dc_array_t { ) -> *mut dc_array_t {
let mut ret = Vec::new(); let mut ret = Vec::new();
@@ -1234,7 +1222,7 @@ pub fn dc_marknoticed_all_chats(context: &Context) -> bool {
pub fn dc_get_chat_media( pub fn dc_get_chat_media(
context: &Context, context: &Context,
chat_id: uint32_t, chat_id: u32,
msg_type: Viewtype, msg_type: Viewtype,
msg_type2: Viewtype, msg_type2: Viewtype,
msg_type3: Viewtype, msg_type3: Viewtype,
@@ -1267,13 +1255,13 @@ pub fn dc_get_chat_media(
pub unsafe fn dc_get_next_media( pub unsafe fn dc_get_next_media(
context: &Context, context: &Context,
curr_msg_id: uint32_t, curr_msg_id: u32,
dir: libc::c_int, dir: libc::c_int,
msg_type: Viewtype, msg_type: Viewtype,
msg_type2: Viewtype, msg_type2: Viewtype,
msg_type3: Viewtype, msg_type3: Viewtype,
) -> uint32_t { ) -> u32 {
let mut ret_msg_id: uint32_t = 0i32 as uint32_t; let mut ret_msg_id: u32 = 0i32 as u32;
let msg: *mut dc_msg_t = dc_msg_new_untyped(context); let msg: *mut dc_msg_t = dc_msg_new_untyped(context);
let mut list: *mut dc_array_t = ptr::null_mut(); let mut list: *mut dc_array_t = ptr::null_mut();
let mut i: libc::c_int; let mut i: libc::c_int;
@@ -1435,7 +1423,7 @@ pub fn dc_get_chat_contacts(context: &Context, chat_id: u32) -> Vec<u32> {
.unwrap_or_default() .unwrap_or_default()
} }
pub unsafe fn dc_get_chat(context: &Context, chat_id: uint32_t) -> *mut Chat { pub unsafe fn dc_get_chat(context: &Context, chat_id: u32) -> *mut Chat {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let obj: *mut Chat = dc_chat_new(context); let obj: *mut Chat = dc_chat_new(context);
@@ -1546,7 +1534,7 @@ pub unsafe fn dc_add_contact_to_chat_ex(
&& contact_id != DC_CONTACT_ID_SELF as u32 && contact_id != DC_CONTACT_ID_SELF as u32
|| !dc_chat_load_from_db(chat, chat_id)) || !dc_chat_load_from_db(chat, chat_id))
{ {
if !(dc_is_contact_in_chat(context, chat_id, 1 as uint32_t) == 1) { if !(dc_is_contact_in_chat(context, chat_id, 1 as u32) == 1) {
log_event!( log_event!(
context, context,
Event::ERROR_SELF_NOT_IN_GROUP, Event::ERROR_SELF_NOT_IN_GROUP,
@@ -1576,7 +1564,7 @@ pub unsafe fn dc_add_contact_to_chat_ex(
} }
} else { } else {
// else continue and send status mail // else continue and send status mail
if (*chat).type_0 == 130 { if (*chat).typ == Chattype::VerifiedGroup {
if contact.is_verified() != VerifiedStatus::BidirectVerified { if contact.is_verified() != VerifiedStatus::BidirectVerified {
error!( error!(
context, 0, context, 0,
@@ -1598,7 +1586,7 @@ pub unsafe fn dc_add_contact_to_chat_ex(
StockMessage::MsgAddMember, StockMessage::MsgAddMember,
contact.get_addr(), contact.get_addr(),
"", "",
DC_CONTACT_ID_SELF as uint32_t, DC_CONTACT_ID_SELF as u32,
)); ));
(*msg).param.set_int(Param::Cmd, 4); (*msg).param.set_int(Param::Cmd, 4);
(*msg).param.set(Param::Arg, contact.get_addr()); (*msg).param.set(Param::Arg, contact.get_addr());
@@ -1689,7 +1677,7 @@ pub unsafe fn dc_remove_contact_from_chat(
/* we do not check if "contact_id" exists but just delete all records with the id from chats_contacts */ /* we do not check if "contact_id" exists but just delete all records with the id from chats_contacts */
/* this allows to delete pending references to deleted contacts. Of course, this should _not_ happen. */ /* this allows to delete pending references to deleted contacts. Of course, this should _not_ happen. */
if !(0 == real_group_exists(context, chat_id) || !dc_chat_load_from_db(chat, chat_id)) { if !(0 == real_group_exists(context, chat_id) || !dc_chat_load_from_db(chat, chat_id)) {
if !(dc_is_contact_in_chat(context, chat_id, 1 as uint32_t) == 1) { if !(dc_is_contact_in_chat(context, chat_id, 1 as u32) == 1) {
log_event!( log_event!(
context, context,
Event::ERROR_SELF_NOT_IN_GROUP, Event::ERROR_SELF_NOT_IN_GROUP,
@@ -1775,7 +1763,7 @@ pub fn dc_is_group_explicitly_left(context: &Context, grpid: *const libc::c_char
// TODO should return bool /rtn // TODO should return bool /rtn
pub unsafe fn dc_set_chat_name( pub unsafe fn dc_set_chat_name(
context: &Context, context: &Context,
chat_id: uint32_t, chat_id: u32,
new_name: *const libc::c_char, new_name: *const libc::c_char,
) -> libc::c_int { ) -> libc::c_int {
/* the function only sets the names of group chats; normal chats get their names from the contacts */ /* the function only sets the names of group chats; normal chats get their names from the contacts */
@@ -1790,7 +1778,7 @@ pub unsafe fn dc_set_chat_name(
if !(0i32 == real_group_exists(context, chat_id) || !dc_chat_load_from_db(chat, chat_id)) { if !(0i32 == real_group_exists(context, chat_id) || !dc_chat_load_from_db(chat, chat_id)) {
if strcmp((*chat).name, new_name) == 0i32 { if strcmp((*chat).name, new_name) == 0i32 {
success = 1i32 success = 1i32
} else if !(dc_is_contact_in_chat(context, chat_id, 1i32 as uint32_t) == 1i32) { } else if !(dc_is_contact_in_chat(context, chat_id, 1i32 as u32) == 1i32) {
log_event!( log_event!(
context, context,
Event::ERROR_SELF_NOT_IN_GROUP, Event::ERROR_SELF_NOT_IN_GROUP,
@@ -1851,7 +1839,7 @@ pub unsafe fn dc_set_chat_name(
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub unsafe fn dc_set_chat_profile_image( pub unsafe fn dc_set_chat_profile_image(
context: &Context, context: &Context,
chat_id: uint32_t, chat_id: u32,
new_image: *const libc::c_char, new_image: *const libc::c_char,
) -> libc::c_int { ) -> libc::c_int {
let mut OK_TO_CONTINUE = true; let mut OK_TO_CONTINUE = true;
@@ -1861,7 +1849,7 @@ pub unsafe fn dc_set_chat_profile_image(
let mut new_image_rel: *mut libc::c_char = ptr::null_mut(); let mut new_image_rel: *mut libc::c_char = ptr::null_mut();
if !(chat_id <= 9i32 as libc::c_uint) { if !(chat_id <= 9i32 as libc::c_uint) {
if !(0i32 == real_group_exists(context, chat_id) || !dc_chat_load_from_db(chat, chat_id)) { if !(0i32 == real_group_exists(context, chat_id) || !dc_chat_load_from_db(chat, chat_id)) {
if !(dc_is_contact_in_chat(context, chat_id, 1i32 as uint32_t) == 1i32) { if !(dc_is_contact_in_chat(context, chat_id, 1i32 as u32) == 1i32) {
log_event!( log_event!(
context, context,
Event::ERROR_SELF_NOT_IN_GROUP, Event::ERROR_SELF_NOT_IN_GROUP,
@@ -1895,7 +1883,7 @@ pub unsafe fn dc_set_chat_profile_image(
}, },
"", "",
"", "",
DC_CONTACT_ID_SELF as uint32_t, DC_CONTACT_ID_SELF as u32,
)); ));
(*msg).id = dc_send_msg(context, chat_id, msg); (*msg).id = dc_send_msg(context, chat_id, msg);
context.call_cb( context.call_cb(
@@ -1975,14 +1963,14 @@ pub unsafe fn dc_forward_msgs(
(*msg).param.remove(Param::ForcePlaintext); (*msg).param.remove(Param::ForcePlaintext);
(*msg).param.remove(Param::Cmd); (*msg).param.remove(Param::Cmd);
let new_msg_id: uint32_t; let new_msg_id: u32;
if (*msg).state == DC_STATE_OUT_PREPARING { if (*msg).state == DC_STATE_OUT_PREPARING {
let fresh9 = curr_timestamp; let fresh9 = curr_timestamp;
curr_timestamp = curr_timestamp + 1; curr_timestamp = curr_timestamp + 1;
new_msg_id = prepare_msg_raw(context, chat, msg, fresh9); new_msg_id = prepare_msg_raw(context, chat, msg, fresh9);
let save_param = (*msg).param.clone(); let save_param = (*msg).param.clone();
(*msg).param = original_param; (*msg).param = original_param;
(*msg).id = src_msg_id as uint32_t; (*msg).id = src_msg_id as u32;
if let Some(old_fwd) = (*msg).param.get(Param::PrepForwards) { if let Some(old_fwd) = (*msg).param.get(Param::PrepForwards) {
let new_fwd = format!("{} {}", old_fwd, new_msg_id); let new_fwd = format!("{} {}", old_fwd, new_msg_id);
@@ -2018,18 +2006,16 @@ pub unsafe fn dc_forward_msgs(
dc_chat_unref(chat); dc_chat_unref(chat);
} }
pub unsafe fn dc_chat_get_id(chat: *const Chat) -> uint32_t { pub unsafe fn dc_chat_get_id(chat: *const Chat) -> u32 {
if chat.is_null() { if chat.is_null() {
return 0i32 as uint32_t; return 0i32 as u32;
} }
(*chat).id (*chat).id
} }
pub unsafe fn dc_chat_get_type(chat: *const Chat) -> libc::c_int { pub unsafe fn dc_chat_get_type(chat: *const Chat) -> Chattype {
if chat.is_null() { assert!(!chat.is_null());
return 0i32; (*chat).typ
}
(*chat).type_0
} }
pub unsafe fn dc_chat_get_name(chat: *const Chat) -> *mut libc::c_char { pub unsafe fn dc_chat_get_name(chat: *const Chat) -> *mut libc::c_char {
@@ -2046,12 +2032,12 @@ pub unsafe fn dc_chat_get_subtitle(chat: *const Chat) -> *mut libc::c_char {
} }
let mut ret: *mut libc::c_char = std::ptr::null_mut(); let mut ret: *mut libc::c_char = std::ptr::null_mut();
if (*chat).type_0 == 100 && (*chat).param.exists(Param::Selftalk) { if (*chat).typ == Chattype::Single && (*chat).param.exists(Param::Selftalk) {
ret = (*chat) ret = (*chat)
.context .context
.stock_str(StockMessage::SelfTalkSubTitle) .stock_str(StockMessage::SelfTalkSubTitle)
.strdup(); .strdup();
} else if (*chat).type_0 == 100 { } else if (*chat).typ == Chattype::Single {
let ret_raw: String = (*chat) let ret_raw: String = (*chat)
.context .context
.sql .sql
@@ -2065,7 +2051,7 @@ pub unsafe fn dc_chat_get_subtitle(chat: *const Chat) -> *mut libc::c_char {
) )
.unwrap_or_else(|| "Err".into()); .unwrap_or_else(|| "Err".into());
ret = ret_raw.strdup(); ret = ret_raw.strdup();
} else if (*chat).type_0 == 120 || (*chat).type_0 == 130 { } else if (*chat).typ == Chattype::Group || (*chat).typ == Chattype::VerifiedGroup {
if (*chat).id == 1 { if (*chat).id == 1 {
ret = (*chat).context.stock_str(StockMessage::DeadDrop).strdup(); ret = (*chat).context.stock_str(StockMessage::DeadDrop).strdup();
} else { } else {
@@ -2107,7 +2093,7 @@ pub unsafe fn dc_chat_get_profile_image(chat: *const Chat) -> *mut libc::c_char
.strdup(); .strdup();
if !image_rel.is_null() && 0 != *image_rel.offset(0isize) as libc::c_int { if !image_rel.is_null() && 0 != *image_rel.offset(0isize) as libc::c_int {
image_abs = dc_get_abs_path((*chat).context, image_rel) image_abs = dc_get_abs_path((*chat).context, image_rel)
} else if (*chat).type_0 == DC_CHAT_TYPE_SINGLE { } else if (*chat).typ == Chattype::Single {
let contacts = dc_get_chat_contacts((*chat).context, (*chat).id); let contacts = dc_get_chat_contacts((*chat).context, (*chat).id);
if !contacts.is_empty() { if !contacts.is_empty() {
if let Ok(contact) = Contact::get_by_id((*chat).context, contacts[0]) { if let Ok(contact) = Contact::get_by_id((*chat).context, contacts[0]) {
@@ -2124,11 +2110,11 @@ pub unsafe fn dc_chat_get_profile_image(chat: *const Chat) -> *mut libc::c_char
image_abs image_abs
} }
pub unsafe fn dc_chat_get_color(chat: *const Chat) -> uint32_t { pub unsafe fn dc_chat_get_color(chat: *const Chat) -> u32 {
let mut color: uint32_t = 0i32 as uint32_t; let mut color: u32 = 0i32 as u32;
if !chat.is_null() { if !chat.is_null() {
if (*chat).type_0 == DC_CHAT_TYPE_SINGLE { if (*chat).typ == Chattype::Single {
let contacts = dc_get_chat_contacts((*chat).context, (*chat).id); let contacts = dc_get_chat_contacts((*chat).context, (*chat).id);
if !contacts.is_empty() { if !contacts.is_empty() {
if let Ok(contact) = Contact::get_by_id((*chat).context, contacts[0]) { if let Ok(contact) = Contact::get_by_id((*chat).context, contacts[0]) {
@@ -2136,7 +2122,7 @@ pub unsafe fn dc_chat_get_color(chat: *const Chat) -> uint32_t {
} }
} }
} else { } else {
color = dc_str_to_color((*chat).name) as uint32_t color = dc_str_to_color((*chat).name) as u32
} }
} }
@@ -2144,9 +2130,9 @@ pub unsafe fn dc_chat_get_color(chat: *const Chat) -> uint32_t {
} }
// TODO should return bool /rtn // TODO should return bool /rtn
pub unsafe fn dc_chat_get_archived(chat: *const Chat) -> libc::c_int { pub unsafe fn dc_chat_get_archived(chat: *const Chat) -> bool {
if chat.is_null() { if chat.is_null() {
return 0i32; return false;
} }
(*chat).archived (*chat).archived
} }
@@ -2164,13 +2150,13 @@ pub unsafe fn dc_chat_is_verified(chat: *const Chat) -> libc::c_int {
if chat.is_null() { if chat.is_null() {
return 0i32; return 0i32;
} }
((*chat).type_0 == 130i32) as libc::c_int ((*chat).typ == Chattype::VerifiedGroup) as libc::c_int
} }
// TODO should return bool /rtn // TODO should return bool /rtn
pub unsafe fn dc_chat_is_sending_locations(chat: *const Chat) -> libc::c_int { pub unsafe fn dc_chat_is_sending_locations(chat: *const Chat) -> bool {
if chat.is_null() { if chat.is_null() {
return 0i32; return false;
} }
(*chat).is_sending_locations (*chat).is_sending_locations
} }
@@ -2195,12 +2181,9 @@ pub fn dc_get_chat_cnt(context: &Context) -> usize {
pub unsafe fn dc_get_chat_id_by_grpid( pub unsafe fn dc_get_chat_id_by_grpid(
context: &Context, context: &Context,
grpid: *const libc::c_char, grpid: *const libc::c_char,
ret_blocked: *mut libc::c_int, ret_blocked: Option<&mut Blocked>,
ret_verified: *mut libc::c_int, ret_verified: *mut libc::c_int,
) -> u32 { ) -> u32 {
if !ret_blocked.is_null() {
*ret_blocked = 0;
}
if !ret_verified.is_null() { if !ret_verified.is_null() {
*ret_verified = 0; *ret_verified = 0;
} }
@@ -2212,20 +2195,21 @@ pub unsafe fn dc_get_chat_id_by_grpid(
params![as_str(grpid)], params![as_str(grpid)],
|row| { |row| {
let chat_id = row.get(0)?; let chat_id = row.get(0)?;
if !ret_blocked.is_null() {
*ret_blocked = row.get(1)?; if let Some(b) = ret_blocked {
} *b = row.get::<_, Option<Blocked>>(1)?.unwrap_or_default();
if !ret_verified.is_null() {
let v: i32 = row.get(2)?;
*ret_verified = (v == 130) as libc::c_int;
} }
let v = row.get::<_, Option<Chattype>>(2)?.unwrap_or_default();
*ret_verified = (v == Chattype::VerifiedGroup) as libc::c_int;
Ok(chat_id) Ok(chat_id)
}, },
) )
.unwrap_or_default() .unwrap_or_default()
} }
pub fn dc_add_device_msg(context: &Context, chat_id: uint32_t, text: *const libc::c_char) { pub fn dc_add_device_msg(context: &Context, chat_id: u32, text: *const libc::c_char) {
if text.is_null() { if text.is_null() {
return; return;
} }

View File

@@ -1,3 +1,4 @@
use crate::constants::Chattype;
use crate::contact::*; use crate::contact::*;
use crate::context::Context; use crate::context::Context;
use crate::dc_chat::*; use crate::dc_chat::*;
@@ -144,7 +145,7 @@ pub unsafe fn dc_lot_fill(
} else if chat.is_null() { } else if chat.is_null() {
(*lot).text1 = 0 as *mut libc::c_char; (*lot).text1 = 0 as *mut libc::c_char;
(*lot).text1_meaning = 0i32 (*lot).text1_meaning = 0i32
} else if (*chat).type_0 == 120i32 || (*chat).type_0 == 130i32 { } else if (*chat).typ == Chattype::Group || (*chat).typ == Chattype::VerifiedGroup {
if 0 != dc_msg_is_info(msg) || contact.is_none() { if 0 != dc_msg_is_info(msg) || contact.is_none() {
(*lot).text1 = 0 as *mut libc::c_char; (*lot).text1 = 0 as *mut libc::c_char;
(*lot).text1_meaning = 0i32 (*lot).text1_meaning = 0i32

View File

@@ -518,7 +518,7 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
let msg: *mut dc_msg_t = (*factory).msg; let msg: *mut dc_msg_t = (*factory).msg;
let mut meta_part: *mut mailmime = 0 as *mut mailmime; let mut meta_part: *mut mailmime = 0 as *mut mailmime;
let mut placeholdertext: *mut libc::c_char = 0 as *mut libc::c_char; let mut placeholdertext: *mut libc::c_char = 0 as *mut libc::c_char;
if (*chat).type_0 == DC_CHAT_TYPE_VERIFIED_GROUP as libc::c_int { if (*chat).typ == Chattype::VerifiedGroup {
mailimf_fields_add( mailimf_fields_add(
imf_fields, imf_fields,
mailimf_field_new_custom( mailimf_field_new_custom(
@@ -549,9 +549,7 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc:
/* build header etc. */ /* build header etc. */
let command = (*msg).param.get_int(Param::Cmd).unwrap_or_default(); let command = (*msg).param.get_int(Param::Cmd).unwrap_or_default();
if (*chat).type_0 == DC_CHAT_TYPE_GROUP as libc::c_int if (*chat).typ == Chattype::Group || (*chat).typ == Chattype::VerifiedGroup {
|| (*chat).type_0 == DC_CHAT_TYPE_VERIFIED_GROUP as libc::c_int
{
mailimf_fields_add( mailimf_fields_add(
imf_fields, imf_fields,
mailimf_field_new_custom( mailimf_field_new_custom(
@@ -1091,9 +1089,7 @@ unsafe fn get_subject(
}; };
if (*msg).param.get_int(Param::Cmd).unwrap_or_default() == 6 { if (*msg).param.get_int(Param::Cmd).unwrap_or_default() == 6 {
ret = context.stock_str(StockMessage::AcSetupMsgSubject).strdup() ret = context.stock_str(StockMessage::AcSetupMsgSubject).strdup()
} else if (*chat).type_0 == DC_CHAT_TYPE_GROUP as libc::c_int } else if (*chat).typ == Chattype::Group || (*chat).typ == Chattype::VerifiedGroup {
|| (*chat).type_0 == DC_CHAT_TYPE_VERIFIED_GROUP as libc::c_int
{
ret = dc_mprintf( ret = dc_mprintf(
b"Chat: %s: %s%s\x00" as *const u8 as *const libc::c_char, b"Chat: %s: %s%s\x00" as *const u8 as *const libc::c_char,
(*chat).name, (*chat).name,

View File

@@ -762,7 +762,7 @@ pub unsafe fn dc_msg_get_summary<'a>(
} }
if ok_to_continue { if ok_to_continue {
let contact = if (*msg).from_id != DC_CONTACT_ID_SELF as libc::c_uint let contact = if (*msg).from_id != DC_CONTACT_ID_SELF as libc::c_uint
&& ((*chat).type_0 == 120 || (*chat).type_0 == 130) && ((*chat).typ == Chattype::Group || (*chat).typ == Chattype::VerifiedGroup)
{ {
Contact::get_by_id((*chat).context, (*msg).from_id).ok() Contact::get_by_id((*chat).context, (*msg).from_id).ok()
} else { } else {
@@ -1393,7 +1393,7 @@ mod tests {
assert!(res.is_ok()); assert!(res.is_ok());
let chat = dc_create_chat_by_contact_id(ctx, contact); let chat = dc_create_chat_by_contact_id(ctx, contact);
assert!(chat != 0); assert!(chat != 0, "failed to create chat");
let msg = dc_msg_new(ctx, Viewtype::Text); let msg = dc_msg_new(ctx, Viewtype::Text);
assert!(!msg.is_null()); assert!(!msg.is_null());

View File

@@ -1,5 +1,6 @@
use percent_encoding::percent_decode_str; use percent_encoding::percent_decode_str;
use crate::constants::Blocked;
use crate::contact::*; use crate::contact::*;
use crate::context::Context; use crate::context::Context;
use crate::dc_chat::*; use crate::dc_chat::*;
@@ -233,9 +234,9 @@ pub unsafe fn dc_check_qr(context: &Context, qr: *const libc::c_char) -> *mut dc
dc_create_or_lookup_nchat_by_contact_id( dc_create_or_lookup_nchat_by_contact_id(
context, context,
(*qr_parsed).id, (*qr_parsed).id,
2i32, Blocked::Deaddrop,
&mut chat_id, &mut chat_id,
0 as *mut libc::c_int, None,
); );
device_msg = dc_mprintf( device_msg = dc_mprintf(
b"%s verified.\x00" as *const u8 as *const libc::c_char, b"%s verified.\x00" as *const u8 as *const libc::c_char,

View File

@@ -284,7 +284,7 @@ unsafe fn add_parts(
) -> Result<()> { ) -> Result<()> {
let mut state: libc::c_int; let mut state: libc::c_int;
let mut msgrmsg: libc::c_int; let mut msgrmsg: libc::c_int;
let mut chat_id_blocked = 0; let mut chat_id_blocked = Blocked::Not;
let mut sort_timestamp = 0; let mut sort_timestamp = 0;
let mut rcvd_timestamp = 0; let mut rcvd_timestamp = 0;
let mut mime_in_reply_to = std::ptr::null_mut(); let mut mime_in_reply_to = std::ptr::null_mut();
@@ -409,7 +409,7 @@ unsafe fn add_parts(
} }
} }
let mut test_normal_chat_id = 0; let mut test_normal_chat_id = 0;
let mut test_normal_chat_id_blocked = 0; let mut test_normal_chat_id_blocked = Blocked::Not;
dc_lookup_real_nchat_by_contact_id( dc_lookup_real_nchat_by_contact_id(
context, context,
@@ -425,12 +425,12 @@ unsafe fn add_parts(
// (groups appear automatically only if the _sender_ is known, see core issue #54) // (groups appear automatically only if the _sender_ is known, see core issue #54)
let create_blocked = if 0 != test_normal_chat_id let create_blocked = if 0 != test_normal_chat_id
&& test_normal_chat_id_blocked == DC_CHAT_NOT_BLOCKED && test_normal_chat_id_blocked == Blocked::Not
|| incoming_origin.is_start_new_chat() || incoming_origin.is_start_new_chat()
{ {
DC_CHAT_NOT_BLOCKED Blocked::Not
} else { } else {
DC_CHAT_DEADDROP_BLOCKED Blocked::Deaddrop
}; };
create_or_lookup_group( create_or_lookup_group(
@@ -443,9 +443,9 @@ unsafe fn add_parts(
chat_id, chat_id,
&mut chat_id_blocked, &mut chat_id_blocked,
); );
if 0 != *chat_id && 0 != chat_id_blocked && 0 == create_blocked { if 0 != *chat_id && Blocked::Not != chat_id_blocked && create_blocked == Blocked::Not {
dc_unblock_chat(context, *chat_id); dc_unblock_chat(context, *chat_id);
chat_id_blocked = 0; chat_id_blocked = Blocked::Not;
} }
} }
@@ -463,27 +463,27 @@ unsafe fn add_parts(
if *chat_id == 0 { if *chat_id == 0 {
// try to create a normal chat // try to create a normal chat
let create_blocked = if incoming_origin.is_start_new_chat() || *from_id == *to_id { let create_blocked = if incoming_origin.is_start_new_chat() || *from_id == *to_id {
DC_CHAT_NOT_BLOCKED Blocked::Not
} else { } else {
DC_CHAT_DEADDROP_BLOCKED Blocked::Deaddrop
}; };
if 0 != test_normal_chat_id { if 0 != test_normal_chat_id {
*chat_id = test_normal_chat_id; *chat_id = test_normal_chat_id;
chat_id_blocked = test_normal_chat_id_blocked chat_id_blocked = test_normal_chat_id_blocked;
} else if 0 != allow_creation { } else if 0 != allow_creation {
dc_create_or_lookup_nchat_by_contact_id( dc_create_or_lookup_nchat_by_contact_id(
context, context,
*from_id, *from_id,
create_blocked, create_blocked,
chat_id, chat_id,
&mut chat_id_blocked, Some(&mut chat_id_blocked),
); );
} }
if 0 != *chat_id && 0 != chat_id_blocked { if 0 != *chat_id && Blocked::Not != chat_id_blocked {
if 0 == create_blocked { if Blocked::Not == create_blocked {
dc_unblock_chat(context, *chat_id); dc_unblock_chat(context, *chat_id);
chat_id_blocked = 0; chat_id_blocked = Blocked::Not;
} else if 0 != dc_is_reply_to_known_message(context, mime_parser) { } else if 0 != dc_is_reply_to_known_message(context, mime_parser) {
// we do not want any chat to be created implicitly. Because of the origin-scale-up, // we do not want any chat to be created implicitly. Because of the origin-scale-up,
// the contact requests will pop up and this should be just fine. // the contact requests will pop up and this should be just fine.
@@ -506,7 +506,7 @@ unsafe fn add_parts(
// if the chat_id is blocked, // if the chat_id is blocked,
// for unknown senders and non-delta messages set the state to NOTICED // for unknown senders and non-delta messages set the state to NOTICED
// to not result in a contact request (this would require the state FRESH) // to not result in a contact request (this would require the state FRESH)
if 0 != chat_id_blocked && state == DC_STATE_IN_FRESH { if Blocked::Not != chat_id_blocked && state == DC_STATE_IN_FRESH {
if !incoming_origin.is_verified() && msgrmsg == 0 { if !incoming_origin.is_verified() && msgrmsg == 0 {
state = DC_STATE_IN_NOTICED; state = DC_STATE_IN_NOTICED;
} }
@@ -525,33 +525,36 @@ unsafe fn add_parts(
context, context,
&mut mime_parser, &mut mime_parser,
allow_creation, allow_creation,
0, Blocked::Not,
*from_id, *from_id,
to_ids, to_ids,
chat_id, chat_id,
&mut chat_id_blocked, &mut chat_id_blocked,
); );
if 0 != *chat_id && 0 != chat_id_blocked { if 0 != *chat_id && Blocked::Not != chat_id_blocked {
dc_unblock_chat(context, *chat_id); dc_unblock_chat(context, *chat_id);
chat_id_blocked = 0 chat_id_blocked = Blocked::Not;
} }
} }
if *chat_id == 0 && 0 != allow_creation { if *chat_id == 0 && 0 != allow_creation {
let create_blocked = if 0 != msgrmsg && !Contact::is_blocked_load(context, *to_id) { let create_blocked = if 0 != msgrmsg && !Contact::is_blocked_load(context, *to_id) {
DC_CHAT_NOT_BLOCKED Blocked::Not
} else { } else {
DC_CHAT_DEADDROP_BLOCKED Blocked::Deaddrop
}; };
dc_create_or_lookup_nchat_by_contact_id( dc_create_or_lookup_nchat_by_contact_id(
context, context,
*to_id, *to_id,
create_blocked, create_blocked,
chat_id, chat_id,
&mut chat_id_blocked, Some(&mut chat_id_blocked),
); );
if 0 != *chat_id && 0 != chat_id_blocked && 0 == create_blocked { if 0 != *chat_id
&& Blocked::Not != chat_id_blocked
&& Blocked::Not == create_blocked
{
dc_unblock_chat(context, *chat_id); dc_unblock_chat(context, *chat_id);
chat_id_blocked = 0 chat_id_blocked = Blocked::Not;
} }
} }
} }
@@ -562,13 +565,13 @@ unsafe fn add_parts(
dc_create_or_lookup_nchat_by_contact_id( dc_create_or_lookup_nchat_by_contact_id(
context, context,
1, 1,
0, Blocked::Not,
chat_id, chat_id,
&mut chat_id_blocked, Some(&mut chat_id_blocked),
); );
if 0 != *chat_id && 0 != chat_id_blocked { if 0 != *chat_id && Blocked::Not != chat_id_blocked {
dc_unblock_chat(context, *chat_id); dc_unblock_chat(context, *chat_id);
chat_id_blocked = 0; chat_id_blocked = Blocked::Not;
} }
} }
} }
@@ -743,7 +746,7 @@ unsafe fn add_parts(
} else if 0 != incoming && state == DC_STATE_IN_FRESH { } else if 0 != incoming && state == DC_STATE_IN_FRESH {
if 0 != from_id_blocked { if 0 != from_id_blocked {
*create_event_to_send = None; *create_event_to_send = None;
} else if 0 != chat_id_blocked { } else if Blocked::Not != chat_id_blocked {
*create_event_to_send = Some(Event::MSGS_CHANGED); *create_event_to_send = Some(Event::MSGS_CHANGED);
} else { } else {
*create_event_to_send = Some(Event::INCOMING_MSG); *create_event_to_send = Some(Event::INCOMING_MSG);
@@ -1043,15 +1046,15 @@ unsafe fn create_or_lookup_group(
context: &Context, context: &Context,
mime_parser: &mut dc_mimeparser_t, mime_parser: &mut dc_mimeparser_t,
allow_creation: libc::c_int, allow_creation: libc::c_int,
create_blocked: libc::c_int, create_blocked: Blocked,
from_id: u32, from_id: u32,
to_ids: &mut Vec<u32>, to_ids: &mut Vec<u32>,
ret_chat_id: *mut uint32_t, ret_chat_id: *mut uint32_t,
ret_chat_id_blocked: *mut libc::c_int, ret_chat_id_blocked: &mut Blocked,
) { ) {
let group_explicitly_left: libc::c_int; let group_explicitly_left: libc::c_int;
let mut chat_id = 0; let mut chat_id = 0;
let mut chat_id_blocked = 0; let mut chat_id_blocked = Blocked::Not;
let mut chat_id_verified = 0; let mut chat_id_verified = 0;
let mut grpid = std::ptr::null_mut(); let mut grpid = std::ptr::null_mut();
let mut grpname = std::ptr::null_mut(); let mut grpname = std::ptr::null_mut();
@@ -1071,9 +1074,9 @@ unsafe fn create_or_lookup_group(
grpname: *mut libc::c_char, grpname: *mut libc::c_char,
failure_reason: *mut libc::c_char, failure_reason: *mut libc::c_char,
ret_chat_id: *mut uint32_t, ret_chat_id: *mut uint32_t,
ret_chat_id_blocked: *mut libc::c_int, ret_chat_id_blocked: &mut Blocked,
chat_id: u32, chat_id: u32,
chat_id_blocked: i32| { chat_id_blocked: Blocked| {
free(grpid.cast()); free(grpid.cast());
free(grpname.cast()); free(grpname.cast());
free(failure_reason.cast()); free(failure_reason.cast());
@@ -1081,9 +1084,11 @@ unsafe fn create_or_lookup_group(
if !ret_chat_id.is_null() { if !ret_chat_id.is_null() {
*ret_chat_id = chat_id; *ret_chat_id = chat_id;
} }
if !ret_chat_id_blocked.is_null() { *ret_chat_id_blocked = if 0 != chat_id {
*ret_chat_id_blocked = if 0 != chat_id { chat_id_blocked } else { 0 }; chat_id_blocked
} } else {
Blocked::Not
};
}; };
if mime_parser.is_system_message == DC_CMD_LOCATION_STREAMING_ENABLED { if mime_parser.is_system_message == DC_CMD_LOCATION_STREAMING_ENABLED {
@@ -1231,7 +1236,12 @@ unsafe fn create_or_lookup_group(
set_better_msg(mime_parser, &better_msg); set_better_msg(mime_parser, &better_msg);
// check, if we have a chat with this group ID // check, if we have a chat with this group ID
chat_id = dc_get_chat_id_by_grpid(context, grpid, &mut chat_id_blocked, &mut chat_id_verified); chat_id = dc_get_chat_id_by_grpid(
context,
grpid,
Some(&mut chat_id_blocked),
&mut chat_id_verified,
);
if chat_id != 0 { if chat_id != 0 {
if 0 != chat_id_verified if 0 != chat_id_verified
&& 0 == check_verified_properties( && 0 == check_verified_properties(
@@ -1472,34 +1482,32 @@ unsafe fn create_or_lookup_adhoc_group(
context: &Context, context: &Context,
mime_parser: &dc_mimeparser_t, mime_parser: &dc_mimeparser_t,
allow_creation: libc::c_int, allow_creation: libc::c_int,
create_blocked: libc::c_int, create_blocked: Blocked,
from_id: u32, from_id: u32,
to_ids: &mut Vec<u32>, to_ids: &mut Vec<u32>,
ret_chat_id: *mut uint32_t, ret_chat_id: *mut uint32_t,
ret_chat_id_blocked: *mut libc::c_int, ret_chat_id_blocked: &mut Blocked,
) { ) {
// if we're here, no grpid was found, check there is an existing ad-hoc // if we're here, no grpid was found, check there is an existing ad-hoc
// group matching the to-list or if we can create one // group matching the to-list or if we can create one
let mut chat_id = 0; let mut chat_id = 0;
let mut chat_id_blocked = 0; let mut chat_id_blocked = Blocked::Not;
let mut grpid = 0 as *mut libc::c_char; let mut grpid = 0 as *mut libc::c_char;
let mut grpname = 0 as *mut libc::c_char; let mut grpname = 0 as *mut libc::c_char;
let cleanup = |grpid: *mut libc::c_char, let cleanup = |grpid: *mut libc::c_char,
grpname: *mut libc::c_char, grpname: *mut libc::c_char,
ret_chat_id: *mut uint32_t, ret_chat_id: *mut uint32_t,
ret_chat_id_blocked: *mut libc::c_int, ret_chat_id_blocked: &mut Blocked,
chat_id: u32, chat_id: u32,
chat_id_blocked: i32| { chat_id_blocked: Blocked| {
free(grpid as *mut libc::c_void); free(grpid as *mut libc::c_void);
free(grpname as *mut libc::c_void); free(grpname as *mut libc::c_void);
if !ret_chat_id.is_null() { if !ret_chat_id.is_null() {
*ret_chat_id = chat_id *ret_chat_id = chat_id;
} }
if !ret_chat_id_blocked.is_null() { *ret_chat_id_blocked = chat_id_blocked;
*ret_chat_id_blocked = chat_id_blocked
};
}; };
// build member list from the given ids // build member list from the given ids
@@ -1547,7 +1555,7 @@ unsafe fn create_or_lookup_adhoc_group(
), ),
params![], params![],
|row| { |row| {
Ok((row.get::<_, i32>(0)?, row.get::<_, Option<i32>>(1)?.unwrap_or_default())) Ok((row.get::<_, i32>(0)?, row.get::<_, Option<Blocked>>(1)?.unwrap_or_default()))
} }
); );
@@ -1628,7 +1636,7 @@ fn create_group_record(
context: &Context, context: &Context,
grpid: *const libc::c_char, grpid: *const libc::c_char,
grpname: *const libc::c_char, grpname: *const libc::c_char,
create_blocked: libc::c_int, create_blocked: Blocked,
create_verified: libc::c_int, create_verified: libc::c_int,
) -> u32 { ) -> u32 {
if sql::execute( if sql::execute(

View File

@@ -234,12 +234,9 @@ pub unsafe fn dc_join_securejoin(context: &Context, qr: *const libc::c_char) ->
bob.expects = 0; bob.expects = 0;
if bob.status == 1 { if bob.status == 1 {
if 0 != join_vg { if 0 != join_vg {
ret_chat_id = dc_get_chat_id_by_grpid( ret_chat_id =
context, dc_get_chat_id_by_grpid(context, (*qr_scan).text2, None, 0 as *mut libc::c_int)
(*qr_scan).text2, as libc::c_int
0 as *mut libc::c_int,
0 as *mut libc::c_int,
) as libc::c_int
} else { } else {
ret_chat_id = contact_chat_id as libc::c_int ret_chat_id = contact_chat_id as libc::c_int
} }
@@ -346,7 +343,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
let mut auth: *mut libc::c_char = 0 as *mut libc::c_char; let mut auth: *mut libc::c_char = 0 as *mut libc::c_char;
let mut own_fingerprint: *mut libc::c_char = 0 as *mut libc::c_char; let mut own_fingerprint: *mut libc::c_char = 0 as *mut libc::c_char;
let mut contact_chat_id: uint32_t = 0i32 as uint32_t; let mut contact_chat_id: uint32_t = 0i32 as uint32_t;
let mut contact_chat_id_blocked: libc::c_int = 0i32; let mut contact_chat_id_blocked = Blocked::Not;
let mut grpid: *mut libc::c_char = 0 as *mut libc::c_char; let mut grpid: *mut libc::c_char = 0 as *mut libc::c_char;
let mut ret: libc::c_int = 0i32; let mut ret: libc::c_int = 0i32;
@@ -364,11 +361,11 @@ pub unsafe fn dc_handle_securejoin_handshake(
dc_create_or_lookup_nchat_by_contact_id( dc_create_or_lookup_nchat_by_contact_id(
context, context,
contact_id, contact_id,
0i32, Blocked::Not,
&mut contact_chat_id, &mut contact_chat_id,
&mut contact_chat_id_blocked, Some(&mut contact_chat_id_blocked),
); );
if 0 != contact_chat_id_blocked { if Blocked::Not != contact_chat_id_blocked {
dc_unblock_chat(context, contact_chat_id); dc_unblock_chat(context, contact_chat_id);
} }
ret = 0x2i32; ret = 0x2i32;
@@ -583,7 +580,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
let group_chat_id: uint32_t = dc_get_chat_id_by_grpid( let group_chat_id: uint32_t = dc_get_chat_id_by_grpid(
context, context,
grpid, grpid,
0 as *mut libc::c_int, None,
0 as *mut libc::c_int, 0 as *mut libc::c_int,
); );
if group_chat_id == 0i32 as libc::c_uint { if group_chat_id == 0i32 as libc::c_uint {
@@ -653,12 +650,7 @@ pub unsafe fn dc_handle_securejoin_handshake(
let mut vg_expect_encrypted: libc::c_int = 1i32; let mut vg_expect_encrypted: libc::c_int = 1i32;
if 0 != join_vg { if 0 != join_vg {
let mut is_verified_group: libc::c_int = 0i32; let mut is_verified_group: libc::c_int = 0i32;
dc_get_chat_id_by_grpid( dc_get_chat_id_by_grpid(context, grpid, None, &mut is_verified_group);
context,
grpid,
0 as *mut libc::c_int,
&mut is_verified_group,
);
if 0 == is_verified_group { if 0 == is_verified_group {
vg_expect_encrypted = 0i32 vg_expect_encrypted = 0i32
} }
@@ -938,9 +930,9 @@ pub unsafe fn dc_handle_degrade_event(context: &Context, peerstate: &Peerstate)
dc_create_or_lookup_nchat_by_contact_id( dc_create_or_lookup_nchat_by_contact_id(
context, context,
contact_id as u32, contact_id as u32,
2, Blocked::Deaddrop,
&mut contact_chat_id, &mut contact_chat_id,
0 as *mut libc::c_int, None,
); );
let peeraddr: &str = match peerstate.addr { let peeraddr: &str = match peerstate.addr {
Some(ref addr) => &addr, Some(ref addr) => &addr,