Skip to content

Commit e17afae

Browse files
committed
Mute&archive self-reporting bot chat
1 parent 1799422 commit e17afae

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::{
@@ -1213,7 +1213,18 @@ impl Context {
12131213
.context("Self reporting bot vCard does not contain a contact")?;
12141214
mark_contact_id_as_verified(self, contact_id, ContactId::SELF).await?;
12151215

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

src/receive_imf.rs

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

17101710
let state = if !mime_parser.incoming {
17111711
MessageState::OutDelivered
1712-
} else if seen || is_mdn || chat_id_blocked == Blocked::Yes || group_changes.silent
1712+
} else if seen
1713+
|| is_mdn
1714+
|| chat_id_blocked == Blocked::Yes
1715+
|| group_changes.silent
1716+
|| mime_parser.from.addr == "self_reporting@testrun.org"
17131717
// No check for `hidden` because only reactions are such and they should be `InFresh`.
17141718
{
17151719
MessageState::InSeen

0 commit comments

Comments
 (0)