Explicit API for creating chats with blocked status

This introduces the explicit ChatIdBlocked struct to more explicitly
create a chat with a blocked status.  It also adds a common shortcut
to ChatId itself which is more natural to use in many cases.
This commit is contained in:
Floris Bruynooghe
2021-03-04 19:58:37 +01:00
parent 99d9773b75
commit be413b20f1
7 changed files with 186 additions and 116 deletions

View File

@@ -6,12 +6,13 @@ use percent_encoding::percent_decode_str;
use serde::Deserialize;
use std::collections::BTreeMap;
use crate::chat;
use crate::chat::{self, ChatIdBlocked};
use crate::config::Config;
use crate::constants::Blocked;
use crate::contact::{addr_normalize, may_be_valid_addr, Contact, Origin};
use crate::context::Context;
use crate::key::Fingerprint;
use crate::log::LogExt;
use crate::lot::{Lot, LotState};
use crate::message::Message;
use crate::peerstate::Peerstate;
@@ -165,11 +166,12 @@ async fn decode_openpgp(context: &Context, qr: &str) -> Lot {
.map(|(id, _)| id)
.unwrap_or_default();
let (id, _) = chat::create_or_lookup_by_contact_id(context, lot.id, Blocked::Deaddrop)
if let Ok(chat) = ChatIdBlocked::get_for_contact(context, lot.id, Blocked::Deaddrop)
.await
.unwrap_or_default();
chat::add_info_msg(context, id, format!("{} verified.", peerstate.addr)).await;
.log_err(context, "Failed to create (new) chat for contact")
{
chat::add_info_msg(context, chat.id, format!("{} verified.", peerstate.addr)).await;
}
} else if let Some(addr) = addr {
lot.state = LotState::QrFprMismatch;
lot.id = match Contact::lookup_id_by_addr(context, &addr, Origin::Unknown).await {