-pub fn generate_followers_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
- Ok(Url::parse(&format!("{}/followers", actor_id))?.into())
-}
-
-pub fn generate_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
- Ok(Url::parse(&format!("{}/inbox", actor_id))?.into())
-}
-
-pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, LemmyError> {
- let actor_id: Url = actor_id.clone().into();
- let url = format!(
- "{}://{}{}/inbox",
- &actor_id.scheme(),
- &actor_id.host_str().context(location_info!())?,
- if let Some(port) = actor_id.port() {
- format!(":{}", port)
- } else {
- "".to_string()
- },
- );
- Ok(Url::parse(&url)?.into())
-}
-
-fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
- Ok(Url::parse(&format!("{}/moderators", community_id))?.into())
-}
-
-/// Takes in a shortname of the type dessalines@xyz.tld or dessalines (assumed to be local), and outputs the actor id.
-/// Used in the API for communities and users.
-pub fn build_actor_id_from_shortname(
- endpoint_type: EndpointType,
- short_name: &str,
-) -> Result<DbUrl, ParseError> {
- let split = short_name.split('@').collect::<Vec<&str>>();
-
- let name = split[0];
-
- // If there's no @, its local
- let domain = if split.len() == 1 {
- Settings::get().get_protocol_and_hostname()
- } else {
- format!("{}://{}", Settings::get().get_protocol_string(), split[1])
- };
-
- generate_apub_endpoint_for_domain(endpoint_type, name, &domain)
-}
-
-/// Store a sent or received activity in the database, for logging purposes. These records are not
-/// persistent.
-async fn insert_activity<T>(
- ap_id: &Url,
- activity: T,
- local: bool,
- sensitive: bool,
- pool: &DbPool,
-) -> Result<(), LemmyError>
-where
- T: Serialize + std::fmt::Debug + Send + 'static,
-{
- let ap_id = ap_id.to_owned().into();
- blocking(pool, move |conn| {
- Activity::insert(conn, ap_id, &activity, local, sensitive)
- })
- .await??;
- Ok(())
-}
-
-pub enum PostOrComment {
- Comment(Box<Comment>),
- Post(Box<Post>),
-}
-
-impl PostOrComment {
- pub(crate) fn ap_id(&self) -> Url {
- match self {
- PostOrComment::Post(p) => p.ap_id.clone(),
- PostOrComment::Comment(c) => c.ap_id.clone(),
- }
- .into()
- }
-}
-
-/// Tries to find a post or comment in the local database, without any network requests.
-/// This is used to handle deletions and removals, because in case we dont have the object, we can
-/// simply ignore the activity.
-pub(crate) async fn find_post_or_comment_by_id(