Skip to content

Commit

Permalink
remove pseudo-contact in domain @mailing.list
Browse files Browse the repository at this point in the history
1. the pseudo-contact was added to the mailing list contacts,
   which is not needed.
   might be that we want to add the recent contacts there in a subsequent pr
   (we do not know all contacts of a mailing list)

2. the pseudo-contact was used to block
   mailing lists; this is done by setting the chat to Blocked::Manually now

3- the pseudo-contact was used for unblocking;
   as it is very neat not to require additional ui for mailing list unblocking,
   might be that we introduce a similar pseudo-contact for this limited purpose
   in a subsequent pr, however, the pseudo-contact needs to exist only
   during unblocking then, maybe also the special domain is not needed,
   we'll see :)
  • Loading branch information
r10s committed Feb 6, 2021
1 parent 8a824a3 commit 3c0d1a5
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 87 deletions.
5 changes: 0 additions & 5 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,11 +1316,6 @@ pub async fn create_by_contact_id(context: &Context, contact_id: u32) -> Result<
);
return Err(err);
} else {
let c = Contact::load_from_db(context, contact_id).await?;
if let Some(list_chat_id) = c.param.get_int(Param::MailingListPseudoContact) {
return Ok(ChatId::new(list_chat_id as u32));
}

let (chat_id, _) =
create_or_lookup_by_contact_id(context, contact_id, Blocked::Not).await?;
Contact::scaleup_origin_by_id(context, contact_id, Origin::CreateChat).await;
Expand Down
37 changes: 2 additions & 35 deletions src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use itertools::Itertools;
use once_cell::sync::Lazy;
use regex::Regex;

use crate::aheader::EncryptPreference;
use crate::chat::ChatId;
use crate::config::Config;
use crate::constants::{
Chattype, DC_CHAT_ID_DEADDROP, DC_CONTACT_ID_DEVICE, DC_CONTACT_ID_DEVICE_ADDR,
Expand All @@ -25,8 +27,6 @@ use crate::param::{Param, Params};
use crate::peerstate::{Peerstate, PeerstateVerifiedStatus};
use crate::provider::Socket;
use crate::stock::StockMessage;
use crate::{aheader::EncryptPreference, chat};
use crate::{chat::ChatId, constants::Blocked};

/// An object representing a single contact in memory.
///
Expand Down Expand Up @@ -1045,28 +1045,6 @@ impl Contact {
.await
.is_ok()
}

/// Looks up or creates a pseudo contact of the form {List-Id}@mailing.list
pub(crate) async fn grpid_to_mailinglist_contact(
context: &Context,
name: &str,
grpid: &str,
chat_id: ChatId,
) -> Result<Contact> {
let addr = format!("{}@mailing.list", grpid);
let (contact_id, _) =
Contact::add_or_lookup(context, name, addr, Origin::IncomingUnknownFrom).await?;

chat::add_to_chat_contacts_table(context, chat_id, contact_id).await;

let mut contact = Contact::load_from_db(context, contact_id).await?;
contact
.param
.set_int(Param::MailingListPseudoContact, chat_id.to_u32() as i32);
contact.update_param(context).await?;

Ok(contact)
}
}

/// Returns false if addr is an invalid address, otherwise true.
Expand Down Expand Up @@ -1134,17 +1112,6 @@ async fn set_block_contact(context: &Context, contact_id: u32, new_blocking: boo
Contact::mark_noticed(context, contact_id).await;
context.emit_event(EventType::ContactsChanged(Some(contact_id)));
}

if let Some(chat_id) = contact.param.get_int(Param::MailingListPseudoContact) {
let new_blocked = if new_blocking {
Blocked::Manually
} else {
Blocked::Not
};
ChatId::new(chat_id as u32)
.set_blocked(context, new_blocked)
.await;
}
}
}
}
Expand Down
34 changes: 1 addition & 33 deletions src/dc_receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,18 +1514,6 @@ async fn create_or_lookup_mailinglist(
match create_mailinglist_record(context, &listid, &name, create_blocked).await {
Ok(chat_id) => {
chat::add_to_chat_contacts_table(context, chat_id, DC_CONTACT_ID_SELF).await;

match Contact::grpid_to_mailinglist_contact(context, &name, &listid, chat_id).await
{
Err(e) => warn!(context, "grpid_to_mailinglist_contact failed: {}", e),
Ok(contact) => {
if contact.is_blocked() {
chat_id.set_blocked(context, Blocked::Manually).await;
return (chat_id, Blocked::Manually);
}
}
}

(chat_id, create_blocked)
}
Err(e) => {
Expand Down Expand Up @@ -2764,7 +2752,7 @@ mod tests {
assert!(chat.is_mailing_list());
assert_eq!(chat.can_send(), false);
assert_eq!(chat.name, "deltachat/deltachat-core-rust");
assert_eq!(chat::get_chat_contacts(&t.ctx, chat_id).await.len(), 2);
assert_eq!(chat::get_chat_contacts(&t.ctx, chat_id).await.len(), 1);

dc_receive_imf(&t.ctx, GH_MAILINGLIST2, "INBOX", 1, false)
.await
Expand All @@ -2786,25 +2774,6 @@ mod tests {
let contact2 = Contact::load_from_db(&t.ctx, msg2.from_id).await.unwrap();
assert_eq!(contact2.get_addr(), "notifications@github.com");

let pseudo_contact = Contact::grpid_to_mailinglist_contact(
&t.ctx,
"",
"deltachat-core-rust.deltachat.github.com",
chat_id,
)
.await
.unwrap();
assert_eq!(
pseudo_contact.get_display_name(),
"deltachat/deltachat-core-rust"
);
assert_eq!(
pseudo_contact
.param
.get(Param::MailingListPseudoContact)
.unwrap(),
&chat_id.to_u32().to_string()
);
assert_eq!(msg1.get_override_sender_name().unwrap(), "Max Mustermann");
assert_eq!(msg2.get_override_sender_name().unwrap(), "Github");
}
Expand Down Expand Up @@ -2851,7 +2820,6 @@ mod tests {
let msg = get_chat_msg(&t, chat_id, 0, 1).await;
let contact1 = Contact::load_from_db(&t.ctx, msg.from_id).await.unwrap();
assert_eq!(contact1.get_addr(), "bob@posteo.org");
assert_eq!(contact1.param.get(Param::MailingListPseudoContact), None);
}

#[async_std::test]
Expand Down
12 changes: 2 additions & 10 deletions src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1150,16 +1150,8 @@ pub async fn decide_on_contact_request(

(Block, false) => Contact::block(context, msg.from_id).await,
(Block, true) => {
match Contact::grpid_to_mailinglist_contact(
context,
&chat.name,
&chat.grpid,
msg.chat_id,
)
.await
{
Err(e) => warn!(context, "Can't get mailing list contact: {}", e),
Ok(contact) => Contact::block(context, contact.id).await,
if !msg.chat_id.set_blocked(context, Blocked::Manually).await {
warn!(context, "Block mailing list failed.")
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ pub enum Param {
/// For Groups and Contacts
ProfileImage = b'i',

/// For contacts, contains the chat id of the mailing list if this is a pseudo contacts.
/// If the List-Id is e.g. delta.chat.1234, then the pseudo contact is delta.chat.1234@mailing.list
MailingListPseudoContact = b'p',

/// For Chats
Selftalk = b'K',

Expand Down

0 comments on commit 3c0d1a5

Please sign in to comment.