mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
add decision- and blocking-functions to repl, cleanup (#2258)
* deprecate mostly unused dc_get_blocked_cnt() api instead, the size returned by get_blocked_contacts() should be checked, this is safer and allows easier adaption of blocking rules. ui or python seems not to use dc_get_blocked_cnt(), however, there is one test in node, therefore, the function will continue working for now (by just returning Contact::get_all_blocked().len() then) * add decision api to repl tool * add block/unblock api to repl tool * unify usage of @deprecated doxygen command
This commit is contained in:
@@ -672,8 +672,6 @@ dc_chatlist_t* dc_get_chatlist (dc_context_t* context, int flags,
|
||||
// handle chats
|
||||
|
||||
/**
|
||||
* DEPRECATED Use dc_decide_on_contact_request().
|
||||
*
|
||||
* Create a normal chat or a group chat by a messages ID that comes typically
|
||||
* from the deaddrop, DC_CHAT_ID_DEADDROP (1).
|
||||
*
|
||||
@@ -693,7 +691,7 @@ dc_chatlist_t* dc_get_chatlist (dc_context_t* context, int flags,
|
||||
* same group may be shown or not - so, all in all, it is fine to show the
|
||||
* contact name only.
|
||||
*
|
||||
* @deprecated Use dc_decide_on_contact_request() instead
|
||||
* @deprecated Deprecated 2021-02-07, use dc_decide_on_contact_request() instead
|
||||
* @memberof dc_context_t
|
||||
* @param context The context object as returned from dc_context_new().
|
||||
* @param msg_id The message ID to create the chat for.
|
||||
@@ -1547,8 +1545,6 @@ void dc_forward_msgs (dc_context_t* context, const uint3
|
||||
|
||||
|
||||
/**
|
||||
* DEPRECATED
|
||||
*
|
||||
* Mark all messages sent by the given contact as _noticed_.
|
||||
* This function is typically used to ignore a user in the deaddrop temporarily ("Not now" button).
|
||||
*
|
||||
@@ -1557,7 +1553,7 @@ void dc_forward_msgs (dc_context_t* context, const uint3
|
||||
*
|
||||
* See also dc_marknoticed_chat() and dc_markseen_msgs()
|
||||
*
|
||||
* @deprecated Use dc_decide_on_contact_request() if the user just hit "Not now" on a button in the deaddrop,
|
||||
* @deprecated Deprecated 2021-02-07, use dc_decide_on_contact_request() if the user just hit "Not now" on a button in the deaddrop,
|
||||
* dc_marknoticed_chat() if the user has entered a chat
|
||||
* and dc_markseen_msgs() if the user actually _saw_ a message.
|
||||
* @memberof dc_context_t
|
||||
@@ -1757,6 +1753,7 @@ dc_array_t* dc_get_contacts (dc_context_t* context, uint32_t fl
|
||||
/**
|
||||
* Get the number of blocked contacts.
|
||||
*
|
||||
* @deprecated Deprecated 2021-02-22, use dc_array_get_cnt() on dc_get_blocked_contacts() instead.
|
||||
* @memberof dc_context_t
|
||||
* @param context The context object.
|
||||
* @return The number of blocked contacts.
|
||||
@@ -5285,7 +5282,7 @@ void dc_event_unref(dc_event_t* event);
|
||||
/// Used to build the string returned by dc_get_contact_encrinfo().
|
||||
#define DC_STR_E2E_AVAILABLE 25
|
||||
|
||||
/// DEPRECATED 2021-02-07
|
||||
/// @deprecated Deprecated 2021-02-07, this string is no longer needed.
|
||||
#define DC_STR_ENCR_TRANSP 27
|
||||
|
||||
/// "No encryption."
|
||||
@@ -5475,9 +5472,7 @@ void dc_event_unref(dc_event_t* event);
|
||||
/// Used in status messages.
|
||||
#define DC_STR_EPHEMERAL_WEEK 80
|
||||
|
||||
/// DEPRECATED
|
||||
///
|
||||
/// DC_STR_EPHEMERAL_WEEKS is used instead.
|
||||
/// @deprecated Deprecated 2021-01-30, DC_STR_EPHEMERAL_WEEKS is used instead.
|
||||
#define DC_STR_EPHEMERAL_FOUR_WEEKS 81
|
||||
|
||||
/// "Video chat invitation"
|
||||
|
||||
@@ -1640,7 +1640,7 @@ pub unsafe extern "C" fn dc_get_blocked_cnt(context: *mut dc_context_t) -> libc:
|
||||
}
|
||||
let ctx = &*context;
|
||||
|
||||
block_on(Contact::get_blocked_cnt(&ctx)) as libc::c_int
|
||||
block_on(async move { Contact::get_all_blocked(&ctx).await.len() as libc::c_int })
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
@@ -255,14 +255,10 @@ async fn log_msglist(context: &Context, msglist: &[MsgId]) -> Result<(), Error>
|
||||
}
|
||||
|
||||
async fn log_contactlist(context: &Context, contacts: &[u32]) {
|
||||
let mut contacts = contacts.to_vec();
|
||||
if !contacts.contains(&1) {
|
||||
contacts.push(1);
|
||||
}
|
||||
for contact_id in contacts {
|
||||
let line;
|
||||
let mut line2 = "".to_string();
|
||||
if let Ok(contact) = Contact::get_by_id(context, contact_id).await {
|
||||
if let Ok(contact) = Contact::get_by_id(context, *contact_id).await {
|
||||
let name = contact.get_display_name();
|
||||
let addr = contact.get_addr();
|
||||
let verified_state = contact.is_verified(context).await;
|
||||
@@ -292,14 +288,14 @@ async fn log_contactlist(context: &Context, contacts: &[u32]) {
|
||||
let peerstate = Peerstate::from_addr(context, &addr)
|
||||
.await
|
||||
.expect("peerstate error");
|
||||
if peerstate.is_some() && contact_id != 1 as libc::c_uint {
|
||||
if peerstate.is_some() && *contact_id != 1 as libc::c_uint {
|
||||
line2 = format!(
|
||||
", prefer-encrypt={}",
|
||||
peerstate.as_ref().unwrap().prefer_encrypt
|
||||
);
|
||||
}
|
||||
|
||||
println!("Contact#{}: {}{}", contact_id, line, line2);
|
||||
println!("Contact#{}: {}{}", *contact_id, line, line2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -359,7 +355,6 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
listarchived\n\
|
||||
chat [<chat-id>|0]\n\
|
||||
createchat <contact-id>\n\
|
||||
createchatbymsg <msg-id>\n\
|
||||
creategroup <name>\n\
|
||||
createprotected <name>\n\
|
||||
addmember <contact-id>\n\
|
||||
@@ -386,6 +381,10 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
protect <chat-id>\n\
|
||||
unprotect <chat-id>\n\
|
||||
delchat <chat-id>\n\
|
||||
===========================Contact requests==\n\
|
||||
decidestartchat <msg-id>\n\
|
||||
decideblock <msg-id>\n\
|
||||
decidenotnow <msg-id>\n\
|
||||
===========================Message commands==\n\
|
||||
listmsgs <query>\n\
|
||||
msginfo <msg-id>\n\
|
||||
@@ -401,6 +400,9 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
contactinfo <contact-id>\n\
|
||||
delcontact <contact-id>\n\
|
||||
cleanupcontacts\n\
|
||||
block <contact-id>\n\
|
||||
unblock <contact-id>\n\
|
||||
listblocked\n\
|
||||
======================================Misc.==\n\
|
||||
getqr [<chat-id>]\n\
|
||||
getbadqr\n\
|
||||
@@ -659,7 +661,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
|
||||
println!("Single#{} created successfully.", chat_id,);
|
||||
}
|
||||
"createchatbymsg" => {
|
||||
"decidestartchat" | "createchatbymsg" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <msg-id> missing");
|
||||
let msg_id = MsgId::new(arg1.parse()?);
|
||||
match message::decide_on_contact_request(
|
||||
@@ -676,6 +678,18 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
None => println!("Cannot crate chat."),
|
||||
}
|
||||
}
|
||||
"decidenotnow" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <msg-id> missing");
|
||||
let msg_id = MsgId::new(arg1.parse()?);
|
||||
message::decide_on_contact_request(&context, msg_id, ContactRequestDecision::NotNow)
|
||||
.await;
|
||||
}
|
||||
"decideblock" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <msg-id> missing");
|
||||
let msg_id = MsgId::new(arg1.parse()?);
|
||||
message::decide_on_contact_request(&context, msg_id, ContactRequestDecision::Block)
|
||||
.await;
|
||||
}
|
||||
"creategroup" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <name> missing.");
|
||||
let chat_id =
|
||||
@@ -1078,6 +1092,21 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
||||
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
||||
Contact::delete(&context, arg1.parse()?).await?;
|
||||
}
|
||||
"block" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
||||
let contact_id = arg1.parse()?;
|
||||
Contact::block(&context, contact_id).await;
|
||||
}
|
||||
"unblock" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
|
||||
let contact_id = arg1.parse()?;
|
||||
Contact::unblock(&context, contact_id).await;
|
||||
}
|
||||
"listblocked" => {
|
||||
let contacts = Contact::get_all_blocked(&context).await;
|
||||
log_contactlist(&context, &contacts).await;
|
||||
println!("{} blocked contacts.", contacts.len());
|
||||
}
|
||||
"checkqr" => {
|
||||
ensure!(!arg1.is_empty(), "Argument <qr-content> missing.");
|
||||
let res = check_qr(&context, arg1).await;
|
||||
|
||||
@@ -168,12 +168,14 @@ const DB_COMMANDS: [&str; 9] = [
|
||||
"housekeeping",
|
||||
];
|
||||
|
||||
const CHAT_COMMANDS: [&str; 28] = [
|
||||
const CHAT_COMMANDS: [&str; 30] = [
|
||||
"listchats",
|
||||
"listarchived",
|
||||
"chat",
|
||||
"createchat",
|
||||
"createchatbymsg",
|
||||
"decidestartchat",
|
||||
"decideblock",
|
||||
"decidenotnow",
|
||||
"creategroup",
|
||||
"createverified",
|
||||
"addmember",
|
||||
@@ -206,13 +208,16 @@ const MESSAGE_COMMANDS: [&str; 6] = [
|
||||
"markseen",
|
||||
"delmsg",
|
||||
];
|
||||
const CONTACT_COMMANDS: [&str; 6] = [
|
||||
const CONTACT_COMMANDS: [&str; 9] = [
|
||||
"listcontacts",
|
||||
"listverified",
|
||||
"addcontact",
|
||||
"contactinfo",
|
||||
"delcontact",
|
||||
"cleanupcontacts",
|
||||
"block",
|
||||
"unblock",
|
||||
"listblocked",
|
||||
];
|
||||
const MISC_COMMANDS: [&str; 10] = [
|
||||
"getqr",
|
||||
|
||||
@@ -674,18 +674,6 @@ impl Contact {
|
||||
Ok(ret)
|
||||
}
|
||||
|
||||
pub async fn get_blocked_cnt(context: &Context) -> usize {
|
||||
context
|
||||
.sql
|
||||
.query_get_value::<isize>(
|
||||
context,
|
||||
"SELECT COUNT(*) FROM contacts WHERE id>? AND blocked!=0",
|
||||
paramsv![DC_CONTACT_ID_LAST_SPECIAL as i32],
|
||||
)
|
||||
.await
|
||||
.unwrap_or_default() as usize
|
||||
}
|
||||
|
||||
/// Get blocked contacts.
|
||||
pub async fn get_all_blocked(context: &Context) -> Vec<u32> {
|
||||
context
|
||||
|
||||
Reference in New Issue
Block a user