diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index dc3019a44..36190f393 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -2264,6 +2264,26 @@ pub unsafe extern "C" fn dc_chat_is_self_talk(chat: *mut dc_chat_t) -> libc::c_i ffi_chat.chat.is_self_talk() as libc::c_int } +#[no_mangle] +pub unsafe extern "C" fn dc_chat_is_device_talk(chat: *mut dc_chat_t) -> libc::c_int { + if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_is_device_talk()"); + return 0; + } + let ffi_chat = &*chat; + ffi_chat.chat.is_device_talk() as libc::c_int +} + +#[no_mangle] +pub unsafe extern "C" fn dc_chat_is_writable(chat: *mut dc_chat_t) -> libc::c_int { + if chat.is_null() { + eprintln!("ignoring careless call to dc_chat_is_writable()"); + return 0; + } + let ffi_chat = &*chat; + ffi_chat.chat.is_writable() as libc::c_int +} + #[no_mangle] pub unsafe extern "C" fn dc_chat_is_verified(chat: *mut dc_chat_t) -> libc::c_int { if chat.is_null() { diff --git a/python/src/deltachat/const.py b/python/src/deltachat/const.py index e3e2bfc7e..ff22addb2 100644 --- a/python/src/deltachat/const.py +++ b/python/src/deltachat/const.py @@ -48,6 +48,7 @@ DC_STATE_OUT_DELIVERED = 26 DC_STATE_OUT_MDN_RCVD = 28 DC_CONTACT_ID_SELF = 1 DC_CONTACT_ID_INFO = 2 +DC_CONTACT_ID_DEVICE = 5 DC_CONTACT_ID_LAST_SPECIAL = 9 DC_MSG_TEXT = 10 DC_MSG_IMAGE = 20 diff --git a/src/chat.rs b/src/chat.rs index b1c6f777b..c806a2a9c 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -109,6 +109,14 @@ impl Chat { self.param.exists(Param::Selftalk) } + pub fn is_device_talk(&self) -> bool { + self.param.exists(Param::Devicetalk) + } + + pub fn is_writable(&self) -> bool { + self.id > DC_CHAT_ID_LAST_SPECIAL && !self.is_device_talk() + } + pub fn update_param(&mut self, context: &Context) -> Result<(), Error> { sql::execute( context, @@ -605,7 +613,11 @@ pub fn create_or_lookup_by_contact_id( "INSERT INTO chats (type, name, param, blocked, grpid) VALUES({}, '{}', '{}', {}, '{}')", 100, chat_name, - if contact_id == DC_CONTACT_ID_SELF as u32 { "K=1" } else { "" }, + match contact_id { + DC_CONTACT_ID_SELF => "K=1", // K = Param::Selftalk + DC_CONTACT_ID_DEVICE => "D=1", // K = Param::Devicetalk + _ => "" + }, create_blocked as u8, contact.get_addr(), ), diff --git a/src/constants.rs b/src/constants.rs index 23ce20c1b..68783837f 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -131,6 +131,7 @@ const DC_MAX_GET_INFO_LEN: usize = 100000; pub const DC_CONTACT_ID_UNDEFINED: u32 = 0; pub const DC_CONTACT_ID_SELF: u32 = 1; pub const DC_CONTACT_ID_INFO: u32 = 2; +pub const DC_CONTACT_ID_DEVICE: u32 = 5; pub const DC_CONTACT_ID_LAST_SPECIAL: u32 = 9; pub const DC_CREATE_MVBOX: usize = 1; diff --git a/src/param.rs b/src/param.rs index 9fcdf0db3..524fcedf6 100644 --- a/src/param.rs +++ b/src/param.rs @@ -76,6 +76,8 @@ pub enum Param { ProfileImage = b'i', // For Chats Selftalk = b'K', + // For Chats + Devicetalk = b'D', // For QR Auth = b's', // For QR diff --git a/src/sql.rs b/src/sql.rs index eab1374b7..2b9fa2aac 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -383,8 +383,8 @@ fn open( )?; sql.execute( "INSERT INTO contacts (id,name,origin) VALUES \ - (1,'self',262144), (2,'device',262144), (3,'rsvd',262144), \ - (4,'rsvd',262144), (5,'rsvd',262144), (6,'rsvd',262144), \ + (1,'self',262144), (2,'info',262144), (3,'rsvd',262144), \ + (4,'rsvd',262144), (5,'device',262144), (6,'rsvd',262144), \ (7,'rsvd',262144), (8,'rsvd',262144), (9,'rsvd',262144);", params![], )?;