Skip to content

Commit f7f8ea8

Browse files
committed
refactor: remove ProtectionStatus
1 parent 859725e commit f7f8ea8

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.
@@ -1373,9 +1337,6 @@ pub struct Chat {
13731337

13741338
/// Duration of the chat being muted.
13751339
pub mute_duration: MuteDuration,
1376-
1377-
/// If the chat is protected (verified).
1378-
pub(crate) protected: ProtectionStatus,
13791340
}
13801341

13811342
impl Chat {
@@ -1385,7 +1346,7 @@ impl Chat {
13851346
.sql
13861347
.query_row(
13871348
"SELECT c.type, c.name, c.grpid, c.param, c.archived,
1388-
c.blocked, c.locations_send_until, c.muted_until, c.protected
1349+
c.blocked, c.locations_send_until, c.muted_until
13891350
FROM chats c
13901351
WHERE c.id=?;",
13911352
(chat_id,),
@@ -1400,7 +1361,6 @@ impl Chat {
14001361
blocked: row.get::<_, Option<_>>(5)?.unwrap_or_default(),
14011362
is_sending_locations: row.get(6)?,
14021363
mute_duration: row.get(7)?,
1403-
protected: row.get(8)?,
14041364
};
14051365
Ok(c)
14061366
},
@@ -2423,27 +2383,21 @@ impl ChatIdBlocked {
24232383
_ => (),
24242384
}
24252385

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

24292388
let chat_id = context
24302389
.sql
24312390
.transaction(move |transaction| {
24322391
transaction.execute(
24332392
"INSERT INTO chats
2434-
(type, name, param, blocked, created_timestamp, protected)
2435-
VALUES(?, ?, ?, ?, ?, ?)",
2393+
(type, name, param, blocked, created_timestamp)
2394+
VALUES(?, ?, ?, ?, ?)",
24362395
(
24372396
Chattype::Single,
24382397
chat_name,
24392398
params.to_string(),
24402399
create_blocked as u8,
24412400
smeared_time,
2442-
if protected {
2443-
ProtectionStatus::Protected
2444-
} else {
2445-
ProtectionStatus::Unprotected
2446-
},
24472401
),
24482402
)?;
24492403
let chat_id = ChatId::new(
@@ -4404,24 +4358,21 @@ pub(crate) async fn get_chat_cnt(context: &Context) -> Result<usize> {
44044358
}
44054359
}
44064360

4407-
/// Returns a tuple of `(chatid, is_protected, blocked)`.
4361+
/// Returns a tuple of `(chatid, blocked)`.
44084362
pub(crate) async fn get_chat_id_by_grpid(
44094363
context: &Context,
44104364
grpid: &str,
4411-
) -> Result<Option<(ChatId, bool, Blocked)>> {
4365+
) -> Result<Option<(ChatId, Blocked)>> {
44124366
context
44134367
.sql
44144368
.query_row_optional(
4415-
"SELECT id, blocked, protected FROM chats WHERE grpid=?;",
4369+
"SELECT id, blocked FROM chats WHERE grpid=?;",
44164370
(grpid,),
44174371
|row| {
44184372
let chat_id = row.get::<_, ChatId>(0)?;
44194373

44204374
let b = row.get::<_, Option<Blocked>>(1)?.unwrap_or_default();
4421-
let p = row
4422-
.get::<_, Option<ProtectionStatus>>(2)?
4423-
.unwrap_or_default();
4424-
Ok((chat_id, p == ProtectionStatus::Protected, b))
4375+
Ok((chat_id, b))
44254376
},
44264377
)
44274378
.await

src/contact.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,9 +1790,7 @@ WHERE type=? AND id IN (
17901790
// also unblock mailinglist
17911791
// if the contact is a mailinglist address explicitly created to allow unblocking
17921792
if !new_blocking && contact.origin == Origin::MailinglistAddress {
1793-
if let Some((chat_id, _, _)) =
1794-
chat::get_chat_id_by_grpid(context, &contact.addr).await?
1795-
{
1793+
if let Some((chat_id, ..)) = chat::get_chat_id_by_grpid(context, &contact.addr).await? {
17961794
chat_id.unblock_ex(context, Nosync).await?;
17971795
}
17981796
}

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::{
@@ -1089,7 +1089,6 @@ impl Context {
10891089
async fn get_self_report(&self) -> Result<String> {
10901090
#[derive(Default)]
10911091
struct ChatNumbers {
1092-
protected: u32,
10931092
opportunistic_dc: u32,
10941093
opportunistic_mua: u32,
10951094
unencrypted_dc: u32,
@@ -1124,7 +1123,6 @@ impl Context {
11241123
res += &format!("key_created {key_created}\n");
11251124

11261125
// how many of the chats active in the last months are:
1127-
// - protected
11281126
// - opportunistic-encrypted and the contact uses Delta Chat
11291127
// - opportunistic-encrypted and the contact uses a classical MUA
11301128
// - unencrypted and the contact uses Delta Chat
@@ -1133,7 +1131,7 @@ impl Context {
11331131
let chats = self
11341132
.sql
11351133
.query_map(
1136-
"SELECT c.protected, m.param, m.msgrmsg
1134+
"SELECT m.param, m.msgrmsg
11371135
FROM chats c
11381136
JOIN msgs m
11391137
ON c.id=m.chat_id
@@ -1151,23 +1149,20 @@ impl Context {
11511149
GROUP BY c.id",
11521150
(DownloadState::Done, ContactId::INFO, three_months_ago),
11531151
|row| {
1154-
let protected: ProtectionStatus = row.get(0)?;
11551152
let message_param: Params =
11561153
row.get::<_, String>(1)?.parse().unwrap_or_default();
11571154
let is_dc_message: bool = row.get(2)?;
1158-
Ok((protected, message_param, is_dc_message))
1155+
Ok((message_param, is_dc_message))
11591156
},
11601157
|rows| {
11611158
let mut chats = ChatNumbers::default();
11621159
for row in rows {
1163-
let (protected, message_param, is_dc_message) = row?;
1160+
let (message_param, is_dc_message) = row?;
11641161
let encrypted = message_param
11651162
.get_bool(Param::GuaranteeE2ee)
11661163
.unwrap_or(false);
11671164

1168-
if protected == ProtectionStatus::Protected {
1169-
chats.protected += 1;
1170-
} else if encrypted {
1165+
if encrypted {
11711166
if is_dc_message {
11721167
chats.opportunistic_dc += 1;
11731168
} else {
@@ -1183,7 +1178,6 @@ impl Context {
11831178
},
11841179
)
11851180
.await?;
1186-
res += &format!("chats_protected {}\n", chats.protected);
11871181
res += &format!("chats_opportunistic_dc {}\n", chats.opportunistic_dc);
11881182
res += &format!("chats_opportunistic_mua {}\n", chats.opportunistic_mua);
11891183
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
@@ -1357,9 +1355,7 @@ async fn do_chat_assignment(
13571355
}
13581356
ChatAssignment::GroupChat { grpid } => {
13591357
// Try to assign to a chat based on Chat-Group-ID.
1360-
if let Some((id, _protected, blocked)) =
1361-
chat::get_chat_id_by_grpid(context, grpid).await?
1362-
{
1358+
if let Some((id, blocked)) = chat::get_chat_id_by_grpid(context, grpid).await? {
13631359
chat_id = Some(id);
13641360
chat_id_blocked = blocked;
13651361
} else if allow_creation || test_normal_chat.is_some() {
@@ -1488,9 +1484,7 @@ async fn do_chat_assignment(
14881484
chat_id = Some(DC_CHAT_ID_TRASH);
14891485
}
14901486
ChatAssignment::GroupChat { grpid } => {
1491-
if let Some((id, _protected, blocked)) =
1492-
chat::get_chat_id_by_grpid(context, grpid).await?
1493-
{
1487+
if let Some((id, blocked)) = chat::get_chat_id_by_grpid(context, grpid).await? {
14941488
chat_id = Some(id);
14951489
chat_id_blocked = blocked;
14961490
} else if allow_creation {
@@ -1557,7 +1551,7 @@ async fn do_chat_assignment(
15571551
if chat_id.is_none() && allow_creation {
15581552
let to_contact = Contact::get_by_id(context, to_id).await?;
15591553
if let Some(list_id) = to_contact.param.get(Param::ListId) {
1560-
if let Some((id, _, blocked)) =
1554+
if let Some((id, blocked)) =
15611555
chat::get_chat_id_by_grpid(context, list_id).await?
15621556
{
15631557
chat_id = Some(id);
@@ -3189,7 +3183,7 @@ async fn create_or_lookup_mailinglist_or_broadcast(
31893183
) -> Result<Option<(ChatId, Blocked)>> {
31903184
let listid = mailinglist_header_listid(list_id_header)?;
31913185

3192-
if let Some((chat_id, _, blocked)) = chat::get_chat_id_by_grpid(context, &listid).await? {
3186+
if let Some((chat_id, blocked)) = chat::get_chat_id_by_grpid(context, &listid).await? {
31933187
return Ok(Some((chat_id, blocked)));
31943188
}
31953189

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)