mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +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();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let mut add_self = false;
|
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() {
|
if (listflags & DC_GCL_VERIFIED_ONLY) > 0 || query.is_some() {
|
||||||
let s3str_like_cmd = format!(
|
let s3str_like_cmd = format!(
|
||||||
@@ -509,7 +509,7 @@ impl<'a> Contact<'a> {
|
|||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|ids| {
|
|ids| {
|
||||||
for id in ids {
|
for id in ids {
|
||||||
ret.add_id(id? as u32);
|
ret.push(id? as u32);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
@@ -537,7 +537,7 @@ impl<'a> Contact<'a> {
|
|||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|ids| {
|
|ids| {
|
||||||
for id in ids {
|
for id in ids {
|
||||||
ret.add_id(id? as u32);
|
ret.push(id? as u32);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -545,10 +545,10 @@ impl<'a> Contact<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if 0 != listflags & DC_GCL_ADD_SELF as u32 && add_self {
|
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 {
|
pub fn get_blocked_cnt(context: &Context) -> usize {
|
||||||
@@ -572,13 +572,13 @@ impl<'a> Contact<'a> {
|
|||||||
params![DC_CONTACT_ID_LAST_SPECIAL as i32],
|
params![DC_CONTACT_ID_LAST_SPECIAL as i32],
|
||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|ids| {
|
|ids| {
|
||||||
let mut ret = dc_array_t::new(100);
|
let mut ret = Vec::new();
|
||||||
|
|
||||||
for id in ids {
|
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())
|
.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 }],
|
&[10, 9, if 0 != show_deaddrop { 2 } else { 0 }],
|
||||||
|row| row.get(0),
|
|row| row.get(0),
|
||||||
|rows| {
|
|rows| {
|
||||||
let mut ret = dc_array_t::new(128);
|
let mut ret = Vec::new();
|
||||||
|
|
||||||
for row in rows {
|
for row in rows {
|
||||||
let id = row?;
|
let id: u32 = row?;
|
||||||
ret.add_id(id);
|
ret.push(id);
|
||||||
}
|
}
|
||||||
Ok(ret.into_raw())
|
Ok(dc_array_t::from(ret).into_raw())
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap()
|
.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;"
|
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
|
let success = context
|
||||||
.sql
|
.sql
|
||||||
@@ -546,7 +545,7 @@ pub fn dc_search_msgs(
|
|||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|rows| {
|
|rows| {
|
||||||
for id in rows {
|
for id in rows {
|
||||||
ret.add_id(id? as u32);
|
ret.push(id? as u32);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
@@ -554,7 +553,7 @@ pub fn dc_search_msgs(
|
|||||||
.is_ok();
|
.is_ok();
|
||||||
|
|
||||||
if success {
|
if success {
|
||||||
return ret.into_raw();
|
return dc_array_t::from(ret).into_raw();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ptr::null_mut()
|
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 {
|
impl From<Vec<dc_location>> for dc_array_t {
|
||||||
fn from(array: Vec<dc_location>) -> Self {
|
fn from(array: Vec<dc_location>) -> Self {
|
||||||
dc_array_t::Locations(array)
|
dc_array_t::Locations(array)
|
||||||
|
|||||||
@@ -1072,7 +1072,7 @@ pub fn dc_get_chat_msgs(
|
|||||||
flags: uint32_t,
|
flags: uint32_t,
|
||||||
marker1before: uint32_t,
|
marker1before: uint32_t,
|
||||||
) -> *mut dc_array_t {
|
) -> *mut dc_array_t {
|
||||||
let mut ret = dc_array_t::new(512);
|
let mut ret = Vec::new();
|
||||||
|
|
||||||
let mut last_day = 0;
|
let mut last_day = 0;
|
||||||
let cnv_to_local = dc_gm2local_offset();
|
let cnv_to_local = dc_gm2local_offset();
|
||||||
@@ -1082,17 +1082,17 @@ pub fn dc_get_chat_msgs(
|
|||||||
for row in rows {
|
for row in rows {
|
||||||
let (curr_id, ts) = row?;
|
let (curr_id, ts) = row?;
|
||||||
if curr_id as u32 == marker1before {
|
if curr_id as u32 == marker1before {
|
||||||
ret.add_id(1);
|
ret.push(DC_MSG_ID_MARKER1 as u32);
|
||||||
}
|
}
|
||||||
if 0 != flags & 0x1 {
|
if 0 != flags & 0x1 {
|
||||||
let curr_local_timestamp = ts + cnv_to_local;
|
let curr_local_timestamp = ts + cnv_to_local;
|
||||||
let curr_day = (curr_local_timestamp / 86400) as libc::c_int;
|
let curr_day = (curr_local_timestamp / 86400) as libc::c_int;
|
||||||
if curr_day != last_day {
|
if curr_day != last_day {
|
||||||
ret.add_id(9);
|
ret.push(DC_MSG_ID_LAST_SPECIAL as u32);
|
||||||
last_day = curr_day;
|
last_day = curr_day;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret.add_id(curr_id as u32);
|
ret.push(curr_id as u32);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
@@ -1140,7 +1140,7 @@ pub fn dc_get_chat_msgs(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if success.is_ok() {
|
if success.is_ok() {
|
||||||
ret.into_raw()
|
dc_array_t::from(ret).into_raw()
|
||||||
} else {
|
} else {
|
||||||
0 as *mut dc_array_t
|
0 as *mut dc_array_t
|
||||||
}
|
}
|
||||||
@@ -1253,11 +1253,11 @@ pub fn dc_get_chat_media(
|
|||||||
],
|
],
|
||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|ids| {
|
|ids| {
|
||||||
let mut ret = dc_array_t::new(100);
|
let mut ret = Vec::new();
|
||||||
for id in ids {
|
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())
|
).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],
|
params![chat_id as i32],
|
||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|ids| {
|
|ids| {
|
||||||
let mut ret = dc_array_t::new(100);
|
let mut ret = Vec::new();
|
||||||
|
|
||||||
for id in ids {
|
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())
|
.unwrap_or_else(|_| std::ptr::null_mut())
|
||||||
|
|||||||
Reference in New Issue
Block a user