diff --git a/packages/backend-rs/index.d.ts b/packages/backend-rs/index.d.ts index d7051191c4..5c99b4d437 100644 --- a/packages/backend-rs/index.d.ts +++ b/packages/backend-rs/index.d.ts @@ -1554,7 +1554,7 @@ export interface UserKeypair { export interface UserLike { id: string host: string | null - uri: string + uri: string | null } export interface UserList { diff --git a/packages/backend-rs/src/federation/activitypub/object/follow.rs b/packages/backend-rs/src/federation/activitypub/object/follow.rs index d90ba70d7e..d2db5afdaa 100644 --- a/packages/backend-rs/src/federation/activitypub/object/follow.rs +++ b/packages/backend-rs/src/federation/activitypub/object/follow.rs @@ -5,7 +5,7 @@ use crate::{config::CONFIG, federation::internal_actor, misc::user}; pub struct UserLike { pub id: String, pub host: Option, - pub uri: String, + pub uri: Option, } #[macros::export(object)] @@ -18,23 +18,31 @@ pub struct Follow { impl ActivityPubObject for Follow {} +#[macros::errors] +pub enum Error { + #[error("follower uri is missing")] + MissingFollowerUri, + #[error("followee uri is missing")] + MissingFolloweeUri, +} + impl Follow { #[allow(dead_code)] // TODO: remove this line - fn new(follower: UserLike, followee: UserLike, request_id: Option) -> Self { - Self { + fn new(follower: UserLike, followee: UserLike, request_id: Option) -> Result { + Ok(Self { id: request_id.unwrap_or_else(|| { format!("{}/follows/{}/{}", CONFIG.url, follower.id, followee.id) }), r#type: Activity::Follow, actor: match user::is_local!(follower) { true => format!("{}/users/{}", CONFIG.url, follower.id), - false => follower.uri, + false => follower.uri.ok_or(Error::MissingFollowerUri)?, }, object: match user::is_local!(followee) { true => format!("{}/users/{}", CONFIG.url, followee.id), - false => followee.uri, + false => followee.uri.ok_or(Error::MissingFolloweeUri)?, }, - } + }) } #[allow(dead_code)] // TODO: remove this line @@ -53,7 +61,7 @@ impl Follow { } #[macros::ts_export] -pub fn render_follow(follower: UserLike, followee: UserLike, request_id: Option) -> Follow { +pub fn render_follow(follower: UserLike, followee: UserLike, request_id: Option) -> Result { Follow::new(follower, followee, request_id) }