diff --git a/src/receive_imf.rs b/src/receive_imf.rs index ea8b81a04..26f96d67f 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1678,17 +1678,6 @@ async fn create_or_lookup_group( members.dedup(); chat::add_to_chat_contacts_table(context, new_chat_id, &members).await?; - // once, we have protected-chats explained in UI, we can uncomment the following lines. - // ("verified groups" did not add a message anyway) - // - //if create_protected == ProtectionStatus::Protected { - // set from_id=0 as it is not clear that the sender of this random group message - // actually really has enabled chat-protection at some point. - //new_chat_id - // .add_protection_msg(context, ProtectionStatus::Protected, false, 0) - // .await?; - //} - context.emit_event(EventType::ChatModified(new_chat_id)); } @@ -1791,7 +1780,12 @@ async fn apply_group_changes( if !chat.is_protected() { chat_id - .inner_set_protection(context, ProtectionStatus::Protected) + .set_protection( + context, + ProtectionStatus::Protected, + smeared_time(context), + Some(from_id), + ) .await?; } } @@ -2453,6 +2447,40 @@ async fn has_verified_encryption( if let Some(fp) = peerstate.gossip_key_fingerprint.clone() { peerstate.set_verified(PeerstateKeyType::GossipKey, fp, verifier_addr)?; peerstate.save_to_db(&context.sql).await?; + + // TODO check if in other places where set_verified() is used we should also + // also set the chat as verified (& create a hidden chat if necessary) + + // TODO There is may be some code duplication with other code added recently + // and also some function should be extracted here because has_verified_encryption() + // is becoming very long and nested + if !is_verified { + let to_id = Contact::add_or_lookup( + context, + "", + ContactAddress::new(&to_addr)?, + Origin::Hidden, + ) + .await? + .0; + let chat_id = ChatId::create_for_contact_with_blocked( + context, + to_id, + Blocked::Yes, + ) + .await + .with_context(|| { + format!("can't create chat for contact {}", to_addr) + })?; + chat_id + .set_protection( + context, + ProtectionStatus::Protected, + smeared_time(context), + Some(to_id), + ) + .await?; + } } } else { // The contact already has a verified key.