Skip to content

Commit 38f6907

Browse files
committed
api!: remove Chat.is_protected()
1 parent 2a51117 commit 38f6907

16 files changed

+54
-178
lines changed

deltachat-repl/src/cmdline.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
566566
for i in (0..cnt).rev() {
567567
let chat = Chat::load_from_db(&context, chatlist.get_chat_id(i)?).await?;
568568
println!(
569-
"{}#{}: {} [{} fresh] {}{}{}{}",
569+
"{}#{}: {} [{} fresh] {}{}{}",
570570
chat_prefix(&chat),
571571
chat.get_id(),
572572
chat.get_name(),
@@ -577,7 +577,6 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
577577
ChatVisibility::Archived => "📦",
578578
ChatVisibility::Pinned => "📌",
579579
},
580-
if chat.is_protected() { "🛡️" } else { "" },
581580
if chat.is_contact_request() {
582581
"🆕"
583582
} else {
@@ -692,7 +691,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
692691
format!("{} member(s)", members.len())
693692
};
694693
println!(
695-
"{}#{}: {} [{}]{}{}{} {}",
694+
"{}#{}: {} [{}]{}{}{}",
696695
chat_prefix(sel_chat),
697696
sel_chat.get_id(),
698697
sel_chat.get_name(),
@@ -710,11 +709,6 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
710709
},
711710
_ => "".to_string(),
712711
},
713-
if sel_chat.is_protected() {
714-
"🛡️"
715-
} else {
716-
""
717-
},
718712
);
719713
log_msglist(&context, &msglist).await?;
720714
if let Some(draft) = sel_chat.get_id().get_draft(&context).await? {

src/chat.rs

Lines changed: 25 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,16 +1221,6 @@ impl ChatId {
12211221
Ok(())
12221222
}
12231223

1224-
/// Returns true if the chat is protected.
1225-
pub(crate) async fn is_protected(self, context: &Context) -> Result<ProtectionStatus> {
1226-
let protection_status = context
1227-
.sql
1228-
.query_get_value("SELECT protected FROM chats WHERE id=?", (self,))
1229-
.await?
1230-
.unwrap_or_default();
1231-
Ok(protection_status)
1232-
}
1233-
12341224
/// Returns the sort timestamp for a new message in the chat.
12351225
///
12361226
/// `message_timestamp` should be either the message "sent" timestamp or a timestamp of the
@@ -1693,53 +1683,38 @@ impl Chat {
16931683
!self.is_unpromoted()
16941684
}
16951685

1696-
/// Returns true if chat protection is enabled.
1697-
///
1698-
/// UI should display a green checkmark
1699-
/// in the chat title,
1700-
/// in the chat profile title and
1701-
/// in the chatlist item
1702-
/// if chat protection is enabled.
1703-
/// UI should also display a green checkmark
1704-
/// in the contact profile
1705-
/// if 1:1 chat with this contact exists and is protected.
1706-
pub fn is_protected(&self) -> bool {
1707-
self.protected == ProtectionStatus::Protected
1708-
}
1709-
17101686
/// Returns true if the chat is encrypted.
17111687
pub async fn is_encrypted(&self, context: &Context) -> Result<bool> {
1712-
let is_encrypted = self.is_protected()
1713-
|| match self.typ {
1714-
Chattype::Single => {
1715-
match context
1716-
.sql
1717-
.query_row_optional(
1718-
"SELECT cc.contact_id, c.fingerprint<>''
1688+
let is_encrypted = match self.typ {
1689+
Chattype::Single => {
1690+
match context
1691+
.sql
1692+
.query_row_optional(
1693+
"SELECT cc.contact_id, c.fingerprint<>''
17191694
FROM chats_contacts cc LEFT JOIN contacts c
17201695
ON c.id=cc.contact_id
17211696
WHERE cc.chat_id=?
17221697
",
1723-
(self.id,),
1724-
|row| {
1725-
let id: ContactId = row.get(0)?;
1726-
let is_key: bool = row.get(1)?;
1727-
Ok((id, is_key))
1728-
},
1729-
)
1730-
.await?
1731-
{
1732-
Some((id, is_key)) => is_key || id == ContactId::DEVICE,
1733-
None => true,
1734-
}
1735-
}
1736-
Chattype::Group => {
1737-
// Do not encrypt ad-hoc groups.
1738-
!self.grpid.is_empty()
1698+
(self.id,),
1699+
|row| {
1700+
let id: ContactId = row.get(0)?;
1701+
let is_key: bool = row.get(1)?;
1702+
Ok((id, is_key))
1703+
},
1704+
)
1705+
.await?
1706+
{
1707+
Some((id, is_key)) => is_key || id == ContactId::DEVICE,
1708+
None => true,
17391709
}
1740-
Chattype::Mailinglist => false,
1741-
Chattype::OutBroadcast | Chattype::InBroadcast => true,
1742-
};
1710+
}
1711+
Chattype::Group => {
1712+
// Do not encrypt ad-hoc groups.
1713+
!self.grpid.is_empty()
1714+
}
1715+
Chattype::Mailinglist => false,
1716+
Chattype::OutBroadcast | Chattype::InBroadcast => true,
1717+
};
17431718
Ok(is_encrypted)
17441719
}
17451720

@@ -3796,13 +3771,6 @@ pub(crate) async fn add_contact_to_chat_ex(
37963771
}
37973772
} else {
37983773
// else continue and send status mail
3799-
if chat.is_protected() && !contact.is_verified(context).await? {
3800-
error!(
3801-
context,
3802-
"Cannot add non-bidirectionally verified contact {contact_id} to protected chat {chat_id}."
3803-
);
3804-
return Ok(false);
3805-
}
38063774
if is_contact_in_chat(context, chat_id, contact_id).await? {
38073775
return Ok(false);
38083776
}

src/contact/contact_tests.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use deltachat_contact_tools::{addr_cmp, may_be_valid_addr};
22

33
use super::*;
4-
use crate::chat::{Chat, ProtectionStatus, get_chat_contacts, send_text_msg};
4+
use crate::chat::{Chat, get_chat_contacts, send_text_msg};
55
use crate::chatlist::Chatlist;
66
use crate::receive_imf::receive_imf;
77
use crate::test_utils::{self, TestContext, TestContextManager, TimeShiftFalsePositiveNote};
@@ -1295,22 +1295,6 @@ async fn test_import_vcard_key_change() -> Result<()> {
12951295
Ok(())
12961296
}
12971297

1298-
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
1299-
async fn test_self_is_verified() -> Result<()> {
1300-
let mut tcm = TestContextManager::new();
1301-
let alice = tcm.alice().await;
1302-
1303-
let contact = Contact::get_by_id(&alice, ContactId::SELF).await?;
1304-
assert_eq!(contact.is_verified(&alice).await?, true);
1305-
assert!(contact.get_verifier_id(&alice).await?.is_none());
1306-
assert!(contact.is_key_contact());
1307-
1308-
let chat_id = ChatId::get_for_contact(&alice, ContactId::SELF).await?;
1309-
assert!(chat_id.is_protected(&alice).await.unwrap() == ProtectionStatus::Protected);
1310-
1311-
Ok(())
1312-
}
1313-
13141298
/// Tests that importing a vCard with a key creates a key-contact.
13151299
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
13161300
async fn test_vcard_creates_key_contact() -> Result<()> {

src/context/context_tests.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -606,13 +606,10 @@ async fn test_draft_self_report() -> Result<()> {
606606
let msg = get_chat_msg(&alice, chat_id, 0, 1).await;
607607
assert_eq!(msg.get_info_type(), SystemMessage::ChatE2ee);
608608

609-
let chat = Chat::load_from_db(&alice, chat_id).await?;
610-
assert!(chat.is_protected());
611-
612609
let mut draft = chat_id.get_draft(&alice).await?.unwrap();
613610
assert!(draft.text.starts_with("core_version"));
614611

615-
// Test that sending into the protected chat works:
612+
// Test that sending into the chat works:
616613
let _sent = alice.send_msg(chat_id, &mut draft).await;
617614

618615
Ok(())

src/mimefactory.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,20 +1334,6 @@ impl MimeFactory {
13341334
let command = msg.param.get_cmd();
13351335
let mut placeholdertext = None;
13361336

1337-
let send_verified_headers = match chat.typ {
1338-
Chattype::Single => true,
1339-
Chattype::Group => true,
1340-
// Mailinglists and broadcast channels can actually never be verified:
1341-
Chattype::Mailinglist => false,
1342-
Chattype::OutBroadcast | Chattype::InBroadcast => false,
1343-
};
1344-
if chat.is_protected() && send_verified_headers {
1345-
headers.push((
1346-
"Chat-Verified",
1347-
mail_builder::headers::raw::Raw::new("1").into(),
1348-
));
1349-
}
1350-
13511337
if chat.typ == Chattype::Group {
13521338
// Send group ID unless it is an ad hoc group that has no ID.
13531339
if !chat.grpid.is_empty() {

src/securejoin/bob.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use anyhow::{Context as _, Result};
44

55
use super::HandshakeMessage;
66
use super::qrinvite::QrInvite;
7-
use crate::chat::{self, ChatId, ProtectionStatus, is_contact_in_chat};
7+
use crate::chat::{self, ChatId, is_contact_in_chat};
88
use crate::constants::{Blocked, Chattype};
99
use crate::contact::Origin;
1010
use crate::context::Context;
@@ -113,21 +113,19 @@ pub(super) async fn start_protocol(context: &Context, invite: QrInvite) -> Resul
113113
let ts_sort = chat_id
114114
.calc_sort_timestamp(context, 0, sort_to_bottom, received, incoming)
115115
.await?;
116-
if chat_id.is_protected(context).await? == ProtectionStatus::Unprotected {
117-
let ts_start = time();
118-
chat::add_info_msg_with_cmd(
119-
context,
120-
chat_id,
121-
&stock_str::securejoin_wait(context).await,
122-
SystemMessage::SecurejoinWait,
123-
ts_sort,
124-
Some(ts_start),
125-
None,
126-
None,
127-
None,
128-
)
129-
.await?;
130-
}
116+
let ts_start = time();
117+
chat::add_info_msg_with_cmd(
118+
context,
119+
chat_id,
120+
&stock_str::securejoin_wait(context).await,
121+
SystemMessage::SecurejoinWait,
122+
ts_sort,
123+
Some(ts_start),
124+
None,
125+
None,
126+
None,
127+
)
128+
.await?;
131129
Ok(chat_id)
132130
}
133131
}

src/test_utils.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ impl TestContext {
10061006
};
10071007
writeln!(
10081008
res,
1009-
"{}#{}: {} [{}]{}{}{} {}",
1009+
"{}#{}: {} [{}]{}{}{}",
10101010
sel_chat.typ,
10111011
sel_chat.get_id(),
10121012
sel_chat.get_name(),
@@ -1024,11 +1024,6 @@ impl TestContext {
10241024
},
10251025
_ => "".to_string(),
10261026
},
1027-
if sel_chat.is_protected() {
1028-
"🛡️"
1029-
} else {
1030-
""
1031-
},
10321027
)
10331028
.unwrap();
10341029

src/tests/verified_chats.rs

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,12 @@ async fn test_create_verified_oneonone_chat() -> Result<()> {
132132
tcm.send_recv(&fiona_new, &alice, "I have a new device")
133133
.await;
134134

135-
// Alice gets a new unprotected chat with new Fiona contact.
135+
// Alice gets a new chat with new Fiona contact.
136136
{
137137
let chat = alice.get_chat(&fiona_new).await;
138-
assert!(!chat.is_protected());
139138

140139
let msg = get_chat_msg(&alice, chat.id, 1, E2EE_INFO_MSGS + 1).await;
141140
assert_eq!(msg.text, "I have a new device");
142-
143-
// After recreating the chat, it should still be unprotected
144-
chat.id.delete(&alice).await?;
145-
146-
let chat = alice.create_chat(&fiona_new).await;
147-
assert!(!chat.is_protected());
148141
}
149142

150143
Ok(())
@@ -179,42 +172,6 @@ async fn test_missing_key_reexecute_securejoin() -> Result<()> {
179172
Ok(())
180173
}
181174

182-
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
183-
async fn test_create_unverified_oneonone_chat() -> Result<()> {
184-
let mut tcm = TestContextManager::new();
185-
let alice = tcm.alice().await;
186-
let bob = tcm.bob().await;
187-
enable_verified_oneonone_chats(&[&alice, &bob]).await;
188-
189-
// A chat with an unknown contact should be created unprotected
190-
let chat = alice.create_chat(&bob).await;
191-
assert!(!chat.is_protected());
192-
193-
receive_imf(
194-
&alice,
195-
b"From: Bob <[email protected]>\n\
196-
197-
Message-ID: <[email protected]>\n\
198-
\n\
199-
hello\n",
200-
false,
201-
)
202-
.await?;
203-
204-
chat.id.delete(&alice).await.unwrap();
205-
// Now Bob is a known contact, new chats should still be created unprotected
206-
let chat = alice.create_chat(&bob).await;
207-
assert!(!chat.is_protected());
208-
209-
tcm.send_recv(&bob, &alice, "hi").await;
210-
chat.id.delete(&alice).await.unwrap();
211-
// Now we have a public key, new chats should still be created unprotected
212-
let chat = alice.create_chat(&bob).await;
213-
assert!(!chat.is_protected());
214-
215-
Ok(())
216-
}
217-
218175
/// Tests that receiving unencrypted message
219176
/// does not disable protection of 1:1 chat.
220177
///
@@ -229,7 +186,6 @@ async fn test_degrade_verified_oneonone_chat() -> Result<()> {
229186
mark_as_verified(&alice, &bob).await;
230187

231188
let alice_chat = alice.create_chat(&bob).await;
232-
assert!(alice_chat.is_protected());
233189

234190
receive_imf(
235191
&alice,
@@ -496,8 +452,6 @@ async fn test_message_from_old_dc_setup() -> Result<()> {
496452
// The outdated Bob's Autocrypt header isn't applied
497453
// and the message goes to another chat, so the verification preserves.
498454
assert!(contact.is_verified(alice).await.unwrap());
499-
let chat = alice.get_chat(bob).await;
500-
assert!(chat.is_protected());
501455
Ok(())
502456
}
503457

@@ -602,9 +556,9 @@ async fn test_verified_member_added_reordering() -> Result<()> {
602556
// "Member added" message, so unverified group is created.
603557
let fiona_received_message = fiona.recv_msg(&bob_sent_message).await;
604558
let fiona_chat = Chat::load_from_db(fiona, fiona_received_message.chat_id).await?;
559+
assert!(!fiona_chat.can_send(fiona).await?);
605560

606561
assert_eq!(fiona_received_message.get_text(), "Hi");
607-
assert_eq!(fiona_chat.is_protected(), false);
608562

609563
// Fiona receives late "Member added" message
610564
// and the chat becomes protected.

test-data/golden/chat_test_parallel_member_remove

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Group#Chat#10: Group chat [3 member(s)]
1+
Group#Chat#10: Group chat [3 member(s)]
22
--------------------------------------------------------------------------------
33
Msg#10: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO]
44
Msg#11🔒: (Contact#Contact#10): Hi! I created a group. [FRESH]

test-data/golden/receive_imf_delayed_removal_is_ignored

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Group#Chat#10: Group [5 member(s)]
1+
Group#Chat#10: Group [5 member(s)]
22
--------------------------------------------------------------------------------
33
Msg#10: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO]
44
Msg#11🔒: Me (Contact#Contact#Self): populate √

0 commit comments

Comments
 (0)