mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 05:16:28 +03:00
basic devicetalk implementation
This commit is contained in:
committed by
holger krekel
parent
50539465b9
commit
cbaa4e03b3
@@ -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
|
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]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_chat_is_verified(chat: *mut dc_chat_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_chat_is_verified(chat: *mut dc_chat_t) -> libc::c_int {
|
||||||
if chat.is_null() {
|
if chat.is_null() {
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ DC_STATE_OUT_DELIVERED = 26
|
|||||||
DC_STATE_OUT_MDN_RCVD = 28
|
DC_STATE_OUT_MDN_RCVD = 28
|
||||||
DC_CONTACT_ID_SELF = 1
|
DC_CONTACT_ID_SELF = 1
|
||||||
DC_CONTACT_ID_INFO = 2
|
DC_CONTACT_ID_INFO = 2
|
||||||
|
DC_CONTACT_ID_DEVICE = 5
|
||||||
DC_CONTACT_ID_LAST_SPECIAL = 9
|
DC_CONTACT_ID_LAST_SPECIAL = 9
|
||||||
DC_MSG_TEXT = 10
|
DC_MSG_TEXT = 10
|
||||||
DC_MSG_IMAGE = 20
|
DC_MSG_IMAGE = 20
|
||||||
|
|||||||
14
src/chat.rs
14
src/chat.rs
@@ -109,6 +109,14 @@ impl Chat {
|
|||||||
self.param.exists(Param::Selftalk)
|
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> {
|
pub fn update_param(&mut self, context: &Context) -> Result<(), Error> {
|
||||||
sql::execute(
|
sql::execute(
|
||||||
context,
|
context,
|
||||||
@@ -605,7 +613,11 @@ pub fn create_or_lookup_by_contact_id(
|
|||||||
"INSERT INTO chats (type, name, param, blocked, grpid) VALUES({}, '{}', '{}', {}, '{}')",
|
"INSERT INTO chats (type, name, param, blocked, grpid) VALUES({}, '{}', '{}', {}, '{}')",
|
||||||
100,
|
100,
|
||||||
chat_name,
|
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,
|
create_blocked as u8,
|
||||||
contact.get_addr(),
|
contact.get_addr(),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -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_UNDEFINED: u32 = 0;
|
||||||
pub const DC_CONTACT_ID_SELF: u32 = 1;
|
pub const DC_CONTACT_ID_SELF: u32 = 1;
|
||||||
pub const DC_CONTACT_ID_INFO: u32 = 2;
|
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_CONTACT_ID_LAST_SPECIAL: u32 = 9;
|
||||||
|
|
||||||
pub const DC_CREATE_MVBOX: usize = 1;
|
pub const DC_CREATE_MVBOX: usize = 1;
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ pub enum Param {
|
|||||||
ProfileImage = b'i',
|
ProfileImage = b'i',
|
||||||
// For Chats
|
// For Chats
|
||||||
Selftalk = b'K',
|
Selftalk = b'K',
|
||||||
|
// For Chats
|
||||||
|
Devicetalk = b'D',
|
||||||
// For QR
|
// For QR
|
||||||
Auth = b's',
|
Auth = b's',
|
||||||
// For QR
|
// For QR
|
||||||
|
|||||||
@@ -383,8 +383,8 @@ fn open(
|
|||||||
)?;
|
)?;
|
||||||
sql.execute(
|
sql.execute(
|
||||||
"INSERT INTO contacts (id,name,origin) VALUES \
|
"INSERT INTO contacts (id,name,origin) VALUES \
|
||||||
(1,'self',262144), (2,'device',262144), (3,'rsvd',262144), \
|
(1,'self',262144), (2,'info',262144), (3,'rsvd',262144), \
|
||||||
(4,'rsvd',262144), (5,'rsvd',262144), (6,'rsvd',262144), \
|
(4,'rsvd',262144), (5,'device',262144), (6,'rsvd',262144), \
|
||||||
(7,'rsvd',262144), (8,'rsvd',262144), (9,'rsvd',262144);",
|
(7,'rsvd',262144), (8,'rsvd',262144), (9,'rsvd',262144);",
|
||||||
params![],
|
params![],
|
||||||
)?;
|
)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user