Limit type/method visibility in apub code

This commit is contained in:
Felix Ableitner 2021-08-08 13:13:28 +02:00
parent 353a1fe0a0
commit dacf1e6229
8 changed files with 18 additions and 21 deletions

View file

@ -2,7 +2,7 @@ use activitystreams::{base::AnyBase, context, primitives::OneOrMany};
use serde_json::json;
use url::Url;
pub fn lemmy_context() -> OneOrMany<AnyBase> {
pub(crate) fn lemmy_context() -> OneOrMany<AnyBase> {
let context_ext = AnyBase::from_arbitrary_json(json!(
{
"sc": "http://schema.org#",

View file

@ -62,7 +62,7 @@ pub(crate) async fn sign_and_send(
}
/// Verifies the HTTP signature on an incoming inbox request.
pub fn verify_signature(request: &HttpRequest, public_key: &str) -> Result<(), LemmyError> {
pub(crate) fn verify_signature(request: &HttpRequest, public_key: &str) -> Result<(), LemmyError> {
let verified = CONFIG2
.begin_verify(
request.method(),

View file

@ -25,7 +25,7 @@ use url::Url;
///
/// If it exists locally and `!should_refetch_actor()`, it is returned directly from the database.
/// Otherwise it is fetched from the remote instance, stored and returned.
pub async fn get_or_fetch_and_upsert_community(
pub(crate) async fn get_or_fetch_and_upsert_community(
apub_id: &Url,
context: &LemmyContext,
recursion_counter: &mut i32,

View file

@ -42,7 +42,7 @@ where
///
/// If it exists locally and `!should_refetch_actor()`, it is returned directly from the database.
/// Otherwise it is fetched from the remote instance, stored and returned.
pub async fn get_or_fetch_and_upsert_actor(
pub(crate) async fn get_or_fetch_and_upsert_actor(
apub_id: &Url,
context: &LemmyContext,
recursion_counter: &mut i32,

View file

@ -17,7 +17,7 @@ use url::Url;
/// pulled from its apub ID, inserted and returned.
///
/// The parent community is also pulled if necessary. Comments are not pulled.
pub async fn get_or_fetch_and_insert_post(
pub(crate) async fn get_or_fetch_and_insert_post(
post_ap_id: &Url,
context: &LemmyContext,
recursion_counter: &mut i32,
@ -46,7 +46,7 @@ pub async fn get_or_fetch_and_insert_post(
/// pulled from its apub ID, inserted and returned.
///
/// The parent community, post and comment are also pulled if necessary.
pub async fn get_or_fetch_and_insert_comment(
pub(crate) async fn get_or_fetch_and_insert_comment(
comment_ap_id: &Url,
context: &LemmyContext,
recursion_counter: &mut i32,
@ -80,7 +80,7 @@ pub async fn get_or_fetch_and_insert_comment(
}
}
pub async fn get_or_fetch_and_insert_post_or_comment(
pub(crate) async fn get_or_fetch_and_insert_post_or_comment(
ap_id: &Url,
context: &LemmyContext,
recursion_counter: &mut i32,

View file

@ -16,7 +16,7 @@ use url::Url;
///
/// If it exists locally and `!should_refetch_actor()`, it is returned directly from the database.
/// Otherwise it is fetched from the remote instance, stored and returned.
pub async fn get_or_fetch_and_upsert_person(
pub(crate) async fn get_or_fetch_and_upsert_person(
apub_id: &Url,
context: &LemmyContext,
recursion_counter: &mut i32,

View file

@ -34,7 +34,7 @@ use serde::Serialize;
use std::net::IpAddr;
use url::{ParseError, Url};
pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";
static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";
/// Checks if the ID is allowed for sending or receiving.
///
@ -123,7 +123,7 @@ pub trait ApubObjectType {
/// Common methods provided by ActivityPub actors (community and person). Not all methods are
/// implemented by all actors.
pub trait ActorType {
trait ActorType {
fn is_local(&self) -> bool;
fn actor_id(&self) -> Url;
fn name(&self) -> String;
@ -209,7 +209,7 @@ pub enum EndpointType {
}
/// Generates an apub endpoint for a given domain, IE xyz.tld
pub(crate) fn generate_apub_endpoint_for_domain(
fn generate_apub_endpoint_for_domain(
endpoint_type: EndpointType,
name: &str,
domain: &str,
@ -260,7 +260,7 @@ pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, LemmyError>
Ok(Url::parse(&url)?.into())
}
pub fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
Ok(Url::parse(&format!("{}/moderators", community_id))?.into())
}
@ -286,7 +286,7 @@ pub fn build_actor_id_from_shortname(
/// Store a sent or received activity in the database, for logging purposes. These records are not
/// persistent.
pub(crate) async fn insert_activity<T>(
async fn insert_activity<T>(
ap_id: &Url,
activity: T,
local: bool,
@ -348,7 +348,7 @@ pub(crate) async fn find_post_or_comment_by_id(
}
#[derive(Debug)]
pub enum Object {
enum Object {
Comment(Box<Comment>),
Post(Box<Post>),
Community(Box<Community>),
@ -356,10 +356,7 @@ pub enum Object {
PrivateMessage(Box<PrivateMessage>),
}
pub(crate) async fn find_object_by_id(
context: &LemmyContext,
apub_id: Url,
) -> Result<Object, LemmyError> {
async fn find_object_by_id(context: &LemmyContext, apub_id: Url) -> Result<Object, LemmyError> {
let ap_id = apub_id.clone();
if let Ok(pc) = find_post_or_comment_by_id(context, ap_id.to_owned()).await {
return Ok(match pc {
@ -397,7 +394,7 @@ pub(crate) async fn find_object_by_id(
Err(NotFound.into())
}
pub(crate) async fn check_community_or_site_ban(
async fn check_community_or_site_ban(
person: &Person,
community_id: CommunityId,
pool: &DbPool,

View file

@ -19,14 +19,14 @@ pub(crate) mod private_message;
/// Trait for converting an object or actor into the respective ActivityPub type.
#[async_trait::async_trait(?Send)]
pub trait ToApub {
pub(crate) trait ToApub {
type ApubType;
async fn to_apub(&self, pool: &DbPool) -> Result<Self::ApubType, LemmyError>;
fn to_tombstone(&self) -> Result<Tombstone, LemmyError>;
}
#[async_trait::async_trait(?Send)]
pub trait FromApub {
pub(crate) trait FromApub {
type ApubType;
/// Converts an object from ActivityPub type to Lemmy internal type.
///