Skip to content

Commit c248c82

Browse files
committed
api!: remove Chat.is_protected()
1 parent 73e55d3 commit c248c82

16 files changed

+54
-164
lines changed

deltachat-repl/src/cmdline.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
560560
for i in (0..cnt).rev() {
561561
let chat = Chat::load_from_db(&context, chatlist.get_chat_id(i)?).await?;
562562
println!(
563-
"{}#{}: {} [{} fresh] {}{}{}{}",
563+
"{}#{}: {} [{} fresh] {}{}{}",
564564
chat_prefix(&chat),
565565
chat.get_id(),
566566
chat.get_name(),
@@ -571,7 +571,6 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
571571
ChatVisibility::Archived => "📦",
572572
ChatVisibility::Pinned => "📌",
573573
},
574-
if chat.is_protected() { "🛡️" } else { "" },
575574
if chat.is_contact_request() {
576575
"🆕"
577576
} else {
@@ -686,7 +685,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
686685
format!("{} member(s)", members.len())
687686
};
688687
println!(
689-
"{}#{}: {} [{}]{}{}{} {}",
688+
"{}#{}: {} [{}]{}{}{}",
690689
chat_prefix(sel_chat),
691690
sel_chat.get_id(),
692691
sel_chat.get_name(),
@@ -704,11 +703,6 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
704703
},
705704
_ => "".to_string(),
706705
},
707-
if sel_chat.is_protected() {
708-
"🛡️"
709-
} else {
710-
""
711-
},
712706
);
713707
log_msglist(&context, &msglist).await?;
714708
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
@@ -1219,16 +1219,6 @@ impl ChatId {
12191219
Ok(())
12201220
}
12211221

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

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

@@ -3770,13 +3745,6 @@ pub(crate) async fn add_contact_to_chat_ex(
37703745
}
37713746
} else {
37723747
// else continue and send status mail
3773-
if chat.is_protected() && !contact.is_verified(context).await? {
3774-
error!(
3775-
context,
3776-
"Cannot add non-bidirectionally verified contact {contact_id} to protected chat {chat_id}."
3777-
);
3778-
return Ok(false);
3779-
}
37803748
if is_contact_in_chat(context, chat_id, contact_id).await? {
37813749
return Ok(false);
37823750
}

src/contact/contact_tests.rs

Lines changed: 1 addition & 4 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::securejoin::get_securejoin_qr;
@@ -1320,9 +1320,6 @@ async fn test_self_is_verified() -> Result<()> {
13201320
assert!(contact.get_verifier_id(&alice).await?.is_none());
13211321
assert!(contact.is_key_contact());
13221322

1323-
let chat_id = ChatId::get_for_contact(&alice, ContactId::SELF).await?;
1324-
assert!(chat_id.is_protected(&alice).await.unwrap() == ProtectionStatus::Protected);
1325-
13261323
Ok(())
13271324
}
13281325

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
@@ -1331,20 +1331,6 @@ impl MimeFactory {
13311331
let command = msg.param.get_cmd();
13321332
let mut placeholdertext = None;
13331333

1334-
let send_verified_headers = match chat.typ {
1335-
Chattype::Single => true,
1336-
Chattype::Group => true,
1337-
// Mailinglists and broadcast channels can actually never be verified:
1338-
Chattype::Mailinglist => false,
1339-
Chattype::OutBroadcast | Chattype::InBroadcast => false,
1340-
};
1341-
if chat.is_protected() && send_verified_headers {
1342-
headers.push((
1343-
"Chat-Verified",
1344-
mail_builder::headers::raw::Raw::new("1").into(),
1345-
));
1346-
}
1347-
13481334
if chat.typ == Chattype::Group {
13491335
// Send group ID unless it is an ad hoc group that has no ID.
13501336
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
@@ -1013,7 +1013,7 @@ impl TestContext {
10131013
};
10141014
writeln!(
10151015
res,
1016-
"{}#{}: {} [{}]{}{}{} {}",
1016+
"{}#{}: {} [{}]{}{}{}",
10171017
sel_chat.typ,
10181018
sel_chat.get_id(),
10191019
sel_chat.get_name(),
@@ -1031,11 +1031,6 @@ impl TestContext {
10311031
},
10321032
_ => "".to_string(),
10331033
},
1034-
if sel_chat.is_protected() {
1035-
"🛡️"
1036-
} else {
1037-
""
1038-
},
10391034
)
10401035
.unwrap();
10411036

src/tests/verified_chats.rs

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

132-
// Alice gets a new unprotected chat with new Fiona contact.
132+
// Alice gets a new chat with new Fiona contact.
133133
{
134134
let chat = alice.get_chat(&fiona_new).await;
135-
assert!(!chat.is_protected());
136135

137136
let msg = get_chat_msg(&alice, chat.id, 1, E2EE_INFO_MSGS + 1).await;
138137
assert_eq!(msg.text, "I have a new device");
139-
140-
// After recreating the chat, it should still be unprotected
141-
chat.id.delete(&alice).await?;
142-
143-
let chat = alice.create_chat(&fiona_new).await;
144-
assert!(!chat.is_protected());
145138
}
146139

147140
Ok(())
@@ -175,41 +168,6 @@ async fn test_missing_key_reexecute_securejoin() -> Result<()> {
175168
Ok(())
176169
}
177170

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

225183
let alice_chat = alice.create_chat(&bob).await;
226-
assert!(alice_chat.is_protected());
227184

228185
receive_imf(
229186
&alice,
@@ -484,8 +441,6 @@ async fn test_message_from_old_dc_setup() -> Result<()> {
484441
// The outdated Bob's Autocrypt header isn't applied
485442
// and the message goes to another chat, so the verification preserves.
486443
assert!(contact.is_verified(alice).await.unwrap());
487-
let chat = alice.get_chat(bob).await;
488-
assert!(chat.is_protected());
489444
Ok(())
490445
}
491446

@@ -587,9 +542,9 @@ async fn test_verified_member_added_reordering() -> Result<()> {
587542
// "Member added" message, so unverified group is created.
588543
let fiona_received_message = fiona.recv_msg(&bob_sent_message).await;
589544
let fiona_chat = Chat::load_from_db(fiona, fiona_received_message.chat_id).await?;
545+
assert!(!fiona_chat.can_send(fiona).await?);
590546

591547
assert_eq!(fiona_received_message.get_text(), "Hi");
592-
assert_eq!(fiona_chat.is_protected(), false);
593548

594549
// Fiona receives late "Member added" message
595550
// 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)