fix: some impls dont include to in folreqs

i mean, it's obviously addressed to the target actor of this activity,
but it would cost nothing to put it in the `to` field... i do! added
special cases to make sure follow/accept/reject activities are at least
addressed to target actor
This commit is contained in:
əlemi 2024-05-02 14:36:56 +02:00
parent 34ebd9628b
commit 23c9a0a106
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -114,10 +114,17 @@ impl apb::server::Inbox for Context {
async fn follow(&self, _: String, activity: serde_json::Value) -> crate::Result<()> { async fn follow(&self, _: String, activity: serde_json::Value) -> crate::Result<()> {
let activity_model = model::activity::Model::new(&activity)?; let activity_model = model::activity::Model::new(&activity)?;
let aid = activity_model.id.clone(); let aid = activity_model.id.clone();
tracing::info!("{} wants to follow {}", activity_model.actor, activity_model.object.as_deref().unwrap_or("<no-one???>")); let target_user_id = activity_model.object
.as_deref()
.ok_or_else(UpubError::bad_request)?
.to_string();
tracing::info!("{} wants to follow {}", activity_model.actor, target_user_id);
model::activity::Entity::insert(activity_model.into_active_model()) model::activity::Entity::insert(activity_model.into_active_model())
.exec(self.db()).await?; .exec(self.db()).await?;
let expanded_addressing = self.expand_addressing(activity.addressed()).await?; let mut expanded_addressing = self.expand_addressing(activity.addressed()).await?;
if !expanded_addressing.contains(&target_user_id) {
expanded_addressing.push(target_user_id);
}
self.address_to(Some(&aid), None, &expanded_addressing).await?; self.address_to(Some(&aid), None, &expanded_addressing).await?;
Ok(()) Ok(())
} }
@ -166,13 +173,16 @@ impl apb::server::Inbox for Context {
.await?; .await?;
model::relation::Entity::insert( model::relation::Entity::insert(
model::relation::ActiveModel { model::relation::ActiveModel {
follower: Set(follow_activity.actor), follower: Set(follow_activity.actor.clone()),
following: Set(activity_model.actor), following: Set(activity_model.actor),
..Default::default() ..Default::default()
} }
).exec(self.db()).await?; ).exec(self.db()).await?;
let expanded_addressing = self.expand_addressing(activity.addressed()).await?; let mut expanded_addressing = self.expand_addressing(activity.addressed()).await?;
if !expanded_addressing.contains(&follow_activity.actor) {
expanded_addressing.push(follow_activity.actor);
}
self.address_to(Some(&activity_model.id), None, &expanded_addressing).await?; self.address_to(Some(&activity_model.id), None, &expanded_addressing).await?;
Ok(()) Ok(())
} }
@ -198,7 +208,10 @@ impl apb::server::Inbox for Context {
.exec(self.db()) .exec(self.db())
.await?; .await?;
let expanded_addressing = self.expand_addressing(activity.addressed()).await?; let mut expanded_addressing = self.expand_addressing(activity.addressed()).await?;
if !expanded_addressing.contains(&follow_activity.actor) {
expanded_addressing.push(follow_activity.actor);
}
self.address_to(Some(&activity_model.id), None, &expanded_addressing).await?; self.address_to(Some(&activity_model.id), None, &expanded_addressing).await?;
Ok(()) Ok(())
} }