Auto-accept contact requests for bots (#3567)

Auto accept contact request for bots
Co-authored-by: Hocuri <hocuri@gmx.de>
This commit is contained in:
Sebastian Klähn
2022-09-01 14:58:47 +02:00
committed by GitHub
parent 25bff21edd
commit 97982ef93a
2 changed files with 27 additions and 6 deletions

View File

@@ -19,7 +19,7 @@
### Fixes
- do not emit notifications for blocked chats #3557
- Show attached .eml files correctly #3561
- Auto accept contact requests if `Config::Bot` is set for a client #3567
## 1.93.0

View File

@@ -388,6 +388,9 @@ pub async fn from_field_to_contact_id(
}
}
/// Creates a `ReceivedMsg` from given parts which might consist of
/// mulitple messages (if there are multiple attachments).
/// Every entry in `mime_parser.parts` produces a new row in the `msgs` table.
#[allow(clippy::too_many_arguments, clippy::cognitive_complexity)]
async fn add_parts(
context: &Context,
@@ -492,7 +495,7 @@ async fn add_parts(
}
let test_normal_chat = if from_id == ContactId::UNDEFINED {
Default::default()
None
} else {
ChatIdBlocked::lookup_by_contact(context, from_id).await?
};
@@ -513,6 +516,9 @@ async fn add_parts(
}
}
// signals wether the current user is a bot
let is_bot = context.get_config(Config::Bot).await?.is_some();
if chat_id.is_none() {
// try to create a group
@@ -521,6 +527,7 @@ async fn add_parts(
id: _,
blocked: Blocked::Not,
}) => Blocked::Not,
_ if is_bot => Blocked::Not,
_ => Blocked::Request,
};
@@ -540,6 +547,9 @@ async fn add_parts(
{
chat_id = Some(new_chat_id);
chat_id_blocked = new_chat_id_blocked;
// if the chat is somehow blocked but we want to create a non-blocked chat,
// unblock the chat
if chat_id_blocked != Blocked::Not && create_blocked == Blocked::Not {
new_chat_id.unblock(context).await?;
chat_id_blocked = Blocked::Not;
@@ -637,10 +647,10 @@ async fn add_parts(
Blocked::Not
} else {
let contact = Contact::load_from_db(context, from_id).await?;
if contact.is_blocked() {
Blocked::Yes
} else {
Blocked::Request
match contact.is_blocked() {
true => Blocked::Yes,
false if is_bot => Blocked::Not,
false => Blocked::Request,
}
};
@@ -5090,6 +5100,17 @@ Reply from different address
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_auto_accept_for_bots() -> Result<()> {
let t = TestContext::new_alice().await;
t.set_config(Config::Bot, Some("1")).await.unwrap();
receive_imf(&t, MSGRMSG, false).await?;
let msg = t.get_last_msg().await;
let chat = chat::Chat::load_from_db(&t, msg.chat_id).await?;
assert!(!chat.is_contact_request());
Ok(())
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_no_private_reply_to_blocked_account() -> Result<()> {
let mut tcm = TestContextManager::new().await;