Skip to content

Commit 0fd053a

Browse files
committed
Mute&archive self-reporting bot chat
1 parent c4dd392 commit 0fd053a

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/context.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ratelimit::Ratelimit;
1515
use serde::Serialize;
1616
use tokio::sync::{Mutex, Notify, RwLock};
1717

18-
use crate::chat::{get_chat_cnt, ChatId, ProtectionStatus};
18+
use crate::chat::{self, get_chat_cnt, ChatId, ChatVisibility, MuteDuration, ProtectionStatus};
1919
use crate::chatlist_events;
2020
use crate::config::Config;
2121
use crate::constants::{
@@ -1215,7 +1215,18 @@ impl Context {
12151215
.context("Self reporting bot vCard does not contain a contact")?;
12161216
mark_contact_id_as_verified(self, contact_id, ContactId::SELF).await?;
12171217

1218-
let chat_id = ChatId::create_for_contact(self, contact_id).await?;
1218+
let chat_id = if let Some(res) = ChatId::lookup_by_contact(self, contact_id).await? {
1219+
// Already exists, no need to create.
1220+
res
1221+
} else {
1222+
let chat_id = ChatId::get_for_contact(self, contact_id).await?;
1223+
chat_id
1224+
.set_visibility(self, ChatVisibility::Archived)
1225+
.await?;
1226+
chat::set_muted(self, chat_id, MuteDuration::Forever).await?;
1227+
chat_id
1228+
};
1229+
12191230
chat_id
12201231
.set_protection(self, ProtectionStatus::Protected, time(), Some(contact_id))
12211232
.await?;

src/receive_imf.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,11 @@ async fn add_parts(
16721672

16731673
let state = if !mime_parser.incoming {
16741674
MessageState::OutDelivered
1675-
} else if seen || is_mdn || chat_id_blocked == Blocked::Yes || group_changes.silent
1675+
} else if seen
1676+
|| is_mdn
1677+
|| chat_id_blocked == Blocked::Yes
1678+
|| group_changes.silent
1679+
|| mime_parser.from.addr == "self_reporting@testrun.org"
16761680
// No check for `hidden` because only reactions are such and they should be `InFresh`.
16771681
{
16781682
MessageState::InSeen

0 commit comments

Comments
 (0)