Skip to content

Commit a4d64cb

Browse files
committed
Mute&archive self-reporting bot chat
1 parent b8c5e76 commit a4d64cb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/context.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use serde::Serialize;
1717
use tokio::sync::{Mutex, Notify, RwLock};
1818

1919
use crate::aheader::EncryptPreference;
20-
use crate::chat::{get_chat_cnt, ChatId, ProtectionStatus};
20+
use crate::chat::{self, get_chat_cnt, ChatId, ChatVisibility, MuteDuration, ProtectionStatus};
2121
use crate::chatlist_events;
2222
use crate::config::Config;
2323
use crate::constants::{
@@ -1200,7 +1200,17 @@ impl Context {
12001200
const SELF_REPORTING_BOT: &str = "self_reporting@testrun.org";
12011201

12021202
let contact_id = Contact::create(self, "Statistics bot", SELF_REPORTING_BOT).await?;
1203-
let chat_id = ChatId::create_for_contact(self, contact_id).await?;
1203+
let chat_id = if let Some(res) = ChatId::lookup_by_contact(self, contact_id).await? {
1204+
// Already exists, no need to create.
1205+
res
1206+
} else {
1207+
let chat_id = ChatId::get_for_contact(self, contact_id).await?;
1208+
chat_id
1209+
.set_visibility(self, ChatVisibility::Archived)
1210+
.await?;
1211+
chat::set_muted(self, chat_id, MuteDuration::Forever).await?;
1212+
chat_id
1213+
};
12041214

12051215
// We're including the bot's public key in Delta Chat
12061216
// so that the first message to the bot can directly be encrypted:

src/receive_imf.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,11 @@ async fn add_parts(
10411041
}
10421042
}
10431043

1044-
state = if seen || is_mdn || chat_id_blocked == Blocked::Yes || group_changes.silent
1044+
state = if seen
1045+
|| is_mdn
1046+
|| chat_id_blocked == Blocked::Yes
1047+
|| group_changes.silent
1048+
|| mime_parser.from.addr == "self_reporting@testrun.org"
10451049
// No check for `hidden` because only reactions are such and they should be `InFresh`.
10461050
{
10471051
MessageState::InSeen

0 commit comments

Comments
 (0)