Skip to content

Commit 6052d1a

Browse files
committed
refactor: remove ProtectionStatus
1 parent 77271d7 commit 6052d1a

File tree

6 files changed

+20
-83
lines changed

6 files changed

+20
-83
lines changed

src/chat.rs

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::time::Duration;
1212
use anyhow::{Context as _, Result, anyhow, bail, ensure};
1313
use chrono::TimeZone;
1414
use deltachat_contact_tools::{ContactAddress, sanitize_bidi_characters, sanitize_single_line};
15-
use deltachat_derive::{FromSql, ToSql};
1615
use mail_builder::mime::MimePart;
1716
use serde::{Deserialize, Serialize};
1817
use strum_macros::EnumIter;
@@ -67,41 +66,6 @@ pub enum ChatItem {
6766
},
6867
}
6968

70-
/// Chat protection status.
71-
#[derive(
72-
Debug,
73-
Default,
74-
Display,
75-
Clone,
76-
Copy,
77-
PartialEq,
78-
Eq,
79-
FromPrimitive,
80-
ToPrimitive,
81-
FromSql,
82-
ToSql,
83-
IntoStaticStr,
84-
Serialize,
85-
Deserialize,
86-
)]
87-
#[repr(u32)]
88-
pub enum ProtectionStatus {
89-
/// Chat is not protected.
90-
#[default]
91-
Unprotected = 0,
92-
93-
/// Chat is protected.
94-
///
95-
/// All members of the chat must be verified.
96-
Protected = 1,
97-
// `2` was never used as a value.
98-
99-
// Chats don't break in Core v2 anymore. Chats with broken protection existing before the
100-
// key-contacts migration are treated as `Unprotected`.
101-
//
102-
// ProtectionBroken = 3,
103-
}
104-
10569
/// The reason why messages cannot be sent to the chat.
10670
///
10771
/// The reason is mainly for logging and displaying in debug REPL, thus not translated.
@@ -1375,9 +1339,6 @@ pub struct Chat {
13751339

13761340
/// Duration of the chat being muted.
13771341
pub mute_duration: MuteDuration,
1378-
1379-
/// If the chat is protected (verified).
1380-
pub(crate) protected: ProtectionStatus,
13811342
}
13821343

