mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 12:56:30 +03:00
refactor(msg): use rust based allocations
This commit is contained in:
@@ -505,7 +505,6 @@ int dc_chat_is_sending_locations (const dc_chat_t*);
|
|||||||
|
|
||||||
dc_msg_t* dc_msg_new (dc_context_t*, int viewtype);
|
dc_msg_t* dc_msg_new (dc_context_t*, int viewtype);
|
||||||
void dc_msg_unref (dc_msg_t*);
|
void dc_msg_unref (dc_msg_t*);
|
||||||
void dc_msg_empty (dc_msg_t*);
|
|
||||||
uint32_t dc_msg_get_id (const dc_msg_t*);
|
uint32_t dc_msg_get_id (const dc_msg_t*);
|
||||||
uint32_t dc_msg_get_from_id (const dc_msg_t*);
|
uint32_t dc_msg_get_from_id (const dc_msg_t*);
|
||||||
uint32_t dc_msg_get_chat_id (const dc_msg_t*);
|
uint32_t dc_msg_get_chat_id (const dc_msg_t*);
|
||||||
|
|||||||
@@ -354,12 +354,13 @@ pub unsafe extern "C" fn dc_get_chat_id_by_contact_id(
|
|||||||
pub unsafe extern "C" fn dc_prepare_msg(
|
pub unsafe extern "C" fn dc_prepare_msg(
|
||||||
context: *mut dc_context_t,
|
context: *mut dc_context_t,
|
||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
msg: *mut dc_msg::dc_msg_t,
|
msg: *mut dc_msg_t,
|
||||||
) -> u32 {
|
) -> u32 {
|
||||||
assert!(!context.is_null());
|
assert!(!context.is_null());
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
let context = &*context;
|
let context = &mut *context;
|
||||||
|
|
||||||
|
let msg = &mut *msg;
|
||||||
chat::prepare_msg(context, chat_id, msg)
|
chat::prepare_msg(context, chat_id, msg)
|
||||||
.unwrap_or_log_default(context, "Failed to prepare message")
|
.unwrap_or_log_default(context, "Failed to prepare message")
|
||||||
}
|
}
|
||||||
@@ -368,11 +369,12 @@ pub unsafe extern "C" fn dc_prepare_msg(
|
|||||||
pub unsafe extern "C" fn dc_send_msg(
|
pub unsafe extern "C" fn dc_send_msg(
|
||||||
context: *mut dc_context_t,
|
context: *mut dc_context_t,
|
||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
msg: *mut dc_msg::dc_msg_t,
|
msg: *mut dc_msg_t,
|
||||||
) -> u32 {
|
) -> u32 {
|
||||||
assert!(!context.is_null());
|
assert!(!context.is_null());
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
let context = &*context;
|
let context = &mut *context;
|
||||||
|
let msg = &mut *msg;
|
||||||
|
|
||||||
chat::send_msg(context, chat_id, msg).unwrap_or_log_default(context, "Failed to send message")
|
chat::send_msg(context, chat_id, msg).unwrap_or_log_default(context, "Failed to send message")
|
||||||
}
|
}
|
||||||
@@ -396,10 +398,11 @@ pub unsafe extern "C" fn dc_send_text_msg(
|
|||||||
pub unsafe extern "C" fn dc_set_draft(
|
pub unsafe extern "C" fn dc_set_draft(
|
||||||
context: *mut dc_context_t,
|
context: *mut dc_context_t,
|
||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
msg: *mut dc_msg::dc_msg_t,
|
msg: *mut dc_msg_t,
|
||||||
) {
|
) {
|
||||||
assert!(!context.is_null());
|
assert!(!context.is_null());
|
||||||
let context = &*context;
|
let context = &*context;
|
||||||
|
let msg = if msg.is_null() { None } else { Some(&mut *msg) };
|
||||||
|
|
||||||
chat::set_draft(context, chat_id, msg)
|
chat::set_draft(context, chat_id, msg)
|
||||||
}
|
}
|
||||||
@@ -408,11 +411,11 @@ pub unsafe extern "C" fn dc_set_draft(
|
|||||||
pub unsafe extern "C" fn dc_get_draft<'a>(
|
pub unsafe extern "C" fn dc_get_draft<'a>(
|
||||||
context: *mut dc_context_t,
|
context: *mut dc_context_t,
|
||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
) -> *mut dc_msg::dc_msg_t<'a> {
|
) -> *mut dc_msg_t<'a> {
|
||||||
assert!(!context.is_null());
|
assert!(!context.is_null());
|
||||||
let context = &*context;
|
let context = &*context;
|
||||||
|
|
||||||
chat::get_draft(context, chat_id)
|
chat::get_draft(context, chat_id).into_raw()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@@ -778,11 +781,11 @@ pub unsafe extern "C" fn dc_star_msgs(
|
|||||||
pub unsafe extern "C" fn dc_get_msg<'a>(
|
pub unsafe extern "C" fn dc_get_msg<'a>(
|
||||||
context: *mut dc_context_t,
|
context: *mut dc_context_t,
|
||||||
msg_id: u32,
|
msg_id: u32,
|
||||||
) -> *mut dc_msg::dc_msg_t<'a> {
|
) -> *mut dc_msg_t<'a> {
|
||||||
assert!(!context.is_null());
|
assert!(!context.is_null());
|
||||||
let context = &*context;
|
let context = &*context;
|
||||||
|
|
||||||
dc_msg::dc_get_msg(context, msg_id)
|
dc_msg::dc_get_msg(context, msg_id).into_raw()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@@ -1398,299 +1401,325 @@ pub unsafe extern "C" fn dc_chat_is_sending_locations(chat: *mut dc_chat_t) -> l
|
|||||||
// dc_msg_t
|
// dc_msg_t
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub type dc_msg_t<'a> = dc_msg::dc_msg_t<'a>;
|
pub type dc_msg_t<'a> = dc_msg::Message<'a>;
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_new<'a>(
|
pub unsafe extern "C" fn dc_msg_new<'a>(
|
||||||
context: *mut dc_context_t,
|
context: *mut dc_context_t,
|
||||||
viewtype: libc::c_int,
|
viewtype: libc::c_int,
|
||||||
) -> *mut dc_msg::dc_msg_t<'a> {
|
) -> *mut dc_msg_t<'a> {
|
||||||
assert!(!context.is_null());
|
assert!(!context.is_null());
|
||||||
let context = &*context;
|
let context = &*context;
|
||||||
let viewtype = from_prim(viewtype).expect(&format!("invalid viewtype = {}", viewtype));
|
let viewtype = from_prim(viewtype).expect(&format!("invalid viewtype = {}", viewtype));
|
||||||
|
|
||||||
dc_msg::dc_msg_new(context, viewtype)
|
Box::into_raw(Box::new(dc_msg::dc_msg_new(context, viewtype)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_unref(msg: *mut dc_msg::dc_msg_t) {
|
pub unsafe extern "C" fn dc_msg_unref(msg: *mut dc_msg_t) {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
dc_msg::dc_msg_unref(msg)
|
Box::from_raw(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_empty(msg: *mut dc_msg::dc_msg_t) {
|
pub unsafe extern "C" fn dc_msg_get_id(msg: *mut dc_msg_t) -> u32 {
|
||||||
assert!(!msg.is_null());
|
|
||||||
|
|
||||||
dc_msg::dc_msg_empty(msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn dc_msg_get_id(msg: *mut dc_msg::dc_msg_t) -> u32 {
|
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_id(msg)
|
dc_msg::dc_msg_get_id(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_from_id(msg: *mut dc_msg::dc_msg_t) -> u32 {
|
pub unsafe extern "C" fn dc_msg_get_from_id(msg: *mut dc_msg_t) -> u32 {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_from_id(msg)
|
dc_msg::dc_msg_get_from_id(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_chat_id(msg: *mut dc_msg::dc_msg_t) -> u32 {
|
pub unsafe extern "C" fn dc_msg_get_chat_id(msg: *mut dc_msg_t) -> u32 {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_chat_id(msg)
|
dc_msg::dc_msg_get_chat_id(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_viewtype(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_get_viewtype(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_viewtype(msg)
|
dc_msg::dc_msg_get_viewtype(msg)
|
||||||
.to_i64()
|
.to_i64()
|
||||||
.expect("impossible: Viewtype -> i64 conversion failed") as libc::c_int
|
.expect("impossible: Viewtype -> i64 conversion failed") as libc::c_int
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_state(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_get_state(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_state(msg) as libc::c_int
|
dc_msg::dc_msg_get_state(msg) as libc::c_int
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_timestamp(msg: *mut dc_msg::dc_msg_t) -> i64 {
|
pub unsafe extern "C" fn dc_msg_get_timestamp(msg: *mut dc_msg_t) -> i64 {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_timestamp(msg)
|
dc_msg::dc_msg_get_timestamp(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_received_timestamp(msg: *mut dc_msg::dc_msg_t) -> i64 {
|
pub unsafe extern "C" fn dc_msg_get_received_timestamp(msg: *mut dc_msg_t) -> i64 {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_received_timestamp(msg)
|
dc_msg::dc_msg_get_received_timestamp(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_sort_timestamp(msg: *mut dc_msg::dc_msg_t) -> i64 {
|
pub unsafe extern "C" fn dc_msg_get_sort_timestamp(msg: *mut dc_msg_t) -> i64 {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_sort_timestamp(msg)
|
dc_msg::dc_msg_get_sort_timestamp(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_text(msg: *mut dc_msg::dc_msg_t) -> *mut libc::c_char {
|
pub unsafe extern "C" fn dc_msg_get_text(msg: *mut dc_msg_t) -> *mut libc::c_char {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_text(msg)
|
dc_msg::dc_msg_get_text(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_file(msg: *mut dc_msg::dc_msg_t) -> *mut libc::c_char {
|
pub unsafe extern "C" fn dc_msg_get_file(msg: *mut dc_msg_t) -> *mut libc::c_char {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_file(msg)
|
dc_msg::dc_msg_get_file(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_filename(msg: *mut dc_msg::dc_msg_t) -> *mut libc::c_char {
|
pub unsafe extern "C" fn dc_msg_get_filename(msg: *mut dc_msg_t) -> *mut libc::c_char {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_filename(msg)
|
dc_msg::dc_msg_get_filename(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_filemime(msg: *mut dc_msg::dc_msg_t) -> *mut libc::c_char {
|
pub unsafe extern "C" fn dc_msg_get_filemime(msg: *mut dc_msg_t) -> *mut libc::c_char {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_filemime(msg)
|
dc_msg::dc_msg_get_filemime(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_filebytes(msg: *mut dc_msg::dc_msg_t) -> u64 {
|
pub unsafe extern "C" fn dc_msg_get_filebytes(msg: *mut dc_msg_t) -> u64 {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_filebytes(msg)
|
dc_msg::dc_msg_get_filebytes(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_width(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_get_width(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_width(msg)
|
dc_msg::dc_msg_get_width(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_height(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_get_height(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_height(msg)
|
dc_msg::dc_msg_get_height(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_duration(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_get_duration(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_duration(msg)
|
dc_msg::dc_msg_get_duration(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_showpadlock(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_get_showpadlock(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_showpadlock(msg)
|
dc_msg::dc_msg_get_showpadlock(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_summary<'a>(
|
pub unsafe extern "C" fn dc_msg_get_summary<'a>(
|
||||||
msg: *mut dc_msg::dc_msg_t<'a>,
|
msg: *mut dc_msg_t<'a>,
|
||||||
chat: *mut dc_chat_t<'a>,
|
chat: *mut dc_chat_t<'a>,
|
||||||
) -> *mut dc_lot_t {
|
) -> *mut dc_lot_t {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
let chat = if chat.is_null() { None } else { Some(&*chat) };
|
let chat = if chat.is_null() { None } else { Some(&*chat) };
|
||||||
|
|
||||||
|
let msg = &mut *msg;
|
||||||
|
|
||||||
let lot = dc_msg::dc_msg_get_summary(msg, chat);
|
let lot = dc_msg::dc_msg_get_summary(msg, chat);
|
||||||
Box::into_raw(Box::new(lot))
|
Box::into_raw(Box::new(lot))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_summarytext(
|
pub unsafe extern "C" fn dc_msg_get_summarytext(
|
||||||
msg: *mut dc_msg::dc_msg_t,
|
msg: *mut dc_msg_t,
|
||||||
approx_characters: libc::c_int,
|
approx_characters: libc::c_int,
|
||||||
) -> *mut libc::c_char {
|
) -> *mut libc::c_char {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &mut *msg;
|
||||||
dc_msg::dc_msg_get_summarytext(msg, approx_characters.try_into().unwrap())
|
dc_msg::dc_msg_get_summarytext(msg, approx_characters.try_into().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_has_deviating_timestamp(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_has_deviating_timestamp(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_has_deviating_timestamp(msg)
|
dc_msg::dc_msg_has_deviating_timestamp(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_has_location(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_has_location(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_has_location(msg) as libc::c_int
|
dc_msg::dc_msg_has_location(msg) as libc::c_int
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_is_sent(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_is_sent(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_is_sent(msg)
|
dc_msg::dc_msg_is_sent(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_is_starred(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_is_starred(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_is_starred(msg).into()
|
dc_msg::dc_msg_is_starred(msg).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_is_forwarded(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_is_forwarded(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_is_forwarded(msg)
|
dc_msg::dc_msg_is_forwarded(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_is_info(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_is_info(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_is_info(msg)
|
dc_msg::dc_msg_is_info(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_is_increation(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_is_increation(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_is_increation(msg)
|
dc_msg::dc_msg_is_increation(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_is_setupmessage(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
|
pub unsafe extern "C" fn dc_msg_is_setupmessage(msg: *mut dc_msg_t) -> libc::c_int {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_is_setupmessage(msg) as libc::c_int
|
dc_msg::dc_msg_is_setupmessage(msg) as libc::c_int
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_setupcodebegin(
|
pub unsafe extern "C" fn dc_msg_get_setupcodebegin(msg: *mut dc_msg_t) -> *mut libc::c_char {
|
||||||
msg: *mut dc_msg::dc_msg_t,
|
|
||||||
) -> *mut libc::c_char {
|
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &*msg;
|
||||||
dc_msg::dc_msg_get_setupcodebegin(msg)
|
dc_msg::dc_msg_get_setupcodebegin(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_set_text(msg: *mut dc_msg::dc_msg_t, text: *mut libc::c_char) {
|
pub unsafe extern "C" fn dc_msg_set_text(msg: *mut dc_msg_t, text: *mut libc::c_char) {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &mut *msg;
|
||||||
// TODO: {text} equal to NULL is treated as "", which is strange. Does anyone rely on it?
|
// TODO: {text} equal to NULL is treated as "", which is strange. Does anyone rely on it?
|
||||||
dc_msg::dc_msg_set_text(msg, text)
|
dc_msg::dc_msg_set_text(msg, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_set_file(
|
pub unsafe extern "C" fn dc_msg_set_file(
|
||||||
msg: *mut dc_msg::dc_msg_t,
|
msg: *mut dc_msg_t,
|
||||||
file: *mut libc::c_char,
|
file: *mut libc::c_char,
|
||||||
filemime: *mut libc::c_char,
|
filemime: *mut libc::c_char,
|
||||||
) {
|
) {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &mut *msg;
|
||||||
dc_msg::dc_msg_set_file(msg, file, filemime)
|
dc_msg::dc_msg_set_file(msg, file, filemime)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_set_dimension(
|
pub unsafe extern "C" fn dc_msg_set_dimension(
|
||||||
msg: *mut dc_msg::dc_msg_t,
|
msg: *mut dc_msg_t,
|
||||||
width: libc::c_int,
|
width: libc::c_int,
|
||||||
height: libc::c_int,
|
height: libc::c_int,
|
||||||
) {
|
) {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &mut *msg;
|
||||||
dc_msg::dc_msg_set_dimension(msg, width, height)
|
dc_msg::dc_msg_set_dimension(msg, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_set_duration(msg: *mut dc_msg::dc_msg_t, duration: libc::c_int) {
|
pub unsafe extern "C" fn dc_msg_set_duration(msg: *mut dc_msg_t, duration: libc::c_int) {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &mut *msg;
|
||||||
dc_msg::dc_msg_set_duration(msg, duration)
|
dc_msg::dc_msg_set_duration(msg, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_set_location(
|
pub unsafe extern "C" fn dc_msg_set_location(
|
||||||
msg: *mut dc_msg::dc_msg_t,
|
msg: *mut dc_msg_t,
|
||||||
latitude: libc::c_double,
|
latitude: libc::c_double,
|
||||||
longitude: libc::c_double,
|
longitude: libc::c_double,
|
||||||
) {
|
) {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &mut *msg;
|
||||||
dc_msg::dc_msg_set_location(msg, latitude, longitude)
|
dc_msg::dc_msg_set_location(msg, latitude, longitude)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_latefiling_mediasize(
|
pub unsafe extern "C" fn dc_msg_latefiling_mediasize(
|
||||||
msg: *mut dc_msg::dc_msg_t,
|
msg: *mut dc_msg_t,
|
||||||
width: libc::c_int,
|
width: libc::c_int,
|
||||||
height: libc::c_int,
|
height: libc::c_int,
|
||||||
duration: libc::c_int,
|
duration: libc::c_int,
|
||||||
) {
|
) {
|
||||||
assert!(!msg.is_null());
|
assert!(!msg.is_null());
|
||||||
|
|
||||||
|
let msg = &mut *msg;
|
||||||
dc_msg::dc_msg_latefiling_mediasize(msg, width, height, duration)
|
dc_msg::dc_msg_latefiling_mediasize(msg, width, height, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1869,7 +1898,7 @@ fn as_opt_str<'a>(s: *const libc::c_char) -> Option<&'a str> {
|
|||||||
Some(dc_tools::as_str(s))
|
Some(dc_tools::as_str(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ResultExt<T: Default> {
|
pub trait ResultExt<T> {
|
||||||
fn unwrap_or_log_default(self, context: &context::Context, message: &str) -> T;
|
fn unwrap_or_log_default(self, context: &context::Context, message: &str) -> T;
|
||||||
fn log_err(&self, context: &context::Context, message: &str);
|
fn log_err(&self, context: &context::Context, message: &str);
|
||||||
}
|
}
|
||||||
@@ -1898,3 +1927,16 @@ unsafe fn strdup_opt(s: Option<impl AsRef<str>>) -> *mut libc::c_char {
|
|||||||
None => ptr::null_mut(),
|
None => ptr::null_mut(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait ResultNullableExt<T> {
|
||||||
|
fn into_raw(self) -> *mut T;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, E> ResultNullableExt<T> for Result<T, E> {
|
||||||
|
fn into_raw(self) -> *mut T {
|
||||||
|
match self {
|
||||||
|
Ok(t) => Box::into_raw(Box::new(t)),
|
||||||
|
Err(_) => ptr::null_mut(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ use deltachat::dc_location::*;
|
|||||||
use deltachat::dc_msg::*;
|
use deltachat::dc_msg::*;
|
||||||
use deltachat::dc_receive_imf::*;
|
use deltachat::dc_receive_imf::*;
|
||||||
use deltachat::dc_tools::*;
|
use deltachat::dc_tools::*;
|
||||||
|
use deltachat::error::Error;
|
||||||
use deltachat::job::*;
|
use deltachat::job::*;
|
||||||
use deltachat::lot::LotState;
|
use deltachat::lot::LotState;
|
||||||
use deltachat::peerstate::*;
|
use deltachat::peerstate::*;
|
||||||
@@ -210,7 +211,7 @@ unsafe fn poke_spec(context: &Context, spec: *const libc::c_char) -> libc::c_int
|
|||||||
success
|
success
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: *mut dc_msg_t) {
|
unsafe fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: &Message) {
|
||||||
let contact = Contact::get_by_id(context, dc_msg_get_from_id(msg)).expect("invalid contact");
|
let contact = Contact::get_by_id(context, dc_msg_get_from_id(msg)).expect("invalid contact");
|
||||||
let contact_name = contact.get_name();
|
let contact_name = contact.get_name();
|
||||||
let contact_id = contact.get_id();
|
let contact_id = contact.get_id();
|
||||||
@@ -260,7 +261,7 @@ unsafe fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: *mut dc_msg_t
|
|||||||
free(msgtext as *mut libc::c_void);
|
free(msgtext as *mut libc::c_void);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn log_msglist(context: &Context, msglist: &Vec<u32>) {
|
unsafe fn log_msglist(context: &Context, msglist: &Vec<u32>) -> Result<(), Error> {
|
||||||
let mut lines_out = 0;
|
let mut lines_out = 0;
|
||||||
for &msg_id in msglist {
|
for &msg_id in msglist {
|
||||||
if msg_id == 9 as libc::c_uint {
|
if msg_id == 9 as libc::c_uint {
|
||||||
@@ -279,9 +280,8 @@ unsafe fn log_msglist(context: &Context, msglist: &Vec<u32>) {
|
|||||||
);
|
);
|
||||||
lines_out += 1
|
lines_out += 1
|
||||||
}
|
}
|
||||||
let msg = dc_get_msg(context, msg_id);
|
let msg = dc_get_msg(context, msg_id)?;
|
||||||
log_msg(context, "Msg", msg);
|
log_msg(context, "Msg", &msg);
|
||||||
dc_msg_unref(msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if lines_out > 0 {
|
if lines_out > 0 {
|
||||||
@@ -290,6 +290,7 @@ unsafe fn log_msglist(context: &Context, msglist: &Vec<u32>) {
|
|||||||
0, "--------------------------------------------------------------------------------"
|
0, "--------------------------------------------------------------------------------"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn log_contactlist(context: &Context, contacts: &Vec<u32>) {
|
unsafe fn log_contactlist(context: &Context, contacts: &Vec<u32>) {
|
||||||
@@ -496,9 +497,9 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
"get-setupcodebegin" => {
|
"get-setupcodebegin" => {
|
||||||
ensure!(!arg1.is_empty(), "Argument <msg-id> missing.");
|
ensure!(!arg1.is_empty(), "Argument <msg-id> missing.");
|
||||||
let msg_id: u32 = arg1.parse()?;
|
let msg_id: u32 = arg1.parse()?;
|
||||||
let msg: *mut dc_msg_t = dc_get_msg(context, msg_id);
|
let msg = dc_get_msg(context, msg_id)?;
|
||||||
if dc_msg_is_setupmessage(msg) {
|
if dc_msg_is_setupmessage(&msg) {
|
||||||
let setupcodebegin = dc_msg_get_setupcodebegin(msg);
|
let setupcodebegin = dc_msg_get_setupcodebegin(&msg);
|
||||||
println!(
|
println!(
|
||||||
"The setup code for setup message Msg#{} starts with: {}",
|
"The setup code for setup message Msg#{} starts with: {}",
|
||||||
msg_id,
|
msg_id,
|
||||||
@@ -508,7 +509,6 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
} else {
|
} else {
|
||||||
bail!("Msg#{} is no setup message.", msg_id,);
|
bail!("Msg#{} is no setup message.", msg_id,);
|
||||||
}
|
}
|
||||||
dc_msg_unref(msg);
|
|
||||||
}
|
}
|
||||||
"continue-key-transfer" => {
|
"continue-key-transfer" => {
|
||||||
ensure!(
|
ensure!(
|
||||||
@@ -688,12 +688,11 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
""
|
""
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
log_msglist(context, &msglist);
|
log_msglist(context, &msglist)?;
|
||||||
let draft = chat::get_draft(context, sel_chat.get_id());
|
if let Ok(draft) = chat::get_draft(context, sel_chat.get_id()) {
|
||||||
if !draft.is_null() {
|
log_msg(context, "Draft", &draft);
|
||||||
log_msg(context, "Draft", draft);
|
|
||||||
dc_msg_unref(draft);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{} messages.",
|
"{} messages.",
|
||||||
chat::get_msg_cnt(context, sel_chat.get_id())
|
chat::get_msg_cnt(context, sel_chat.get_id())
|
||||||
@@ -861,7 +860,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
ensure!(sel_chat.is_some(), "No chat selected.");
|
ensure!(sel_chat.is_some(), "No chat selected.");
|
||||||
ensure!(!arg1.is_empty() && !arg2.is_empty(), "No file given.");
|
ensure!(!arg1.is_empty() && !arg2.is_empty(), "No file given.");
|
||||||
|
|
||||||
let msg_0 = dc_msg_new(
|
let mut msg = dc_msg_new(
|
||||||
context,
|
context,
|
||||||
if arg0 == "sendimage" {
|
if arg0 == "sendimage" {
|
||||||
Viewtype::Image
|
Viewtype::Image
|
||||||
@@ -869,10 +868,9 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
Viewtype::File
|
Viewtype::File
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
dc_msg_set_file(msg_0, arg1_c, 0 as *const libc::c_char);
|
dc_msg_set_file(&mut msg, arg1_c, 0 as *const libc::c_char);
|
||||||
dc_msg_set_text(msg_0, arg2_c);
|
dc_msg_set_text(&mut msg, arg2_c);
|
||||||
chat::send_msg(context, sel_chat.as_ref().unwrap().get_id(), msg_0)?;
|
chat::send_msg(context, sel_chat.as_ref().unwrap().get_id(), &mut msg)?;
|
||||||
dc_msg_unref(msg_0);
|
|
||||||
}
|
}
|
||||||
"listmsgs" => {
|
"listmsgs" => {
|
||||||
ensure!(!arg1.is_empty(), "Argument <query> missing.");
|
ensure!(!arg1.is_empty(), "Argument <query> missing.");
|
||||||
@@ -885,24 +883,23 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
|
|
||||||
let msglist = dc_search_msgs(context, chat, arg1_c);
|
let msglist = dc_search_msgs(context, chat, arg1_c);
|
||||||
|
|
||||||
log_msglist(context, &msglist);
|
log_msglist(context, &msglist)?;
|
||||||
println!("{} messages.", msglist.len());
|
println!("{} messages.", msglist.len());
|
||||||
}
|
}
|
||||||
"draft" => {
|
"draft" => {
|
||||||
ensure!(sel_chat.is_some(), "No chat selected.");
|
ensure!(sel_chat.is_some(), "No chat selected.");
|
||||||
|
|
||||||
if !arg1.is_empty() {
|
if !arg1.is_empty() {
|
||||||
let draft_0 = dc_msg_new(context, Viewtype::Text);
|
let mut draft = dc_msg_new(context, Viewtype::Text);
|
||||||
dc_msg_set_text(draft_0, arg1_c);
|
dc_msg_set_text(&mut draft, arg1_c);
|
||||||
chat::set_draft(context, sel_chat.as_ref().unwrap().get_id(), draft_0);
|
|
||||||
dc_msg_unref(draft_0);
|
|
||||||
println!("Draft saved.");
|
|
||||||
} else {
|
|
||||||
chat::set_draft(
|
chat::set_draft(
|
||||||
context,
|
context,
|
||||||
sel_chat.as_ref().unwrap().get_id(),
|
sel_chat.as_ref().unwrap().get_id(),
|
||||||
0 as *mut dc_msg_t,
|
Some(&mut draft),
|
||||||
);
|
);
|
||||||
|
println!("Draft saved.");
|
||||||
|
} else {
|
||||||
|
chat::set_draft(context, sel_chat.as_ref().unwrap().get_id(), None);
|
||||||
println!("Draft deleted.");
|
println!("Draft deleted.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -949,7 +946,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
"listfresh" => {
|
"listfresh" => {
|
||||||
let msglist = dc_get_fresh_msgs(context);
|
let msglist = dc_get_fresh_msgs(context);
|
||||||
|
|
||||||
log_msglist(context, &msglist);
|
log_msglist(context, &msglist)?;
|
||||||
print!("{} fresh messages.", msglist.len());
|
print!("{} fresh messages.", msglist.len());
|
||||||
}
|
}
|
||||||
"forward" => {
|
"forward" => {
|
||||||
|
|||||||
267
src/chat.rs
267
src/chat.rs
@@ -272,7 +272,7 @@ impl<'a> Chat<'a> {
|
|||||||
unsafe fn prepare_msg_raw(
|
unsafe fn prepare_msg_raw(
|
||||||
&mut self,
|
&mut self,
|
||||||
context: &Context,
|
context: &Context,
|
||||||
msg: *mut dc_msg_t,
|
msg: &mut Message,
|
||||||
timestamp: i64,
|
timestamp: i64,
|
||||||
) -> Result<u32, Error> {
|
) -> Result<u32, Error> {
|
||||||
let mut do_guarantee_e2ee: libc::c_int;
|
let mut do_guarantee_e2ee: libc::c_int;
|
||||||
@@ -351,11 +351,7 @@ impl<'a> Chat<'a> {
|
|||||||
.get_config_int(context, "e2ee_enabled")
|
.get_config_int(context, "e2ee_enabled")
|
||||||
.unwrap_or_else(|| 1);
|
.unwrap_or_else(|| 1);
|
||||||
if 0 != e2ee_enabled
|
if 0 != e2ee_enabled
|
||||||
&& (*msg)
|
&& msg.param.get_int(Param::ForcePlaintext).unwrap_or_default() == 0
|
||||||
.param
|
|
||||||
.get_int(Param::ForcePlaintext)
|
|
||||||
.unwrap_or_default()
|
|
||||||
== 0
|
|
||||||
{
|
{
|
||||||
let mut can_encrypt = 1;
|
let mut can_encrypt = 1;
|
||||||
let mut all_mutual = 1;
|
let mut all_mutual = 1;
|
||||||
@@ -409,9 +405,9 @@ impl<'a> Chat<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if 0 != do_guarantee_e2ee {
|
if 0 != do_guarantee_e2ee {
|
||||||
(*msg).param.set_int(Param::GuranteeE2ee, 1);
|
msg.param.set_int(Param::GuranteeE2ee, 1);
|
||||||
}
|
}
|
||||||
(*msg).param.remove(Param::ErroneousE2ee);
|
msg.param.remove(Param::ErroneousE2ee);
|
||||||
if !self.is_self_talk()
|
if !self.is_self_talk()
|
||||||
&& self
|
&& self
|
||||||
.get_parent_mime_headers(
|
.get_parent_mime_headers(
|
||||||
@@ -466,7 +462,7 @@ impl<'a> Chat<'a> {
|
|||||||
|
|
||||||
// add independent location to database
|
// add independent location to database
|
||||||
|
|
||||||
if (*msg).param.exists(Param::SetLatitude) {
|
if msg.param.exists(Param::SetLatitude) {
|
||||||
if sql::execute(
|
if sql::execute(
|
||||||
context,
|
context,
|
||||||
&context.sql,
|
&context.sql,
|
||||||
@@ -477,14 +473,8 @@ impl<'a> Chat<'a> {
|
|||||||
timestamp,
|
timestamp,
|
||||||
DC_CONTACT_ID_SELF as i32,
|
DC_CONTACT_ID_SELF as i32,
|
||||||
self.id as i32,
|
self.id as i32,
|
||||||
(*msg)
|
msg.param.get_float(Param::SetLatitude).unwrap_or_default(),
|
||||||
.param
|
msg.param.get_float(Param::SetLongitude).unwrap_or_default(),
|
||||||
.get_float(Param::SetLatitude)
|
|
||||||
.unwrap_or_default(),
|
|
||||||
(*msg)
|
|
||||||
.param
|
|
||||||
.get_float(Param::SetLongitude)
|
|
||||||
.unwrap_or_default(),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.is_ok()
|
.is_ok()
|
||||||
@@ -513,11 +503,11 @@ impl<'a> Chat<'a> {
|
|||||||
1i32,
|
1i32,
|
||||||
to_id as i32,
|
to_id as i32,
|
||||||
timestamp,
|
timestamp,
|
||||||
(*msg).type_0,
|
msg.type_0,
|
||||||
(*msg).state,
|
msg.state,
|
||||||
(*msg).text,
|
msg.text,
|
||||||
(*msg).param.to_string(),
|
msg.param.to_string(),
|
||||||
(*msg).hidden,
|
msg.hidden,
|
||||||
to_string(new_in_reply_to),
|
to_string(new_in_reply_to),
|
||||||
to_string(new_references),
|
to_string(new_references),
|
||||||
location_id as i32,
|
location_id as i32,
|
||||||
@@ -574,27 +564,20 @@ impl<'a> Chat<'a> {
|
|||||||
pub fn create_by_msg_id(context: &Context, msg_id: u32) -> Result<u32, Error> {
|
pub fn create_by_msg_id(context: &Context, msg_id: u32) -> Result<u32, Error> {
|
||||||
let mut chat_id = 0;
|
let mut chat_id = 0;
|
||||||
let mut send_event = false;
|
let mut send_event = false;
|
||||||
let msg = unsafe { dc_msg_new_untyped(context) };
|
|
||||||
|
|
||||||
if dc_msg_load_from_db(msg, context, msg_id) {
|
if let Ok(msg) = dc_msg_load_from_db(context, msg_id) {
|
||||||
if let Ok(chat) = Chat::load_from_db(context, unsafe { (*msg).chat_id }) {
|
if let Ok(chat) = Chat::load_from_db(context, msg.chat_id) {
|
||||||
if chat.id > DC_CHAT_ID_LAST_SPECIAL as u32 {
|
if chat.id > DC_CHAT_ID_LAST_SPECIAL as u32 {
|
||||||
chat_id = chat.id;
|
chat_id = chat.id;
|
||||||
if chat.blocked != Blocked::Not {
|
if chat.blocked != Blocked::Not {
|
||||||
unblock(context, chat.id);
|
unblock(context, chat.id);
|
||||||
send_event = true;
|
send_event = true;
|
||||||
}
|
}
|
||||||
Contact::scaleup_origin_by_id(
|
Contact::scaleup_origin_by_id(context, msg.from_id, Origin::CreateChat);
|
||||||
context,
|
|
||||||
unsafe { (*msg).from_id },
|
|
||||||
Origin::CreateChat,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe { dc_msg_unref(msg) };
|
|
||||||
|
|
||||||
if send_event {
|
if send_event {
|
||||||
context.call_cb(Event::MSGS_CHANGED, 0, 0);
|
context.call_cb(Event::MSGS_CHANGED, 0, 0);
|
||||||
}
|
}
|
||||||
@@ -721,20 +704,19 @@ pub fn get_by_contact_id(context: &Context, contact_id: u32) -> Result<u32, Erro
|
|||||||
pub fn prepare_msg<'a>(
|
pub fn prepare_msg<'a>(
|
||||||
context: &'a Context,
|
context: &'a Context,
|
||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
mut msg: *mut dc_msg_t<'a>,
|
msg: &mut Message<'a>,
|
||||||
) -> Result<u32, Error> {
|
) -> Result<u32, Error> {
|
||||||
ensure!(!msg.is_null(), "No message provided");
|
|
||||||
ensure!(
|
ensure!(
|
||||||
chat_id > DC_CHAT_ID_LAST_SPECIAL as u32,
|
chat_id > DC_CHAT_ID_LAST_SPECIAL as u32,
|
||||||
"Cannot prepare message for special chat"
|
"Cannot prepare message for special chat"
|
||||||
);
|
);
|
||||||
|
|
||||||
unsafe { (*msg).state = MessageState::OutPreparing };
|
msg.state = MessageState::OutPreparing;
|
||||||
let msg_id = prepare_msg_common(context, chat_id, msg)?;
|
let msg_id = prepare_msg_common(context, chat_id, msg)?;
|
||||||
context.call_cb(
|
context.call_cb(
|
||||||
Event::MSGS_CHANGED,
|
Event::MSGS_CHANGED,
|
||||||
unsafe { (*msg).chat_id as uintptr_t },
|
msg.chat_id as uintptr_t,
|
||||||
unsafe { (*msg).id as uintptr_t },
|
msg.id as uintptr_t,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(msg_id)
|
Ok(msg_id)
|
||||||
@@ -755,12 +737,8 @@ pub fn msgtype_has_file(msgtype: Viewtype) -> bool {
|
|||||||
fn prepare_msg_common<'a>(
|
fn prepare_msg_common<'a>(
|
||||||
context: &'a Context,
|
context: &'a Context,
|
||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
msg: *mut dc_msg_t<'a>,
|
msg: &mut Message<'a>,
|
||||||
) -> Result<u32, Error> {
|
) -> Result<u32, Error> {
|
||||||
ensure!(!msg.is_null(), "No message provided");
|
|
||||||
|
|
||||||
let msg = unsafe { &mut *msg };
|
|
||||||
|
|
||||||
msg.id = 0;
|
msg.id = 0;
|
||||||
msg.context = context;
|
msg.context = context;
|
||||||
|
|
||||||
@@ -881,39 +859,37 @@ pub fn unarchive(context: &Context, chat_id: u32) -> Result<(), Error> {
|
|||||||
pub unsafe fn send_msg<'a>(
|
pub unsafe fn send_msg<'a>(
|
||||||
context: &'a Context,
|
context: &'a Context,
|
||||||
chat_id: u32,
|
chat_id: u32,
|
||||||
msg: *mut dc_msg_t<'a>,
|
msg: &mut Message<'a>,
|
||||||
) -> Result<u32, Error> {
|
) -> Result<u32, Error> {
|
||||||
ensure!(!msg.is_null(), "Invalid message");
|
if msg.state != MessageState::OutPreparing {
|
||||||
|
|
||||||
if (*msg).state != MessageState::OutPreparing {
|
|
||||||
// automatically prepare normal messages
|
// automatically prepare normal messages
|
||||||
prepare_msg_common(context, chat_id, msg)?;
|
prepare_msg_common(context, chat_id, msg)?;
|
||||||
} else {
|
} else {
|
||||||
// update message state of separately prepared messages
|
// update message state of separately prepared messages
|
||||||
ensure!(
|
ensure!(
|
||||||
chat_id == 0 || chat_id == (*msg).chat_id,
|
chat_id == 0 || chat_id == msg.chat_id,
|
||||||
"Inconsistent chat ID"
|
"Inconsistent chat ID"
|
||||||
);
|
);
|
||||||
dc_update_msg_state(context, (*msg).id, MessageState::OutPending);
|
dc_update_msg_state(context, msg.id, MessageState::OutPending);
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure!(
|
ensure!(
|
||||||
job_send_msg(context, (*msg).id) != 0,
|
job_send_msg(context, msg.id) != 0,
|
||||||
"Failed to initiate send job"
|
"Failed to initiate send job"
|
||||||
);
|
);
|
||||||
|
|
||||||
context.call_cb(
|
context.call_cb(
|
||||||
Event::MSGS_CHANGED,
|
Event::MSGS_CHANGED,
|
||||||
(*msg).chat_id as uintptr_t,
|
msg.chat_id as uintptr_t,
|
||||||
(*msg).id as uintptr_t,
|
msg.id as uintptr_t,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (*msg).param.exists(Param::SetLatitude) {
|
if msg.param.exists(Param::SetLatitude) {
|
||||||
context.call_cb(Event::LOCATION_CHANGED, DC_CONTACT_ID_SELF, 0);
|
context.call_cb(Event::LOCATION_CHANGED, DC_CONTACT_ID_SELF, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if 0 == chat_id {
|
if 0 == chat_id {
|
||||||
let forwards = (*msg).param.get(Param::PrepForwards);
|
let forwards = msg.param.get(Param::PrepForwards);
|
||||||
if let Some(forwards) = forwards {
|
if let Some(forwards) = forwards {
|
||||||
for forward in forwards.split(' ') {
|
for forward in forwards.split(' ') {
|
||||||
let id: i32 = forward.parse().unwrap_or_default();
|
let id: i32 = forward.parse().unwrap_or_default();
|
||||||
@@ -921,20 +897,18 @@ pub unsafe fn send_msg<'a>(
|
|||||||
// avoid hanging if user tampers with db
|
// avoid hanging if user tampers with db
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
let copy = dc_get_msg(context, id as u32);
|
if let Ok(mut copy) = dc_get_msg(context, id as u32) {
|
||||||
if !copy.is_null() {
|
|
||||||
// TODO: handle cleanup and return early instead
|
// TODO: handle cleanup and return early instead
|
||||||
send_msg(context, 0, copy).unwrap();
|
send_msg(context, 0, &mut copy).unwrap();
|
||||||
}
|
}
|
||||||
dc_msg_unref(copy);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(*msg).param.remove(Param::PrepForwards);
|
msg.param.remove(Param::PrepForwards);
|
||||||
dc_msg_save_param_to_disk(msg);
|
dc_msg_save_param_to_disk(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((*msg).id)
|
Ok(msg.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn send_text_msg(
|
pub unsafe fn send_text_msg(
|
||||||
@@ -949,11 +923,12 @@ pub unsafe fn send_text_msg(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let mut msg = dc_msg_new(context, Viewtype::Text);
|
let mut msg = dc_msg_new(context, Viewtype::Text);
|
||||||
(*msg).text = Some(text_to_send);
|
msg.text = Some(text_to_send);
|
||||||
send_msg(context, chat_id, msg)
|
send_msg(context, chat_id, &mut msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn set_draft(context: &Context, chat_id: u32, msg: *mut dc_msg_t) {
|
// passing `None` as message jsut deletes the draft
|
||||||
|
pub unsafe fn set_draft(context: &Context, chat_id: u32, msg: Option<&mut Message>) {
|
||||||
if chat_id <= DC_CHAT_ID_LAST_SPECIAL as u32 {
|
if chat_id <= DC_CHAT_ID_LAST_SPECIAL as u32 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -962,31 +937,32 @@ pub unsafe fn set_draft(context: &Context, chat_id: u32, msg: *mut dc_msg_t) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// similar to as dc_set_draft() but does not emit an event
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
unsafe fn set_draft_raw(context: &Context, chat_id: u32, msg: *mut dc_msg_t) -> bool {
|
unsafe fn set_draft_raw(context: &Context, chat_id: u32, mut msg: Option<&mut Message>) -> bool {
|
||||||
let mut OK_TO_CONTINUE = true;
|
let mut OK_TO_CONTINUE = true;
|
||||||
// similar to as dc_set_draft() but does not emit an event
|
|
||||||
let prev_draft_msg_id: u32;
|
|
||||||
let mut sth_changed = false;
|
let mut sth_changed = false;
|
||||||
|
|
||||||
prev_draft_msg_id = get_draft_msg_id(context, chat_id);
|
let prev_draft_msg_id = get_draft_msg_id(context, chat_id);
|
||||||
if 0 != prev_draft_msg_id {
|
if 0 != prev_draft_msg_id {
|
||||||
dc_delete_msg_from_db(context, prev_draft_msg_id);
|
dc_delete_msg_from_db(context, prev_draft_msg_id);
|
||||||
sth_changed = true;
|
sth_changed = true;
|
||||||
}
|
}
|
||||||
// save new draft
|
|
||||||
if !msg.is_null() {
|
if let Some(ref mut msg) = msg {
|
||||||
if (*msg).type_0 == Viewtype::Text {
|
// save new draft
|
||||||
OK_TO_CONTINUE = (*msg).text.as_ref().map_or(false, |s| !s.is_empty());
|
if msg.type_0 == Viewtype::Text {
|
||||||
} else if msgtype_has_file((*msg).type_0) {
|
OK_TO_CONTINUE = msg.text.as_ref().map_or(false, |s| !s.is_empty());
|
||||||
if let Some(path_filename) = (*msg).param.get(Param::File) {
|
} else if msgtype_has_file(msg.type_0) {
|
||||||
|
if let Some(path_filename) = msg.param.get(Param::File) {
|
||||||
let mut path_filename = path_filename.to_string();
|
let mut path_filename = path_filename.to_string();
|
||||||
if 0 != dc_msg_is_increation(msg) && !dc_is_blobdir_path(context, &path_filename) {
|
if 0 != dc_msg_is_increation(msg) && !dc_is_blobdir_path(context, &path_filename) {
|
||||||
OK_TO_CONTINUE = false;
|
OK_TO_CONTINUE = false;
|
||||||
} else if !dc_make_rel_and_copy(context, &mut path_filename) {
|
} else if !dc_make_rel_and_copy(context, &mut path_filename) {
|
||||||
OK_TO_CONTINUE = false;
|
OK_TO_CONTINUE = false;
|
||||||
} else {
|
} else {
|
||||||
(*msg).param.set(Param::File, path_filename);
|
msg.param.set(Param::File, path_filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1002,10 +978,10 @@ unsafe fn set_draft_raw(context: &Context, chat_id: u32, msg: *mut dc_msg_t) ->
|
|||||||
chat_id as i32,
|
chat_id as i32,
|
||||||
1,
|
1,
|
||||||
time(),
|
time(),
|
||||||
(*msg).type_0,
|
msg.type_0,
|
||||||
MessageState::OutDraft,
|
MessageState::OutDraft,
|
||||||
(*msg).text.as_ref().map(String::as_str).unwrap_or(""),
|
msg.text.as_ref().map(String::as_str).unwrap_or(""),
|
||||||
(*msg).param.to_string(),
|
msg.param.to_string(),
|
||||||
1,
|
1,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@@ -1015,7 +991,6 @@ unsafe fn set_draft_raw(context: &Context, chat_id: u32, msg: *mut dc_msg_t) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sth_changed
|
sth_changed
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1031,21 +1006,12 @@ fn get_draft_msg_id(context: &Context, chat_id: u32) -> u32 {
|
|||||||
.unwrap_or_default() as u32
|
.unwrap_or_default() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn get_draft(context: &Context, chat_id: u32) -> *mut dc_msg_t {
|
pub unsafe fn get_draft(context: &Context, chat_id: u32) -> Result<Message, Error> {
|
||||||
if chat_id <= DC_CHAT_ID_LAST_SPECIAL as u32 {
|
ensure!(chat_id > DC_CHAT_ID_LAST_SPECIAL as u32, "Invalid chat ID");
|
||||||
return ptr::null_mut();
|
|
||||||
}
|
|
||||||
let draft_msg_id = get_draft_msg_id(context, chat_id);
|
let draft_msg_id = get_draft_msg_id(context, chat_id);
|
||||||
if draft_msg_id == 0 {
|
ensure!(draft_msg_id != 0, "Invalid draft message ID");
|
||||||
return ptr::null_mut();
|
|
||||||
}
|
|
||||||
let draft_msg = dc_msg_new_untyped(context);
|
|
||||||
if !dc_msg_load_from_db(draft_msg, context, draft_msg_id) {
|
|
||||||
dc_msg_unref(draft_msg);
|
|
||||||
return ptr::null_mut();
|
|
||||||
}
|
|
||||||
|
|
||||||
draft_msg
|
dc_msg_load_from_db(context, draft_msg_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_chat_msgs(context: &Context, chat_id: u32, flags: u32, marker1before: u32) -> Vec<u32> {
|
pub fn get_chat_msgs(context: &Context, chat_id: u32, flags: u32, marker1before: u32) -> Vec<u32> {
|
||||||
@@ -1235,15 +1201,15 @@ pub unsafe fn get_next_media(
|
|||||||
msg_type3: Viewtype,
|
msg_type3: Viewtype,
|
||||||
) -> u32 {
|
) -> u32 {
|
||||||
let mut ret = 0;
|
let mut ret = 0;
|
||||||
let msg: *mut dc_msg_t = dc_msg_new_untyped(context);
|
|
||||||
if dc_msg_load_from_db(msg, context, curr_msg_id) {
|
if let Ok(msg) = dc_msg_load_from_db(context, curr_msg_id) {
|
||||||
let list = get_chat_media(
|
let list = get_chat_media(
|
||||||
context,
|
context,
|
||||||
(*msg).chat_id,
|
msg.chat_id,
|
||||||
if msg_type != Viewtype::Unknown {
|
if msg_type != Viewtype::Unknown {
|
||||||
msg_type
|
msg_type
|
||||||
} else {
|
} else {
|
||||||
(*msg).type_0
|
msg.type_0
|
||||||
},
|
},
|
||||||
msg_type2,
|
msg_type2,
|
||||||
msg_type3,
|
msg_type3,
|
||||||
@@ -1263,8 +1229,6 @@ pub unsafe fn get_next_media(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dc_msg_unref(msg);
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1400,10 +1364,9 @@ pub unsafe fn create_group_chat(
|
|||||||
|
|
||||||
if chat_id != 0 {
|
if chat_id != 0 {
|
||||||
if 0 != add_to_chat_contacts_table(context, chat_id, 1) {
|
if 0 != add_to_chat_contacts_table(context, chat_id, 1) {
|
||||||
let draft_msg = dc_msg_new(context, Viewtype::Text);
|
let mut draft_msg = dc_msg_new(context, Viewtype::Text);
|
||||||
dc_msg_set_text(draft_msg, draft_txt.as_ptr());
|
dc_msg_set_text(&mut draft_msg, draft_txt.as_ptr());
|
||||||
set_draft_raw(context, chat_id, draft_msg);
|
set_draft_raw(context, chat_id, Some(&mut draft_msg));
|
||||||
dc_msg_unref(draft_msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
context.call_cb(Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t);
|
context.call_cb(Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t);
|
||||||
@@ -1506,21 +1469,21 @@ pub unsafe fn add_contact_to_chat_ex(
|
|||||||
}
|
}
|
||||||
if OK_TO_CONTINUE {
|
if OK_TO_CONTINUE {
|
||||||
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
||||||
(*msg).type_0 = Viewtype::Text;
|
msg.type_0 = Viewtype::Text;
|
||||||
(*msg).text = Some(context.stock_system_msg(
|
msg.text = Some(context.stock_system_msg(
|
||||||
StockMessage::MsgAddMember,
|
StockMessage::MsgAddMember,
|
||||||
contact.get_addr(),
|
contact.get_addr(),
|
||||||
"",
|
"",
|
||||||
DC_CONTACT_ID_SELF as u32,
|
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());
|
||||||
(*msg).param.set_int(Param::Arg2, flags);
|
msg.param.set_int(Param::Arg2, flags);
|
||||||
(*msg).id = send_msg(context, chat_id, msg).unwrap_or_default();
|
msg.id = send_msg(context, chat_id, &mut msg).unwrap_or_default();
|
||||||
context.call_cb(
|
context.call_cb(
|
||||||
Event::MSGS_CHANGED,
|
Event::MSGS_CHANGED,
|
||||||
chat_id as uintptr_t,
|
chat_id as uintptr_t,
|
||||||
(*msg).id as uintptr_t,
|
msg.id as uintptr_t,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
context.call_cb(Event::MSGS_CHANGED, chat_id as uintptr_t, 0 as uintptr_t);
|
context.call_cb(Event::MSGS_CHANGED, chat_id as uintptr_t, 0 as uintptr_t);
|
||||||
@@ -1530,8 +1493,6 @@ pub unsafe fn add_contact_to_chat_ex(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_msg_unref(msg);
|
|
||||||
|
|
||||||
success
|
success
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1619,30 +1580,30 @@ pub unsafe fn remove_contact_from_chat(
|
|||||||
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
|
/* we should respect this - whatever we send to the group, it gets discarded anyway! */
|
||||||
if let Ok(contact) = Contact::get_by_id(context, contact_id) {
|
if let Ok(contact) = Contact::get_by_id(context, contact_id) {
|
||||||
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
||||||
(*msg).type_0 = Viewtype::Text;
|
msg.type_0 = Viewtype::Text;
|
||||||
if contact.id == DC_CONTACT_ID_SELF as u32 {
|
if contact.id == DC_CONTACT_ID_SELF as u32 {
|
||||||
set_group_explicitly_left(context, chat.grpid).unwrap();
|
set_group_explicitly_left(context, chat.grpid).unwrap();
|
||||||
(*msg).text = Some(context.stock_system_msg(
|
msg.text = Some(context.stock_system_msg(
|
||||||
StockMessage::MsgGroupLeft,
|
StockMessage::MsgGroupLeft,
|
||||||
"",
|
"",
|
||||||
"",
|
"",
|
||||||
DC_CONTACT_ID_SELF as u32,
|
DC_CONTACT_ID_SELF as u32,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
(*msg).text = Some(context.stock_system_msg(
|
msg.text = Some(context.stock_system_msg(
|
||||||
StockMessage::MsgDelMember,
|
StockMessage::MsgDelMember,
|
||||||
contact.get_addr(),
|
contact.get_addr(),
|
||||||
"",
|
"",
|
||||||
DC_CONTACT_ID_SELF as u32,
|
DC_CONTACT_ID_SELF as u32,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
(*msg).param.set_int(Param::Cmd, 5);
|
msg.param.set_int(Param::Cmd, 5);
|
||||||
(*msg).param.set(Param::Arg, contact.get_addr());
|
msg.param.set(Param::Arg, contact.get_addr());
|
||||||
(*msg).id = send_msg(context, chat_id, msg).unwrap_or_default();
|
msg.id = send_msg(context, chat_id, &mut msg).unwrap_or_default();
|
||||||
context.call_cb(
|
context.call_cb(
|
||||||
Event::MSGS_CHANGED,
|
Event::MSGS_CHANGED,
|
||||||
chat_id as uintptr_t,
|
chat_id as uintptr_t,
|
||||||
(*msg).id as uintptr_t,
|
msg.id as uintptr_t,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1660,8 +1621,6 @@ pub unsafe fn remove_contact_from_chat(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_msg_unref(msg);
|
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
bail!("Failed to remove contact");
|
bail!("Failed to remove contact");
|
||||||
}
|
}
|
||||||
@@ -1728,22 +1687,22 @@ pub unsafe fn set_chat_name(
|
|||||||
.is_ok()
|
.is_ok()
|
||||||
{
|
{
|
||||||
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
||||||
(*msg).type_0 = Viewtype::Text;
|
msg.type_0 = Viewtype::Text;
|
||||||
(*msg).text = Some(context.stock_system_msg(
|
msg.text = Some(context.stock_system_msg(
|
||||||
StockMessage::MsgGrpName,
|
StockMessage::MsgGrpName,
|
||||||
&chat.name,
|
&chat.name,
|
||||||
new_name.as_ref(),
|
new_name.as_ref(),
|
||||||
DC_CONTACT_ID_SELF as u32,
|
DC_CONTACT_ID_SELF as u32,
|
||||||
));
|
));
|
||||||
(*msg).param.set_int(Param::Cmd, 2);
|
msg.param.set_int(Param::Cmd, 2);
|
||||||
if !chat.name.is_empty() {
|
if !chat.name.is_empty() {
|
||||||
(*msg).param.set(Param::Arg, &chat.name);
|
msg.param.set(Param::Arg, &chat.name);
|
||||||
}
|
}
|
||||||
(*msg).id = send_msg(context, chat_id, msg).unwrap_or_default();
|
msg.id = send_msg(context, chat_id, &mut msg).unwrap_or_default();
|
||||||
context.call_cb(
|
context.call_cb(
|
||||||
Event::MSGS_CHANGED,
|
Event::MSGS_CHANGED,
|
||||||
chat_id as uintptr_t,
|
chat_id as uintptr_t,
|
||||||
(*msg).id as uintptr_t,
|
msg.id as uintptr_t,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
context.call_cb(
|
context.call_cb(
|
||||||
@@ -1756,8 +1715,6 @@ pub unsafe fn set_chat_name(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_msg_unref(msg);
|
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
bail!("Failed to set name");
|
bail!("Failed to set name");
|
||||||
}
|
}
|
||||||
@@ -1806,12 +1763,12 @@ pub unsafe fn set_chat_profile_image(
|
|||||||
}
|
}
|
||||||
if chat.update_param().is_ok() {
|
if chat.update_param().is_ok() {
|
||||||
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
if chat.param.get_int(Param::Unpromoted).unwrap_or_default() == 0 {
|
||||||
(*msg).param.set_int(Param::Cmd, 3);
|
msg.param.set_int(Param::Cmd, 3);
|
||||||
if let Some(ref new_image_rel) = new_image_rel {
|
if let Some(ref new_image_rel) = new_image_rel {
|
||||||
(*msg).param.set(Param::Arg, new_image_rel);
|
msg.param.set(Param::Arg, new_image_rel);
|
||||||
}
|
}
|
||||||
(*msg).type_0 = Viewtype::Text;
|
msg.type_0 = Viewtype::Text;
|
||||||
(*msg).text = Some(context.stock_system_msg(
|
msg.text = Some(context.stock_system_msg(
|
||||||
if new_image_rel.is_some() {
|
if new_image_rel.is_some() {
|
||||||
StockMessage::MsgGrpImgChanged
|
StockMessage::MsgGrpImgChanged
|
||||||
} else {
|
} else {
|
||||||
@@ -1821,11 +1778,11 @@ pub unsafe fn set_chat_profile_image(
|
|||||||
"",
|
"",
|
||||||
DC_CONTACT_ID_SELF as u32,
|
DC_CONTACT_ID_SELF as u32,
|
||||||
));
|
));
|
||||||
(*msg).id = send_msg(context, chat_id, msg).unwrap_or_default();
|
msg.id = send_msg(context, chat_id, &mut msg).unwrap_or_default();
|
||||||
context.call_cb(
|
context.call_cb(
|
||||||
Event::MSGS_CHANGED,
|
Event::MSGS_CHANGED,
|
||||||
chat_id as uintptr_t,
|
chat_id as uintptr_t,
|
||||||
(*msg).id as uintptr_t,
|
msg.id as uintptr_t,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
context.call_cb(
|
context.call_cb(
|
||||||
@@ -1838,8 +1795,6 @@ pub unsafe fn set_chat_profile_image(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_msg_unref(msg);
|
|
||||||
|
|
||||||
if !success {
|
if !success {
|
||||||
bail!("Failed to set profile image");
|
bail!("Failed to set profile image");
|
||||||
}
|
}
|
||||||
@@ -1857,7 +1812,6 @@ pub unsafe fn forward_msgs(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let msg = dc_msg_new_untyped(context);
|
|
||||||
let mut created_db_entries = Vec::new();
|
let mut created_db_entries = Vec::new();
|
||||||
let mut curr_timestamp: i64;
|
let mut curr_timestamp: i64;
|
||||||
|
|
||||||
@@ -1887,45 +1841,45 @@ pub unsafe fn forward_msgs(
|
|||||||
|
|
||||||
for id in ids {
|
for id in ids {
|
||||||
let src_msg_id = id;
|
let src_msg_id = id;
|
||||||
if !dc_msg_load_from_db(msg, context, src_msg_id as u32) {
|
let msg = dc_msg_load_from_db(context, src_msg_id as u32);
|
||||||
|
if msg.is_err() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let original_param = (*msg).param.clone();
|
let mut msg = msg.unwrap();
|
||||||
if (*msg).from_id != DC_CONTACT_ID_SELF as u32 {
|
let original_param = msg.param.clone();
|
||||||
(*msg).param.set_int(Param::Forwarded, 1);
|
if msg.from_id != DC_CONTACT_ID_SELF as u32 {
|
||||||
|
msg.param.set_int(Param::Forwarded, 1);
|
||||||
}
|
}
|
||||||
(*msg).param.remove(Param::GuranteeE2ee);
|
msg.param.remove(Param::GuranteeE2ee);
|
||||||
(*msg).param.remove(Param::ForcePlaintext);
|
msg.param.remove(Param::ForcePlaintext);
|
||||||
(*msg).param.remove(Param::Cmd);
|
msg.param.remove(Param::Cmd);
|
||||||
|
|
||||||
let new_msg_id: u32;
|
let new_msg_id: u32;
|
||||||
if (*msg).state == MessageState::OutPreparing {
|
if msg.state == MessageState::OutPreparing {
|
||||||
let fresh9 = curr_timestamp;
|
let fresh9 = curr_timestamp;
|
||||||
curr_timestamp = curr_timestamp + 1;
|
curr_timestamp = curr_timestamp + 1;
|
||||||
new_msg_id = chat
|
new_msg_id = chat
|
||||||
.prepare_msg_raw(context, msg, fresh9)
|
.prepare_msg_raw(context, &mut msg, fresh9)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
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 u32;
|
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);
|
||||||
(*msg).param.set(Param::PrepForwards, new_fwd);
|
msg.param.set(Param::PrepForwards, new_fwd);
|
||||||
} else {
|
} else {
|
||||||
(*msg)
|
msg.param.set(Param::PrepForwards, new_msg_id.to_string());
|
||||||
.param
|
|
||||||
.set(Param::PrepForwards, new_msg_id.to_string());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_msg_save_param_to_disk(msg);
|
dc_msg_save_param_to_disk(&mut msg);
|
||||||
(*msg).param = save_param;
|
msg.param = save_param;
|
||||||
} else {
|
} else {
|
||||||
(*msg).state = MessageState::OutPending;
|
msg.state = MessageState::OutPending;
|
||||||
let fresh10 = curr_timestamp;
|
let fresh10 = curr_timestamp;
|
||||||
curr_timestamp = curr_timestamp + 1;
|
curr_timestamp = curr_timestamp + 1;
|
||||||
new_msg_id = chat
|
new_msg_id = chat
|
||||||
.prepare_msg_raw(context, msg, fresh10)
|
.prepare_msg_raw(context, &mut msg, fresh10)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
job_send_msg(context, new_msg_id);
|
job_send_msg(context, new_msg_id);
|
||||||
}
|
}
|
||||||
@@ -1941,7 +1895,6 @@ pub unsafe fn forward_msgs(
|
|||||||
created_db_entries[i + 1] as uintptr_t,
|
created_db_entries[i + 1] as uintptr_t,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
dc_msg_unref(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_chat_contact_cnt(context: &Context, chat_id: u32) -> libc::c_int {
|
pub fn get_chat_contact_cnt(context: &Context, chat_id: u32) -> libc::c_int {
|
||||||
|
|||||||
@@ -275,29 +275,36 @@ impl<'a> Chatlist<'a> {
|
|||||||
let mut lastcontact = None;
|
let mut lastcontact = None;
|
||||||
|
|
||||||
let lastmsg = if 0 != lastmsg_id {
|
let lastmsg = if 0 != lastmsg_id {
|
||||||
let lastmsg = dc_msg_new_untyped(self.context);
|
if let Ok(lastmsg) = dc_msg_load_from_db(self.context, lastmsg_id) {
|
||||||
dc_msg_load_from_db(lastmsg, self.context, lastmsg_id);
|
if lastmsg.from_id != 1 as libc::c_uint
|
||||||
|
&& (chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup)
|
||||||
|
{
|
||||||
|
lastcontact = Contact::load_from_db(self.context, lastmsg.from_id).ok();
|
||||||
|
}
|
||||||
|
|
||||||
if (*lastmsg).from_id != 1 as libc::c_uint
|
Some(lastmsg)
|
||||||
&& (chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup)
|
} else {
|
||||||
{
|
None
|
||||||
lastcontact = Contact::load_from_db(self.context, (*lastmsg).from_id).ok();
|
|
||||||
}
|
}
|
||||||
lastmsg
|
|
||||||
} else {
|
} else {
|
||||||
std::ptr::null_mut()
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
if chat.id == DC_CHAT_ID_ARCHIVED_LINK as u32 {
|
if chat.id == DC_CHAT_ID_ARCHIVED_LINK as u32 {
|
||||||
ret.text2 = None;
|
ret.text2 = None;
|
||||||
} else if lastmsg.is_null() || (*lastmsg).from_id == DC_CONTACT_ID_UNDEFINED as u32 {
|
} else if lastmsg.is_none()
|
||||||
|
|| lastmsg.as_ref().unwrap().from_id == DC_CONTACT_ID_UNDEFINED as u32
|
||||||
|
{
|
||||||
ret.text2 = Some(self.context.stock_str(StockMessage::NoMessages).to_string());
|
ret.text2 = Some(self.context.stock_str(StockMessage::NoMessages).to_string());
|
||||||
} else {
|
} else {
|
||||||
ret.fill(lastmsg, chat, lastcontact.as_ref(), self.context);
|
ret.fill(
|
||||||
|
&mut lastmsg.unwrap(),
|
||||||
|
chat,
|
||||||
|
lastcontact.as_ref(),
|
||||||
|
self.context,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_msg_unref(lastmsg);
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ pub unsafe fn dc_imex_has_backup(
|
|||||||
|
|
||||||
pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
||||||
let mut setup_file_name: *mut libc::c_char = ptr::null_mut();
|
let mut setup_file_name: *mut libc::c_char = ptr::null_mut();
|
||||||
let mut msg: *mut dc_msg_t = ptr::null_mut();
|
let mut msg: Message;
|
||||||
if dc_alloc_ongoing(context) == 0 {
|
if dc_alloc_ongoing(context) == 0 {
|
||||||
return std::ptr::null_mut();
|
return std::ptr::null_mut();
|
||||||
}
|
}
|
||||||
@@ -140,14 +140,13 @@ pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
|||||||
{
|
{
|
||||||
if let Ok(chat_id) = chat::create_by_contact_id(context, 1) {
|
if let Ok(chat_id) = chat::create_by_contact_id(context, 1) {
|
||||||
msg = dc_msg_new_untyped(context);
|
msg = dc_msg_new_untyped(context);
|
||||||
(*msg).type_0 = Viewtype::File;
|
msg.type_0 = Viewtype::File;
|
||||||
(*msg).param.set(Param::File, as_str(setup_file_name));
|
msg.param.set(Param::File, as_str(setup_file_name));
|
||||||
|
|
||||||
(*msg)
|
msg.param
|
||||||
.param
|
|
||||||
.set(Param::MimeType, "application/autocrypt-setup");
|
.set(Param::MimeType, "application/autocrypt-setup");
|
||||||
(*msg).param.set_int(Param::Cmd, 6);
|
msg.param.set_int(Param::Cmd, 6);
|
||||||
(*msg).param.set_int(Param::ForcePlaintext, 2);
|
msg.param.set_int(Param::ForcePlaintext, 2);
|
||||||
|
|
||||||
if !context
|
if !context
|
||||||
.running_state
|
.running_state
|
||||||
@@ -156,9 +155,7 @@ pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.shall_stop_ongoing
|
.shall_stop_ongoing
|
||||||
{
|
{
|
||||||
if let Ok(msg_id) = chat::send_msg(context, chat_id, msg) {
|
if let Ok(msg_id) = chat::send_msg(context, chat_id, &mut msg) {
|
||||||
dc_msg_unref(msg);
|
|
||||||
msg = ptr::null_mut();
|
|
||||||
info!(context, 0, "Wait for setup message being sent ...",);
|
info!(context, 0, "Wait for setup message being sent ...",);
|
||||||
loop {
|
loop {
|
||||||
if context
|
if context
|
||||||
@@ -171,13 +168,12 @@ pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||||
msg = dc_get_msg(context, msg_id);
|
if let Ok(msg) = dc_get_msg(context, msg_id) {
|
||||||
if 0 != dc_msg_is_sent(msg) {
|
if 0 != dc_msg_is_sent(&msg) {
|
||||||
info!(context, 0, "... setup message sent.",);
|
info!(context, 0, "... setup message sent.",);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dc_msg_unref(msg);
|
|
||||||
msg = 0 as *mut dc_msg_t
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,7 +183,6 @@ pub unsafe fn dc_initiate_key_transfer(context: &Context) -> *mut libc::c_char {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(setup_file_name as *mut libc::c_void);
|
free(setup_file_name as *mut libc::c_void);
|
||||||
dc_msg_unref(msg);
|
|
||||||
dc_free_ongoing(context);
|
dc_free_ongoing(context);
|
||||||
|
|
||||||
setup_code.strdup()
|
setup_code.strdup()
|
||||||
@@ -284,18 +279,17 @@ pub unsafe fn dc_continue_key_transfer(
|
|||||||
setup_code: *const libc::c_char,
|
setup_code: *const libc::c_char,
|
||||||
) -> libc::c_int {
|
) -> libc::c_int {
|
||||||
let mut success: libc::c_int = 0i32;
|
let mut success: libc::c_int = 0i32;
|
||||||
let mut msg: *mut dc_msg_t = ptr::null_mut();
|
|
||||||
let mut filename: *mut libc::c_char = ptr::null_mut();
|
let mut filename: *mut libc::c_char = ptr::null_mut();
|
||||||
let mut filecontent: *mut libc::c_char = ptr::null_mut();
|
let mut filecontent: *mut libc::c_char = ptr::null_mut();
|
||||||
let mut filebytes: size_t = 0i32 as size_t;
|
let mut filebytes: size_t = 0i32 as size_t;
|
||||||
let mut armored_key: *mut libc::c_char = ptr::null_mut();
|
let mut armored_key: *mut libc::c_char = ptr::null_mut();
|
||||||
let mut norm_sc: *mut libc::c_char = ptr::null_mut();
|
let mut norm_sc: *mut libc::c_char = ptr::null_mut();
|
||||||
if !(msg_id <= 9i32 as libc::c_uint || setup_code.is_null()) {
|
if !(msg_id <= 9i32 as libc::c_uint || setup_code.is_null()) {
|
||||||
msg = dc_get_msg(context, msg_id);
|
let msg = dc_get_msg(context, msg_id);
|
||||||
if msg.is_null()
|
if msg.is_err()
|
||||||
|| !dc_msg_is_setupmessage(msg)
|
|| !dc_msg_is_setupmessage(msg.as_ref().unwrap())
|
||||||
|| {
|
|| {
|
||||||
filename = dc_msg_get_file(msg);
|
filename = dc_msg_get_file(msg.as_ref().unwrap());
|
||||||
filename.is_null()
|
filename.is_null()
|
||||||
}
|
}
|
||||||
|| *filename.offset(0isize) as libc::c_int == 0i32
|
|| *filename.offset(0isize) as libc::c_int == 0i32
|
||||||
@@ -331,7 +325,6 @@ pub unsafe fn dc_continue_key_transfer(
|
|||||||
free(armored_key as *mut libc::c_void);
|
free(armored_key as *mut libc::c_void);
|
||||||
free(filecontent as *mut libc::c_void);
|
free(filecontent as *mut libc::c_void);
|
||||||
free(filename as *mut libc::c_void);
|
free(filename as *mut libc::c_void);
|
||||||
dc_msg_unref(msg);
|
|
||||||
free(norm_sc as *mut libc::c_void);
|
free(norm_sc as *mut libc::c_void);
|
||||||
|
|
||||||
success
|
success
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ impl dc_kml_t {
|
|||||||
// location streaming
|
// location streaming
|
||||||
pub unsafe fn dc_send_locations_to_chat(context: &Context, chat_id: uint32_t, seconds: i64) {
|
pub unsafe fn dc_send_locations_to_chat(context: &Context, chat_id: uint32_t, seconds: i64) {
|
||||||
let now = time();
|
let now = time();
|
||||||
let mut msg: *mut dc_msg_t = 0 as *mut dc_msg_t;
|
let mut msg: Message;
|
||||||
let is_sending_locations_before: bool;
|
let is_sending_locations_before: bool;
|
||||||
if !(seconds < 0 || chat_id <= 9i32 as libc::c_uint) {
|
if !(seconds < 0 || chat_id <= 9i32 as libc::c_uint) {
|
||||||
is_sending_locations_before = dc_is_sending_locations_to_chat(context, chat_id);
|
is_sending_locations_before = dc_is_sending_locations_to_chat(context, chat_id);
|
||||||
@@ -91,10 +91,10 @@ pub unsafe fn dc_send_locations_to_chat(context: &Context, chat_id: uint32_t, se
|
|||||||
{
|
{
|
||||||
if 0 != seconds && !is_sending_locations_before {
|
if 0 != seconds && !is_sending_locations_before {
|
||||||
msg = dc_msg_new(context, Viewtype::Text);
|
msg = dc_msg_new(context, Viewtype::Text);
|
||||||
(*msg).text =
|
msg.text =
|
||||||
Some(context.stock_system_msg(StockMessage::MsgLocationEnabled, "", "", 0));
|
Some(context.stock_system_msg(StockMessage::MsgLocationEnabled, "", "", 0));
|
||||||
(*msg).param.set_int(Param::Cmd, 8);
|
msg.param.set_int(Param::Cmd, 8);
|
||||||
chat::send_msg(context, chat_id, msg).unwrap();
|
chat::send_msg(context, chat_id, &mut msg).unwrap();
|
||||||
} else if 0 == seconds && is_sending_locations_before {
|
} else if 0 == seconds && is_sending_locations_before {
|
||||||
let stock_str =
|
let stock_str =
|
||||||
context.stock_system_msg(StockMessage::MsgLocationDisabled, "", "", 0);
|
context.stock_system_msg(StockMessage::MsgLocationDisabled, "", "", 0);
|
||||||
@@ -117,7 +117,6 @@ pub unsafe fn dc_send_locations_to_chat(context: &Context, chat_id: uint32_t, se
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dc_msg_unref(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@@ -680,11 +679,10 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &Context, _job: &Jo
|
|||||||
// (might not be 100%, however, as positions are sent combined later
|
// (might not be 100%, however, as positions are sent combined later
|
||||||
// and dc_set_location() is typically called periodically, this is ok)
|
// and dc_set_location() is typically called periodically, this is ok)
|
||||||
let mut msg = dc_msg_new(context, Viewtype::Text);
|
let mut msg = dc_msg_new(context, Viewtype::Text);
|
||||||
(*msg).hidden = 1;
|
msg.hidden = true;
|
||||||
(*msg).param.set_int(Param::Cmd, 9);
|
msg.param.set_int(Param::Cmd, 9);
|
||||||
// TODO: handle cleanup on error
|
// TODO: handle cleanup on error
|
||||||
chat::send_msg(context, chat_id as u32, msg).unwrap();
|
chat::send_msg(context, chat_id as u32, &mut msg).unwrap();
|
||||||
dc_msg_unref(msg);
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -18,29 +18,27 @@ pub unsafe fn dc_do_heuristics_moves(context: &Context, folder: &str, msg_id: u3
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let msg = dc_msg_new_load(context, msg_id);
|
if let Ok(msg) = dc_msg_new_load(context, msg_id) {
|
||||||
if dc_msg_is_setupmessage(msg) {
|
if dc_msg_is_setupmessage(&msg) {
|
||||||
// do not move setup messages;
|
// do not move setup messages;
|
||||||
// there may be a non-delta device that wants to handle it
|
// there may be a non-delta device that wants to handle it
|
||||||
dc_msg_unref(msg);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if dc_is_mvbox(context, folder) {
|
if dc_is_mvbox(context, folder) {
|
||||||
dc_update_msg_move_state(context, (*msg).rfc724_mid, MoveState::Stay);
|
dc_update_msg_move_state(context, msg.rfc724_mid, MoveState::Stay);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 = dc message, 2 = reply to dc message
|
// 1 = dc message, 2 = reply to dc message
|
||||||
if 0 != (*msg).is_dc_message {
|
if 0 != msg.is_dc_message {
|
||||||
job_add(
|
job_add(
|
||||||
context,
|
context,
|
||||||
Action::MoveMsg,
|
Action::MoveMsg,
|
||||||
(*msg).id as libc::c_int,
|
msg.id as libc::c_int,
|
||||||
Params::new(),
|
Params::new(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
dc_update_msg_move_state(context, (*msg).rfc724_mid, MoveState::Moving);
|
dc_update_msg_move_state(context, msg.rfc724_mid, MoveState::Moving);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_msg_unref(msg);
|
|
||||||
}
|
}
|
||||||
|
|||||||
650
src/dc_msg.rs
650
src/dc_msg.rs
File diff suppressed because it is too large
Load Diff
@@ -293,38 +293,37 @@ unsafe fn send_handshake_msg(
|
|||||||
fingerprint: *const libc::c_char,
|
fingerprint: *const libc::c_char,
|
||||||
grpid: impl AsRef<str>,
|
grpid: impl AsRef<str>,
|
||||||
) {
|
) {
|
||||||
let mut msg: *mut dc_msg_t = dc_msg_new_untyped(context);
|
let mut msg = dc_msg_new_untyped(context);
|
||||||
(*msg).type_0 = Viewtype::Text;
|
msg.type_0 = Viewtype::Text;
|
||||||
(*msg).text = Some(format!("Secure-Join: {}", to_string(step)));
|
msg.text = Some(format!("Secure-Join: {}", to_string(step)));
|
||||||
(*msg).hidden = 1;
|
msg.hidden = true;
|
||||||
(*msg).param.set_int(Param::Cmd, 7);
|
msg.param.set_int(Param::Cmd, 7);
|
||||||
if step.is_null() {
|
if step.is_null() {
|
||||||
(*msg).param.remove(Param::Arg);
|
msg.param.remove(Param::Arg);
|
||||||
} else {
|
} else {
|
||||||
(*msg).param.set(Param::Arg, as_str(step));
|
msg.param.set(Param::Arg, as_str(step));
|
||||||
}
|
}
|
||||||
if !param2.as_ref().is_empty() {
|
if !param2.as_ref().is_empty() {
|
||||||
(*msg).param.set(Param::Arg2, param2);
|
msg.param.set(Param::Arg2, param2);
|
||||||
}
|
}
|
||||||
if !fingerprint.is_null() {
|
if !fingerprint.is_null() {
|
||||||
(*msg).param.set(Param::Arg3, as_str(fingerprint));
|
msg.param.set(Param::Arg3, as_str(fingerprint));
|
||||||
}
|
}
|
||||||
if !grpid.as_ref().is_empty() {
|
if !grpid.as_ref().is_empty() {
|
||||||
(*msg).param.set(Param::Arg4, grpid.as_ref());
|
msg.param.set(Param::Arg4, grpid.as_ref());
|
||||||
}
|
}
|
||||||
if strcmp(step, b"vg-request\x00" as *const u8 as *const libc::c_char) == 0i32
|
if strcmp(step, b"vg-request\x00" as *const u8 as *const libc::c_char) == 0i32
|
||||||
|| strcmp(step, b"vc-request\x00" as *const u8 as *const libc::c_char) == 0i32
|
|| strcmp(step, b"vc-request\x00" as *const u8 as *const libc::c_char) == 0i32
|
||||||
{
|
{
|
||||||
(*msg).param.set_int(
|
msg.param.set_int(
|
||||||
Param::ForcePlaintext,
|
Param::ForcePlaintext,
|
||||||
ForcePlaintext::AddAutocryptHeader as i32,
|
ForcePlaintext::AddAutocryptHeader as i32,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
(*msg).param.set_int(Param::GuranteeE2ee, 1);
|
msg.param.set_int(Param::GuranteeE2ee, 1);
|
||||||
}
|
}
|
||||||
// TODO. handle cleanup on error
|
// TODO. handle cleanup on error
|
||||||
chat::send_msg(context, contact_chat_id, msg).unwrap();
|
chat::send_msg(context, contact_chat_id, &mut msg).unwrap();
|
||||||
dc_msg_unref(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn chat_id_2_contact_id(context: &Context, contact_chat_id: uint32_t) -> uint32_t {
|
unsafe fn chat_id_2_contact_id(context: &Context, contact_chat_id: uint32_t) -> uint32_t {
|
||||||
|
|||||||
214
src/job.rs
214
src/job.rs
@@ -226,7 +226,6 @@ impl Job {
|
|||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn do_DC_JOB_MOVE_MSG(&mut self, context: &Context) {
|
fn do_DC_JOB_MOVE_MSG(&mut self, context: &Context) {
|
||||||
let ok_to_continue;
|
let ok_to_continue;
|
||||||
let msg = unsafe { dc_msg_new_untyped(context) };
|
|
||||||
let mut dest_uid = 0;
|
let mut dest_uid = 0;
|
||||||
|
|
||||||
let inbox = context.inbox.read().unwrap();
|
let inbox = context.inbox.read().unwrap();
|
||||||
@@ -243,7 +242,7 @@ impl Job {
|
|||||||
ok_to_continue = true;
|
ok_to_continue = true;
|
||||||
}
|
}
|
||||||
if ok_to_continue {
|
if ok_to_continue {
|
||||||
if dc_msg_load_from_db(msg, context, self.foreign_id) {
|
if let Ok(msg) = dc_msg_load_from_db(context, self.foreign_id) {
|
||||||
if context
|
if context
|
||||||
.sql
|
.sql
|
||||||
.get_config_int(context, "folders_configured")
|
.get_config_int(context, "folders_configured")
|
||||||
@@ -254,8 +253,6 @@ impl Job {
|
|||||||
}
|
}
|
||||||
let dest_folder = context.sql.get_config(context, "configured_mvbox_folder");
|
let dest_folder = context.sql.get_config(context, "configured_mvbox_folder");
|
||||||
|
|
||||||
let msg = unsafe { &mut *msg };
|
|
||||||
|
|
||||||
if let Some(dest_folder) = dest_folder {
|
if let Some(dest_folder) = dest_folder {
|
||||||
let server_folder = msg.server_folder.as_ref().unwrap();
|
let server_folder = msg.server_folder.as_ref().unwrap();
|
||||||
|
|
||||||
@@ -278,71 +275,65 @@ impl Job {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe { dc_msg_unref(msg) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn do_DC_JOB_DELETE_MSG_ON_IMAP(&mut self, context: &Context) {
|
fn do_DC_JOB_DELETE_MSG_ON_IMAP(&mut self, context: &Context) {
|
||||||
let mut delete_from_server = 1;
|
let mut delete_from_server = 1;
|
||||||
let msg = unsafe { dc_msg_new_untyped(context) };
|
|
||||||
let inbox = context.inbox.read().unwrap();
|
let inbox = context.inbox.read().unwrap();
|
||||||
|
|
||||||
if !(!dc_msg_load_from_db(msg, context, self.foreign_id)
|
if let Ok(mut msg) = dc_msg_load_from_db(context, self.foreign_id) {
|
||||||
|| unsafe { (*msg).rfc724_mid.is_null() }
|
if !(msg.rfc724_mid.is_null()
|
||||||
|| unsafe { *(*msg).rfc724_mid.offset(0isize) as libc::c_int == 0 })
|
|| unsafe { *msg.rfc724_mid.offset(0isize) as libc::c_int == 0 })
|
||||||
{
|
{
|
||||||
let ok_to_continue1;
|
let ok_to_continue1;
|
||||||
/* eg. device messages have no Message-ID */
|
/* eg. device messages have no Message-ID */
|
||||||
if dc_rfc724_mid_cnt(context, unsafe { (*msg).rfc724_mid }) != 1 {
|
if dc_rfc724_mid_cnt(context, msg.rfc724_mid) != 1 {
|
||||||
info!(
|
info!(
|
||||||
context,
|
context,
|
||||||
0, "The message is deleted from the server when all parts are deleted.",
|
0, "The message is deleted from the server when all parts are deleted.",
|
||||||
);
|
);
|
||||||
delete_from_server = 0i32
|
delete_from_server = 0i32
|
||||||
}
|
}
|
||||||
/* if this is the last existing part of the message, we delete the message from the server */
|
/* if this is the last existing part of the message, we delete the message from the server */
|
||||||
if 0 != delete_from_server {
|
if 0 != delete_from_server {
|
||||||
let ok_to_continue;
|
let ok_to_continue;
|
||||||
if !inbox.is_connected() {
|
|
||||||
connect_to_inbox(context, &inbox);
|
|
||||||
if !inbox.is_connected() {
|
if !inbox.is_connected() {
|
||||||
self.try_again_later(3i32, None);
|
connect_to_inbox(context, &inbox);
|
||||||
ok_to_continue = false;
|
if !inbox.is_connected() {
|
||||||
|
self.try_again_later(3i32, None);
|
||||||
|
ok_to_continue = false;
|
||||||
|
} else {
|
||||||
|
ok_to_continue = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ok_to_continue = true;
|
ok_to_continue = true;
|
||||||
}
|
}
|
||||||
} else {
|
if ok_to_continue {
|
||||||
ok_to_continue = true;
|
let mid = unsafe { CStr::from_ptr(msg.rfc724_mid).to_str().unwrap() };
|
||||||
}
|
let server_folder = msg.server_folder.as_ref().unwrap();
|
||||||
if ok_to_continue {
|
if 0 == inbox.delete_msg(context, mid, server_folder, &mut msg.server_uid) {
|
||||||
let mid = unsafe { CStr::from_ptr((*msg).rfc724_mid).to_str().unwrap() };
|
self.try_again_later(-1i32, None);
|
||||||
let server_folder = unsafe { (*msg).server_folder.as_ref().unwrap() };
|
ok_to_continue1 = false;
|
||||||
if 0 == inbox.delete_msg(context, mid, server_folder, unsafe {
|
} else {
|
||||||
&mut (*msg).server_uid
|
ok_to_continue1 = true;
|
||||||
}) {
|
}
|
||||||
self.try_again_later(-1i32, None);
|
|
||||||
ok_to_continue1 = false;
|
|
||||||
} else {
|
} else {
|
||||||
ok_to_continue1 = true;
|
ok_to_continue1 = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ok_to_continue1 = false;
|
ok_to_continue1 = true;
|
||||||
|
}
|
||||||
|
if ok_to_continue1 {
|
||||||
|
dc_delete_msg_from_db(context, msg.id);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ok_to_continue1 = true;
|
|
||||||
}
|
|
||||||
if ok_to_continue1 {
|
|
||||||
unsafe { dc_delete_msg_from_db(context, (*msg).id) };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsafe { dc_msg_unref(msg) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn do_DC_JOB_MARKSEEN_MSG_ON_IMAP(&mut self, context: &Context) {
|
fn do_DC_JOB_MARKSEEN_MSG_ON_IMAP(&mut self, context: &Context) {
|
||||||
let ok_to_continue;
|
let ok_to_continue;
|
||||||
let msg = unsafe { dc_msg_new_untyped(context) };
|
|
||||||
let inbox = context.inbox.read().unwrap();
|
let inbox = context.inbox.read().unwrap();
|
||||||
|
|
||||||
if !inbox.is_connected() {
|
if !inbox.is_connected() {
|
||||||
@@ -357,32 +348,29 @@ impl Job {
|
|||||||
ok_to_continue = true;
|
ok_to_continue = true;
|
||||||
}
|
}
|
||||||
if ok_to_continue {
|
if ok_to_continue {
|
||||||
if dc_msg_load_from_db(msg, context, self.foreign_id) {
|
if let Ok(msg) = dc_msg_load_from_db(context, self.foreign_id) {
|
||||||
let server_folder = unsafe { (*msg).server_folder.as_ref().unwrap() };
|
let server_folder = msg.server_folder.as_ref().unwrap();
|
||||||
match inbox.set_seen(context, server_folder, unsafe { (*msg).server_uid })
|
match inbox.set_seen(context, server_folder, msg.server_uid) as libc::c_uint {
|
||||||
as libc::c_uint
|
|
||||||
{
|
|
||||||
0 => {}
|
0 => {}
|
||||||
1 => {
|
1 => {
|
||||||
self.try_again_later(3i32, None);
|
self.try_again_later(3i32, None);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if 0 != unsafe { (*msg).param.get_int(Param::WantsMdn).unwrap_or_default() }
|
if 0 != msg.param.get_int(Param::WantsMdn).unwrap_or_default()
|
||||||
&& 0 != context
|
&& 0 != context
|
||||||
.sql
|
.sql
|
||||||
.get_config_int(context, "mdns_enabled")
|
.get_config_int(context, "mdns_enabled")
|
||||||
.unwrap_or_else(|| 1)
|
.unwrap_or_else(|| 1)
|
||||||
{
|
{
|
||||||
let folder = unsafe { (*msg).server_folder.as_ref().unwrap() };
|
let folder = msg.server_folder.as_ref().unwrap();
|
||||||
|
|
||||||
match inbox.set_mdnsent(context, folder, unsafe { (*msg).server_uid })
|
match inbox.set_mdnsent(context, folder, msg.server_uid) as libc::c_uint
|
||||||
as libc::c_uint
|
|
||||||
{
|
{
|
||||||
1 => {
|
1 => {
|
||||||
self.try_again_later(3i32, None);
|
self.try_again_later(3i32, None);
|
||||||
}
|
}
|
||||||
3 => {
|
3 => {
|
||||||
send_mdn(context, unsafe { (*msg).id });
|
send_mdn(context, msg.id);
|
||||||
}
|
}
|
||||||
0 | 2 | _ => {}
|
0 | 2 | _ => {}
|
||||||
}
|
}
|
||||||
@@ -391,7 +379,6 @@ impl Job {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsafe { dc_msg_unref(msg) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
@@ -674,55 +661,38 @@ pub fn job_action_exists(context: &Context, action: Action) -> bool {
|
|||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub unsafe fn job_send_msg(context: &Context, msg_id: uint32_t) -> libc::c_int {
|
pub unsafe fn job_send_msg(context: &Context, msg_id: uint32_t) -> libc::c_int {
|
||||||
let mut success = 0;
|
let mut success = 0;
|
||||||
let mut mimefactory = dc_mimefactory_t {
|
|
||||||
from_addr: ptr::null_mut(),
|
|
||||||
from_displayname: ptr::null_mut(),
|
|
||||||
selfstatus: ptr::null_mut(),
|
|
||||||
recipients_names: ptr::null_mut(),
|
|
||||||
recipients_addr: ptr::null_mut(),
|
|
||||||
timestamp: 0,
|
|
||||||
rfc724_mid: ptr::null_mut(),
|
|
||||||
loaded: DC_MF_NOTHING_LOADED,
|
|
||||||
msg: ptr::null_mut(),
|
|
||||||
chat: None,
|
|
||||||
increation: 0,
|
|
||||||
in_reply_to: ptr::null_mut(),
|
|
||||||
references: ptr::null_mut(),
|
|
||||||
req_mdn: 0,
|
|
||||||
out: ptr::null_mut(),
|
|
||||||
out_encrypted: 0,
|
|
||||||
out_gossiped: 0,
|
|
||||||
out_last_added_location_id: 0,
|
|
||||||
error: ptr::null_mut(),
|
|
||||||
context,
|
|
||||||
};
|
|
||||||
|
|
||||||
/* load message data */
|
/* load message data */
|
||||||
if 0 == dc_mimefactory_load_msg(&mut mimefactory, msg_id) || mimefactory.from_addr.is_null() {
|
let mimefactory = dc_mimefactory_load_msg(context, msg_id);
|
||||||
|
if mimefactory.is_err() || mimefactory.as_ref().unwrap().from_addr.is_null() {
|
||||||
warn!(
|
warn!(
|
||||||
context,
|
context,
|
||||||
0, "Cannot load data to send, maybe the message is deleted in between.",
|
0, "Cannot load data to send, maybe the message is deleted in between.",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
let mut mimefactory = mimefactory.unwrap();
|
||||||
// no redo, no IMAP. moreover, as the data does not exist, there is no need in calling dc_set_msg_failed()
|
// no redo, no IMAP. moreover, as the data does not exist, there is no need in calling dc_set_msg_failed()
|
||||||
if chat::msgtype_has_file((*mimefactory.msg).type_0) {
|
if chat::msgtype_has_file(mimefactory.msg.type_0) {
|
||||||
if let Some(pathNfilename) = (*mimefactory.msg).param.get(Param::File) {
|
let file_param = mimefactory
|
||||||
if ((*mimefactory.msg).type_0 == Viewtype::Image
|
.msg
|
||||||
|| (*mimefactory.msg).type_0 == Viewtype::Gif)
|
.param
|
||||||
&& !(*mimefactory.msg).param.exists(Param::Width)
|
.get(Param::File)
|
||||||
|
.map(|s| s.to_string());
|
||||||
|
if let Some(pathNfilename) = file_param {
|
||||||
|
if (mimefactory.msg.type_0 == Viewtype::Image
|
||||||
|
|| mimefactory.msg.type_0 == Viewtype::Gif)
|
||||||
|
&& !mimefactory.msg.param.exists(Param::Width)
|
||||||
{
|
{
|
||||||
(*mimefactory.msg).param.set_int(Param::Width, 0);
|
mimefactory.msg.param.set_int(Param::Width, 0);
|
||||||
(*mimefactory.msg).param.set_int(Param::Height, 0);
|
mimefactory.msg.param.set_int(Param::Height, 0);
|
||||||
|
|
||||||
if let Some(buf) = dc_read_file_safe(context, pathNfilename) {
|
if let Some(buf) = dc_read_file_safe(context, pathNfilename) {
|
||||||
if let Ok((width, height)) = dc_get_filemeta(&buf) {
|
if let Ok((width, height)) = dc_get_filemeta(&buf) {
|
||||||
(*mimefactory.msg).param.set_int(Param::Width, width as i32);
|
mimefactory.msg.param.set_int(Param::Width, width as i32);
|
||||||
(*mimefactory.msg)
|
mimefactory.msg.param.set_int(Param::Height, height as i32);
|
||||||
.param
|
|
||||||
.set_int(Param::Height, height as i32);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dc_msg_save_param_to_disk(mimefactory.msg);
|
dc_msg_save_param_to_disk(&mut mimefactory.msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -730,7 +700,8 @@ pub unsafe fn job_send_msg(context: &Context, msg_id: uint32_t) -> libc::c_int {
|
|||||||
if 0 == dc_mimefactory_render(&mut mimefactory) {
|
if 0 == dc_mimefactory_render(&mut mimefactory) {
|
||||||
dc_set_msg_failed(context, msg_id, as_opt_str(mimefactory.error));
|
dc_set_msg_failed(context, msg_id, as_opt_str(mimefactory.error));
|
||||||
} else if 0
|
} else if 0
|
||||||
!= (*mimefactory.msg)
|
!= mimefactory
|
||||||
|
.msg
|
||||||
.param
|
.param
|
||||||
.get_int(Param::GuranteeE2ee)
|
.get_int(Param::GuranteeE2ee)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@@ -741,7 +712,7 @@ pub unsafe fn job_send_msg(context: &Context, msg_id: uint32_t) -> libc::c_int {
|
|||||||
0,
|
0,
|
||||||
"e2e encryption unavailable {} - {:?}",
|
"e2e encryption unavailable {} - {:?}",
|
||||||
msg_id,
|
msg_id,
|
||||||
(*mimefactory.msg).param.get_int(Param::GuranteeE2ee),
|
mimefactory.msg.param.get_int(Param::GuranteeE2ee),
|
||||||
);
|
);
|
||||||
dc_set_msg_failed(
|
dc_set_msg_failed(
|
||||||
context,
|
context,
|
||||||
@@ -765,32 +736,32 @@ pub unsafe fn job_send_msg(context: &Context, msg_id: uint32_t) -> libc::c_int {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if 0 != mimefactory.out_gossiped {
|
if 0 != mimefactory.out_gossiped {
|
||||||
chat::set_gossiped_timestamp(context, (*mimefactory.msg).chat_id, time());
|
chat::set_gossiped_timestamp(context, mimefactory.msg.chat_id, time());
|
||||||
}
|
}
|
||||||
if 0 != mimefactory.out_last_added_location_id {
|
if 0 != mimefactory.out_last_added_location_id {
|
||||||
dc_set_kml_sent_timestamp(context, (*mimefactory.msg).chat_id, time());
|
dc_set_kml_sent_timestamp(context, mimefactory.msg.chat_id, time());
|
||||||
if 0 == (*mimefactory.msg).hidden {
|
if !mimefactory.msg.hidden {
|
||||||
dc_set_msg_location_id(
|
dc_set_msg_location_id(
|
||||||
context,
|
context,
|
||||||
(*mimefactory.msg).id,
|
mimefactory.msg.id,
|
||||||
mimefactory.out_last_added_location_id,
|
mimefactory.out_last_added_location_id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if 0 != mimefactory.out_encrypted
|
if 0 != mimefactory.out_encrypted
|
||||||
&& (*mimefactory.msg)
|
&& mimefactory
|
||||||
|
.msg
|
||||||
.param
|
.param
|
||||||
.get_int(Param::GuranteeE2ee)
|
.get_int(Param::GuranteeE2ee)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
== 0
|
== 0
|
||||||
{
|
{
|
||||||
(*mimefactory.msg).param.set_int(Param::GuranteeE2ee, 1);
|
mimefactory.msg.param.set_int(Param::GuranteeE2ee, 1);
|
||||||
dc_msg_save_param_to_disk(mimefactory.msg);
|
dc_msg_save_param_to_disk(&mut mimefactory.msg);
|
||||||
}
|
}
|
||||||
success = add_smtp_job(context, Action::SendMsgToSmtp, &mut mimefactory);
|
success = add_smtp_job(context, Action::SendMsgToSmtp, &mut mimefactory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dc_mimefactory_empty(&mut mimefactory);
|
|
||||||
|
|
||||||
success
|
success
|
||||||
}
|
}
|
||||||
@@ -979,9 +950,7 @@ fn job_perform(context: &Context, thread: Thread, probe_network: bool) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if job.action == Action::SendMsgToSmtp {
|
if job.action == Action::SendMsgToSmtp {
|
||||||
unsafe {
|
dc_set_msg_failed(context, job.foreign_id, job.pending_error.as_ref());
|
||||||
dc_set_msg_failed(context, job.foreign_id, job.pending_error.as_ref())
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
job.delete(context);
|
job.delete(context);
|
||||||
}
|
}
|
||||||
@@ -1034,33 +1003,10 @@ fn connect_to_inbox(context: &Context, inbox: &Imap) -> libc::c_int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn send_mdn(context: &Context, msg_id: uint32_t) {
|
fn send_mdn(context: &Context, msg_id: uint32_t) {
|
||||||
let mut mimefactory = dc_mimefactory_t {
|
if let Ok(mut mimefactory) = unsafe { dc_mimefactory_load_mdn(context, msg_id) } {
|
||||||
from_addr: ptr::null_mut(),
|
if 0 != unsafe { dc_mimefactory_render(&mut mimefactory) } {
|
||||||
from_displayname: ptr::null_mut(),
|
add_smtp_job(context, Action::SendMdn, &mut mimefactory);
|
||||||
selfstatus: ptr::null_mut(),
|
}
|
||||||
recipients_names: ptr::null_mut(),
|
|
||||||
recipients_addr: ptr::null_mut(),
|
|
||||||
timestamp: 0,
|
|
||||||
rfc724_mid: ptr::null_mut(),
|
|
||||||
loaded: DC_MF_NOTHING_LOADED,
|
|
||||||
msg: ptr::null_mut(),
|
|
||||||
chat: None,
|
|
||||||
increation: 0,
|
|
||||||
in_reply_to: ptr::null_mut(),
|
|
||||||
references: ptr::null_mut(),
|
|
||||||
req_mdn: 0,
|
|
||||||
out: ptr::null_mut(),
|
|
||||||
out_encrypted: 0,
|
|
||||||
out_gossiped: 0,
|
|
||||||
out_last_added_location_id: 0,
|
|
||||||
error: ptr::null_mut(),
|
|
||||||
context,
|
|
||||||
};
|
|
||||||
|
|
||||||
if !(0 == unsafe { dc_mimefactory_load_mdn(&mut mimefactory, msg_id) }
|
|
||||||
|| 0 == unsafe { dc_mimefactory_render(&mut mimefactory) })
|
|
||||||
{
|
|
||||||
add_smtp_job(context, Action::SendMdn, &mut mimefactory);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1116,7 +1062,7 @@ fn add_smtp_job(context: &Context, action: Action, mimefactory: &dc_mimefactory_
|
|||||||
(if mimefactory.loaded as libc::c_uint
|
(if mimefactory.loaded as libc::c_uint
|
||||||
== DC_MF_MSG_LOADED as libc::c_int as libc::c_uint
|
== DC_MF_MSG_LOADED as libc::c_int as libc::c_uint
|
||||||
{
|
{
|
||||||
unsafe { (*mimefactory.msg).id }
|
mimefactory.msg.id
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
}) as libc::c_int,
|
}) as libc::c_int,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ extern crate strum_macros;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod log;
|
mod log;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod error;
|
pub mod error;
|
||||||
|
|
||||||
mod aheader;
|
mod aheader;
|
||||||
pub mod chat;
|
pub mod chat;
|
||||||
|
|||||||
Reference in New Issue
Block a user