Rename some functions

This commit is contained in:
silverpill 2022-10-15 12:32:27 +00:00
parent b26b2419ed
commit 0ce634564b
25 changed files with 107 additions and 53 deletions

View file

@ -39,7 +39,7 @@ fn build_announce_note(
) -> Announce {
let actor_id = local_actor_id(instance_url, sender_username);
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 recipient_id = post.author.actor_id(instance_url);
let followers = local_actor_followers(instance_url, sender_username);

View file

@ -123,7 +123,7 @@ pub fn build_note(
assert_eq!(post.links.len(), post.linked.len());
for linked in &post.linked {
// 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 {
name: Some(format!("RE: {}", link_href)),
tag_type: LINK.to_string(),
@ -134,7 +134,7 @@ pub fn build_note(
// tags.push(tag);
};
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 {
Some(in_reply_to_id) => {
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) {
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,
};

View file

@ -21,7 +21,7 @@ fn build_delete_note(
instance_url: &str,
post: &Post,
) -> Activity {
let object_id = post.get_object_id(instance_url);
let object_id = post.object_id(instance_url);
let object = Object {
context: Some(json!(AP_CONTEXT)),
id: object_id,

View file

@ -74,7 +74,7 @@ pub async fn prepare_like_note(
&instance.url(),
post,
).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 activity = build_like_note(
&instance.url(),

View file

@ -12,11 +12,11 @@ use crate::activitypub::handlers::{
use crate::activitypub::identifiers::parse_local_object_id;
use crate::config::{Config, Instance};
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::profiles::queries::{
get_profile_by_actor_id,
get_profile_by_acct,
get_profile_by_remote_actor_id,
create_profile,
};
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()) {
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) => {
if profile.possibly_outdated() {
// Try to re-fetch actor profile
@ -215,7 +218,10 @@ pub async fn import_post(
assert!(objects.len() > 0);
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) => {
// Object already fetched
if objects.len() == 0 {

View file

@ -8,7 +8,7 @@ use crate::activitypub::{
};
use crate::config::Config;
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::{
follow_request_accepted,
get_follow_request_by_id,
@ -21,7 +21,10 @@ pub async fn handle_accept_follow(
db_client: &mut impl GenericClient,
activity: Activity,
) -> 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 follow_request_id = parse_local_object_id(
&config.instance_url(),

View file

@ -9,7 +9,7 @@ use crate::activitypub::{
};
use crate::config::Config;
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::users::queries::get_user_by_name;
use super::HandlerResult;
@ -19,7 +19,7 @@ pub async fn handle_add(
db_client: &mut impl GenericClient,
activity: Activity,
) -> HandlerResult {
let actor_profile = get_profile_by_actor_id(
let actor_profile = get_profile_by_remote_actor_id(
db_client,
&activity.actor,
).await?;

View file

@ -9,7 +9,10 @@ use crate::activitypub::{
};
use crate::config::Config;
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 super::HandlerResult;
@ -19,7 +22,10 @@ pub async fn handle_announce(
activity: Activity,
) -> HandlerResult {
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
Err(DatabaseError::NotFound(_)) => (),
Err(other_error) => return Err(other_error.into()),

View file

@ -27,7 +27,7 @@ use crate::models::posts::mentions::mention_to_address;
use crate::models::posts::queries::{
create_post,
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::profiles::queries::get_profile_by_acct;
@ -137,7 +137,7 @@ async fn get_internal_post_id(
Err(_) => {
let real_object_id = redirects.get(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)
},
}

View file

@ -7,10 +7,13 @@ use crate::activitypub::{
};
use crate::config::Config;
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::{
delete_profile,
get_profile_by_actor_id,
get_profile_by_remote_actor_id,
};
use super::HandlerResult;
@ -22,7 +25,10 @@ pub async fn handle_delete(
let object_id = find_object_id(&activity.object)?;
if object_id == activity.actor {
// 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,
// Ignore Delete(Person) if profile is not found
Err(DatabaseError::NotFound(_)) => return Ok(None),
@ -36,13 +42,19 @@ pub async fn handle_delete(
log::info!("deleted profile {}", profile.acct);
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,
// Ignore Delete(Note) if post is not found
Err(DatabaseError::NotFound(_)) => return Ok(None),
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 {
return Err(ValidationError("actor is not an author").into());
};

View file

@ -10,7 +10,7 @@ use crate::activitypub::{
use crate::config::Config;
use crate::errors::DatabaseError;
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;
pub async fn handle_like(
@ -25,10 +25,16 @@ pub async fn handle_like(
&activity.actor,
).await?;
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,
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,
// Ignore like if post is not found locally
Err(DatabaseError::NotFound(_)) => return Ok(None),

View file

@ -8,7 +8,7 @@ use crate::activitypub::{
};
use crate::config::Config;
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::{
follow_request_rejected,
get_follow_request_by_id,
@ -21,7 +21,10 @@ pub async fn handle_reject_follow(
db_client: &impl GenericClient,
activity: Activity,
) -> 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 follow_request_id = parse_local_object_id(
&config.instance_url(),

View file

@ -12,7 +12,7 @@ use crate::errors::{DatabaseError, ValidationError};
use crate::models::notifications::queries::{
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::users::queries::get_user_by_name;
use super::HandlerResult;
@ -22,7 +22,7 @@ pub async fn handle_remove(
db_client: &mut impl GenericClient,
activity: Activity,
) -> HandlerResult {
let actor_profile = get_profile_by_actor_id(
let actor_profile = get_profile_by_remote_actor_id(
db_client,
&activity.actor,
).await?;

View file

@ -8,12 +8,12 @@ use crate::activitypub::{
use crate::errors::{DatabaseError, ValidationError};
use crate::models::posts::queries::{
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::{
delete_reaction,
get_reaction_by_activity_id,
get_reaction_by_remote_activity_id,
};
use super::HandlerResult;
@ -21,9 +21,12 @@ pub async fn handle_undo(
db_client: &mut impl GenericClient,
activity: Activity,
) -> 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)?;
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) => {
// Undo(Like)
if reaction.author_id != actor_profile.id {
@ -38,7 +41,10 @@ pub async fn handle_undo(
},
Err(DatabaseError::NotFound(_)) => {
// 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,
// Ignore undo if neither reaction nor repost is found
Err(DatabaseError::NotFound(_)) => return Ok(None),

View file

@ -9,7 +9,7 @@ use crate::config::Config;
use crate::errors::{DatabaseError, ValidationError};
use crate::models::profiles::queries::{
get_profile_by_acct,
get_profile_by_actor_id,
get_profile_by_remote_actor_id,
};
use crate::models::relationships::queries::unfollow;
use super::HandlerResult;
@ -21,7 +21,10 @@ pub async fn handle_undo_follow(
) -> HandlerResult {
let object: Object = serde_json::from_value(activity.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
.ok_or(ValidationError("invalid object"))?;
let target_username = parse_local_actor_id(

View file

@ -6,7 +6,7 @@ use crate::activitypub::identifiers::parse_local_object_id;
use crate::activitypub::vocabulary::NOTE;
use crate::errors::DatabaseError;
use crate::models::posts::queries::{
get_post_by_object_id,
get_post_by_remote_object_id,
update_post,
};
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) {
Ok(post_id) => post_id,
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,
// Ignore Update if post is not found locally
Err(DatabaseError::NotFound(_)) => return Ok(None),

View file

@ -11,7 +11,7 @@ use crate::activitypub::{
};
use crate::errors::ValidationError;
use crate::models::profiles::queries::{
get_profile_by_actor_id,
get_profile_by_remote_actor_id,
update_profile,
};
use crate::models::profiles::types::{DbActorProfile, ProfileUpdateData};
@ -27,7 +27,10 @@ pub async fn handle_update_person(
if actor.id != activity.actor {
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?;
Ok(Some(PERSON))
}

View file

@ -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::profiles::queries::{
delete_profile,
get_profile_by_actor_id,
get_profile_by_id,
get_profile_by_remote_actor_id,
};
use crate::models::subscriptions::queries::reset_subscriptions;
use crate::models::users::queries::{
@ -130,7 +130,10 @@ impl RefetchActor {
config: &Config,
db_client: &impl GenericClient,
) -> 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?;
update_remote_profile(db_client, &config.media_dir(), profile, actor).await?;
println!("profile updated");

View file

@ -14,7 +14,7 @@ use crate::activitypub::fetcher::helpers::{
};
use crate::config::Config;
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::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_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 {
match get_or_import_profile_by_actor_id(
db_client,

View file

@ -81,7 +81,7 @@ pub struct Status {
impl Status {
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()
.map(|item| Attachment::from_db(item, instance_url))
.collect();

View file

@ -114,7 +114,7 @@ async fn create_status(
// Append inline quote and add author to mentions
post_data.content += &format!(
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 {
post_data.mentions.push(linked.author.id);
@ -433,7 +433,7 @@ async fn make_permanent(
attachment.ipfs_cid = Some(image_cid.clone());
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()
.and_then(|attachment| attachment.ipfs_cid.as_deref());
let post_metadata = PostMetadata::new(

View file

@ -656,7 +656,7 @@ pub async fn get_thread(
Ok(posts)
}
pub async fn get_post_by_object_id(
pub async fn get_post_by_remote_object_id(
db_client: &impl GenericClient,
object_id: &str,
) -> Result<Post, DatabaseError> {

View file

@ -171,7 +171,7 @@ impl Post {
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 {
Some(object_id) => object_id.to_string(),
None => local_object_id(instance_url, &self.id),

View file

@ -123,7 +123,7 @@ pub async fn get_profile_by_id(
Ok(profile)
}
pub async fn get_profile_by_actor_id(
pub async fn get_profile_by_remote_actor_id(
db_client: &impl GenericClient,
actor_id: &str,
) -> Result<DbActorProfile, DatabaseError> {

View file

@ -48,7 +48,7 @@ pub async fn create_reaction(
Ok(reaction)
}
pub async fn get_reaction_by_activity_id(
pub async fn get_reaction_by_remote_activity_id(
db_client: &impl GenericClient,
activity_id: &str,
) -> Result<DbReaction, DatabaseError> {