mirror of
https://github.com/chatmail/core.git
synced 2026-04-23 00:16:34 +03:00
refactor(params): rustify
This commit is contained in:
committed by
GitHub
parent
669ed0e0df
commit
188da2a020
304
src/dc_chat.rs
304
src/dc_chat.rs
@@ -7,8 +7,8 @@ use crate::dc_array::*;
|
||||
use crate::dc_contact::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_param::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::param::*;
|
||||
use crate::sql::{self, Sql};
|
||||
use crate::stock::StockMessage;
|
||||
use crate::types::*;
|
||||
@@ -22,7 +22,7 @@ use crate::x::*;
|
||||
* and are not updated on database changes;
|
||||
* if you want an update, you have to recreate the object.
|
||||
*/
|
||||
#[derive(Copy, Clone)]
|
||||
#[derive(Clone)]
|
||||
pub struct Chat<'a> {
|
||||
magic: uint32_t,
|
||||
pub id: uint32_t,
|
||||
@@ -32,7 +32,7 @@ pub struct Chat<'a> {
|
||||
pub context: &'a Context,
|
||||
pub grpid: *mut libc::c_char,
|
||||
blocked: libc::c_int,
|
||||
pub param: *mut dc_param_t,
|
||||
pub param: Params,
|
||||
pub gossiped_timestamp: i64,
|
||||
is_sending_locations: libc::c_int,
|
||||
}
|
||||
@@ -64,13 +64,21 @@ 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> {
|
||||
let mut chat: *mut Chat;
|
||||
chat = calloc(1, ::std::mem::size_of::<Chat>()) as *mut Chat;
|
||||
(*chat).magic = 0xc4a7c4a7u32;
|
||||
(*chat).context = context;
|
||||
(*chat).type_0 = 0i32;
|
||||
(*chat).param = dc_param_new();
|
||||
chat
|
||||
let chat = Chat {
|
||||
magic: 0xc4a7c4a7,
|
||||
id: 0,
|
||||
type_0: 0,
|
||||
name: std::ptr::null_mut(),
|
||||
archived: 0,
|
||||
context,
|
||||
grpid: std::ptr::null_mut(),
|
||||
blocked: 0,
|
||||
param: Params::new(),
|
||||
gossiped_timestamp: 0,
|
||||
is_sending_locations: 0,
|
||||
};
|
||||
|
||||
Box::into_raw(Box::new(chat))
|
||||
}
|
||||
|
||||
pub unsafe fn dc_chat_unref(mut chat: *mut Chat) {
|
||||
@@ -78,9 +86,8 @@ pub unsafe fn dc_chat_unref(mut chat: *mut Chat) {
|
||||
return;
|
||||
}
|
||||
dc_chat_empty(chat);
|
||||
dc_param_unref((*chat).param);
|
||||
(*chat).magic = 0i32 as uint32_t;
|
||||
free(chat as *mut libc::c_void);
|
||||
(*chat).magic = 0;
|
||||
Box::from_raw(chat);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_chat_empty(mut chat: *mut Chat) {
|
||||
@@ -95,7 +102,7 @@ pub unsafe fn dc_chat_empty(mut chat: *mut Chat) {
|
||||
(*chat).grpid = 0 as *mut libc::c_char;
|
||||
(*chat).blocked = 0i32;
|
||||
(*chat).gossiped_timestamp = 0;
|
||||
dc_param_set_packed((*chat).param, 0 as *const libc::c_char);
|
||||
(*chat).param = Params::new();
|
||||
}
|
||||
|
||||
pub unsafe fn dc_unblock_chat(context: &Context, chat_id: uint32_t) {
|
||||
@@ -139,16 +146,12 @@ pub fn dc_chat_load_from_db(chat: *mut Chat, chat_id: u32) -> bool {
|
||||
unsafe { to_cstring(raw) }
|
||||
};
|
||||
|
||||
let packed: String = row.get(4)?;
|
||||
unsafe {
|
||||
let p = to_cstring(&packed);
|
||||
dc_param_set_packed((*chat).param, p);
|
||||
free(p as *mut _);
|
||||
};
|
||||
c.param = row.get::<_, String>(4)?.parse().unwrap_or_default();
|
||||
c.archived = row.get(5)?;
|
||||
c.blocked = row.get::<_, Option<i32>>(6)?.unwrap_or_default();
|
||||
c.gossiped_timestamp = row.get(7)?;
|
||||
c.is_sending_locations = row.get(8)?;
|
||||
|
||||
Ok(())
|
||||
},
|
||||
);
|
||||
@@ -182,7 +185,7 @@ pub fn dc_chat_load_from_db(chat: *mut Chat, chat_id: u32) -> bool {
|
||||
(*chat).name = to_cstring((*chat).context.stock_str(StockMessage::StarredMsgs));
|
||||
},
|
||||
_ => {
|
||||
if 0 != unsafe { dc_param_exists((*chat).param, DC_PARAM_SELFTALK as i32) } {
|
||||
if unsafe { &(*chat).param }.exists(Param::Selftalk) {
|
||||
unsafe {
|
||||
free((*chat).name as *mut libc::c_void);
|
||||
(*chat).name =
|
||||
@@ -387,13 +390,16 @@ unsafe fn prepare_msg_common<'a>(
|
||||
mut msg: *mut dc_msg_t<'a>,
|
||||
) -> uint32_t {
|
||||
let mut OK_TO_CONTINUE = true;
|
||||
let mut pathNfilename: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
(*msg).id = 0i32 as uint32_t;
|
||||
(*msg).context = context;
|
||||
if (*msg).type_0 == DC_MSG_TEXT {
|
||||
/* the caller should check if the message text is empty */
|
||||
} else if msgtype_has_file((*msg).type_0) {
|
||||
pathNfilename = dc_param_get((*msg).param, DC_PARAM_FILE as i32, 0 as *const libc::c_char);
|
||||
let mut pathNfilename = (*msg)
|
||||
.param
|
||||
.get(Param::File)
|
||||
.map(|s| to_cstring(s))
|
||||
.unwrap_or_else(|| std::ptr::null_mut());
|
||||
if pathNfilename.is_null() {
|
||||
error!(
|
||||
context,
|
||||
@@ -410,29 +416,34 @@ unsafe fn prepare_msg_common<'a>(
|
||||
} else if !dc_make_rel_and_copy(context, &mut pathNfilename) {
|
||||
OK_TO_CONTINUE = false;
|
||||
} else {
|
||||
dc_param_set((*msg).param, DC_PARAM_FILE as i32, pathNfilename);
|
||||
(*msg).param.set(Param::File, as_str(pathNfilename));
|
||||
if (*msg).type_0 == DC_MSG_FILE || (*msg).type_0 == DC_MSG_IMAGE {
|
||||
/* Correct the type, take care not to correct already very special formats as GIF or VOICE.
|
||||
Typical conversions:
|
||||
- from FILE to AUDIO/VIDEO/IMAGE
|
||||
- from FILE/IMAGE to GIF */
|
||||
let mut better_type: libc::c_int = 0i32;
|
||||
let mut better_mime: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut better_type = 0;
|
||||
let mut better_mime = std::ptr::null_mut();
|
||||
|
||||
dc_msg_guess_msgtype_from_suffix(pathNfilename, &mut better_type, &mut better_mime);
|
||||
if 0 != better_type {
|
||||
if 0 != better_type && !better_mime.is_null() {
|
||||
(*msg).type_0 = better_type;
|
||||
dc_param_set((*msg).param, DC_PARAM_MIMETYPE as i32, better_mime);
|
||||
(*msg).param.set(Param::MimeType, as_str(better_mime));
|
||||
}
|
||||
free(better_mime as *mut libc::c_void);
|
||||
} else if 0 == dc_param_exists((*msg).param, DC_PARAM_MIMETYPE as i32) {
|
||||
let mut better_mime_0: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
} else if !(*msg).param.exists(Param::MimeType) {
|
||||
let mut better_mime = std::ptr::null_mut();
|
||||
|
||||
dc_msg_guess_msgtype_from_suffix(
|
||||
pathNfilename,
|
||||
0 as *mut libc::c_int,
|
||||
&mut better_mime_0,
|
||||
&mut better_mime,
|
||||
);
|
||||
dc_param_set((*msg).param, DC_PARAM_MIMETYPE as i32, better_mime_0);
|
||||
free(better_mime_0 as *mut libc::c_void);
|
||||
|
||||
if !better_mime.is_null() {
|
||||
(*msg).param.set(Param::MimeType, as_str(better_mime));
|
||||
}
|
||||
free(better_mime as *mut _);
|
||||
}
|
||||
info!(
|
||||
context,
|
||||
@@ -441,6 +452,8 @@ unsafe fn prepare_msg_common<'a>(
|
||||
as_str(pathNfilename),
|
||||
(*msg).type_0
|
||||
);
|
||||
|
||||
free(pathNfilename as *mut _);
|
||||
}
|
||||
} else {
|
||||
error!(
|
||||
@@ -463,8 +476,6 @@ unsafe fn prepare_msg_common<'a>(
|
||||
}
|
||||
dc_chat_unref(chat);
|
||||
}
|
||||
/* potential error already logged */
|
||||
free(pathNfilename as *mut libc::c_void);
|
||||
|
||||
(*msg).id
|
||||
}
|
||||
@@ -473,7 +484,7 @@ unsafe fn prepare_msg_common<'a>(
|
||||
unsafe fn prepare_msg_raw(
|
||||
context: &Context,
|
||||
chat: *mut Chat,
|
||||
msg: *const dc_msg_t,
|
||||
msg: *mut dc_msg_t,
|
||||
timestamp: i64,
|
||||
) -> uint32_t {
|
||||
let mut do_guarantee_e2ee: libc::c_int;
|
||||
@@ -537,12 +548,8 @@ unsafe fn prepare_msg_raw(
|
||||
if (*chat).type_0 == DC_CHAT_TYPE_GROUP
|
||||
|| (*chat).type_0 == DC_CHAT_TYPE_VERIFIED_GROUP
|
||||
{
|
||||
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 1 {
|
||||
dc_param_set(
|
||||
(*chat).param,
|
||||
DC_PARAM_UNPROMOTED as i32,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
if (*chat).param.get_int(Param::Unpromoted).unwrap_or_default() == 1 {
|
||||
(*chat).param.remove(Param::Unpromoted);
|
||||
dc_chat_update_param(chat);
|
||||
}
|
||||
}
|
||||
@@ -558,7 +565,11 @@ unsafe fn prepare_msg_raw(
|
||||
.get_config_int(context, "e2ee_enabled")
|
||||
.unwrap_or_else(|| 1);
|
||||
if 0 != e2ee_enabled
|
||||
&& dc_param_get_int((*msg).param, DC_PARAM_FORCE_PLAINTEXT as i32, 0) == 0
|
||||
&& (*msg)
|
||||
.param
|
||||
.get_int(Param::ForcePlaintext)
|
||||
.unwrap_or_default()
|
||||
== 0
|
||||
{
|
||||
let mut can_encrypt = 1;
|
||||
let mut all_mutual = 1;
|
||||
@@ -613,13 +624,9 @@ unsafe fn prepare_msg_raw(
|
||||
}
|
||||
}
|
||||
if 0 != do_guarantee_e2ee {
|
||||
dc_param_set_int((*msg).param, DC_PARAM_GUARANTEE_E2EE as i32, 1);
|
||||
(*msg).param.set_int(Param::GuranteeE2ee, 1);
|
||||
}
|
||||
dc_param_set(
|
||||
(*msg).param,
|
||||
DC_PARAM_ERRONEOUS_E2EE as i32,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
(*msg).param.remove(Param::ErroneousE2ee);
|
||||
if 0 == dc_chat_is_self_talk(chat)
|
||||
&& 0 != get_parent_mime_headers(
|
||||
chat,
|
||||
@@ -673,7 +680,7 @@ unsafe fn prepare_msg_raw(
|
||||
|
||||
// add independent location to database
|
||||
|
||||
if 0 != dc_param_exists((*msg).param, DC_PARAM_SET_LATITUDE as libc::c_int) {
|
||||
if (*msg).param.exists(Param::SetLatitude) {
|
||||
if sql::execute(
|
||||
context,
|
||||
&context.sql,
|
||||
@@ -684,16 +691,14 @@ unsafe fn prepare_msg_raw(
|
||||
timestamp,
|
||||
DC_CONTACT_ID_SELF as i32,
|
||||
(*chat).id as i32,
|
||||
dc_param_get_float(
|
||||
(*msg).param,
|
||||
DC_PARAM_SET_LATITUDE as libc::c_int,
|
||||
0.0,
|
||||
),
|
||||
dc_param_get_float(
|
||||
(*msg).param,
|
||||
DC_PARAM_SET_LONGITUDE as libc::c_int,
|
||||
0.0,
|
||||
),
|
||||
(*msg)
|
||||
.param
|
||||
.get_float(Param::SetLatitude)
|
||||
.unwrap_or_default(),
|
||||
(*msg)
|
||||
.param
|
||||
.get_float(Param::SetLongitude)
|
||||
.unwrap_or_default(),
|
||||
],
|
||||
)
|
||||
.is_ok()
|
||||
@@ -725,7 +730,7 @@ unsafe fn prepare_msg_raw(
|
||||
(*msg).type_0,
|
||||
(*msg).state,
|
||||
if !(*msg).text.is_null() { Some(as_str((*msg).text)) } else { None },
|
||||
if (*(*msg).param).packed.is_null() { None } else { Some(as_str((*(*msg).param).packed)) },
|
||||
(*msg).param.to_string(),
|
||||
(*msg).hidden,
|
||||
to_string(new_in_reply_to),
|
||||
to_string(new_references),
|
||||
@@ -816,9 +821,9 @@ unsafe fn get_parent_mime_headers(
|
||||
|
||||
pub unsafe fn dc_chat_is_self_talk(chat: *const Chat) -> libc::c_int {
|
||||
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
|
||||
return 0i32;
|
||||
return 0;
|
||||
}
|
||||
dc_param_exists((*chat).param, DC_PARAM_SELFTALK as i32)
|
||||
(*chat).param.exists(Param::Selftalk) as libc::c_int
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
@@ -830,7 +835,6 @@ unsafe fn last_msg_in_chat_encrypted(
|
||||
sql: &Sql,
|
||||
chat_id: uint32_t,
|
||||
) -> libc::c_int {
|
||||
let mut last_is_encrypted: libc::c_int = 0i32;
|
||||
let packed: Option<String> = sql.query_row_col(
|
||||
context,
|
||||
"SELECT param \
|
||||
@@ -840,19 +844,17 @@ unsafe fn last_msg_in_chat_encrypted(
|
||||
0,
|
||||
);
|
||||
|
||||
if let Some(packed) = packed {
|
||||
let msg_param = dc_param_new();
|
||||
let packed_c = to_cstring(packed);
|
||||
dc_param_set_packed(msg_param, packed_c);
|
||||
free(packed_c as *mut _);
|
||||
|
||||
if 0 != dc_param_exists(msg_param, DC_PARAM_GUARANTEE_E2EE as i32) {
|
||||
last_is_encrypted = 1;
|
||||
if let Some(ref packed) = packed {
|
||||
match packed.parse::<Params>() {
|
||||
Ok(param) => param.exists(Param::GuranteeE2ee) as libc::c_int,
|
||||
Err(err) => {
|
||||
error!(context, 0, "invalid params stored: '{}', {:?}", packed, err);
|
||||
0
|
||||
}
|
||||
}
|
||||
dc_param_unref(msg_param);
|
||||
} else {
|
||||
0
|
||||
}
|
||||
|
||||
last_is_encrypted
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
@@ -861,7 +863,7 @@ pub unsafe fn dc_chat_update_param(chat: *mut Chat) -> libc::c_int {
|
||||
(*chat).context,
|
||||
&(*chat).context.sql,
|
||||
"UPDATE chats SET param=? WHERE id=?",
|
||||
params![to_string((*(*chat).param).packed), (*chat).id as i32],
|
||||
params![(*chat).param.to_string(), (*chat).id as i32],
|
||||
)
|
||||
.is_ok() as libc::c_int
|
||||
}
|
||||
@@ -921,39 +923,29 @@ pub unsafe fn dc_send_msg<'a>(
|
||||
(*msg).id as uintptr_t,
|
||||
);
|
||||
|
||||
if 0 != dc_param_exists((*msg).param, DC_PARAM_SET_LATITUDE as libc::c_int) {
|
||||
if (*msg).param.exists(Param::SetLatitude) {
|
||||
context.call_cb(Event::LOCATION_CHANGED, DC_CONTACT_ID_SELF, 0);
|
||||
}
|
||||
|
||||
if 0 == chat_id {
|
||||
let forwards = dc_param_get(
|
||||
(*msg).param,
|
||||
DC_PARAM_PREP_FORWARDS as i32,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
if !forwards.is_null() {
|
||||
let mut p = forwards;
|
||||
while 0 != *p {
|
||||
let id = strtol(p, &mut p, 10) as int32_t;
|
||||
let forwards = (*msg).param.get(Param::PrepForwards);
|
||||
if let Some(forwards) = forwards {
|
||||
for forward in forwards.split(' ') {
|
||||
let id: i32 = forward.parse().unwrap_or_default();
|
||||
if 0 == id {
|
||||
// avoid hanging if user tampers with db
|
||||
break;
|
||||
} else {
|
||||
let copy = dc_get_msg(context, id as uint32_t);
|
||||
let copy = dc_get_msg(context, id as u32);
|
||||
if !copy.is_null() {
|
||||
dc_send_msg(context, 0 as uint32_t, copy);
|
||||
dc_send_msg(context, 0, copy);
|
||||
}
|
||||
dc_msg_unref(copy);
|
||||
}
|
||||
}
|
||||
dc_param_set(
|
||||
(*msg).param,
|
||||
DC_PARAM_PREP_FORWARDS as i32,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
(*msg).param.remove(Param::PrepForwards);
|
||||
dc_msg_save_param_to_disk(msg);
|
||||
}
|
||||
free(forwards as *mut libc::c_void);
|
||||
}
|
||||
|
||||
(*msg).id
|
||||
@@ -1003,7 +995,6 @@ pub unsafe fn dc_set_draft(context: &Context, chat_id: uint32_t, msg: *mut dc_ms
|
||||
unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t) -> libc::c_int {
|
||||
let mut OK_TO_CONTINUE = true;
|
||||
// similar to as dc_set_draft() but does not emit an event
|
||||
let mut pathNfilename: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let prev_draft_msg_id: uint32_t;
|
||||
let mut sth_changed: libc::c_int = 0i32;
|
||||
prev_draft_msg_id = get_draft_msg_id(context, chat_id);
|
||||
@@ -1018,8 +1009,11 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
|
||||
OK_TO_CONTINUE = false;
|
||||
}
|
||||
} else if msgtype_has_file((*msg).type_0) {
|
||||
pathNfilename =
|
||||
dc_param_get((*msg).param, DC_PARAM_FILE as i32, 0 as *const libc::c_char);
|
||||
let mut pathNfilename = (*msg)
|
||||
.param
|
||||
.get(Param::File)
|
||||
.map(|s| to_cstring(s))
|
||||
.unwrap_or_else(|| std::ptr::null_mut());
|
||||
if pathNfilename.is_null() {
|
||||
OK_TO_CONTINUE = false;
|
||||
} else if 0 != dc_msg_is_increation(msg) && !dc_is_blobdir_path(context, pathNfilename)
|
||||
@@ -1028,8 +1022,9 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
|
||||
} else if !dc_make_rel_and_copy(context, &mut pathNfilename) {
|
||||
OK_TO_CONTINUE = false;
|
||||
} else {
|
||||
dc_param_set((*msg).param, DC_PARAM_FILE as i32, pathNfilename);
|
||||
(*msg).param.set(Param::File, as_str(pathNfilename));
|
||||
}
|
||||
free(pathNfilename as *mut _);
|
||||
} else {
|
||||
OK_TO_CONTINUE = false;
|
||||
}
|
||||
@@ -1050,7 +1045,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
|
||||
} else {
|
||||
""
|
||||
},
|
||||
to_string((*(*msg).param).packed),
|
||||
(*msg).param.to_string(),
|
||||
1,
|
||||
],
|
||||
)
|
||||
@@ -1060,7 +1055,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
|
||||
}
|
||||
}
|
||||
}
|
||||
free(pathNfilename as *mut libc::c_void);
|
||||
|
||||
sth_changed
|
||||
}
|
||||
|
||||
@@ -1432,7 +1427,7 @@ pub fn dc_delete_chat(context: &Context, chat_id: u32) -> bool {
|
||||
context.call_cb(Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t);
|
||||
|
||||
dc_job_kill_action(context, 105);
|
||||
unsafe { dc_job_add(context, 105, 0, 0 as *const libc::c_char, 10) };
|
||||
unsafe { dc_job_add(context, 105, 0, Params::new(), 10) };
|
||||
|
||||
true
|
||||
}
|
||||
@@ -1587,13 +1582,9 @@ pub unsafe fn dc_add_contact_to_chat_ex(
|
||||
} else {
|
||||
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
|
||||
if 0 != flags & 0x1
|
||||
&& dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 1
|
||||
&& (*chat).param.get_int(Param::Unpromoted).unwrap_or_default() == 1
|
||||
{
|
||||
dc_param_set(
|
||||
(*chat).param,
|
||||
DC_PARAM_UNPROMOTED as i32,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
(*chat).param.remove(Param::Unpromoted);
|
||||
dc_chat_update_param(chat);
|
||||
}
|
||||
let self_addr = context
|
||||
@@ -1627,7 +1618,7 @@ pub unsafe fn dc_add_contact_to_chat_ex(
|
||||
}
|
||||
}
|
||||
if OK_TO_CONTINUE {
|
||||
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 0 {
|
||||
if (*chat).param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
||||
(*msg).type_0 = DC_MSG_TEXT;
|
||||
(*msg).text = to_cstring(context.stock_system_msg(
|
||||
StockMessage::MsgAddMember,
|
||||
@@ -1635,9 +1626,11 @@ pub unsafe fn dc_add_contact_to_chat_ex(
|
||||
"",
|
||||
DC_CONTACT_ID_SELF as uint32_t,
|
||||
));
|
||||
dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 4);
|
||||
dc_param_set((*msg).param, DC_PARAM_CMD_ARG as i32, (*contact).addr);
|
||||
dc_param_set_int((*msg).param, DC_PARAM_CMD_ARG2 as i32, flags);
|
||||
(*msg).param.set_int(Param::Cmd, 4);
|
||||
if !(*contact).addr.is_null() {
|
||||
(*msg).param.set(Param::Arg, as_str((*contact).addr));
|
||||
}
|
||||
(*msg).param.set_int(Param::Arg2, flags);
|
||||
(*msg).id = dc_send_msg(context, chat_id, msg);
|
||||
context.call_cb(
|
||||
Event::MSGS_CHANGED,
|
||||
@@ -1736,7 +1729,7 @@ pub unsafe fn dc_remove_contact_from_chat(
|
||||
} else {
|
||||
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
|
||||
if !contact.is_null() {
|
||||
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 0 {
|
||||
if (*chat).param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
||||
(*msg).type_0 = DC_MSG_TEXT;
|
||||
if (*contact).id == 1 as libc::c_uint {
|
||||
dc_set_group_explicitly_left(context, (*chat).grpid);
|
||||
@@ -1754,8 +1747,10 @@ pub unsafe fn dc_remove_contact_from_chat(
|
||||
DC_CONTACT_ID_SELF as u32,
|
||||
));
|
||||
}
|
||||
dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 5);
|
||||
dc_param_set((*msg).param, DC_PARAM_CMD_ARG as i32, (*contact).addr);
|
||||
(*msg).param.set_int(Param::Cmd, 5);
|
||||
if !(*contact).addr.is_null() {
|
||||
(*msg).param.set(Param::Arg, as_str((*contact).addr));
|
||||
}
|
||||
(*msg).id = dc_send_msg(context, chat_id, msg);
|
||||
context.call_cb(
|
||||
Event::MSGS_CHANGED,
|
||||
@@ -1849,7 +1844,7 @@ pub unsafe fn dc_set_chat_name(
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0i32) == 0i32 {
|
||||
if (*chat).param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
||||
(*msg).type_0 = DC_MSG_TEXT;
|
||||
(*msg).text = to_cstring(context.stock_system_msg(
|
||||
StockMessage::MsgGrpName,
|
||||
@@ -1857,8 +1852,10 @@ pub unsafe fn dc_set_chat_name(
|
||||
as_str(new_name),
|
||||
DC_CONTACT_ID_SELF as u32,
|
||||
));
|
||||
dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 2);
|
||||
dc_param_set((*msg).param, DC_PARAM_CMD_ARG as i32, (*chat).name);
|
||||
(*msg).param.set_int(Param::Cmd, 2);
|
||||
if !(*chat).name.is_null() {
|
||||
(*msg).param.set(Param::Arg, as_str((*chat).name));
|
||||
}
|
||||
(*msg).id = dc_send_msg(context, chat_id, msg);
|
||||
context.call_cb(
|
||||
Event::MSGS_CHANGED,
|
||||
@@ -1913,12 +1910,13 @@ pub unsafe fn dc_set_chat_profile_image(
|
||||
}
|
||||
}
|
||||
if OK_TO_CONTINUE {
|
||||
dc_param_set((*chat).param, DC_PARAM_PROFILE_IMAGE as i32, new_image_rel);
|
||||
(*chat)
|
||||
.param
|
||||
.set(Param::ProfileImage, as_str(new_image_rel));
|
||||
if !(0 == dc_chat_update_param(chat)) {
|
||||
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0i32) == 0i32
|
||||
{
|
||||
dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 3i32);
|
||||
dc_param_set((*msg).param, DC_PARAM_CMD_ARG as i32, new_image_rel);
|
||||
if (*chat).param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
||||
(*msg).param.set_int(Param::Cmd, 3);
|
||||
(*msg).param.set(Param::Arg, as_str(new_image_rel));
|
||||
(*msg).type_0 = DC_MSG_TEXT;
|
||||
(*msg).text = to_cstring(context.stock_system_msg(
|
||||
if !new_image_rel.is_null() {
|
||||
@@ -1972,7 +1970,6 @@ pub unsafe fn dc_forward_msgs(
|
||||
let created_db_entries = carray_new(16);
|
||||
let mut curr_timestamp: i64;
|
||||
|
||||
let original_param: *mut dc_param_t = dc_param_new();
|
||||
dc_unarchive_chat(context, chat_id);
|
||||
if dc_chat_load_from_db(chat, chat_id) {
|
||||
curr_timestamp = dc_create_smeared_timestamps(context, msg_cnt);
|
||||
@@ -2002,44 +1999,34 @@ pub unsafe fn dc_forward_msgs(
|
||||
if !dc_msg_load_from_db(msg, context, src_msg_id as u32) {
|
||||
break;
|
||||
}
|
||||
dc_param_set_packed(original_param, (*(*msg).param).packed);
|
||||
if (*msg).from_id != 1i32 as libc::c_uint {
|
||||
dc_param_set_int((*msg).param, DC_PARAM_FORWARDED as i32, 1i32);
|
||||
let original_param = (*msg).param.clone();
|
||||
if (*msg).from_id != 1 {
|
||||
(*msg).param.set_int(Param::Forwarded, 1);
|
||||
}
|
||||
dc_param_set(
|
||||
(*msg).param,
|
||||
DC_PARAM_GUARANTEE_E2EE as i32,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
dc_param_set(
|
||||
(*msg).param,
|
||||
DC_PARAM_FORCE_PLAINTEXT as i32,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
dc_param_set((*msg).param, DC_PARAM_CMD as i32, 0 as *const libc::c_char);
|
||||
(*msg).param.remove(Param::GuranteeE2ee);
|
||||
(*msg).param.remove(Param::ForcePlaintext);
|
||||
(*msg).param.remove(Param::Cmd);
|
||||
|
||||
let new_msg_id: uint32_t;
|
||||
if (*msg).state == DC_STATE_OUT_PREPARING {
|
||||
let fresh9 = curr_timestamp;
|
||||
curr_timestamp = curr_timestamp + 1;
|
||||
new_msg_id = prepare_msg_raw(context, chat, msg, fresh9);
|
||||
let save_param: *mut dc_param_t = (*msg).param;
|
||||
let save_param = (*msg).param.clone();
|
||||
(*msg).param = original_param;
|
||||
(*msg).id = src_msg_id as uint32_t;
|
||||
let old_fwd: *mut libc::c_char = dc_param_get(
|
||||
(*msg).param,
|
||||
DC_PARAM_PREP_FORWARDS as i32,
|
||||
b"\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
let new_fwd: *mut libc::c_char = dc_mprintf(
|
||||
b"%s %d\x00" as *const u8 as *const libc::c_char,
|
||||
old_fwd,
|
||||
new_msg_id,
|
||||
);
|
||||
dc_param_set((*msg).param, DC_PARAM_PREP_FORWARDS as i32, new_fwd);
|
||||
|
||||
if let Some(old_fwd) = (*msg).param.get(Param::PrepForwards) {
|
||||
let new_fwd = format!("{} {}", old_fwd, new_msg_id);
|
||||
(*msg).param.set(Param::PrepForwards, new_fwd);
|
||||
} else {
|
||||
(*msg)
|
||||
.param
|
||||
.set(Param::PrepForwards, new_msg_id.to_string());
|
||||
}
|
||||
|
||||
dc_msg_save_param_to_disk(msg);
|
||||
free(new_fwd as *mut libc::c_void);
|
||||
free(old_fwd as *mut libc::c_void);
|
||||
(*msg).param = save_param
|
||||
(*msg).param = save_param;
|
||||
} else {
|
||||
(*msg).state = DC_STATE_OUT_PENDING;
|
||||
let fresh10 = curr_timestamp;
|
||||
@@ -2076,7 +2063,6 @@ pub unsafe fn dc_forward_msgs(
|
||||
dc_contact_unref(contact);
|
||||
dc_msg_unref(msg);
|
||||
dc_chat_unref(chat);
|
||||
dc_param_unref(original_param);
|
||||
}
|
||||
|
||||
pub unsafe fn dc_chat_get_id(chat: *const Chat) -> uint32_t {
|
||||
@@ -2107,7 +2093,7 @@ 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();
|
||||
if (*chat).type_0 == 100 && 0 != dc_param_exists((*chat).param, DC_PARAM_SELFTALK as i32) {
|
||||
if (*chat).type_0 == 100 && (*chat).param.exists(Param::Selftalk) {
|
||||
ret = to_cstring((*chat).context.stock_str(StockMessage::SelfTalkSubTitle));
|
||||
} else if (*chat).type_0 == 100 {
|
||||
let ret_raw: String = (*chat)
|
||||
@@ -2160,11 +2146,7 @@ pub unsafe fn dc_chat_get_profile_image(chat: *const Chat) -> *mut libc::c_char
|
||||
let mut contacts: *mut dc_array_t = 0 as *mut dc_array_t;
|
||||
let mut contact: *mut dc_contact_t = 0 as *mut dc_contact_t;
|
||||
if !(chat.is_null() || (*chat).magic != 0xc4a7c4a7u32) {
|
||||
image_rel = dc_param_get(
|
||||
(*chat).param,
|
||||
DC_PARAM_PROFILE_IMAGE as i32,
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
image_rel = to_cstring((*chat).param.get(Param::ProfileImage).unwrap_or_default());
|
||||
if !image_rel.is_null() && 0 != *image_rel.offset(0isize) as libc::c_int {
|
||||
image_abs = dc_get_abs_path((*chat).context, image_rel)
|
||||
} else if (*chat).type_0 == 100i32 {
|
||||
@@ -2216,9 +2198,9 @@ pub unsafe fn dc_chat_get_archived(chat: *const Chat) -> libc::c_int {
|
||||
// TODO should return bool /rtn
|
||||
pub unsafe fn dc_chat_is_unpromoted(chat: *const Chat) -> libc::c_int {
|
||||
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
|
||||
return 0i32;
|
||||
return 0;
|
||||
}
|
||||
dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0i32)
|
||||
(*chat).param.get_int(Param::Unpromoted).unwrap_or_default() as libc::c_int
|
||||
}
|
||||
|
||||
// TODO should return bool /rtn
|
||||
|
||||
Reference in New Issue
Block a user