mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
refactor: remove ProtectionStatus
This commit is contained in:
63
src/chat.rs
63
src/chat.rs
@@ -12,7 +12,6 @@ use std::time::Duration;
|
|||||||
use anyhow::{Context as _, Result, anyhow, bail, ensure};
|
use anyhow::{Context as _, Result, anyhow, bail, ensure};
|
||||||
use chrono::TimeZone;
|
use chrono::TimeZone;
|
||||||
use deltachat_contact_tools::{ContactAddress, sanitize_bidi_characters, sanitize_single_line};
|
use deltachat_contact_tools::{ContactAddress, sanitize_bidi_characters, sanitize_single_line};
|
||||||
use deltachat_derive::{FromSql, ToSql};
|
|
||||||
use mail_builder::mime::MimePart;
|
use mail_builder::mime::MimePart;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum_macros::EnumIter;
|
use strum_macros::EnumIter;
|
||||||
@@ -67,41 +66,6 @@ pub enum ChatItem {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Chat protection status.
|
|
||||||
#[derive(
|
|
||||||
Debug,
|
|
||||||
Default,
|
|
||||||
Display,
|
|
||||||
Clone,
|
|
||||||
Copy,
|
|
||||||
PartialEq,
|
|
||||||
Eq,
|
|
||||||
FromPrimitive,
|
|
||||||
ToPrimitive,
|
|
||||||
FromSql,
|
|
||||||
ToSql,
|
|
||||||
IntoStaticStr,
|
|
||||||
Serialize,
|
|
||||||
Deserialize,
|
|
||||||
)]
|
|
||||||
#[repr(u32)]
|
|
||||||
pub enum ProtectionStatus {
|
|
||||||
/// Chat is not protected.
|
|
||||||
#[default]
|
|
||||||
Unprotected = 0,
|
|
||||||
|
|
||||||
/// Chat is protected.
|
|
||||||
///
|
|
||||||
/// All members of the chat must be verified.
|
|
||||||
Protected = 1,
|
|
||||||
// `2` was never used as a value.
|
|
||||||
|
|
||||||
// Chats don't break in Core v2 anymore. Chats with broken protection existing before the
|
|
||||||
// key-contacts migration are treated as `Unprotected`.
|
|
||||||
//
|
|
||||||
// ProtectionBroken = 3,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The reason why messages cannot be sent to the chat.
|
/// The reason why messages cannot be sent to the chat.
|
||||||
///
|
///
|
||||||
/// The reason is mainly for logging and displaying in debug REPL, thus not translated.
|
/// The reason is mainly for logging and displaying in debug REPL, thus not translated.
|
||||||
@@ -1373,9 +1337,6 @@ pub struct Chat {
|
|||||||
|
|
||||||
/// Duration of the chat being muted.
|
/// Duration of the chat being muted.
|
||||||
pub mute_duration: MuteDuration,
|
pub mute_duration: MuteDuration,
|
||||||
|
|
||||||
/// If the chat is protected (verified).
|
|
||||||
pub(crate) protected: ProtectionStatus,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Chat {
|
impl Chat {
|
||||||
@@ -1385,7 +1346,7 @@ impl Chat {
|
|||||||
.sql
|
.sql
|
||||||
.query_row(
|
.query_row(
|
||||||
"SELECT c.type, c.name, c.grpid, c.param, c.archived,
|
"SELECT c.type, c.name, c.grpid, c.param, c.archived,
|
||||||
c.blocked, c.locations_send_until, c.muted_until, c.protected
|
c.blocked, c.locations_send_until, c.muted_until
|
||||||
FROM chats c
|
FROM chats c
|
||||||
WHERE c.id=?;",
|
WHERE c.id=?;",
|
||||||
(chat_id,),
|
(chat_id,),
|
||||||
@@ -1400,7 +1361,6 @@ impl Chat {
|
|||||||
blocked: row.get::<_, Option<_>>(5)?.unwrap_or_default(),
|
blocked: row.get::<_, Option<_>>(5)?.unwrap_or_default(),
|
||||||
is_sending_locations: row.get(6)?,
|
is_sending_locations: row.get(6)?,
|
||||||
mute_duration: row.get(7)?,
|
mute_duration: row.get(7)?,
|
||||||
protected: row.get(8)?,
|
|
||||||
};
|
};
|
||||||
Ok(c)
|
Ok(c)
|
||||||
},
|
},
|
||||||
@@ -2423,7 +2383,6 @@ impl ChatIdBlocked {
|
|||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
let protected = contact_id == ContactId::SELF || contact.is_verified(context).await?;
|
|
||||||
let smeared_time = create_smeared_timestamp(context);
|
let smeared_time = create_smeared_timestamp(context);
|
||||||
|
|
||||||
let chat_id = context
|
let chat_id = context
|
||||||
@@ -2431,19 +2390,14 @@ impl ChatIdBlocked {
|
|||||||
.transaction(move |transaction| {
|
.transaction(move |transaction| {
|
||||||
transaction.execute(
|
transaction.execute(
|
||||||
"INSERT INTO chats
|
"INSERT INTO chats
|
||||||
(type, name, param, blocked, created_timestamp, protected)
|
(type, name, param, blocked, created_timestamp)
|
||||||
VALUES(?, ?, ?, ?, ?, ?)",
|
VALUES(?, ?, ?, ?, ?)",
|
||||||
(
|
(
|
||||||
Chattype::Single,
|
Chattype::Single,
|
||||||
chat_name,
|
chat_name,
|
||||||
params.to_string(),
|
params.to_string(),
|
||||||
create_blocked as u8,
|
create_blocked as u8,
|
||||||
smeared_time,
|
smeared_time,
|
||||||
if protected {
|
|
||||||
ProtectionStatus::Protected
|
|
||||||
} else {
|
|
||||||
ProtectionStatus::Unprotected
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
)?;
|
)?;
|
||||||
let chat_id = ChatId::new(
|
let chat_id = ChatId::new(
|
||||||
@@ -4404,24 +4358,21 @@ pub(crate) async fn get_chat_cnt(context: &Context) -> Result<usize> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a tuple of `(chatid, is_protected, blocked)`.
|
/// Returns a tuple of `(chatid, blocked)`.
|
||||||
pub(crate) async fn get_chat_id_by_grpid(
|
pub(crate) async fn get_chat_id_by_grpid(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
grpid: &str,
|
grpid: &str,
|
||||||
) -> Result<Option<(ChatId, bool, Blocked)>> {
|
) -> Result<Option<(ChatId, Blocked)>> {
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.query_row_optional(
|
.query_row_optional(
|
||||||
"SELECT id, blocked, protected FROM chats WHERE grpid=?;",
|
"SELECT id, blocked FROM chats WHERE grpid=?;",
|
||||||
(grpid,),
|
(grpid,),
|
||||||
|row| {
|
|row| {
|
||||||
let chat_id = row.get::<_, ChatId>(0)?;
|
let chat_id = row.get::<_, ChatId>(0)?;
|
||||||
|
|
||||||
let b = row.get::<_, Option<Blocked>>(1)?.unwrap_or_default();
|
let b = row.get::<_, Option<Blocked>>(1)?.unwrap_or_default();
|
||||||
let p = row
|
Ok((chat_id, b))
|
||||||
.get::<_, Option<ProtectionStatus>>(2)?
|
|
||||||
.unwrap_or_default();
|
|
||||||
Ok((chat_id, p == ProtectionStatus::Protected, b))
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -1790,9 +1790,7 @@ WHERE type=? AND id IN (
|
|||||||
// also unblock mailinglist
|
// also unblock mailinglist
|
||||||
// if the contact is a mailinglist address explicitly created to allow unblocking
|
// if the contact is a mailinglist address explicitly created to allow unblocking
|
||||||
if !new_blocking && contact.origin == Origin::MailinglistAddress {
|
if !new_blocking && contact.origin == Origin::MailinglistAddress {
|
||||||
if let Some((chat_id, _, _)) =
|
if let Some((chat_id, ..)) = chat::get_chat_id_by_grpid(context, &contact.addr).await? {
|
||||||
chat::get_chat_id_by_grpid(context, &contact.addr).await?
|
|
||||||
{
|
|
||||||
chat_id.unblock_ex(context, Nosync).await?;
|
chat_id.unblock_ex(context, Nosync).await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use pgp::types::PublicKeyTrait;
|
|||||||
use ratelimit::Ratelimit;
|
use ratelimit::Ratelimit;
|
||||||
use tokio::sync::{Mutex, Notify, RwLock};
|
use tokio::sync::{Mutex, Notify, RwLock};
|
||||||
|
|
||||||
use crate::chat::{ChatId, ProtectionStatus, get_chat_cnt};
|
use crate::chat::{ChatId, get_chat_cnt};
|
||||||
use crate::chatlist_events;
|
use crate::chatlist_events;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::constants::{
|
use crate::constants::{
|
||||||
@@ -1089,7 +1089,6 @@ impl Context {
|
|||||||
async fn get_self_report(&self) -> Result<String> {
|
async fn get_self_report(&self) -> Result<String> {
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct ChatNumbers {
|
struct ChatNumbers {
|
||||||
protected: u32,
|
|
||||||
opportunistic_dc: u32,
|
opportunistic_dc: u32,
|
||||||
opportunistic_mua: u32,
|
opportunistic_mua: u32,
|
||||||
unencrypted_dc: u32,
|
unencrypted_dc: u32,
|
||||||
@@ -1124,7 +1123,6 @@ impl Context {
|
|||||||
res += &format!("key_created {key_created}\n");
|
res += &format!("key_created {key_created}\n");
|
||||||
|
|
||||||
// how many of the chats active in the last months are:
|
// how many of the chats active in the last months are:
|
||||||
// - protected
|
|
||||||
// - opportunistic-encrypted and the contact uses Delta Chat
|
// - opportunistic-encrypted and the contact uses Delta Chat
|
||||||
// - opportunistic-encrypted and the contact uses a classical MUA
|
// - opportunistic-encrypted and the contact uses a classical MUA
|
||||||
// - unencrypted and the contact uses Delta Chat
|
// - unencrypted and the contact uses Delta Chat
|
||||||
@@ -1133,7 +1131,7 @@ impl Context {
|
|||||||
let chats = self
|
let chats = self
|
||||||
.sql
|
.sql
|
||||||
.query_map(
|
.query_map(
|
||||||
"SELECT c.protected, m.param, m.msgrmsg
|
"SELECT m.param, m.msgrmsg
|
||||||
FROM chats c
|
FROM chats c
|
||||||
JOIN msgs m
|
JOIN msgs m
|
||||||
ON c.id=m.chat_id
|
ON c.id=m.chat_id
|
||||||
@@ -1151,23 +1149,20 @@ impl Context {
|
|||||||
GROUP BY c.id",
|
GROUP BY c.id",
|
||||||
(DownloadState::Done, ContactId::INFO, three_months_ago),
|
(DownloadState::Done, ContactId::INFO, three_months_ago),
|
||||||
|row| {
|
|row| {
|
||||||
let protected: ProtectionStatus = row.get(0)?;
|
|
||||||
let message_param: Params =
|
let message_param: Params =
|
||||||
row.get::<_, String>(1)?.parse().unwrap_or_default();
|
row.get::<_, String>(1)?.parse().unwrap_or_default();
|
||||||
let is_dc_message: bool = row.get(2)?;
|
let is_dc_message: bool = row.get(2)?;
|
||||||
Ok((protected, message_param, is_dc_message))
|
Ok((message_param, is_dc_message))
|
||||||
},
|
},
|
||||||
|rows| {
|
|rows| {
|
||||||
let mut chats = ChatNumbers::default();
|
let mut chats = ChatNumbers::default();
|
||||||
for row in rows {
|
for row in rows {
|
||||||
let (protected, message_param, is_dc_message) = row?;
|
let (message_param, is_dc_message) = row?;
|
||||||
let encrypted = message_param
|
let encrypted = message_param
|
||||||
.get_bool(Param::GuaranteeE2ee)
|
.get_bool(Param::GuaranteeE2ee)
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
if protected == ProtectionStatus::Protected {
|
if encrypted {
|
||||||
chats.protected += 1;
|
|
||||||
} else if encrypted {
|
|
||||||
if is_dc_message {
|
if is_dc_message {
|
||||||
chats.opportunistic_dc += 1;
|
chats.opportunistic_dc += 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -1183,7 +1178,6 @@ impl Context {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
res += &format!("chats_protected {}\n", chats.protected);
|
|
||||||
res += &format!("chats_opportunistic_dc {}\n", chats.opportunistic_dc);
|
res += &format!("chats_opportunistic_dc {}\n", chats.opportunistic_dc);
|
||||||
res += &format!("chats_opportunistic_mua {}\n", chats.opportunistic_mua);
|
res += &format!("chats_opportunistic_mua {}\n", chats.opportunistic_mua);
|
||||||
res += &format!("chats_unencrypted_dc {}\n", chats.unencrypted_dc);
|
res += &format!("chats_unencrypted_dc {}\n", chats.unencrypted_dc);
|
||||||
|
|||||||
@@ -246,9 +246,7 @@ async fn get_to_and_past_contact_ids(
|
|||||||
let chat_id = match chat_assignment {
|
let chat_id = match chat_assignment {
|
||||||
ChatAssignment::Trash => None,
|
ChatAssignment::Trash => None,
|
||||||
ChatAssignment::GroupChat { grpid } => {
|
ChatAssignment::GroupChat { grpid } => {
|
||||||
if let Some((chat_id, _protected, _blocked)) =
|
if let Some((chat_id, _blocked)) = chat::get_chat_id_by_grpid(context, grpid).await? {
|
||||||
chat::get_chat_id_by_grpid(context, grpid).await?
|
|
||||||
{
|
|
||||||
Some(chat_id)
|
Some(chat_id)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -1357,9 +1355,7 @@ async fn do_chat_assignment(
|
|||||||
}
|
}
|
||||||
ChatAssignment::GroupChat { grpid } => {
|
ChatAssignment::GroupChat { grpid } => {
|
||||||
// Try to assign to a chat based on Chat-Group-ID.
|
// Try to assign to a chat based on Chat-Group-ID.
|
||||||
if let Some((id, _protected, blocked)) =
|
if let Some((id, blocked)) = chat::get_chat_id_by_grpid(context, grpid).await? {
|
||||||
chat::get_chat_id_by_grpid(context, grpid).await?
|
|
||||||
{
|
|
||||||
chat_id = Some(id);
|
chat_id = Some(id);
|
||||||
chat_id_blocked = blocked;
|
chat_id_blocked = blocked;
|
||||||
} else if allow_creation || test_normal_chat.is_some() {
|
} else if allow_creation || test_normal_chat.is_some() {
|
||||||
@@ -1488,9 +1484,7 @@ async fn do_chat_assignment(
|
|||||||
chat_id = Some(DC_CHAT_ID_TRASH);
|
chat_id = Some(DC_CHAT_ID_TRASH);
|
||||||
}
|
}
|
||||||
ChatAssignment::GroupChat { grpid } => {
|
ChatAssignment::GroupChat { grpid } => {
|
||||||
if let Some((id, _protected, blocked)) =
|
if let Some((id, blocked)) = chat::get_chat_id_by_grpid(context, grpid).await? {
|
||||||
chat::get_chat_id_by_grpid(context, grpid).await?
|
|
||||||
{
|
|
||||||
chat_id = Some(id);
|
chat_id = Some(id);
|
||||||
chat_id_blocked = blocked;
|
chat_id_blocked = blocked;
|
||||||
} else if allow_creation {
|
} else if allow_creation {
|
||||||
@@ -1557,7 +1551,7 @@ async fn do_chat_assignment(
|
|||||||
if chat_id.is_none() && allow_creation {
|
if chat_id.is_none() && allow_creation {
|
||||||
let to_contact = Contact::get_by_id(context, to_id).await?;
|
let to_contact = Contact::get_by_id(context, to_id).await?;
|
||||||
if let Some(list_id) = to_contact.param.get(Param::ListId) {
|
if let Some(list_id) = to_contact.param.get(Param::ListId) {
|
||||||
if let Some((id, _, blocked)) =
|
if let Some((id, blocked)) =
|
||||||
chat::get_chat_id_by_grpid(context, list_id).await?
|
chat::get_chat_id_by_grpid(context, list_id).await?
|
||||||
{
|
{
|
||||||
chat_id = Some(id);
|
chat_id = Some(id);
|
||||||
@@ -3189,7 +3183,7 @@ async fn create_or_lookup_mailinglist_or_broadcast(
|
|||||||
) -> Result<Option<(ChatId, Blocked)>> {
|
) -> Result<Option<(ChatId, Blocked)>> {
|
||||||
let listid = mailinglist_header_listid(list_id_header)?;
|
let listid = mailinglist_header_listid(list_id_header)?;
|
||||||
|
|
||||||
if let Some((chat_id, _, blocked)) = chat::get_chat_id_by_grpid(context, &listid).await? {
|
if let Some((chat_id, blocked)) = chat::get_chat_id_by_grpid(context, &listid).await? {
|
||||||
return Ok(Some((chat_id, blocked)));
|
return Ok(Some((chat_id, blocked)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1000,7 +1000,7 @@ async fn test_other_device_writes_to_mailinglist() -> Result<()> {
|
|||||||
chat::get_chat_id_by_grpid(&t, "delta.codespeak.net")
|
chat::get_chat_id_by_grpid(&t, "delta.codespeak.net")
|
||||||
.await?
|
.await?
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
(first_chat.id, false, Blocked::Request)
|
(first_chat.id, Blocked::Request)
|
||||||
);
|
);
|
||||||
|
|
||||||
receive_imf(
|
receive_imf(
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ async fn joining_chat_id(
|
|||||||
QrInvite::Contact { .. } => Ok(alice_chat_id),
|
QrInvite::Contact { .. } => Ok(alice_chat_id),
|
||||||
QrInvite::Group { grpid, name, .. } => {
|
QrInvite::Group { grpid, name, .. } => {
|
||||||
let group_chat_id = match chat::get_chat_id_by_grpid(context, grpid).await? {
|
let group_chat_id = match chat::get_chat_id_by_grpid(context, grpid).await? {
|
||||||
Some((chat_id, _protected, _blocked)) => {
|
Some((chat_id, _blocked)) => {
|
||||||
chat_id.unblock_ex(context, Nosync).await?;
|
chat_id.unblock_ex(context, Nosync).await?;
|
||||||
chat_id
|
chat_id
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user