Add actor_id method to actor profile type

This commit is contained in:
silverpill 2021-11-10 17:21:54 +00:00
parent 7f07468d14
commit 0fd7c0fae3
2 changed files with 21 additions and 9 deletions

View file

@ -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,

View file

@ -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<String, ConversionError> {
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)]