diff --git a/deltachat-ffi/deltachat.h b/deltachat-ffi/deltachat.h index fb606d8fd..62b7a5363 100644 --- a/deltachat-ffi/deltachat.h +++ b/deltachat-ffi/deltachat.h @@ -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" diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 1abfe635a..da3dad227 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -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] diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 072463cc9..5cf1a9a89 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -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 [|0]\n\ createchat \n\ - createchatbymsg \n\ creategroup \n\ createprotected \n\ addmember \n\ @@ -386,6 +381,10 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu protect \n\ unprotect \n\ delchat \n\ + ===========================Contact requests==\n\ + decidestartchat \n\ + decideblock \n\ + decidenotnow \n\ ===========================Message commands==\n\ listmsgs \n\ msginfo \n\ @@ -401,6 +400,9 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu contactinfo \n\ delcontact \n\ cleanupcontacts\n\ + block \n\ + unblock \n\ + listblocked\n\ ======================================Misc.==\n\ getqr []\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 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 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 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 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 missing."); Contact::delete(&context, arg1.parse()?).await?; } + "block" => { + ensure!(!arg1.is_empty(), "Argument missing."); + let contact_id = arg1.parse()?; + Contact::block(&context, contact_id).await; + } + "unblock" => { + ensure!(!arg1.is_empty(), "Argument 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 missing."); let res = check_qr(&context, arg1).await; diff --git a/examples/repl/main.rs b/examples/repl/main.rs index 812845277..3bb2a9ea3 100644 --- a/examples/repl/main.rs +++ b/examples/repl/main.rs @@ -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", diff --git a/src/contact.rs b/src/contact.rs index d72a51d7e..f9c1519c3 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -674,18 +674,6 @@ impl Contact { Ok(ret) } - pub async fn get_blocked_cnt(context: &Context) -> usize { - context - .sql - .query_get_value::( - 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 { context