mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Merge pull request #396 from deltachat/chat-array
Remove dc_array_t from chat.rs
This commit is contained in:
@@ -498,7 +498,14 @@ pub unsafe extern "C" fn dc_get_chat_media(
|
|||||||
let or_msg_type3 =
|
let or_msg_type3 =
|
||||||
from_prim(or_msg_type3).expect(&format!("incorrect or_msg_type3 = {}", or_msg_type3));
|
from_prim(or_msg_type3).expect(&format!("incorrect or_msg_type3 = {}", or_msg_type3));
|
||||||
|
|
||||||
chat::get_chat_media(context, chat_id, msg_type, or_msg_type2, or_msg_type3)
|
dc_array_t::from(chat::get_chat_media(
|
||||||
|
context,
|
||||||
|
chat_id,
|
||||||
|
msg_type,
|
||||||
|
or_msg_type2,
|
||||||
|
or_msg_type3,
|
||||||
|
))
|
||||||
|
.into_raw()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ use deltachat::config;
|
|||||||
use deltachat::constants::*;
|
use deltachat::constants::*;
|
||||||
use deltachat::contact::*;
|
use deltachat::contact::*;
|
||||||
use deltachat::context::*;
|
use deltachat::context::*;
|
||||||
use deltachat::dc_array::*;
|
|
||||||
use deltachat::dc_configure::*;
|
use deltachat::dc_configure::*;
|
||||||
use deltachat::dc_imex::*;
|
use deltachat::dc_imex::*;
|
||||||
use deltachat::dc_job::*;
|
use deltachat::dc_job::*;
|
||||||
@@ -917,10 +916,8 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
Viewtype::Gif,
|
Viewtype::Gif,
|
||||||
Viewtype::Video,
|
Viewtype::Video,
|
||||||
);
|
);
|
||||||
let icnt: libc::c_int = dc_array_get_cnt(images) as libc::c_int;
|
println!("{} images or videos: ", images.len());
|
||||||
println!("{} images or videos: ", icnt);
|
for (i, data) in images.iter().enumerate() {
|
||||||
for i in 0..icnt {
|
|
||||||
let data = dc_array_get_id(images, i as size_t);
|
|
||||||
if 0 == i {
|
if 0 == i {
|
||||||
print!("Msg#{}", data);
|
print!("Msg#{}", data);
|
||||||
} else {
|
} else {
|
||||||
@@ -928,7 +925,6 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
print!("\n");
|
print!("\n");
|
||||||
dc_array_unref(images);
|
|
||||||
}
|
}
|
||||||
"archive" | "unarchive" => {
|
"archive" | "unarchive" => {
|
||||||
ensure!(!arg1.is_empty(), "Argument <chat-id> missing.");
|
ensure!(!arg1.is_empty(), "Argument <chat-id> missing.");
|
||||||
|
|||||||
48
src/chat.rs
48
src/chat.rs
@@ -5,7 +5,6 @@ use crate::chatlist::*;
|
|||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
use crate::contact::*;
|
use crate::contact::*;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::dc_array::*;
|
|
||||||
use crate::dc_job::*;
|
use crate::dc_job::*;
|
||||||
use crate::dc_msg::*;
|
use crate::dc_msg::*;
|
||||||
use crate::dc_tools::*;
|
use crate::dc_tools::*;
|
||||||
@@ -1200,7 +1199,7 @@ pub fn get_chat_media(
|
|||||||
msg_type: Viewtype,
|
msg_type: Viewtype,
|
||||||
msg_type2: Viewtype,
|
msg_type2: Viewtype,
|
||||||
msg_type3: Viewtype,
|
msg_type3: Viewtype,
|
||||||
) -> *mut dc_array_t {
|
) -> Vec<u32> {
|
||||||
context.sql.query_map(
|
context.sql.query_map(
|
||||||
"SELECT id FROM msgs WHERE chat_id=? AND (type=? OR type=? OR type=?) ORDER BY timestamp, id;",
|
"SELECT id FROM msgs WHERE chat_id=? AND (type=? OR type=? OR type=?) ORDER BY timestamp, id;",
|
||||||
params![
|
params![
|
||||||
@@ -1222,9 +1221,9 @@ pub fn get_chat_media(
|
|||||||
for id in ids {
|
for id in ids {
|
||||||
ret.push(id? as u32);
|
ret.push(id? as u32);
|
||||||
}
|
}
|
||||||
Ok(dc_array_t::from(ret).into_raw())
|
Ok(ret)
|
||||||
}
|
}
|
||||||
).unwrap_or_else(|_| std::ptr::null_mut())
|
).unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn get_next_media(
|
pub unsafe fn get_next_media(
|
||||||
@@ -1235,14 +1234,10 @@ pub unsafe fn get_next_media(
|
|||||||
msg_type2: Viewtype,
|
msg_type2: Viewtype,
|
||||||
msg_type3: Viewtype,
|
msg_type3: Viewtype,
|
||||||
) -> u32 {
|
) -> u32 {
|
||||||
let mut ret_msg_id: u32 = 0i32 as u32;
|
let mut ret = 0;
|
||||||
let msg: *mut dc_msg_t = dc_msg_new_untyped(context);
|
let msg: *mut dc_msg_t = dc_msg_new_untyped(context);
|
||||||
let mut list: *mut dc_array_t = ptr::null_mut();
|
|
||||||
let mut i: libc::c_int;
|
|
||||||
let cnt: libc::c_int;
|
|
||||||
|
|
||||||
if dc_msg_load_from_db(msg, context, curr_msg_id) {
|
if dc_msg_load_from_db(msg, context, curr_msg_id) {
|
||||||
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 {
|
||||||
@@ -1253,33 +1248,24 @@ pub unsafe fn get_next_media(
|
|||||||
msg_type2,
|
msg_type2,
|
||||||
msg_type3,
|
msg_type3,
|
||||||
);
|
);
|
||||||
if !list.is_null() {
|
for i in 0..list.len() {
|
||||||
cnt = dc_array_get_cnt(list) as libc::c_int;
|
if curr_msg_id == list[i] {
|
||||||
i = 0i32;
|
if dir > 0 {
|
||||||
while i < cnt {
|
if i + 1 < list.len() {
|
||||||
if curr_msg_id == dc_array_get_id(list, i as size_t) {
|
ret = list[i + 1]
|
||||||
if dir > 0i32 {
|
}
|
||||||
if i + 1i32 < cnt {
|
} else if dir < 0 {
|
||||||
ret_msg_id = dc_array_get_id(list, (i + 1i32) as size_t)
|
if i >= 1 {
|
||||||
}
|
ret = list[i - 1];
|
||||||
} else if dir < 0i32 {
|
|
||||||
if i - 1i32 >= 0i32 {
|
|
||||||
ret_msg_id = dc_array_get_id(list, (i - 1i32) as size_t)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
i += 1
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !list.is_null() {
|
|
||||||
dc_array_unref(list);
|
|
||||||
}
|
|
||||||
dc_msg_unref(msg);
|
dc_msg_unref(msg);
|
||||||
ret_msg_id
|
|
||||||
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn archive(context: &Context, chat_id: u32, archive: bool) -> Result<(), Error> {
|
pub fn archive(context: &Context, chat_id: u32, archive: bool) -> Result<(), Error> {
|
||||||
|
|||||||
Reference in New Issue
Block a user