mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 02:46:29 +03:00
Replace dc_array_t with Vec in context.rs
This commit is contained in:
committed by
holger krekel
parent
799d362654
commit
6b2fe03d08
@@ -425,7 +425,7 @@ pub unsafe extern "C" fn dc_get_chat_msgs(
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
chat::get_chat_msgs(context, chat_id, flags, marker1before)
|
||||
dc_array_t::from(chat::get_chat_msgs(context, chat_id, flags, marker1before)).into_raw()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -454,7 +454,7 @@ pub unsafe extern "C" fn dc_get_fresh_msgs(
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
context::dc_get_fresh_msgs(context)
|
||||
dc_array_t::from(context::dc_get_fresh_msgs(context)).into_raw()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -571,7 +571,7 @@ pub unsafe extern "C" fn dc_search_msgs(
|
||||
assert!(!query.is_null());
|
||||
let context = &*context;
|
||||
|
||||
context::dc_search_msgs(context, chat_id, query)
|
||||
dc_array_t::from(context::dc_search_msgs(context, chat_id, query)).into_raw()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
@@ -261,11 +261,9 @@ unsafe fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: *mut dc_msg_t
|
||||
free(msgtext as *mut libc::c_void);
|
||||
}
|
||||
|
||||
unsafe fn log_msglist(context: &Context, msglist: *mut dc_array_t) {
|
||||
let cnt = dc_array_get_cnt(msglist) as usize;
|
||||
unsafe fn log_msglist(context: &Context, msglist: &Vec<u32>) {
|
||||
let mut lines_out = 0;
|
||||
for i in 0..cnt {
|
||||
let msg_id = dc_array_get_id(msglist, i as size_t);
|
||||
for &msg_id in msglist {
|
||||
if msg_id == 9 as libc::c_uint {
|
||||
info!(
|
||||
context,
|
||||
@@ -274,7 +272,7 @@ unsafe fn log_msglist(context: &Context, msglist: *mut dc_array_t) {
|
||||
);
|
||||
|
||||
lines_out += 1
|
||||
} else if msg_id > 0 as libc::c_uint {
|
||||
} else if msg_id > 0 {
|
||||
if lines_out == 0 {
|
||||
info!(
|
||||
context, 0,
|
||||
@@ -694,10 +692,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
||||
""
|
||||
},
|
||||
);
|
||||
if !msglist.is_null() {
|
||||
log_msglist(context, msglist);
|
||||
dc_array_unref(msglist);
|
||||
}
|
||||
log_msglist(context, &msglist);
|
||||
let draft = chat::get_draft(context, sel_chat.get_id());
|
||||
if !draft.is_null() {
|
||||
log_msg(context, "Draft", draft);
|
||||
@@ -892,13 +887,10 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
||||
0 as libc::c_uint
|
||||
};
|
||||
|
||||
let msglist_0 = dc_search_msgs(context, chat, arg1_c);
|
||||
let msglist = dc_search_msgs(context, chat, arg1_c);
|
||||
|
||||
if !msglist_0.is_null() {
|
||||
log_msglist(context, msglist_0);
|
||||
println!("{} messages.", dc_array_get_cnt(msglist_0));
|
||||
dc_array_unref(msglist_0);
|
||||
}
|
||||
log_msglist(context, &msglist);
|
||||
println!("{} messages.", msglist.len());
|
||||
}
|
||||
"draft" => {
|
||||
ensure!(sel_chat.is_some(), "No chat selected.");
|
||||
@@ -963,11 +955,9 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
||||
}
|
||||
"listfresh" => {
|
||||
let msglist = dc_get_fresh_msgs(context);
|
||||
ensure!(!msglist.is_null(), "Failed to retrieve messages");
|
||||
|
||||
log_msglist(context, msglist);
|
||||
print!("{} fresh messages.", dc_array_get_cnt(msglist));
|
||||
dc_array_unref(msglist);
|
||||
log_msglist(context, &msglist);
|
||||
print!("{} fresh messages.", msglist.len());
|
||||
}
|
||||
"forward" => {
|
||||
ensure!(
|
||||
|
||||
11
src/chat.rs
11
src/chat.rs
@@ -1049,12 +1049,7 @@ pub unsafe fn get_draft(context: &Context, chat_id: u32) -> *mut dc_msg_t {
|
||||
draft_msg
|
||||
}
|
||||
|
||||
pub fn get_chat_msgs(
|
||||
context: &Context,
|
||||
chat_id: u32,
|
||||
flags: u32,
|
||||
marker1before: u32,
|
||||
) -> *mut dc_array_t {
|
||||
pub fn get_chat_msgs(context: &Context, chat_id: u32, flags: u32, marker1before: u32) -> Vec<u32> {
|
||||
let mut ret = Vec::new();
|
||||
|
||||
let mut last_day = 0;
|
||||
@@ -1123,9 +1118,9 @@ pub fn get_chat_msgs(
|
||||
};
|
||||
|
||||
if success.is_ok() {
|
||||
dc_array_t::from(ret).into_raw()
|
||||
ret
|
||||
} else {
|
||||
0 as *mut dc_array_t
|
||||
Vec::new()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ use std::sync::{Arc, Condvar, Mutex, RwLock};
|
||||
use crate::chat::*;
|
||||
use crate::constants::*;
|
||||
use crate::contact::*;
|
||||
use crate::dc_array::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_jobthread::*;
|
||||
use crate::dc_loginparam::*;
|
||||
@@ -484,7 +483,7 @@ pub unsafe fn dc_get_version_str() -> *mut libc::c_char {
|
||||
(&*DC_VERSION_STR).strdup()
|
||||
}
|
||||
|
||||
pub fn dc_get_fresh_msgs(context: &Context) -> *mut dc_array_t {
|
||||
pub fn dc_get_fresh_msgs(context: &Context) -> Vec<u32> {
|
||||
let show_deaddrop = 0;
|
||||
|
||||
context
|
||||
@@ -504,7 +503,7 @@ pub fn dc_get_fresh_msgs(context: &Context) -> *mut dc_array_t {
|
||||
let id: u32 = row?;
|
||||
ret.push(id);
|
||||
}
|
||||
Ok(dc_array_t::from(ret).into_raw())
|
||||
Ok(ret)
|
||||
},
|
||||
)
|
||||
.unwrap()
|
||||
@@ -515,14 +514,14 @@ pub fn dc_search_msgs(
|
||||
context: &Context,
|
||||
chat_id: uint32_t,
|
||||
query: *const libc::c_char,
|
||||
) -> *mut dc_array_t {
|
||||
) -> Vec<u32> {
|
||||
if query.is_null() {
|
||||
return std::ptr::null_mut();
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let real_query = to_string(query).trim().to_string();
|
||||
if real_query.is_empty() {
|
||||
return std::ptr::null_mut();
|
||||
return Vec::new();
|
||||
}
|
||||
let strLikeInText = format!("%{}%", &real_query);
|
||||
let strLikeBeg = format!("{}%", &real_query);
|
||||
@@ -538,28 +537,21 @@ pub fn dc_search_msgs(
|
||||
AND ct.blocked=0 AND (m.txt LIKE ? OR ct.name LIKE ?) ORDER BY m.timestamp DESC,m.id DESC;"
|
||||
};
|
||||
|
||||
let mut ret = Vec::new();
|
||||
|
||||
let success = context
|
||||
context
|
||||
.sql
|
||||
.query_map(
|
||||
query,
|
||||
params![chat_id as libc::c_int, &strLikeInText, &strLikeBeg],
|
||||
|row| row.get::<_, i32>(0),
|
||||
|rows| {
|
||||
let mut ret = Vec::new();
|
||||
for id in rows {
|
||||
ret.push(id? as u32);
|
||||
}
|
||||
Ok(())
|
||||
Ok(ret)
|
||||
},
|
||||
)
|
||||
.is_ok();
|
||||
|
||||
if success {
|
||||
return dc_array_t::from(ret).into_raw();
|
||||
}
|
||||
|
||||
std::ptr::null_mut()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn dc_is_inbox(_context: &Context, folder_name: impl AsRef<str>) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user