13831344
impl Chat {
@@ -1387,7 +1348,7 @@ impl Chat {
13871348
.sql
13881349
.query_row(
13891350
"SELECT c.type, c.name, c.grpid, c.param, c.archived,
1390-
c.blocked, c.locations_send_until, c.muted_until, c.protected
1351+
c.blocked, c.locations_send_until, c.muted_until
13911352
FROM chats c
13921353
WHERE c.id=?;",
13931354
(chat_id,),
@@ -1402,7 +1363,6 @@ impl Chat {
14021363
blocked: row.get::<_, Option<_>>(5)?.unwrap_or_default(),
14031364
is_sending_locations: row.get(6)?,
14041365
mute_duration: row.get(7)?,
1405-
protected: row.get(8)?,
14061366
};
14071367
Ok(c)
14081368
},
@@ -2422,27 +2382,21 @@ impl ChatIdBlocked {
24222382
_ => (),
24232383
}
24242384

2425-
let protected = contact_id == ContactId::SELF || contact.is_verified(context).await?;
24262385
let smeared_time = create_smeared_timestamp(context);
24272386

24282387
let chat_id = context
24292388
.sql
24302389
.transaction(move |transaction| {
24312390
transaction.execute(
24322391
"INSERT INTO chats
2433-
(type, name, param, blocked, created_timestamp, protected)
2434-
VALUES(?, ?, ?, ?, ?, ?)",
2392+
(type, name, param, blocked, created_timestamp)
2393+
VALUES(?, ?, ?, ?, ?)",
24352394
(
24362395
Chattype::Single,
24372396
chat_name,
24382397
params.to_string(),
24392398
create_blocked as u8,
24402399
smeared_time,
2441-
if protected {
2442-
ProtectionStatus::Protected
2443-
} else {
2444-
ProtectionStatus::Unprotected
2445-
},
24462400
),
24472401
)?;
24482402
let chat_id = ChatId::new(
@@ -4413,24 +4367,21 @@ pub(crate) async fn get_chat_cnt(context: &Context) -> Result<usize> {
44134367
}
44144368
}
44154369

4416-
/// Returns a tuple of `(chatid, is_protected, blocked)`.
4370+
/// Returns a tuple of `(chatid, blocked)`.
44174371
pub(crate) async fn get_chat_id_by_grpid(
44184372
context: &Context,
44194373
grpid: &str,
4420-
) -> Result<Option<(ChatId, bool, Blocked)>> {
4374+
) -> Result<Option<(ChatId, Blocked)>> {
44214375
context
44224376
.sql
44234377
.query_row_optional(
4424-
"SELECT id, blocked, protected FROM chats WHERE grpid=?;",
4378+
"SELECT id, blocked FROM chats WHERE grpid=?;",
44254379
(grpid,),
44264380
|row| {
44274381
let chat_id = row.get::<_, ChatId>(0)?;
44284382

44294383
let b = row.get::<_, Option<Blocked>>(1)?.unwrap_or_default();
4430-
let p = row
4431-
.get::<_, Option<ProtectionStatus>>(2)?
4432-
.unwrap_or_default();
4433-
Ok((chat_id, p == ProtectionStatus::Protected, b))
4384+
Ok((chat_id, b))
44344385
},
44354386
)
44364387
.await

src/contact.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,9 +1778,7 @@ WHERE type=? AND id IN (
17781778
// also unblock mailinglist
17791779
// if the contact is a mailinglist address explicitly created to allow unblocking
17801780
if !new_blocking && contact.origin == Origin::MailinglistAddress {
1781-
if let Some((chat_id, _, _)) =
1782-
chat::get_chat_id_by_grpid(context, &contact.addr).await?
1783-
{
1781+
if let Some((chat_id, ..)) = chat::get_chat_id_by_grpid(context, &contact.addr).await? {
17841782
chat_id.unblock_ex(context, Nosync).await?;
17851783
}
17861784
}

src/context.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use pgp::types::PublicKeyTrait;
1414
use ratelimit::Ratelimit;
1515
use tokio::sync::{Mutex, Notify, RwLock};
1616

17-
use crate::chat::{ChatId, ProtectionStatus, get_chat_cnt};
17+
use crate::chat::{ChatId, get_chat_cnt};
1818
use crate::chatlist_events;
1919
use crate::config::Config;
2020
use crate::constants::{
@@ -1086,7 +1086,6 @@ impl Context {
10861086
async fn get_self_report(&self) -> Result<String> {
10871087
#[derive(Default)]
10881088
struct ChatNumbers {
1089-
protected: u32,
10901089
opportunistic_dc: u32,
10911090
opportunistic_mua: u32,
10921091
unencrypted_dc: u32,
@@ -1121,7 +1120,6 @@ impl Context {
11211120
res += &format!("key_created {key_created}\n");
11221121

11231122
// how many of the chats active in the last months are:
1124-
// - protected
11251123
// - opportunistic-encrypted and the contact uses Delta Chat
11261124
// - opportunistic-encrypted and the contact uses a classical MUA
11271125
// - unencrypted and the contact uses Delta Chat
@@ -1130,7 +1128,7 @@ impl Context {
11301128
let chats = self
11311129
.sql
11321130
.query_map(
1133-
"SELECT c.protected, m.param, m.msgrmsg
1131+
"SELECT m.param, m.msgrmsg
11341132
FROM chats c
11351133
JOIN msgs m
11361134
ON c.id=m.chat_id
@@ -1148,23 +1146,20 @@ impl Context {
11481146
GROUP BY c.id",
11491147
(DownloadState::Done, ContactId::INFO, three_months_ago),
11501148
|row| {
1151-
let protected: ProtectionStatus = row.get(0)?;
11521149
let message_param: Params =
11531150
row.get::<_, String>(1)?.parse().unwrap_or_default();
11541151
let is_dc_message: bool = row.get(2)?;
1155-
Ok((protected, message_param, is_dc_message))
1152+
Ok((message_param, is_dc_message))
11561153
},
11571154
|rows| {
11581155
let mut chats = ChatNumbers::default();
11591156
for row in rows {
1160-
let (protected, message_param, is_dc_message) = row?;
1157+
let (message_param, is_dc_message) = row?;
11611158
let encrypted = message_param
11621159
.get_bool(Param::GuaranteeE2ee)
11631160
.unwrap_or(false);
11641161

1165-
if protected == ProtectionStatus::Protected {
1166-
chats.protected += 1;
1167-
} else if encrypted {
1162+
if encrypted {
11681163
if is_dc_message {
11691164
chats.opportunistic_dc += 1;
11701165
} else {
@@ -1180,7 +1175,6 @@ impl Context {
11801175
},
11811176
)
11821177
.await?;
1183-
res += &format!("chats_protected {}\n", chats.protected);
11841178
res += &format!("chats_opportunistic_dc {}\n", chats.opportunistic_dc);
11851179
res += &format!("chats_opportunistic_mua {}\n", chats.opportunistic_mua);
11861180
res += &format!("chats_unencrypted_dc {}\n", chats.unencrypted_dc);

src/receive_imf.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,7 @@ async fn get_to_and_past_contact_ids(
246246
let chat_id = match chat_assignment {
247247
ChatAssignment::Trash => None,
248248
ChatAssignment::GroupChat { grpid } => {
249-
if let Some((chat_id, _protected, _blocked)) =
250-
chat::get_chat_id_by_grpid(context, grpid).await?
251-
{
249+
if let Some((chat_id, _blocked)) = chat::get_chat_id_by_grpid(context, grpid).await? {
252250
Some(chat_id)
253251
} else {
254252
None
@@ -1340,9 +1338,7 @@ async fn do_chat_assignment(
13401338
}
13411339
ChatAssignment::GroupChat { grpid } => {
13421340
// Try to assign to a chat based on Chat-Group-ID.
1343-
if let Some((id, _protected, blocked)) =
1344-
chat::get_chat_id_by_grpid(context, grpid).await?
1345-
{
1341+
if let Some((id, blocked)) = chat::get_chat_id_by_grpid(context, grpid).await? {
13461342
chat_id = Some(id);
13471343
chat_id_blocked = blocked;
13481344
} else if allow_creation || test_normal_chat.is_some() {
@@ -1471,9 +1467,7 @@ async fn do_chat_assignment(
14711467
chat_id = Some(DC_CHAT_ID_TRASH);
14721468
}
14731469
ChatAssignment::GroupChat { grpid } => {
1474-
if let Some((id, _protected, blocked)) =
1475-
chat::get_chat_id_by_grpid(context, grpid).await?
1476-
{
1470+
if let Some((id, blocked)) = chat::get_chat_id_by_grpid(context, grpid).await? {
14771471
chat_id = Some(id);
14781472
chat_id_blocked = blocked;
14791473
} else if allow_creation {
@@ -1540,7 +1534,7 @@ async fn do_chat_assignment(
15401534
if chat_id.is_none() && allow_creation {
15411535
let to_contact = Contact::get_by_id(context, to_id).await?;
15421536
if let Some(list_id) = to_contact.param.get(Param::ListId) {
1543-
if let Some((id, _, blocked)) =
1537+
if let Some((id, blocked)) =
15441538
chat::get_chat_id_by_grpid(context, list_id).await?
15451539
{
15461540
chat_id = Some(id);
@@ -3146,7 +3140,7 @@ async fn create_or_lookup_mailinglist_or_broadcast(
31463140
) -> Result<Option<(ChatId, Blocked)>> {
31473141
let listid = mailinglist_header_listid(list_id_header)?;
31483142

3149-
if let Some((chat_id, _, blocked)) = chat::get_chat_id_by_grpid(context, &listid).await? {
3143+
if let Some((chat_id, blocked)) = chat::get_chat_id_by_grpid(context, &listid).await? {
31503144
return Ok(Some((chat_id, blocked)));
31513145
}
31523146

src/receive_imf/receive_imf_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ async fn test_other_device_writes_to_mailinglist() -> Result<()> {
10001000
chat::get_chat_id_by_grpid(&t, "delta.codespeak.net")
10011001
.await?
10021002
.unwrap(),
1003-
(first_chat.id, false, Blocked::Request)
1003+
(first_chat.id, Blocked::Request)
10041004
);
10051005

10061006
receive_imf(

src/securejoin/bob.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ async fn joining_chat_id(
327327
QrInvite::Contact { .. } => Ok(alice_chat_id),
328328
QrInvite::Group { grpid, name, .. } => {
329329
let group_chat_id = match chat::get_chat_id_by_grpid(context, grpid).await? {
330-
Some((chat_id, _protected, _blocked)) => {
330+
Some((chat_id, _blocked)) => {
331331
chat_id.unblock_ex(context, Nosync).await?;
332332
chat_id
333333
}

0 commit comments

Comments
 (0)