mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Merge pull request #347 from link2xt/dc_array_t-new
Implement From<Vec<u32>> for dc_array_t and use it instead of new()
This commit is contained in:
@@ -478,7 +478,7 @@ impl<'a> Contact<'a> {
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut add_self = false;
|
||||
let mut ret = dc_array_t::new(100);
|
||||
let mut ret = Vec::new();
|
||||
|
||||
if (listflags & DC_GCL_VERIFIED_ONLY) > 0 || query.is_some() {
|
||||
let s3str_like_cmd = format!(
|
||||
@@ -509,7 +509,7 @@ impl<'a> Contact<'a> {
|
||||
|row| row.get::<_, i32>(0),
|
||||
|ids| {
|
||||
for id in ids {
|
||||
ret.add_id(id? as u32);
|
||||
ret.push(id? as u32);
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
@@ -537,7 +537,7 @@ impl<'a> Contact<'a> {
|
||||
|row| row.get::<_, i32>(0),
|
||||
|ids| {
|
||||
for id in ids {
|
||||
ret.add_id(id? as u32);
|
||||
ret.push(id? as u32);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -545,10 +545,10 @@ impl<'a> Contact<'a> {
|
||||
}
|
||||
|
||||
if 0 != listflags & DC_GCL_ADD_SELF as u32 && add_self {
|
||||
ret.add_id(DC_CONTACT_ID_SELF as u32);
|
||||
ret.push(DC_CONTACT_ID_SELF as u32);
|
||||
}
|
||||
|
||||
Ok(ret.into_raw())
|
||||
Ok(dc_array_t::from(ret).into_raw())
|
||||
}
|
||||
|
||||
pub fn get_blocked_cnt(context: &Context) -> usize {
|
||||
@@ -572,13 +572,13 @@ impl<'a> Contact<'a> {
|
||||
params![DC_CONTACT_ID_LAST_SPECIAL as i32],
|
||||
|row| row.get::<_, i32>(0),
|
||||
|ids| {
|
||||
let mut ret = dc_array_t::new(100);
|
||||
let mut ret = Vec::new();
|
||||
|
||||
for id in ids {
|
||||
ret.add_id(id? as u32);
|
||||
ret.push(id? as u32);
|
||||
}
|
||||
|
||||
Ok(ret.into_raw())
|
||||
Ok(dc_array_t::from(ret).into_raw())
|
||||
},
|
||||
)
|
||||
.unwrap_or_else(|_| std::ptr::null_mut())
|
||||
|
||||
@@ -496,13 +496,12 @@ pub fn dc_get_fresh_msgs(context: &Context) -> *mut dc_array_t {
|
||||
&[10, 9, if 0 != show_deaddrop { 2 } else { 0 }],
|
||||
|row| row.get(0),
|
||||
|rows| {
|
||||
let mut ret = dc_array_t::new(128);
|
||||
|
||||
let mut ret = Vec::new();
|
||||
for row in rows {
|
||||
let id = row?;
|
||||
ret.add_id(id);
|
||||
let id: u32 = row?;
|
||||
ret.push(id);
|
||||
}
|
||||
Ok(ret.into_raw())
|
||||
Ok(dc_array_t::from(ret).into_raw())
|
||||
},
|
||||
)
|
||||
.unwrap()
|
||||
@@ -536,7 +535,7 @@ 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 = dc_array_t::new(100);
|
||||
let mut ret = Vec::new();
|
||||
|
||||
let success = context
|
||||
.sql
|
||||
@@ -546,7 +545,7 @@ pub fn dc_search_msgs(
|
||||
|row| row.get::<_, i32>(0),
|
||||
|rows| {
|
||||
for id in rows {
|
||||
ret.add_id(id? as u32);
|
||||
ret.push(id? as u32);
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
@@ -554,7 +553,7 @@ pub fn dc_search_msgs(
|
||||
.is_ok();
|
||||
|
||||
if success {
|
||||
return ret.into_raw();
|
||||
return dc_array_t::from(ret).into_raw();
|
||||
}
|
||||
|
||||
std::ptr::null_mut()
|
||||
|
||||
@@ -147,6 +147,12 @@ impl dc_array_t {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<u32>> for dc_array_t {
|
||||
fn from(array: Vec<u32>) -> Self {
|
||||
dc_array_t::Uint(array.iter().map(|&x| x as uintptr_t).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<dc_location>> for dc_array_t {
|
||||
fn from(array: Vec<dc_location>) -> Self {
|
||||
dc_array_t::Locations(array)
|
||||
|
||||
@@ -1072,7 +1072,7 @@ pub fn dc_get_chat_msgs(
|
||||
flags: uint32_t,
|
||||
marker1before: uint32_t,
|
||||
) -> *mut dc_array_t {
|
||||
let mut ret = dc_array_t::new(512);
|
||||
let mut ret = Vec::new();
|
||||
|
||||
let mut last_day = 0;
|
||||
let cnv_to_local = dc_gm2local_offset();
|
||||
@@ -1082,17 +1082,17 @@ pub fn dc_get_chat_msgs(
|
||||
for row in rows {
|
||||
let (curr_id, ts) = row?;
|
||||
if curr_id as u32 == marker1before {
|
||||
ret.add_id(1);
|
||||
ret.push(DC_MSG_ID_MARKER1 as u32);
|
||||
}
|
||||
if 0 != flags & 0x1 {
|
||||
let curr_local_timestamp = ts + cnv_to_local;
|
||||
let curr_day = (curr_local_timestamp / 86400) as libc::c_int;
|
||||
if curr_day != last_day {
|
||||
ret.add_id(9);
|
||||
ret.push(DC_MSG_ID_LAST_SPECIAL as u32);
|
||||
last_day = curr_day;
|
||||
}
|
||||
}
|
||||
ret.add_id(curr_id as u32);
|
||||
ret.push(curr_id as u32);
|
||||
}
|
||||
Ok(())
|
||||
};
|
||||
@@ -1140,7 +1140,7 @@ pub fn dc_get_chat_msgs(
|
||||
};
|
||||
|
||||
if success.is_ok() {
|
||||
ret.into_raw()
|
||||
dc_array_t::from(ret).into_raw()
|
||||
} else {
|
||||
0 as *mut dc_array_t
|
||||
}
|
||||
@@ -1253,11 +1253,11 @@ pub fn dc_get_chat_media(
|
||||
],
|
||||
|row| row.get::<_, i32>(0),
|
||||
|ids| {
|
||||
let mut ret = dc_array_t::new(100);
|
||||
let mut ret = Vec::new();
|
||||
for id in ids {
|
||||
ret.add_id(id? as u32);
|
||||
ret.push(id? as u32);
|
||||
}
|
||||
Ok(ret.into_raw())
|
||||
Ok(dc_array_t::from(ret).into_raw())
|
||||
}
|
||||
).unwrap_or_else(|_| std::ptr::null_mut())
|
||||
}
|
||||
@@ -1426,13 +1426,13 @@ pub fn dc_get_chat_contacts(context: &Context, chat_id: u32) -> *mut dc_array_t
|
||||
params![chat_id as i32],
|
||||
|row| row.get::<_, i32>(0),
|
||||
|ids| {
|
||||
let mut ret = dc_array_t::new(100);
|
||||
let mut ret = Vec::new();
|
||||
|
||||
for id in ids {
|
||||
ret.add_id(id? as u32);
|
||||
ret.push(id? as u32);
|
||||
}
|
||||
|
||||
Ok(ret.into_raw())
|
||||
Ok(dc_array_t::from(ret).into_raw())
|
||||
},
|
||||
)
|
||||
.unwrap_or_else(|_| std::ptr::null_mut())
|
||||
|
||||
Reference in New Issue
Block a user