jsonrpc(feat): Add API to get json encryption info

Add a new api to jsonrpc that returns json structured data about chat encryption.
This commit is contained in:
Sebastian Klähn
2024-11-10 11:39:26 +01:00
parent 3b2f18f926
commit 5fde02f9fd
3 changed files with 78 additions and 1 deletions

View File

@@ -45,7 +45,7 @@ pub mod types;
use num_traits::FromPrimitive;
use types::account::Account;
use types::chat::FullChat;
use types::chat::{EncryptionInfo, FullChat};
use types::contact::{ContactObject, VcardContact};
use types::events::Event;
use types::http::HttpResponse;
@@ -708,6 +708,19 @@ impl CommandApi {
ChatId::new(chat_id).get_encryption_info(&ctx).await
}
/// Get encryption info for a chat.
async fn get_chat_encryption_info_json(
&self,
account_id: u32,
chat_id: u32,
) -> Result<EncryptionInfo> {
let ctx = self.get_context(account_id).await?;
Ok(ChatId::new(chat_id)
.get_encryption_info_json(&ctx)
.await?
.into())
}
/// Get QR code text that will offer a [SecureJoin](https://securejoin.delta.chat/) invitation.
///
/// If `chat_id` is a group chat ID, SecureJoin QR code for the group is returned.

View File

@@ -9,6 +9,7 @@ use deltachat::context::Context;
use num_traits::cast::ToPrimitive;
use serde::{Deserialize, Serialize};
use typescript_type_def::TypeDef;
use yerpc::JsonSchema;
use super::color_int_to_hex_string;
use super::contact::ContactObject;
@@ -239,3 +240,23 @@ impl JSONRPCChatVisibility {
}
}
}
#[derive(Debug, JsonSchema, TypeDef, Serialize, Deserialize)]
pub struct EncryptionInfo {
/// Addresses with End-to-end encryption preferred.
pub mutual: Vec<String>,
/// Addresses with End-to-end encryption available.
pub no_preference: Vec<String>,
/// Addresses with no encryption.
pub reset: Vec<String>,
}
impl From<chat::EncryptionInfo> for EncryptionInfo {
fn from(encryption_info: chat::EncryptionInfo) -> Self {
EncryptionInfo {
mutual: encryption_info.mutual,
no_preference: encryption_info.no_preference,
reset: encryption_info.reset,
}
}
}