Add actor_id method to actor profile type
This commit is contained in:
parent
7f07468d14
commit
0fd7c0fae3
2 changed files with 21 additions and 9 deletions
|
@ -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,
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Reference in a new issue