mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 17:06:35 +03:00
refactor(chatlist): rustify
This commit is contained in:
committed by
GitHub
parent
4902310138
commit
b23ca26908
@@ -281,11 +281,20 @@ pub unsafe extern "C" fn dc_get_chatlist<'a>(
|
||||
flags: libc::c_int,
|
||||
query_str: *mut libc::c_char,
|
||||
query_id: u32,
|
||||
) -> *mut dc_chatlist::dc_chatlist_t<'a> {
|
||||
) -> *mut dc_chatlist_t<'a> {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_chatlist::dc_get_chatlist(context, flags, query_str, query_id)
|
||||
let qs = if query_str.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(dc_tools::as_str(query_str))
|
||||
};
|
||||
let qi = if query_id == 0 { None } else { Some(query_id) };
|
||||
match chatlist::Chatlist::try_load(context, flags as usize, qs, qi) {
|
||||
Ok(list) => Box::into_raw(Box::new(list)),
|
||||
Err(_) => std::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -1075,51 +1084,65 @@ pub unsafe fn dc_array_is_independent(
|
||||
// dc_chatlist_t
|
||||
|
||||
#[no_mangle]
|
||||
pub type dc_chatlist_t<'a> = dc_chatlist::dc_chatlist_t<'a>;
|
||||
pub type dc_chatlist_t<'a> = chatlist::Chatlist<'a>;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chatlist_unref(chatlist: *mut dc_chatlist::dc_chatlist_t) {
|
||||
dc_chatlist::dc_chatlist_unref(chatlist)
|
||||
pub unsafe extern "C" fn dc_chatlist_unref(chatlist: *mut dc_chatlist_t) {
|
||||
assert!(!chatlist.is_null());
|
||||
|
||||
Box::from_raw(chatlist);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chatlist_get_cnt(
|
||||
chatlist: *mut dc_chatlist::dc_chatlist_t,
|
||||
) -> libc::size_t {
|
||||
dc_chatlist::dc_chatlist_get_cnt(chatlist)
|
||||
pub unsafe extern "C" fn dc_chatlist_get_cnt(chatlist: *mut dc_chatlist_t) -> libc::size_t {
|
||||
assert!(!chatlist.is_null());
|
||||
|
||||
let list = &*chatlist;
|
||||
list.len() as libc::size_t
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chatlist_get_chat_id(
|
||||
chatlist: *mut dc_chatlist::dc_chatlist_t,
|
||||
chatlist: *mut dc_chatlist_t,
|
||||
index: libc::size_t,
|
||||
) -> u32 {
|
||||
dc_chatlist::dc_chatlist_get_chat_id(chatlist, index)
|
||||
assert!(!chatlist.is_null());
|
||||
|
||||
let list = &*chatlist;
|
||||
list.get_chat_id(index as usize)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chatlist_get_msg_id(
|
||||
chatlist: *mut dc_chatlist::dc_chatlist_t,
|
||||
chatlist: *mut dc_chatlist_t,
|
||||
index: libc::size_t,
|
||||
) -> u32 {
|
||||
dc_chatlist::dc_chatlist_get_msg_id(chatlist, index)
|
||||
assert!(!chatlist.is_null());
|
||||
|
||||
let list = &*chatlist;
|
||||
list.get_msg_id(index as usize)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chatlist_get_summary<'a>(
|
||||
chatlist: *mut dc_chatlist::dc_chatlist_t<'a>,
|
||||
chatlist: *mut dc_chatlist_t<'a>,
|
||||
index: libc::size_t,
|
||||
chat: *mut dc_chat_t<'a>,
|
||||
) -> *mut dc_lot::dc_lot_t {
|
||||
dc_chatlist::dc_chatlist_get_summary(chatlist, index, chat)
|
||||
assert!(!chatlist.is_null());
|
||||
|
||||
let list = &*chatlist;
|
||||
list.get_summary(index as usize, chat)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chatlist_get_context(
|
||||
chatlist: *mut dc_chatlist::dc_chatlist_t,
|
||||
chatlist: *mut dc_chatlist_t,
|
||||
) -> *const dc_context_t {
|
||||
assert!(!chatlist.is_null());
|
||||
(*chatlist).context as *const _
|
||||
let list = &*chatlist;
|
||||
|
||||
list.get_context() as *const _
|
||||
}
|
||||
|
||||
// dc_chat_t
|
||||
|
||||
Reference in New Issue
Block a user