Send Update(Person) to followers after updating profile
This commit is contained in:
parent
a5e3bef70c
commit
e9c5bda55c
|
@ -5,7 +5,9 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use crate::models::posts::types::Post;
|
use crate::models::posts::types::Post;
|
||||||
use crate::models::profiles::types::DbActorProfile;
|
use crate::models::profiles::types::DbActorProfile;
|
||||||
|
use crate::models::users::types::User;
|
||||||
use crate::utils::files::get_file_url;
|
use crate::utils::files::get_file_url;
|
||||||
|
use super::actor::{get_local_actor, ActorKeyError};
|
||||||
use super::constants::{AP_CONTEXT, AP_PUBLIC};
|
use super::constants::{AP_CONTEXT, AP_PUBLIC};
|
||||||
use super::views::{get_actor_url, get_object_url};
|
use super::views::{get_actor_url, get_object_url};
|
||||||
use super::vocabulary::*;
|
use super::vocabulary::*;
|
||||||
|
@ -92,7 +94,7 @@ fn create_activity(
|
||||||
actor_name: &str,
|
actor_name: &str,
|
||||||
activity_type: &str,
|
activity_type: &str,
|
||||||
activity_uuid: Option<Uuid>,
|
activity_uuid: Option<Uuid>,
|
||||||
object: Value,
|
object: impl Serialize,
|
||||||
) -> Activity {
|
) -> Activity {
|
||||||
let actor_id = get_actor_url(
|
let actor_id = get_actor_url(
|
||||||
instance_url,
|
instance_url,
|
||||||
|
@ -107,7 +109,7 @@ fn create_activity(
|
||||||
id: activity_id,
|
id: activity_id,
|
||||||
activity_type: activity_type.to_string(),
|
activity_type: activity_type.to_string(),
|
||||||
actor: actor_id,
|
actor: actor_id,
|
||||||
object: object,
|
object: serde_json::to_value(object).unwrap(),
|
||||||
};
|
};
|
||||||
activity
|
activity
|
||||||
}
|
}
|
||||||
|
@ -193,7 +195,7 @@ pub fn create_activity_note(
|
||||||
&post.author.username,
|
&post.author.username,
|
||||||
CREATE,
|
CREATE,
|
||||||
None,
|
None,
|
||||||
serde_json::to_value(object).unwrap(),
|
object,
|
||||||
);
|
);
|
||||||
activity
|
activity
|
||||||
}
|
}
|
||||||
|
@ -214,7 +216,7 @@ pub fn create_activity_like(
|
||||||
&actor_profile.username,
|
&actor_profile.username,
|
||||||
LIKE,
|
LIKE,
|
||||||
None,
|
None,
|
||||||
serde_json::to_value(object).unwrap(),
|
object,
|
||||||
);
|
);
|
||||||
activity
|
activity
|
||||||
}
|
}
|
||||||
|
@ -236,7 +238,7 @@ pub fn create_activity_follow(
|
||||||
&actor_profile.username,
|
&actor_profile.username,
|
||||||
FOLLOW,
|
FOLLOW,
|
||||||
Some(*follow_request_id),
|
Some(*follow_request_id),
|
||||||
serde_json::to_value(object).unwrap(),
|
object,
|
||||||
);
|
);
|
||||||
activity
|
activity
|
||||||
}
|
}
|
||||||
|
@ -258,7 +260,7 @@ pub fn create_activity_accept_follow(
|
||||||
&actor_profile.username,
|
&actor_profile.username,
|
||||||
ACCEPT,
|
ACCEPT,
|
||||||
None,
|
None,
|
||||||
serde_json::to_value(object).unwrap(),
|
object,
|
||||||
);
|
);
|
||||||
activity
|
activity
|
||||||
}
|
}
|
||||||
|
@ -291,11 +293,26 @@ pub fn create_activity_undo_follow(
|
||||||
&actor_profile.username,
|
&actor_profile.username,
|
||||||
UNDO,
|
UNDO,
|
||||||
None,
|
None,
|
||||||
serde_json::to_value(object).unwrap(),
|
object,
|
||||||
);
|
);
|
||||||
activity
|
activity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_activity_update_person(
|
||||||
|
user: &User,
|
||||||
|
instance_url: &str,
|
||||||
|
) -> Result<Activity, ActorKeyError> {
|
||||||
|
let actor = get_local_actor(user, instance_url)?;
|
||||||
|
let activity = create_activity(
|
||||||
|
instance_url,
|
||||||
|
&user.profile.username,
|
||||||
|
UPDATE,
|
||||||
|
None,
|
||||||
|
actor,
|
||||||
|
);
|
||||||
|
Ok(activity)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct OrderedCollection {
|
pub struct OrderedCollection {
|
||||||
|
|
|
@ -6,7 +6,9 @@ use uuid::Uuid;
|
||||||
use crate::activitypub::activity::{
|
use crate::activitypub::activity::{
|
||||||
create_activity_follow,
|
create_activity_follow,
|
||||||
create_activity_undo_follow,
|
create_activity_undo_follow,
|
||||||
|
create_activity_update_person,
|
||||||
};
|
};
|
||||||
|
use crate::activitypub::actor::Actor;
|
||||||
use crate::activitypub::deliverer::deliver_activity;
|
use crate::activitypub::deliverer::deliver_activity;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::database::{Pool, get_database_client};
|
use crate::database::{Pool, get_database_client};
|
||||||
|
@ -17,6 +19,7 @@ use crate::mastodon_api::oauth::auth::get_current_user;
|
||||||
use crate::models::posts::helpers::get_actions_for_posts;
|
use crate::models::posts::helpers::get_actions_for_posts;
|
||||||
use crate::models::posts::queries::get_posts_by_author;
|
use crate::models::posts::queries::get_posts_by_author;
|
||||||
use crate::models::profiles::queries::{
|
use crate::models::profiles::queries::{
|
||||||
|
get_followers,
|
||||||
get_profile_by_id,
|
get_profile_by_id,
|
||||||
update_profile,
|
update_profile,
|
||||||
};
|
};
|
||||||
|
@ -133,6 +136,21 @@ async fn update_credentials(
|
||||||
¤t_user.id,
|
¤t_user.id,
|
||||||
profile_data,
|
profile_data,
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
|
// Federate
|
||||||
|
let activity = create_activity_update_person(¤t_user, &config.instance_url())
|
||||||
|
.map_err(|_| HttpError::InternalError)?;
|
||||||
|
let followers = get_followers(db_client, ¤t_user.id).await?;
|
||||||
|
let mut recipients: Vec<Actor> = Vec::new();
|
||||||
|
for follower in followers {
|
||||||
|
let maybe_remote_actor = follower.remote_actor()
|
||||||
|
.map_err(|_| HttpError::InternalError)?;
|
||||||
|
if let Some(remote_actor) = maybe_remote_actor {
|
||||||
|
recipients.push(remote_actor);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
deliver_activity(&config, ¤t_user, activity, recipients);
|
||||||
|
|
||||||
let account = Account::from_user(current_user, &config.instance_url());
|
let account = Account::from_user(current_user, &config.instance_url());
|
||||||
Ok(HttpResponse::Ok().json(account))
|
Ok(HttpResponse::Ok().json(account))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue