Skip to content

Commit 4e956bd

Browse files
committed
refactor: remove ProtectionStatus
1 parent 38f6907 commit 4e956bd

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
},
@@ -2425,27 +2385,21 @@ impl ChatIdBlocked {
24252385
_ => (),
24262386
}
24272387

2428-
let protected = contact_id == ContactId::SELF || contact.is_verified(context).await?;
24292388
let smeared_time = create_smeared_timestamp(context);
24302389

24312390
let chat_id = context
24322391
.sql
24332392
.transaction(move |transaction| {
24342393
transaction.execute(
24352394
"INSERT INTO chats
2436-
(type, name, param, blocked, created_timestamp, protected)
2437-
VALUES(?, ?, ?, ?, ?, ?)",
2395+
(type, name, param, blocked, created_timestamp)
2396+
VALUES(?, ?, ?, ?, ?)",
24382397
(
24392398
Chattype::Single,
24402399
chat_name,
24412400
params.to_string(),
24422401
create_blocked as u8,
24432402
smeared_time,
2444-
if protected {
2445-
ProtectionStatus::Protected
2446-
} else {
2447-
ProtectionStatus::Unprotected
2448-
},
24492403
),
24502404
)?;
24512405
let chat_id = ChatId::new(
@@ -4421,24 +4375,21 @@ pub(crate) async fn get_chat_cnt(context: &Context) -> Result<usize> {
44214375
}
44224376
}
44234377

4424-
/// Returns a tuple of `(chatid, is_protected, blocked)`.
4378+
/// Returns a tuple of `(chatid, blocked)`.
44254379
pub(crate) async fn get_chat_id_by_grpid(
44264380
context: &Context,
44274381
grpid: &str,
4428-
) -> Result<Option<(ChatId, bool, Blocked)>> {
4382+
) -> Result<Option<(ChatId, Blocked)>> {
44294383
context
44304384
.sql
44314385
.query_row_optional(
4432-
"SELECT id, blocked, protected FROM chats WHERE grpid=?;",
4386+
"SELECT id, blocked FROM chats WHERE grpid=?;",
44334387
(grpid,),
44344388
|row| {
44354389
let chat_id = row.get::<_, ChatId>(0)?;
44364390

44374391
let b = row.get::<_, Option<Blocked>>(1)?.unwrap_or_default();
4438-
let p = row
4439-
.get::<_, Option<ProtectionStatus>>(2)?
4440-
.unwrap_or_default();
4441-
Ok((chat_id, p == ProtectionStatus::Protected, b))
4392+
Ok((chat_id, b))
44424393
},
44434394
)
44444395
.await

src/contact.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,9 +1783,7 @@ WHERE type=? AND id IN (
17831783
// also unblock mailinglist
17841784
// if the contact is a mailinglist address explicitly created to allow unblocking
17851785
if !new_blocking && contact.origin == Origin::MailinglistAddress {
1786-
if let Some((chat_id, _, _)) =
1787-
chat::get_chat_id_by_grpid(context, &contact.addr).await?
1788-
{
1786+
if let Some((chat_id, ..)) = chat::get_chat_id_by_grpid(context, &contact.addr).await? {
17891787
chat_id.unblock_ex(context, Nosync).await?;
17901788
}
17911789
}

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::{
@@ -1091,7 +1091,6 @@ impl Context {
10911091
async fn get_self_report(&self) -> Result<String> {
10921092
#[derive(Default)]
10931093
struct ChatNumbers {
1094-
protected: u32,
10951094
opportunistic_dc: u32,
10961095
opportunistic_mua: u32,
10971096
unencrypted_dc: u32,
@@ -1126,7 +1125,6 @@ impl Context {
11261125
res += &format!("key_created {key_created}\n");
11271126

11281127
// how many of the chats active in the last months are:
1129-
// - protected
11301128
// - opportunistic-encrypted and the contact uses Delta Chat
11311129
// - opportunistic-encrypted and the contact uses a classical MUA
11321130
// - unencrypted and the contact uses Delta Chat
@@ -1135,7 +1133,7 @@ impl Context {
11351133
let chats = self
11361134
.sql
11371135
.query_map(
1138-
"SELECT c.protected, m.param, m.msgrmsg
1136+
"SELECT m.param, m.msgrmsg
11391137
FROM chats c
11401138
JOIN msgs m
11411139
ON c.id=m.chat_id
@@ -1153,23 +1151,20 @@ impl Context {
11531151
GROUP BY c.id",
11541152
(DownloadState::Done, ContactId::INFO, three_months_ago),
11551153
|row| {
1156-
let protected: ProtectionStatus = row.get(0)?;
11571154
let message_param: Params =
11581155
row.get::<_, String>(1)?.parse().unwrap_or_default();
11591156
let is_dc_message: bool = row.get(2)?;
1160-
Ok((protected, message_param, is_dc_message))
1157+
Ok((message_param, is_dc_message))
11611158
},
11621159
|rows| {
11631160
let mut chats = ChatNumbers::default();
11641161
for row in rows {
1165-
let (protected, message_param, is_dc_message) = row?;
1162+
let (message_param, is_dc_message) = row?;
11661163
let encrypted = message_param
11671164
.get_bool(Param::GuaranteeE2ee)
11681165
.unwrap_or(false);
11691166

1170-
if protected == ProtectionStatus::Protected {
1171-
chats.protected += 1;
1172-
} else if encrypted {
1167+
if encrypted {
11731168
if is_dc_message {
11741169
chats.opportunistic_dc += 1;
11751170
} else {
@@ -1185,7 +1180,6 @@ impl Context {
11851180
},
11861181
)
11871182
.await?;
1188-
res += &format!("chats_protected {}\n", chats.protected);
11891183
res += &format!("chats_opportunistic_dc {}\n", chats.opportunistic_dc);
11901184
res += &format!("chats_opportunistic_mua {}\n", chats.opportunistic_mua);
11911185
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
@@ -1343,9 +1341,7 @@ async fn do_chat_assignment(
13431341
}
13441342
ChatAssignment::GroupChat { grpid } => {
13451343
// Try to assign to a chat based on Chat-Group-ID.
1346-
if let Some((id, _protected, blocked)) =
1347-
chat::get_chat_id_by_grpid(context, grpid).await?
1348-
{
1344+
if let Some((id, blocked)) = chat::get_chat_id_by_grpid(context, grpid).await? {
13491345
chat_id = Some(id);
13501346
chat_id_blocked = blocked;
13511347
} else if allow_creation || test_normal_chat.is_some() {
@@ -1474,9 +1470,7 @@ async fn do_chat_assignment(
14741470
chat_id = Some(DC_CHAT_ID_TRASH);
14751471
}
14761472
ChatAssignment::GroupChat { grpid } => {
1477-
if let Some((id, _protected, blocked)) =
1478-
chat::get_chat_id_by_grpid(context, grpid).await?
1479-
{
1473+
if let Some((id, blocked)) = chat::get_chat_id_by_grpid(context, grpid).await? {
14801474
chat_id = Some(id);
14811475
chat_id_blocked = blocked;
14821476
} else if allow_creation {
@@ -1543,7 +1537,7 @@ async fn do_chat_assignment(
15431537
if chat_id.is_none() && allow_creation {
15441538
let to_contact = Contact::get_by_id(context, to_id).await?;
15451539
if let Some(list_id) = to_contact.param.get(Param::ListId) {
1546-
if let Some((id, _, blocked)) =
1540+
if let Some((id, blocked)) =
15471541
chat::get_chat_id_by_grpid(context, list_id).await?
15481542
{
15491543
chat_id = Some(id);
@@ -3149,7 +3143,7 @@ async fn create_or_lookup_mailinglist_or_broadcast(
31493143
) -> Result<Option<(ChatId, Blocked)>> {
31503144
let listid = mailinglist_header_listid(list_id_header)?;
31513145

3152-
if let Some((chat_id, _, blocked)) = chat::get_chat_id_by_grpid(context, &listid).await? {
3146+
if let Some((chat_id, blocked)) = chat::get_chat_id_by_grpid(context, &listid).await? {
31533147
return Ok(Some((chat_id, blocked)));
31543148
}
31553149

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)