Skip to content

Commit

Permalink
Remove individual user/community inboxes (#5124)
Browse files Browse the repository at this point in the history
* Remove endpoints for individual community/user inboxes

fixes #4147
fixes #3928

* Remove shared_inbox_url columns

* fmt
  • Loading branch information
Nutomic authored Oct 26, 2024
1 parent 920ffe1 commit f05afea
Show file tree
Hide file tree
Showing 24 changed files with 100 additions and 148 deletions.
13 changes: 6 additions & 7 deletions crates/api_common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ use lemmy_utils::{
email::{send_email, translations::Lang},
error::{LemmyError, LemmyErrorExt, LemmyErrorType, LemmyResult},
rate_limit::{ActionType, BucketConfig},
settings::structs::{PictrsImageMode, Settings},
settings::{
structs::{PictrsImageMode, Settings},
SETTINGS,
},
utils::{
markdown::{image_links::markdown_rewrite_image_links, markdown_check_for_blocked_urls},
slurs::{build_slur_regex, remove_slurs},
Expand Down Expand Up @@ -973,12 +976,8 @@ pub fn generate_followers_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
Ok(Url::parse(&format!("{actor_id}/followers"))?.into())
}

pub fn generate_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
Ok(Url::parse(&format!("{actor_id}/inbox"))?.into())
}

pub fn generate_shared_inbox_url(settings: &Settings) -> LemmyResult<DbUrl> {
let url = format!("{}/inbox", settings.get_protocol_and_hostname());
pub fn generate_inbox_url() -> LemmyResult<DbUrl> {
let url = format!("{}/inbox", SETTINGS.get_protocol_and_hostname());
Ok(Url::parse(&url)?.into())
}

Expand Down
4 changes: 1 addition & 3 deletions crates/api_crud/src/community/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use lemmy_api_common::{
generate_followers_url,
generate_inbox_url,
generate_local_apub_endpoint,
generate_shared_inbox_url,
get_url_blocklist,
is_admin,
local_site_to_slur_regex,
Expand Down Expand Up @@ -96,8 +95,7 @@ pub async fn create_community(
actor_id: Some(community_actor_id.clone()),
private_key: Some(keypair.private_key),
followers_url: Some(generate_followers_url(&community_actor_id)?),
inbox_url: Some(generate_inbox_url(&community_actor_id)?),
shared_inbox_url: Some(generate_shared_inbox_url(context.settings())?),
inbox_url: Some(generate_inbox_url()?),
posting_restricted_to_mods: data.posting_restricted_to_mods,
visibility: data.visibility,
..CommunityInsertForm::new(
Expand Down
4 changes: 2 additions & 2 deletions crates/api_crud/src/site/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use lemmy_api_common::{
context::LemmyContext,
site::{CreateSite, SiteResponse},
utils::{
generate_shared_inbox_url,
generate_inbox_url,
get_url_blocklist,
is_admin,
local_site_rate_limit_to_rate_limit_config,
Expand Down Expand Up @@ -55,7 +55,7 @@ pub async fn create_site(
validate_create_payload(&local_site, &data)?;

let actor_id: DbUrl = Url::parse(&context.settings().get_protocol_and_hostname())?.into();
let inbox_url = Some(generate_shared_inbox_url(context.settings())?);
let inbox_url = Some(generate_inbox_url()?);
let keypair = generate_actor_keypair()?;

let slur_regex = local_site_to_slur_regex(&local_site);
Expand Down
4 changes: 1 addition & 3 deletions crates/api_crud/src/user/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use lemmy_api_common::{
check_user_valid,
generate_inbox_url,
generate_local_apub_endpoint,
generate_shared_inbox_url,
honeypot_check,
local_site_to_slur_regex,
password_length_check,
Expand Down Expand Up @@ -418,8 +417,7 @@ async fn create_person(
// Register the new person
let person_form = PersonInsertForm {
actor_id: Some(actor_id.clone()),
inbox_url: Some(generate_inbox_url(&actor_id)?),
shared_inbox_url: Some(generate_shared_inbox_url(context.settings())?),
inbox_url: Some(generate_inbox_url()?),
private_key: Some(actor_keypair.private_key),
..PersonInsertForm::new(username.clone(), actor_keypair.public_key, instance_id)
};
Expand Down
10 changes: 8 additions & 2 deletions crates/apub/src/activities/community/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,14 @@ impl ActivityHandler for UpdateCommunity {
icon: Some(self.object.icon.map(|i| i.url.into())),
banner: Some(self.object.image.map(|i| i.url.into())),
followers_url: self.object.followers.map(Into::into),
inbox_url: Some(self.object.inbox.into()),
shared_inbox_url: Some(self.object.endpoints.map(|e| e.shared_inbox.into())),
inbox_url: Some(
self
.object
.endpoints
.map(|e| e.shared_inbox)
.unwrap_or(self.object.inbox)
.into(),
),
moderators_url: self.object.attributed_to.map(Into::into),
posting_restricted_to_mods: self.object.posting_restricted_to_mods,
featured_url: self.object.featured.map(Into::into),
Expand Down
20 changes: 2 additions & 18 deletions crates/apub/src/http/community.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
use crate::{
activity_lists::GroupInboxActivities,
collections::{
community_featured::ApubCommunityFeatured,
community_follower::ApubCommunityFollower,
community_moderators::ApubCommunityModerators,
community_outbox::ApubCommunityOutbox,
},
http::{check_community_public, create_apub_response, create_apub_tombstone_response},
objects::{community::ApubCommunity, person::ApubPerson},
objects::community::ApubCommunity,
};
use activitypub_federation::{
actix_web::inbox::receive_activity,
config::Data,
protocol::context::WithContext,
traits::{Collection, Object},
};
use actix_web::{web, web::Bytes, HttpRequest, HttpResponse};
use actix_web::{web, HttpResponse};
use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{source::community::Community, traits::ApubActor};
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
Expand Down Expand Up @@ -47,19 +44,6 @@ pub(crate) async fn get_apub_community_http(
create_apub_response(&apub)
}

/// Handler for all incoming receive to community inboxes.
#[tracing::instrument(skip_all)]
pub async fn community_inbox(
request: HttpRequest,
body: Bytes,
data: Data<LemmyContext>,
) -> LemmyResult<HttpResponse> {
receive_activity::<WithContext<GroupInboxActivities>, ApubPerson, LemmyContext>(
request, body, &data,
)
.await
}

/// Returns an empty followers collection, only populating the size (for privacy).
pub(crate) async fn get_apub_community_followers(
info: web::Path<CommunityQuery>,
Expand Down
23 changes: 2 additions & 21 deletions crates/apub/src/http/person.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
use crate::{
activity_lists::PersonInboxActivities,
fetcher::user_or_community::UserOrCommunity,
http::{create_apub_response, create_apub_tombstone_response},
objects::person::ApubPerson,
protocol::collections::empty_outbox::EmptyOutbox,
};
use activitypub_federation::{
actix_web::inbox::receive_activity,
config::Data,
protocol::context::WithContext,
traits::Object,
};
use actix_web::{web, web::Bytes, HttpRequest, HttpResponse};
use activitypub_federation::{config::Data, traits::Object};
use actix_web::{web, HttpResponse};
use lemmy_api_common::{context::LemmyContext, utils::generate_outbox_url};
use lemmy_db_schema::{source::person::Person, traits::ApubActor};
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
Expand Down Expand Up @@ -44,18 +37,6 @@ pub(crate) async fn get_apub_person_http(
}
}

#[tracing::instrument(skip_all)]
pub async fn person_inbox(
request: HttpRequest,
body: Bytes,
data: Data<LemmyContext>,
) -> LemmyResult<HttpResponse> {
receive_activity::<WithContext<PersonInboxActivities>, UserOrCommunity, LemmyContext>(
request, body, &data,
)
.await
}

#[tracing::instrument(skip_all)]
pub(crate) async fn get_apub_person_outbox(
info: web::Path<PersonQuery>,
Expand Down
5 changes: 1 addition & 4 deletions crates/apub/src/http/routes.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use crate::http::{
comment::get_apub_comment,
community::{
community_inbox,
get_apub_community_featured,
get_apub_community_followers,
get_apub_community_http,
get_apub_community_moderators,
get_apub_community_outbox,
},
get_activity,
person::{get_apub_person_http, get_apub_person_outbox, person_inbox},
person::{get_apub_person_http, get_apub_person_outbox},
post::get_apub_post,
shared_inbox,
site::{get_apub_site_http, get_apub_site_outbox},
Expand Down Expand Up @@ -56,8 +55,6 @@ pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("")
.guard(InboxRequestGuard)
.route("/c/{community_name}/inbox", web::post().to(community_inbox))
.route("/u/{user_name}/inbox", web::post().to(person_inbox))
.route("/inbox", web::post().to(shared_inbox)),
);
}
Expand Down
17 changes: 10 additions & 7 deletions crates/apub/src/objects/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
local_site_data_cached,
objects::{instance::fetch_instance_actor_for_object, read_from_string_or_source_opt},
protocol::{
objects::{group::Group, Endpoints, LanguageTag},
objects::{group::Group, LanguageTag},
ImageObject,
Source,
},
Expand Down Expand Up @@ -116,9 +116,7 @@ impl Object for ApubCommunity {
inbox: self.inbox_url.clone().into(),
outbox: generate_outbox_url(&self.actor_id)?.into(),
followers: self.followers_url.clone().map(Into::into),
endpoints: self.shared_inbox_url.clone().map(|s| Endpoints {
shared_inbox: s.into(),
}),
endpoints: None,
public_key: self.public_key(),
language,
published: Some(self.published),
Expand Down Expand Up @@ -165,8 +163,13 @@ impl Object for ApubCommunity {
banner,
description,
followers_url: group.followers.clone().map(Into::into),
inbox_url: Some(group.inbox.into()),
shared_inbox_url: group.endpoints.map(|e| e.shared_inbox.into()),
inbox_url: Some(
group
.endpoints
.map(|e| e.shared_inbox)
.unwrap_or(group.inbox)
.into(),
),
moderators_url: group.attributed_to.clone().map(Into::into),
posting_restricted_to_mods: group.posting_restricted_to_mods,
featured_url: group.featured.clone().map(Into::into),
Expand Down Expand Up @@ -225,7 +228,7 @@ impl Actor for ApubCommunity {
}

fn shared_inbox(&self) -> Option<Url> {
self.shared_inbox_url.clone().map(Into::into)
None
}
}

Expand Down
20 changes: 10 additions & 10 deletions crates/apub/src/objects/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use crate::{
local_site_data_cached,
objects::{instance::fetch_instance_actor_for_object, read_from_string_or_source_opt},
protocol::{
objects::{
person::{Person, UserTypes},
Endpoints,
},
objects::person::{Person, UserTypes},
ImageObject,
Source,
},
Expand Down Expand Up @@ -118,9 +115,7 @@ impl Object for ApubPerson {
matrix_user_id: self.matrix_user_id.clone(),
published: Some(self.published),
outbox: generate_outbox_url(&self.actor_id)?.into(),
endpoints: self.shared_inbox_url.clone().map(|s| Endpoints {
shared_inbox: s.into(),
}),
endpoints: None,
public_key: self.public_key(),
updated: self.updated,
inbox: self.inbox_url.clone().into(),
Expand Down Expand Up @@ -182,8 +177,13 @@ impl Object for ApubPerson {
private_key: None,
public_key: person.public_key.public_key_pem,
last_refreshed_at: Some(naive_now()),
inbox_url: Some(person.inbox.into()),
shared_inbox_url: person.endpoints.map(|e| e.shared_inbox.into()),
inbox_url: Some(
person
.endpoints
.map(|e| e.shared_inbox)
.unwrap_or(person.inbox)
.into(),
),
matrix_user_id: person.matrix_user_id,
instance_id,
};
Expand Down Expand Up @@ -211,7 +211,7 @@ impl Actor for ApubPerson {
}

fn shared_inbox(&self) -> Option<Url> {
self.shared_inbox_url.clone().map(Into::into)
None
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/db_schema/src/impls/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ mod tests {
banner: None,
followers_url: inserted_community.followers_url.clone(),
inbox_url: inserted_community.inbox_url.clone(),
shared_inbox_url: None,
moderators_url: None,
featured_url: None,
hidden: false,
Expand Down
1 change: 0 additions & 1 deletion crates/db_schema/src/impls/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ mod tests {
public_key: "pubkey".to_owned(),
last_refreshed_at: inserted_person.published,
inbox_url: inserted_person.inbox_url.clone(),
shared_inbox_url: None,
matrix_user_id: None,
ban_expires: None,
instance_id: inserted_instance.id,
Expand Down
4 changes: 0 additions & 4 deletions crates/db_schema/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ diesel::table! {
followers_url -> Nullable<Varchar>,
#[max_length = 255]
inbox_url -> Varchar,
#[max_length = 255]
shared_inbox_url -> Nullable<Varchar>,
hidden -> Bool,
posting_restricted_to_mods -> Bool,
instance_id -> Int4,
Expand Down Expand Up @@ -686,8 +684,6 @@ diesel::table! {
deleted -> Bool,
#[max_length = 255]
inbox_url -> Varchar,
#[max_length = 255]
shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>,
bot_account -> Bool,
ban_expires -> Nullable<Timestamptz>,
Expand Down
5 changes: 0 additions & 5 deletions crates/db_schema/src/source/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ pub struct Community {
#[cfg_attr(feature = "full", ts(skip))]
#[serde(skip, default = "placeholder_apub_url")]
pub inbox_url: DbUrl,
#[serde(skip)]
pub shared_inbox_url: Option<DbUrl>,
/// Whether the community is hidden.
pub hidden: bool,
/// Whether posting is restricted to mods only.
Expand Down Expand Up @@ -107,8 +105,6 @@ pub struct CommunityInsertForm {
#[new(default)]
pub inbox_url: Option<DbUrl>,
#[new(default)]
pub shared_inbox_url: Option<DbUrl>,
#[new(default)]
pub moderators_url: Option<DbUrl>,
#[new(default)]
pub featured_url: Option<DbUrl>,
Expand Down Expand Up @@ -140,7 +136,6 @@ pub struct CommunityUpdateForm {
pub banner: Option<Option<DbUrl>>,
pub followers_url: Option<DbUrl>,
pub inbox_url: Option<DbUrl>,
pub shared_inbox_url: Option<Option<DbUrl>>,
pub moderators_url: Option<DbUrl>,
pub featured_url: Option<DbUrl>,
pub hidden: Option<bool>,
Expand Down
5 changes: 0 additions & 5 deletions crates/db_schema/src/source/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ pub struct Person {
#[cfg_attr(feature = "full", ts(skip))]
#[serde(skip, default = "placeholder_apub_url")]
pub inbox_url: DbUrl,
#[serde(skip)]
pub shared_inbox_url: Option<DbUrl>,
/// A matrix id, usually given an @person:matrix.org
pub matrix_user_id: Option<String>,
/// Whether the person is a bot account.
Expand Down Expand Up @@ -93,8 +91,6 @@ pub struct PersonInsertForm {
#[new(default)]
pub inbox_url: Option<DbUrl>,
#[new(default)]
pub shared_inbox_url: Option<DbUrl>,
#[new(default)]
pub matrix_user_id: Option<String>,
#[new(default)]
pub bot_account: Option<bool>,
Expand All @@ -119,7 +115,6 @@ pub struct PersonUpdateForm {
pub banner: Option<Option<DbUrl>>,
pub deleted: Option<bool>,
pub inbox_url: Option<DbUrl>,
pub shared_inbox_url: Option<Option<DbUrl>>,
pub matrix_user_id: Option<Option<String>>,
pub bot_account: Option<bool>,
pub ban_expires: Option<Option<DateTime<Utc>>>,
Expand Down
Loading

0 comments on commit f05afea

Please sign in to comment.