Send Update(Person) to followers after updating profile
This commit is contained in:
parent
a5e3bef70c
commit
e9c5bda55c
2 changed files with 42 additions and 7 deletions
|
@ -5,7 +5,9 @@ use uuid::Uuid;
|
|||
|
||||
use crate::models::posts::types::Post;
|
||||
use crate::models::profiles::types::DbActorProfile;
|
||||
use crate::models::users::types::User;
|
||||
use crate::utils::files::get_file_url;
|
||||
use super::actor::{get_local_actor, ActorKeyError};
|
||||
use super::constants::{AP_CONTEXT, AP_PUBLIC};
|
||||
use super::views::{get_actor_url, get_object_url};
|
||||
use super::vocabulary::*;
|
||||
|
@ -92,7 +94,7 @@ fn create_activity(
|
|||
actor_name: &str,
|
||||
activity_type: &str,
|
||||
activity_uuid: Option<Uuid>,
|
||||
object: Value,
|
||||
object: impl Serialize,
|
||||
) -> Activity {
|
||||
let actor_id = get_actor_url(
|
||||
instance_url,
|
||||
|
@ -107,7 +109,7 @@ fn create_activity(
|
|||
id: activity_id,
|
||||
activity_type: activity_type.to_string(),
|
||||
actor: actor_id,
|
||||
object: object,
|
||||
object: serde_json::to_value(object).unwrap(),
|
||||
};
|
||||
activity
|
||||
}
|
||||
|
@ -193,7 +195,7 @@ pub fn create_activity_note(
|
|||
&post.author.username,
|
||||
CREATE,
|
||||
None,
|
||||
serde_json::to_value(object).unwrap(),
|
||||
object,
|
||||
);
|
||||
activity
|
||||
}
|
||||
|
@ -214,7 +216,7 @@ pub fn create_activity_like(
|
|||
&actor_profile.username,
|
||||
LIKE,
|
||||
None,
|
||||
serde_json::to_value(object).unwrap(),
|
||||
object,
|
||||
);
|
||||
activity
|
||||
}
|
||||
|
@ -236,7 +238,7 @@ pub fn create_activity_follow(
|
|||
&actor_profile.username,
|
||||
FOLLOW,
|
||||
Some(*follow_request_id),
|
||||
serde_json::to_value(object).unwrap(),
|
||||
object,
|
||||
);
|
||||
activity
|
||||
}
|
||||
|
@ -258,7 +260,7 @@ pub fn create_activity_accept_follow(
|
|||
&actor_profile.username,
|
||||
ACCEPT,
|
||||
None,
|
||||
serde_json::to_value(object).unwrap(),
|
||||
object,
|
||||
);
|
||||
activity
|
||||
}
|
||||
|
@ -291,11 +293,26 @@ pub fn create_activity_undo_follow(
|
|||
&actor_profile.username,
|
||||
UNDO,
|
||||
None,
|
||||
serde_json::to_value(object).unwrap(),
|
||||
object,
|
||||
);
|
||||
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)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct OrderedCollection {
|
||||
|
|
|
@ -6,7 +6,9 @@ use uuid::Uuid;
|
|||
use crate::activitypub::activity::{
|
||||
create_activity_follow,
|
||||
create_activity_undo_follow,
|
||||
create_activity_update_person,
|
||||
};
|
||||
use crate::activitypub::actor::Actor;
|
||||
use crate::activitypub::deliverer::deliver_activity;
|
||||
use crate::config::Config;
|
||||
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::queries::get_posts_by_author;
|
||||
use crate::models::profiles::queries::{
|
||||
get_followers,
|
||||
get_profile_by_id,
|
||||
update_profile,
|
||||
};
|
||||
|
@ -133,6 +136,21 @@ async fn update_credentials(
|
|||
¤t_user.id,
|
||||
profile_data,
|
||||
).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());
|
||||
Ok(HttpResponse::Ok().json(account))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue