From 0fd7c0fae3773bb682269271179bf60e635f4555 Mon Sep 17 00:00:00 2001 From: silverpill Date: Wed, 10 Nov 2021 17:21:54 +0000 Subject: [PATCH] Add actor_id method to actor profile type --- src/activitypub/activity.rs | 15 +++++++-------- src/models/profiles/types.rs | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/activitypub/activity.rs b/src/activitypub/activity.rs index cb0f81e..6d88d22 100644 --- a/src/activitypub/activity.rs +++ b/src/activitypub/activity.rs @@ -126,14 +126,13 @@ pub fn create_note( Some(in_reply_to_id) => { let post = in_reply_to.unwrap(); assert_eq!(post.id, in_reply_to_id); - match post.author.actor_json { - Some(ref actor_value) => { - // Replying to remote post - let remote_actor_id = actor_value["id"].as_str().unwrap(); - recipients.push(remote_actor_id.to_string()); - post.object_id.clone() - }, - None => Some(get_object_url(instance_url, &post.id)), + if post.author.is_local() { + Some(get_object_url(instance_url, &post.id)) + } else { + // Replying to remote post + let remote_actor_id = post.author.actor_id(instance_url).unwrap(); + recipients.push(remote_actor_id); + post.object_id.clone() } }, None => None, diff --git a/src/models/profiles/types.rs b/src/models/profiles/types.rs index a6a0359..b328b51 100644 --- a/src/models/profiles/types.rs +++ b/src/models/profiles/types.rs @@ -8,7 +8,8 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use uuid::Uuid; -use crate::errors::ValidationError; +use crate::activitypub::views::get_actor_url; +use crate::errors::{ConversionError, ValidationError}; use crate::utils::html::clean_html; #[derive(Clone, Debug, Deserialize, Serialize)] @@ -72,6 +73,18 @@ impl DbActorProfile { pub fn is_local(&self) -> bool { self.actor_json.is_none() } + + pub fn actor_id(&self, instance_url: &str) -> Result { + let actor_id = match self.actor_json { + Some(ref actor_value) => { + actor_value["id"].as_str() + .ok_or(ConversionError)? + .to_string() + }, + None => get_actor_url(instance_url, &self.username), + }; + Ok(actor_id) + } } #[cfg(test)]