Rename some functions
This commit is contained in:
parent
b26b2419ed
commit
0ce634564b
25 changed files with 107 additions and 53 deletions
|
@ -39,7 +39,7 @@ fn build_announce_note(
|
||||||
) -> Announce {
|
) -> Announce {
|
||||||
let actor_id = local_actor_id(instance_url, sender_username);
|
let actor_id = local_actor_id(instance_url, sender_username);
|
||||||
let post = repost.repost_of.as_ref().unwrap();
|
let post = repost.repost_of.as_ref().unwrap();
|
||||||
let object_id = post.get_object_id(instance_url);
|
let object_id = post.object_id(instance_url);
|
||||||
let activity_id = local_object_id(instance_url, &repost.id);
|
let activity_id = local_object_id(instance_url, &repost.id);
|
||||||
let recipient_id = post.author.actor_id(instance_url);
|
let recipient_id = post.author.actor_id(instance_url);
|
||||||
let followers = local_actor_followers(instance_url, sender_username);
|
let followers = local_actor_followers(instance_url, sender_username);
|
||||||
|
|
|
@ -123,7 +123,7 @@ pub fn build_note(
|
||||||
assert_eq!(post.links.len(), post.linked.len());
|
assert_eq!(post.links.len(), post.linked.len());
|
||||||
for linked in &post.linked {
|
for linked in &post.linked {
|
||||||
// Build FEP-e232 object link
|
// Build FEP-e232 object link
|
||||||
let link_href = linked.get_object_id(instance_url);
|
let link_href = linked.object_id(instance_url);
|
||||||
let _tag = Tag {
|
let _tag = Tag {
|
||||||
name: Some(format!("RE: {}", link_href)),
|
name: Some(format!("RE: {}", link_href)),
|
||||||
tag_type: LINK.to_string(),
|
tag_type: LINK.to_string(),
|
||||||
|
@ -134,7 +134,7 @@ pub fn build_note(
|
||||||
// tags.push(tag);
|
// tags.push(tag);
|
||||||
};
|
};
|
||||||
let maybe_quote_url = post.linked.get(0)
|
let maybe_quote_url = post.linked.get(0)
|
||||||
.map(|linked| linked.get_object_id(instance_url));
|
.map(|linked| linked.object_id(instance_url));
|
||||||
let in_reply_to_object_id = match post.in_reply_to_id {
|
let in_reply_to_object_id = match post.in_reply_to_id {
|
||||||
Some(in_reply_to_id) => {
|
Some(in_reply_to_id) => {
|
||||||
let in_reply_to = post.in_reply_to.as_ref().unwrap();
|
let in_reply_to = post.in_reply_to.as_ref().unwrap();
|
||||||
|
@ -143,7 +143,7 @@ pub fn build_note(
|
||||||
if !primary_audience.contains(&in_reply_to_actor_id) {
|
if !primary_audience.contains(&in_reply_to_actor_id) {
|
||||||
primary_audience.push(in_reply_to_actor_id);
|
primary_audience.push(in_reply_to_actor_id);
|
||||||
};
|
};
|
||||||
Some(in_reply_to.get_object_id(instance_url))
|
Some(in_reply_to.object_id(instance_url))
|
||||||
},
|
},
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,7 +21,7 @@ fn build_delete_note(
|
||||||
instance_url: &str,
|
instance_url: &str,
|
||||||
post: &Post,
|
post: &Post,
|
||||||
) -> Activity {
|
) -> Activity {
|
||||||
let object_id = post.get_object_id(instance_url);
|
let object_id = post.object_id(instance_url);
|
||||||
let object = Object {
|
let object = Object {
|
||||||
context: Some(json!(AP_CONTEXT)),
|
context: Some(json!(AP_CONTEXT)),
|
||||||
id: object_id,
|
id: object_id,
|
||||||
|
|
|
@ -74,7 +74,7 @@ pub async fn prepare_like_note(
|
||||||
&instance.url(),
|
&instance.url(),
|
||||||
post,
|
post,
|
||||||
).await?;
|
).await?;
|
||||||
let note_id = post.get_object_id(&instance.url());
|
let note_id = post.object_id(&instance.url());
|
||||||
let note_author_id = post.author.actor_id(&instance.url());
|
let note_author_id = post.author.actor_id(&instance.url());
|
||||||
let activity = build_like_note(
|
let activity = build_like_note(
|
||||||
&instance.url(),
|
&instance.url(),
|
||||||
|
|
|
@ -12,11 +12,11 @@ use crate::activitypub::handlers::{
|
||||||
use crate::activitypub::identifiers::parse_local_object_id;
|
use crate::activitypub::identifiers::parse_local_object_id;
|
||||||
use crate::config::{Config, Instance};
|
use crate::config::{Config, Instance};
|
||||||
use crate::errors::{DatabaseError, HttpError, ValidationError};
|
use crate::errors::{DatabaseError, HttpError, ValidationError};
|
||||||
use crate::models::posts::queries::get_post_by_object_id;
|
use crate::models::posts::queries::get_post_by_remote_object_id;
|
||||||
use crate::models::posts::types::Post;
|
use crate::models::posts::types::Post;
|
||||||
use crate::models::profiles::queries::{
|
use crate::models::profiles::queries::{
|
||||||
get_profile_by_actor_id,
|
|
||||||
get_profile_by_acct,
|
get_profile_by_acct,
|
||||||
|
get_profile_by_remote_actor_id,
|
||||||
create_profile,
|
create_profile,
|
||||||
};
|
};
|
||||||
use crate::models::profiles::types::{DbActorProfile, ProfileCreateData};
|
use crate::models::profiles::types::{DbActorProfile, ProfileCreateData};
|
||||||
|
@ -97,7 +97,10 @@ pub async fn get_or_import_profile_by_actor_id(
|
||||||
if actor_id.starts_with(&instance.url()) {
|
if actor_id.starts_with(&instance.url()) {
|
||||||
return Err(ImportError::LocalObject);
|
return Err(ImportError::LocalObject);
|
||||||
};
|
};
|
||||||
let profile = match get_profile_by_actor_id(db_client, actor_id).await {
|
let profile = match get_profile_by_remote_actor_id(
|
||||||
|
db_client,
|
||||||
|
actor_id,
|
||||||
|
).await {
|
||||||
Ok(profile) => {
|
Ok(profile) => {
|
||||||
if profile.possibly_outdated() {
|
if profile.possibly_outdated() {
|
||||||
// Try to re-fetch actor profile
|
// Try to re-fetch actor profile
|
||||||
|
@ -215,7 +218,10 @@ pub async fn import_post(
|
||||||
assert!(objects.len() > 0);
|
assert!(objects.len() > 0);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
match get_post_by_object_id(db_client, &object_id).await {
|
match get_post_by_remote_object_id(
|
||||||
|
db_client,
|
||||||
|
&object_id,
|
||||||
|
).await {
|
||||||
Ok(post) => {
|
Ok(post) => {
|
||||||
// Object already fetched
|
// Object already fetched
|
||||||
if objects.len() == 0 {
|
if objects.len() == 0 {
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::activitypub::{
|
||||||
};
|
};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::errors::ValidationError;
|
use crate::errors::ValidationError;
|
||||||
use crate::models::profiles::queries::get_profile_by_actor_id;
|
use crate::models::profiles::queries::get_profile_by_remote_actor_id;
|
||||||
use crate::models::relationships::queries::{
|
use crate::models::relationships::queries::{
|
||||||
follow_request_accepted,
|
follow_request_accepted,
|
||||||
get_follow_request_by_id,
|
get_follow_request_by_id,
|
||||||
|
@ -21,7 +21,10 @@ pub async fn handle_accept_follow(
|
||||||
db_client: &mut impl GenericClient,
|
db_client: &mut impl GenericClient,
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
) -> HandlerResult {
|
) -> HandlerResult {
|
||||||
let actor_profile = get_profile_by_actor_id(db_client, &activity.actor).await?;
|
let actor_profile = get_profile_by_remote_actor_id(
|
||||||
|
db_client,
|
||||||
|
&activity.actor,
|
||||||
|
).await?;
|
||||||
let object_id = find_object_id(&activity.object)?;
|
let object_id = find_object_id(&activity.object)?;
|
||||||
let follow_request_id = parse_local_object_id(
|
let follow_request_id = parse_local_object_id(
|
||||||
&config.instance_url(),
|
&config.instance_url(),
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::activitypub::{
|
||||||
};
|
};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::errors::ValidationError;
|
use crate::errors::ValidationError;
|
||||||
use crate::models::profiles::queries::get_profile_by_actor_id;
|
use crate::models::profiles::queries::get_profile_by_remote_actor_id;
|
||||||
use crate::models::relationships::queries::subscribe_opt;
|
use crate::models::relationships::queries::subscribe_opt;
|
||||||
use crate::models::users::queries::get_user_by_name;
|
use crate::models::users::queries::get_user_by_name;
|
||||||
use super::HandlerResult;
|
use super::HandlerResult;
|
||||||
|
@ -19,7 +19,7 @@ pub async fn handle_add(
|
||||||
db_client: &mut impl GenericClient,
|
db_client: &mut impl GenericClient,
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
) -> HandlerResult {
|
) -> HandlerResult {
|
||||||
let actor_profile = get_profile_by_actor_id(
|
let actor_profile = get_profile_by_remote_actor_id(
|
||||||
db_client,
|
db_client,
|
||||||
&activity.actor,
|
&activity.actor,
|
||||||
).await?;
|
).await?;
|
||||||
|
|
|
@ -9,7 +9,10 @@ use crate::activitypub::{
|
||||||
};
|
};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::errors::DatabaseError;
|
use crate::errors::DatabaseError;
|
||||||
use crate::models::posts::queries::{create_post, get_post_by_object_id};
|
use crate::models::posts::queries::{
|
||||||
|
create_post,
|
||||||
|
get_post_by_remote_object_id,
|
||||||
|
};
|
||||||
use crate::models::posts::types::PostCreateData;
|
use crate::models::posts::types::PostCreateData;
|
||||||
use super::HandlerResult;
|
use super::HandlerResult;
|
||||||
|
|
||||||
|
@ -19,7 +22,10 @@ pub async fn handle_announce(
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
) -> HandlerResult {
|
) -> HandlerResult {
|
||||||
let repost_object_id = activity.id;
|
let repost_object_id = activity.id;
|
||||||
match get_post_by_object_id(db_client, &repost_object_id).await {
|
match get_post_by_remote_object_id(
|
||||||
|
db_client,
|
||||||
|
&repost_object_id,
|
||||||
|
).await {
|
||||||
Ok(_) => return Ok(None), // Ignore if repost already exists
|
Ok(_) => return Ok(None), // Ignore if repost already exists
|
||||||
Err(DatabaseError::NotFound(_)) => (),
|
Err(DatabaseError::NotFound(_)) => (),
|
||||||
Err(other_error) => return Err(other_error.into()),
|
Err(other_error) => return Err(other_error.into()),
|
||||||
|
|
|
@ -27,7 +27,7 @@ use crate::models::posts::mentions::mention_to_address;
|
||||||
use crate::models::posts::queries::{
|
use crate::models::posts::queries::{
|
||||||
create_post,
|
create_post,
|
||||||
get_post_by_id,
|
get_post_by_id,
|
||||||
get_post_by_object_id,
|
get_post_by_remote_object_id,
|
||||||
};
|
};
|
||||||
use crate::models::posts::types::{Post, PostCreateData, Visibility};
|
use crate::models::posts::types::{Post, PostCreateData, Visibility};
|
||||||
use crate::models::profiles::queries::get_profile_by_acct;
|
use crate::models::profiles::queries::get_profile_by_acct;
|
||||||
|
@ -137,7 +137,7 @@ async fn get_internal_post_id(
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let real_object_id = redirects.get(object_id)
|
let real_object_id = redirects.get(object_id)
|
||||||
.unwrap_or(object_id);
|
.unwrap_or(object_id);
|
||||||
let post = get_post_by_object_id(db_client, real_object_id).await?;
|
let post = get_post_by_remote_object_id(db_client, real_object_id).await?;
|
||||||
Ok(post.id)
|
Ok(post.id)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,13 @@ use crate::activitypub::{
|
||||||
};
|
};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::errors::{DatabaseError, ValidationError};
|
use crate::errors::{DatabaseError, ValidationError};
|
||||||
use crate::models::posts::queries::{delete_post, get_post_by_object_id};
|
use crate::models::posts::queries::{
|
||||||
|
delete_post,
|
||||||
|
get_post_by_remote_object_id,
|
||||||
|
};
|
||||||
use crate::models::profiles::queries::{
|
use crate::models::profiles::queries::{
|
||||||
delete_profile,
|
delete_profile,
|
||||||
get_profile_by_actor_id,
|
get_profile_by_remote_actor_id,
|
||||||
};
|
};
|
||||||
use super::HandlerResult;
|
use super::HandlerResult;
|
||||||
|
|
||||||
|
@ -22,7 +25,10 @@ pub async fn handle_delete(
|
||||||
let object_id = find_object_id(&activity.object)?;
|
let object_id = find_object_id(&activity.object)?;
|
||||||
if object_id == activity.actor {
|
if object_id == activity.actor {
|
||||||
// Self-delete
|
// Self-delete
|
||||||
let profile = match get_profile_by_actor_id(db_client, &object_id).await {
|
let profile = match get_profile_by_remote_actor_id(
|
||||||
|
db_client,
|
||||||
|
&object_id,
|
||||||
|
).await {
|
||||||
Ok(profile) => profile,
|
Ok(profile) => profile,
|
||||||
// Ignore Delete(Person) if profile is not found
|
// Ignore Delete(Person) if profile is not found
|
||||||
Err(DatabaseError::NotFound(_)) => return Ok(None),
|
Err(DatabaseError::NotFound(_)) => return Ok(None),
|
||||||
|
@ -36,13 +42,19 @@ pub async fn handle_delete(
|
||||||
log::info!("deleted profile {}", profile.acct);
|
log::info!("deleted profile {}", profile.acct);
|
||||||
return Ok(Some(PERSON));
|
return Ok(Some(PERSON));
|
||||||
};
|
};
|
||||||
let post = match get_post_by_object_id(db_client, &object_id).await {
|
let post = match get_post_by_remote_object_id(
|
||||||
|
db_client,
|
||||||
|
&object_id,
|
||||||
|
).await {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
// Ignore Delete(Note) if post is not found
|
// Ignore Delete(Note) if post is not found
|
||||||
Err(DatabaseError::NotFound(_)) => return Ok(None),
|
Err(DatabaseError::NotFound(_)) => return Ok(None),
|
||||||
Err(other_error) => return Err(other_error.into()),
|
Err(other_error) => return Err(other_error.into()),
|
||||||
};
|
};
|
||||||
let actor_profile = get_profile_by_actor_id(db_client, &activity.actor).await?;
|
let actor_profile = get_profile_by_remote_actor_id(
|
||||||
|
db_client,
|
||||||
|
&activity.actor,
|
||||||
|
).await?;
|
||||||
if post.author.id != actor_profile.id {
|
if post.author.id != actor_profile.id {
|
||||||
return Err(ValidationError("actor is not an author").into());
|
return Err(ValidationError("actor is not an author").into());
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::activitypub::{
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::errors::DatabaseError;
|
use crate::errors::DatabaseError;
|
||||||
use crate::models::reactions::queries::create_reaction;
|
use crate::models::reactions::queries::create_reaction;
|
||||||
use crate::models::posts::queries::get_post_by_object_id;
|
use crate::models::posts::queries::get_post_by_remote_object_id;
|
||||||
use super::HandlerResult;
|
use super::HandlerResult;
|
||||||
|
|
||||||
pub async fn handle_like(
|
pub async fn handle_like(
|
||||||
|
@ -25,10 +25,16 @@ pub async fn handle_like(
|
||||||
&activity.actor,
|
&activity.actor,
|
||||||
).await?;
|
).await?;
|
||||||
let object_id = find_object_id(&activity.object)?;
|
let object_id = find_object_id(&activity.object)?;
|
||||||
let post_id = match parse_local_object_id(&config.instance_url(), &object_id) {
|
let post_id = match parse_local_object_id(
|
||||||
|
&config.instance_url(),
|
||||||
|
&object_id,
|
||||||
|
) {
|
||||||
Ok(post_id) => post_id,
|
Ok(post_id) => post_id,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let post = match get_post_by_object_id(db_client, &object_id).await {
|
let post = match get_post_by_remote_object_id(
|
||||||
|
db_client,
|
||||||
|
&object_id,
|
||||||
|
).await {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
// Ignore like if post is not found locally
|
// Ignore like if post is not found locally
|
||||||
Err(DatabaseError::NotFound(_)) => return Ok(None),
|
Err(DatabaseError::NotFound(_)) => return Ok(None),
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::activitypub::{
|
||||||
};
|
};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::errors::ValidationError;
|
use crate::errors::ValidationError;
|
||||||
use crate::models::profiles::queries::get_profile_by_actor_id;
|
use crate::models::profiles::queries::get_profile_by_remote_actor_id;
|
||||||
use crate::models::relationships::queries::{
|
use crate::models::relationships::queries::{
|
||||||
follow_request_rejected,
|
follow_request_rejected,
|
||||||
get_follow_request_by_id,
|
get_follow_request_by_id,
|
||||||
|
@ -21,7 +21,10 @@ pub async fn handle_reject_follow(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
) -> HandlerResult {
|
) -> HandlerResult {
|
||||||
let actor_profile = get_profile_by_actor_id(db_client, &activity.actor).await?;
|
let actor_profile = get_profile_by_remote_actor_id(
|
||||||
|
db_client,
|
||||||
|
&activity.actor,
|
||||||
|
).await?;
|
||||||
let object_id = find_object_id(&activity.object)?;
|
let object_id = find_object_id(&activity.object)?;
|
||||||
let follow_request_id = parse_local_object_id(
|
let follow_request_id = parse_local_object_id(
|
||||||
&config.instance_url(),
|
&config.instance_url(),
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::errors::{DatabaseError, ValidationError};
|
||||||
use crate::models::notifications::queries::{
|
use crate::models::notifications::queries::{
|
||||||
create_subscription_expiration_notification,
|
create_subscription_expiration_notification,
|
||||||
};
|
};
|
||||||
use crate::models::profiles::queries::get_profile_by_actor_id;
|
use crate::models::profiles::queries::get_profile_by_remote_actor_id;
|
||||||
use crate::models::relationships::queries::unsubscribe;
|
use crate::models::relationships::queries::unsubscribe;
|
||||||
use crate::models::users::queries::get_user_by_name;
|
use crate::models::users::queries::get_user_by_name;
|
||||||
use super::HandlerResult;
|
use super::HandlerResult;
|
||||||
|
@ -22,7 +22,7 @@ pub async fn handle_remove(
|
||||||
db_client: &mut impl GenericClient,
|
db_client: &mut impl GenericClient,
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
) -> HandlerResult {
|
) -> HandlerResult {
|
||||||
let actor_profile = get_profile_by_actor_id(
|
let actor_profile = get_profile_by_remote_actor_id(
|
||||||
db_client,
|
db_client,
|
||||||
&activity.actor,
|
&activity.actor,
|
||||||
).await?;
|
).await?;
|
||||||
|
|
|
@ -8,12 +8,12 @@ use crate::activitypub::{
|
||||||
use crate::errors::{DatabaseError, ValidationError};
|
use crate::errors::{DatabaseError, ValidationError};
|
||||||
use crate::models::posts::queries::{
|
use crate::models::posts::queries::{
|
||||||
delete_post,
|
delete_post,
|
||||||
get_post_by_object_id,
|
get_post_by_remote_object_id,
|
||||||
};
|
};
|
||||||
use crate::models::profiles::queries::get_profile_by_actor_id;
|
use crate::models::profiles::queries::get_profile_by_remote_actor_id;
|
||||||
use crate::models::reactions::queries::{
|
use crate::models::reactions::queries::{
|
||||||
delete_reaction,
|
delete_reaction,
|
||||||
get_reaction_by_activity_id,
|
get_reaction_by_remote_activity_id,
|
||||||
};
|
};
|
||||||
use super::HandlerResult;
|
use super::HandlerResult;
|
||||||
|
|
||||||
|
@ -21,9 +21,12 @@ pub async fn handle_undo(
|
||||||
db_client: &mut impl GenericClient,
|
db_client: &mut impl GenericClient,
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
) -> HandlerResult {
|
) -> HandlerResult {
|
||||||
let actor_profile = get_profile_by_actor_id(db_client, &activity.actor).await?;
|
let actor_profile = get_profile_by_remote_actor_id(
|
||||||
|
db_client,
|
||||||
|
&activity.actor,
|
||||||
|
).await?;
|
||||||
let object_id = find_object_id(&activity.object)?;
|
let object_id = find_object_id(&activity.object)?;
|
||||||
match get_reaction_by_activity_id(db_client, &object_id).await {
|
match get_reaction_by_remote_activity_id(db_client, &object_id).await {
|
||||||
Ok(reaction) => {
|
Ok(reaction) => {
|
||||||
// Undo(Like)
|
// Undo(Like)
|
||||||
if reaction.author_id != actor_profile.id {
|
if reaction.author_id != actor_profile.id {
|
||||||
|
@ -38,7 +41,10 @@ pub async fn handle_undo(
|
||||||
},
|
},
|
||||||
Err(DatabaseError::NotFound(_)) => {
|
Err(DatabaseError::NotFound(_)) => {
|
||||||
// Undo(Announce)
|
// Undo(Announce)
|
||||||
let post = match get_post_by_object_id(db_client, &object_id).await {
|
let post = match get_post_by_remote_object_id(
|
||||||
|
db_client,
|
||||||
|
&object_id,
|
||||||
|
).await {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
// Ignore undo if neither reaction nor repost is found
|
// Ignore undo if neither reaction nor repost is found
|
||||||
Err(DatabaseError::NotFound(_)) => return Ok(None),
|
Err(DatabaseError::NotFound(_)) => return Ok(None),
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::config::Config;
|
||||||
use crate::errors::{DatabaseError, ValidationError};
|
use crate::errors::{DatabaseError, ValidationError};
|
||||||
use crate::models::profiles::queries::{
|
use crate::models::profiles::queries::{
|
||||||
get_profile_by_acct,
|
get_profile_by_acct,
|
||||||
get_profile_by_actor_id,
|
get_profile_by_remote_actor_id,
|
||||||
};
|
};
|
||||||
use crate::models::relationships::queries::unfollow;
|
use crate::models::relationships::queries::unfollow;
|
||||||
use super::HandlerResult;
|
use super::HandlerResult;
|
||||||
|
@ -21,7 +21,10 @@ pub async fn handle_undo_follow(
|
||||||
) -> HandlerResult {
|
) -> HandlerResult {
|
||||||
let object: Object = serde_json::from_value(activity.object)
|
let object: Object = serde_json::from_value(activity.object)
|
||||||
.map_err(|_| ValidationError("invalid object"))?;
|
.map_err(|_| ValidationError("invalid object"))?;
|
||||||
let source_profile = get_profile_by_actor_id(db_client, &activity.actor).await?;
|
let source_profile = get_profile_by_remote_actor_id(
|
||||||
|
db_client,
|
||||||
|
&activity.actor,
|
||||||
|
).await?;
|
||||||
let target_actor_id = object.object
|
let target_actor_id = object.object
|
||||||
.ok_or(ValidationError("invalid object"))?;
|
.ok_or(ValidationError("invalid object"))?;
|
||||||
let target_username = parse_local_actor_id(
|
let target_username = parse_local_actor_id(
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::activitypub::identifiers::parse_local_object_id;
|
||||||
use crate::activitypub::vocabulary::NOTE;
|
use crate::activitypub::vocabulary::NOTE;
|
||||||
use crate::errors::DatabaseError;
|
use crate::errors::DatabaseError;
|
||||||
use crate::models::posts::queries::{
|
use crate::models::posts::queries::{
|
||||||
get_post_by_object_id,
|
get_post_by_remote_object_id,
|
||||||
update_post,
|
update_post,
|
||||||
};
|
};
|
||||||
use crate::models::posts::types::PostUpdateData;
|
use crate::models::posts::types::PostUpdateData;
|
||||||
|
@ -21,7 +21,10 @@ pub async fn handle_update_note(
|
||||||
let post_id = match parse_local_object_id(instance_url, &object.id) {
|
let post_id = match parse_local_object_id(instance_url, &object.id) {
|
||||||
Ok(post_id) => post_id,
|
Ok(post_id) => post_id,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let post = match get_post_by_object_id(db_client, &object.id).await {
|
let post = match get_post_by_remote_object_id(
|
||||||
|
db_client,
|
||||||
|
&object.id,
|
||||||
|
).await {
|
||||||
Ok(post) => post,
|
Ok(post) => post,
|
||||||
// Ignore Update if post is not found locally
|
// Ignore Update if post is not found locally
|
||||||
Err(DatabaseError::NotFound(_)) => return Ok(None),
|
Err(DatabaseError::NotFound(_)) => return Ok(None),
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::activitypub::{
|
||||||
};
|
};
|
||||||
use crate::errors::ValidationError;
|
use crate::errors::ValidationError;
|
||||||
use crate::models::profiles::queries::{
|
use crate::models::profiles::queries::{
|
||||||
get_profile_by_actor_id,
|
get_profile_by_remote_actor_id,
|
||||||
update_profile,
|
update_profile,
|
||||||
};
|
};
|
||||||
use crate::models::profiles::types::{DbActorProfile, ProfileUpdateData};
|
use crate::models::profiles::types::{DbActorProfile, ProfileUpdateData};
|
||||||
|
@ -27,7 +27,10 @@ pub async fn handle_update_person(
|
||||||
if actor.id != activity.actor {
|
if actor.id != activity.actor {
|
||||||
return Err(ValidationError("actor ID mismatch").into());
|
return Err(ValidationError("actor ID mismatch").into());
|
||||||
};
|
};
|
||||||
let profile = get_profile_by_actor_id(db_client, &actor.id).await?;
|
let profile = get_profile_by_remote_actor_id(
|
||||||
|
db_client,
|
||||||
|
&actor.id,
|
||||||
|
).await?;
|
||||||
update_remote_profile(db_client, media_dir, profile, actor).await?;
|
update_remote_profile(db_client, media_dir, profile, actor).await?;
|
||||||
Ok(Some(PERSON))
|
Ok(Some(PERSON))
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ use crate::models::cleanup::find_orphaned_files;
|
||||||
use crate::models::posts::queries::{delete_post, find_extraneous_posts, get_post_by_id};
|
use crate::models::posts::queries::{delete_post, find_extraneous_posts, get_post_by_id};
|
||||||
use crate::models::profiles::queries::{
|
use crate::models::profiles::queries::{
|
||||||
delete_profile,
|
delete_profile,
|
||||||
get_profile_by_actor_id,
|
|
||||||
get_profile_by_id,
|
get_profile_by_id,
|
||||||
|
get_profile_by_remote_actor_id,
|
||||||
};
|
};
|
||||||
use crate::models::subscriptions::queries::reset_subscriptions;
|
use crate::models::subscriptions::queries::reset_subscriptions;
|
||||||
use crate::models::users::queries::{
|
use crate::models::users::queries::{
|
||||||
|
@ -130,7 +130,10 @@ impl RefetchActor {
|
||||||
config: &Config,
|
config: &Config,
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let profile = get_profile_by_actor_id(db_client, &self.id).await?;
|
let profile = get_profile_by_remote_actor_id(
|
||||||
|
db_client,
|
||||||
|
&self.id,
|
||||||
|
).await?;
|
||||||
let actor = fetch_actor(&config.instance(), &self.id).await?;
|
let actor = fetch_actor(&config.instance(), &self.id).await?;
|
||||||
update_remote_profile(db_client, &config.media_dir(), profile, actor).await?;
|
update_remote_profile(db_client, &config.media_dir(), profile, actor).await?;
|
||||||
println!("profile updated");
|
println!("profile updated");
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::activitypub::fetcher::helpers::{
|
||||||
};
|
};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::errors::DatabaseError;
|
use crate::errors::DatabaseError;
|
||||||
use crate::models::profiles::queries::get_profile_by_actor_id;
|
use crate::models::profiles::queries::get_profile_by_remote_actor_id;
|
||||||
use crate::models::profiles::types::DbActorProfile;
|
use crate::models::profiles::types::DbActorProfile;
|
||||||
use crate::utils::crypto::{deserialize_public_key, verify_signature};
|
use crate::utils::crypto::{deserialize_public_key, verify_signature};
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ pub async fn verify_http_signature(
|
||||||
|
|
||||||
let actor_id = key_id_to_actor_id(&signature_data.key_id)?;
|
let actor_id = key_id_to_actor_id(&signature_data.key_id)?;
|
||||||
let actor_profile = if no_fetch {
|
let actor_profile = if no_fetch {
|
||||||
get_profile_by_actor_id(db_client, &actor_id).await?
|
get_profile_by_remote_actor_id(db_client, &actor_id).await?
|
||||||
} else {
|
} else {
|
||||||
match get_or_import_profile_by_actor_id(
|
match get_or_import_profile_by_actor_id(
|
||||||
db_client,
|
db_client,
|
||||||
|
|
|
@ -81,7 +81,7 @@ pub struct Status {
|
||||||
|
|
||||||
impl Status {
|
impl Status {
|
||||||
pub fn from_post(post: Post, instance_url: &str) -> Self {
|
pub fn from_post(post: Post, instance_url: &str) -> Self {
|
||||||
let object_id = post.get_object_id(instance_url);
|
let object_id = post.object_id(instance_url);
|
||||||
let attachments: Vec<Attachment> = post.attachments.into_iter()
|
let attachments: Vec<Attachment> = post.attachments.into_iter()
|
||||||
.map(|item| Attachment::from_db(item, instance_url))
|
.map(|item| Attachment::from_db(item, instance_url))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -114,7 +114,7 @@ async fn create_status(
|
||||||
// Append inline quote and add author to mentions
|
// Append inline quote and add author to mentions
|
||||||
post_data.content += &format!(
|
post_data.content += &format!(
|
||||||
r#"<p class="inline-quote">RE: <a href="{0}">{0}</a></p>"#,
|
r#"<p class="inline-quote">RE: <a href="{0}">{0}</a></p>"#,
|
||||||
linked.get_object_id(&instance.url()),
|
linked.object_id(&instance.url()),
|
||||||
);
|
);
|
||||||
if linked.author.id != current_user.id {
|
if linked.author.id != current_user.id {
|
||||||
post_data.mentions.push(linked.author.id);
|
post_data.mentions.push(linked.author.id);
|
||||||
|
@ -433,7 +433,7 @@ async fn make_permanent(
|
||||||
attachment.ipfs_cid = Some(image_cid.clone());
|
attachment.ipfs_cid = Some(image_cid.clone());
|
||||||
attachments.push((attachment.id, image_cid));
|
attachments.push((attachment.id, image_cid));
|
||||||
};
|
};
|
||||||
let post_url = post.get_object_id(&config.instance_url());
|
let post_url = post.object_id(&config.instance_url());
|
||||||
let maybe_post_image_cid = post.attachments.first()
|
let maybe_post_image_cid = post.attachments.first()
|
||||||
.and_then(|attachment| attachment.ipfs_cid.as_deref());
|
.and_then(|attachment| attachment.ipfs_cid.as_deref());
|
||||||
let post_metadata = PostMetadata::new(
|
let post_metadata = PostMetadata::new(
|
||||||
|
|
|
@ -656,7 +656,7 @@ pub async fn get_thread(
|
||||||
Ok(posts)
|
Ok(posts)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_post_by_object_id(
|
pub async fn get_post_by_remote_object_id(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
object_id: &str,
|
object_id: &str,
|
||||||
) -> Result<Post, DatabaseError> {
|
) -> Result<Post, DatabaseError> {
|
||||||
|
|
|
@ -171,7 +171,7 @@ impl Post {
|
||||||
matches!(self.visibility, Visibility::Public)
|
matches!(self.visibility, Visibility::Public)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_object_id(&self, instance_url: &str) -> String {
|
pub fn object_id(&self, instance_url: &str) -> String {
|
||||||
match &self.object_id {
|
match &self.object_id {
|
||||||
Some(object_id) => object_id.to_string(),
|
Some(object_id) => object_id.to_string(),
|
||||||
None => local_object_id(instance_url, &self.id),
|
None => local_object_id(instance_url, &self.id),
|
||||||
|
|
|
@ -123,7 +123,7 @@ pub async fn get_profile_by_id(
|
||||||
Ok(profile)
|
Ok(profile)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_profile_by_actor_id(
|
pub async fn get_profile_by_remote_actor_id(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
actor_id: &str,
|
actor_id: &str,
|
||||||
) -> Result<DbActorProfile, DatabaseError> {
|
) -> Result<DbActorProfile, DatabaseError> {
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub async fn create_reaction(
|
||||||
Ok(reaction)
|
Ok(reaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_reaction_by_activity_id(
|
pub async fn get_reaction_by_remote_activity_id(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
activity_id: &str,
|
activity_id: &str,
|
||||||
) -> Result<DbReaction, DatabaseError> {
|
) -> Result<DbReaction, DatabaseError> {
|
||||||
|
|
Loading…
Reference in a new issue