add get_webxdc_memberlist

This commit is contained in:
Simon Laux
2025-01-12 05:38:13 +01:00
parent 187274d7b7
commit b2911fe159
3 changed files with 65 additions and 6 deletions

View File

@@ -1829,6 +1829,20 @@ impl CommandApi {
WebxdcMessageInfo::get_for_message(&ctx, MsgId::new(instance_msg_id)).await
}
/// Returns webxdc memberlist, each member is a tuple (private user id, display_name)
/// Only includes members that have a known public key in the database
async fn get_webxdc_memberlist(
&self,
account_id: u32,
instance_msg_id: u32,
) -> Result<Vec<(String, String)>> {
let ctx = self.get_context(account_id).await?;
Message::load_from_db(&ctx, MsgId::new(instance_msg_id))
.await?
.get_webxdc_memberlist(&ctx)
.await
}
/// Get href from a WebxdcInfoMessage which might include a hash holding
/// information about a specific position or state in a webxdc app (optional)
async fn get_webxdc_href(

View File

@@ -1376,6 +1376,18 @@ impl Contact {
&self.addr
}
/// Get display name. This is the name as defined by the contact himself,
/// modified by the user or, if both are unset, an empty string.
pub fn get_display_name_without_email(&self) -> String {
if !self.name.is_empty() {
return self.name.clone();
}
if !self.authname.is_empty() {
return self.authname.clone();
}
String::new()
}
/// Get a summary of authorized name and address.
///
/// The returned string is either "Name (email@domain.com)" or just

View File

@@ -35,16 +35,17 @@ use sha2::{Digest, Sha256};
use crate::chat::{self, Chat};
use crate::constants::Chattype;
use crate::contact::ContactId;
use crate::contact::{self, ContactId};
use crate::context::Context;
use crate::events::EventType;
use crate::key::{load_self_public_key, DcKey};
use crate::key::{load_self_public_key, DcKey, Fingerprint};
use crate::message::{Message, MessageState, MsgId, Viewtype};
use crate::mimefactory::wrapped_base64_encode;
use crate::mimefactory::RECOMMENDED_FILE_SIZE;
use crate::mimeparser::SystemMessage;
use crate::param::Param;
use crate::param::Params;
use crate::peerstate::Peerstate;
use crate::tools::create_id;
use crate::tools::{create_smeared_timestamp, get_abs_path};
@@ -967,11 +968,43 @@ impl Message {
})
}
async fn get_webxdc_self_addr(&self, context: &Context) -> Result<String> {
let fingerprint = load_self_public_key(context).await?.dc_fingerprint().hex();
let data = format!("{}-{}", fingerprint, self.rfc724_mid);
fn get_webxdc_user_id(&self, pub_key_fingerprint: Fingerprint) -> String {
let data = format!("{}-{}", pub_key_fingerprint.hex(), self.rfc724_mid);
let hash = Sha256::digest(data.as_bytes());
Ok(format!("{:x}", hash))
format!("{:x}", hash)
}
async fn get_webxdc_self_addr(&self, context: &Context) -> Result<String> {
let fingerprint = load_self_public_key(context).await?.dc_fingerprint();
Ok(self.get_webxdc_user_id(fingerprint))
}
/// Returns webxdc memberlist, each member is a tuple (private user id, display_name)
/// Only includes members that have a known public key in the database
pub async fn get_webxdc_memberlist(&self, context: &Context) -> Result<Vec<(String, String)>> {
// We could do the following to increase privacy:
// - remove displayname (not that big of a deal in reality)
// - only show people in the list that send an status update before in the group (would decrease usefulness, but would still bring enough benefit, if only as internal function to match avatars)
let contacts = chat::get_chat_contacts(context, self.get_chat_id()).await?;
let mut memberlist = Vec::with_capacity(contacts.len());
for contact in contacts {
if let Some(peerstate) =
Peerstate::from_addr(context, &contact.addr(context).await?).await?
{
// is this correct way to get the right/current key of contact?
if let Some(fingerprint) = peerstate.public_key_fingerprint {
// TODO: think about wether we want to expose the nickname the user set for the contact here or just the name the contact set themselves?
// The former could be interpreted as privacy risk
// A. a webxdc could leak nicknames you set for users in the group,
// B. while the second could be seen as less useful/convinient for users "why are the contacts called differently in the webxdc"
let display_name = contact::Contact::get_by_id(context, contact)
.await?
.get_display_name_without_email();
memberlist.push((self.get_webxdc_user_id(fingerprint), display_name));
}
}
}
Ok(memberlist)
}
/// Get link attached to an info message.