From f05afead02f0e4ca2c54612ef48175465830599a Mon Sep 17 00:00:00 2001 From: Nutomic Date: Sat, 26 Oct 2024 20:54:29 +0200 Subject: [PATCH] Remove individual user/community inboxes (#5124) * Remove endpoints for individual community/user inboxes fixes #4147 fixes #3928 * Remove shared_inbox_url columns * fmt --- crates/api_common/src/utils.rs | 13 +++-- crates/api_crud/src/community/create.rs | 4 +- crates/api_crud/src/site/create.rs | 4 +- crates/api_crud/src/user/create.rs | 4 +- .../apub/src/activities/community/update.rs | 10 +++- crates/apub/src/http/community.rs | 20 +------- crates/apub/src/http/person.rs | 23 +-------- crates/apub/src/http/routes.rs | 5 +- crates/apub/src/objects/community.rs | 17 ++++--- crates/apub/src/objects/person.rs | 20 ++++---- crates/db_schema/src/impls/community.rs | 1 - crates/db_schema/src/impls/person.rs | 1 - crates/db_schema/src/schema.rs | 4 -- crates/db_schema/src/source/community.rs | 5 -- crates/db_schema/src/source/person.rs | 5 -- crates/db_views/src/comment_report_view.rs | 5 -- crates/db_views/src/comment_view.rs | 2 - crates/db_views/src/post_view.rs | 2 - .../src/registration_application_view.rs | 2 - .../src/community_follower_view.rs | 9 ++-- crates/federate/src/worker.rs | 5 +- .../down.sql | 6 +++ .../up.sql | 33 +++++++++++++ src/code_migrations.rs | 48 +++++-------------- 24 files changed, 100 insertions(+), 148 deletions(-) create mode 100644 migrations/2024-10-18-074533_no-individual-inboxes/down.sql create mode 100644 migrations/2024-10-18-074533_no-individual-inboxes/up.sql diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index e255e36c2..87cdf9eef 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -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}, @@ -973,12 +976,8 @@ pub fn generate_followers_url(actor_id: &DbUrl) -> Result { Ok(Url::parse(&format!("{actor_id}/followers"))?.into()) } -pub fn generate_inbox_url(actor_id: &DbUrl) -> Result { - Ok(Url::parse(&format!("{actor_id}/inbox"))?.into()) -} - -pub fn generate_shared_inbox_url(settings: &Settings) -> LemmyResult { - let url = format!("{}/inbox", settings.get_protocol_and_hostname()); +pub fn generate_inbox_url() -> LemmyResult { + let url = format!("{}/inbox", SETTINGS.get_protocol_and_hostname()); Ok(Url::parse(&url)?.into()) } diff --git a/crates/api_crud/src/community/create.rs b/crates/api_crud/src/community/create.rs index 4e3e356e0..f02d733e5 100644 --- a/crates/api_crud/src/community/create.rs +++ b/crates/api_crud/src/community/create.rs @@ -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, @@ -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( diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index 07efa72b9..733837de7 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -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, @@ -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); diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index bf17d6f8e..ed560e3d6 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -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, @@ -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) }; diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index f507b3425..48a64bd9d 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -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), diff --git a/crates/apub/src/http/community.rs b/crates/apub/src/http/community.rs index ca4d2eea5..37482aedb 100644 --- a/crates/apub/src/http/community.rs +++ b/crates/apub/src/http/community.rs @@ -1,5 +1,4 @@ use crate::{ - activity_lists::GroupInboxActivities, collections::{ community_featured::ApubCommunityFeatured, community_follower::ApubCommunityFollower, @@ -7,15 +6,13 @@ use crate::{ 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}; @@ -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, -) -> LemmyResult { - receive_activity::, 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, diff --git a/crates/apub/src/http/person.rs b/crates/apub/src/http/person.rs index e8e072a97..0f628c497 100644 --- a/crates/apub/src/http/person.rs +++ b/crates/apub/src/http/person.rs @@ -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}; @@ -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, -) -> LemmyResult { - receive_activity::, UserOrCommunity, LemmyContext>( - request, body, &data, - ) - .await -} - #[tracing::instrument(skip_all)] pub(crate) async fn get_apub_person_outbox( info: web::Path, diff --git a/crates/apub/src/http/routes.rs b/crates/apub/src/http/routes.rs index ab046afe1..9479e6312 100644 --- a/crates/apub/src/http/routes.rs +++ b/crates/apub/src/http/routes.rs @@ -1,7 +1,6 @@ use crate::http::{ comment::get_apub_comment, community::{ - community_inbox, get_apub_community_featured, get_apub_community_followers, get_apub_community_http, @@ -9,7 +8,7 @@ use crate::http::{ 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}, @@ -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)), ); } diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 2c60b87b3..c8479eaba 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -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, }, @@ -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), @@ -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), @@ -225,7 +228,7 @@ impl Actor for ApubCommunity { } fn shared_inbox(&self) -> Option { - self.shared_inbox_url.clone().map(Into::into) + None } } diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 406a77d94..4e8519f78 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -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, }, @@ -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(), @@ -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, }; @@ -211,7 +211,7 @@ impl Actor for ApubPerson { } fn shared_inbox(&self) -> Option { - self.shared_inbox_url.clone().map(Into::into) + None } } diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index a054059a4..355979264 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -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, diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 0e6dc8556..a5f8ae1a0 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -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, diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 2a8bfd150..544da607b 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -188,8 +188,6 @@ diesel::table! { followers_url -> Nullable, #[max_length = 255] inbox_url -> Varchar, - #[max_length = 255] - shared_inbox_url -> Nullable, hidden -> Bool, posting_restricted_to_mods -> Bool, instance_id -> Int4, @@ -686,8 +684,6 @@ diesel::table! { deleted -> Bool, #[max_length = 255] inbox_url -> Varchar, - #[max_length = 255] - shared_inbox_url -> Nullable, matrix_user_id -> Nullable, bot_account -> Bool, ban_expires -> Nullable, diff --git a/crates/db_schema/src/source/community.rs b/crates/db_schema/src/source/community.rs index ced85bf4c..853667f7f 100644 --- a/crates/db_schema/src/source/community.rs +++ b/crates/db_schema/src/source/community.rs @@ -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, /// Whether the community is hidden. pub hidden: bool, /// Whether posting is restricted to mods only. @@ -107,8 +105,6 @@ pub struct CommunityInsertForm { #[new(default)] pub inbox_url: Option, #[new(default)] - pub shared_inbox_url: Option, - #[new(default)] pub moderators_url: Option, #[new(default)] pub featured_url: Option, @@ -140,7 +136,6 @@ pub struct CommunityUpdateForm { pub banner: Option>, pub followers_url: Option, pub inbox_url: Option, - pub shared_inbox_url: Option>, pub moderators_url: Option, pub featured_url: Option, pub hidden: Option, diff --git a/crates/db_schema/src/source/person.rs b/crates/db_schema/src/source/person.rs index 332b46eb5..c3aeeb4d7 100644 --- a/crates/db_schema/src/source/person.rs +++ b/crates/db_schema/src/source/person.rs @@ -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, /// A matrix id, usually given an @person:matrix.org pub matrix_user_id: Option, /// Whether the person is a bot account. @@ -93,8 +91,6 @@ pub struct PersonInsertForm { #[new(default)] pub inbox_url: Option, #[new(default)] - pub shared_inbox_url: Option, - #[new(default)] pub matrix_user_id: Option, #[new(default)] pub bot_account: Option, @@ -119,7 +115,6 @@ pub struct PersonUpdateForm { pub banner: Option>, pub deleted: Option, pub inbox_url: Option, - pub shared_inbox_url: Option>, pub matrix_user_id: Option>, pub bot_account: Option, pub ban_expires: Option>>, diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 753304f70..c65e121e2 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -402,7 +402,6 @@ mod tests { last_refreshed_at: inserted_community.last_refreshed_at, followers_url: inserted_community.followers_url, inbox_url: inserted_community.inbox_url, - shared_inbox_url: inserted_community.shared_inbox_url, moderators_url: inserted_community.moderators_url, featured_url: inserted_community.featured_url, instance_id: inserted_instance.id, @@ -423,7 +422,6 @@ mod tests { banner: None, updated: None, inbox_url: inserted_jessica.inbox_url.clone(), - shared_inbox_url: None, matrix_user_id: None, ban_expires: None, instance_id: inserted_instance.id, @@ -446,7 +444,6 @@ mod tests { banner: None, updated: None, inbox_url: inserted_timmy.inbox_url.clone(), - shared_inbox_url: None, matrix_user_id: None, ban_expires: None, instance_id: inserted_instance.id, @@ -488,7 +485,6 @@ mod tests { banner: None, updated: None, inbox_url: inserted_sara.inbox_url.clone(), - shared_inbox_url: None, matrix_user_id: None, ban_expires: None, instance_id: inserted_instance.id, @@ -550,7 +546,6 @@ mod tests { private_key: inserted_timmy.private_key.clone(), public_key: inserted_timmy.public_key.clone(), last_refreshed_at: inserted_timmy.last_refreshed_at, - shared_inbox_url: None, matrix_user_id: None, ban_expires: None, instance_id: inserted_instance.id, diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 55fea4d66..ac0e03f65 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -1049,7 +1049,6 @@ mod tests { banner: None, updated: None, inbox_url: data.timmy_local_user_view.person.inbox_url.clone(), - shared_inbox_url: None, matrix_user_id: None, ban_expires: None, instance_id: data.inserted_instance.id, @@ -1105,7 +1104,6 @@ mod tests { last_refreshed_at: data.inserted_community.last_refreshed_at, followers_url: data.inserted_community.followers_url.clone(), inbox_url: data.inserted_community.inbox_url.clone(), - shared_inbox_url: data.inserted_community.shared_inbox_url.clone(), moderators_url: data.inserted_community.moderators_url.clone(), featured_url: data.inserted_community.featured_url.clone(), visibility: CommunityVisibility::Public, diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index e07133471..41b730c46 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -1812,7 +1812,6 @@ mod tests { banner: None, updated: None, inbox_url: inserted_person.inbox_url.clone(), - shared_inbox_url: None, matrix_user_id: None, ban_expires: None, instance_id: data.inserted_instance.id, @@ -1847,7 +1846,6 @@ mod tests { last_refreshed_at: inserted_community.last_refreshed_at, followers_url: inserted_community.followers_url.clone(), inbox_url: inserted_community.inbox_url.clone(), - shared_inbox_url: inserted_community.shared_inbox_url.clone(), moderators_url: inserted_community.moderators_url.clone(), featured_url: inserted_community.featured_url.clone(), visibility: CommunityVisibility::Public, diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index 6460becb7..a0a40789b 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -258,7 +258,6 @@ mod tests { banner: None, updated: None, inbox_url: inserted_sara_person.inbox_url.clone(), - shared_inbox_url: None, matrix_user_id: None, instance_id: inserted_instance.id, private_key: inserted_sara_person.private_key, @@ -328,7 +327,6 @@ mod tests { banner: None, updated: None, inbox_url: inserted_timmy_person.inbox_url.clone(), - shared_inbox_url: None, matrix_user_id: None, instance_id: inserted_instance.id, private_key: inserted_timmy_person.private_key, diff --git a/crates/db_views_actor/src/community_follower_view.rs b/crates/db_views_actor/src/community_follower_view.rs index 7b942e043..92889d12d 100644 --- a/crates/db_views_actor/src/community_follower_view.rs +++ b/crates/db_views_actor/src/community_follower_view.rs @@ -10,7 +10,7 @@ use diesel_async::RunQueryDsl; use lemmy_db_schema::{ newtypes::{CommunityId, DbUrl, InstanceId, PersonId}, schema::{community, community_follower, person}, - utils::{functions::coalesce, get_conn, DbPool}, + utils::{get_conn, DbPool}, }; impl CommunityFollowerView { @@ -37,10 +37,7 @@ impl CommunityFollowerView { // local-person+remote-community or remote-person+local-community .filter(not(person::local)) .filter(community_follower::published.gt(published_since.naive_utc())) - .select(( - community::id, - coalesce(person::shared_inbox_url, person::inbox_url), - )) + .select((community::id, person::inbox_url)) .distinct() // only need each community_id, inbox combination once .load::<(CommunityId, DbUrl)>(conn) .await @@ -54,7 +51,7 @@ impl CommunityFollowerView { .filter(community_follower::community_id.eq(community_id)) .filter(not(person::local)) .inner_join(person::table) - .select(coalesce(person::shared_inbox_url, person::inbox_url)) + .select(person::inbox_url) .distinct() .load::(conn) .await?; diff --git a/crates/federate/src/worker.rs b/crates/federate/src/worker.rs index 0d4ad04d5..b0254ba0b 100644 --- a/crates/federate/src/worker.rs +++ b/crates/federate/src/worker.rs @@ -449,7 +449,7 @@ mod test { protocol::context::WithContext, }; use actix_web::{dev::ServerHandle, web, App, HttpResponse, HttpServer}; - use lemmy_api_common::utils::{generate_inbox_url, generate_shared_inbox_url}; + use lemmy_api_common::utils::generate_inbox_url; use lemmy_db_schema::{ newtypes::DbUrl, source::{ @@ -491,8 +491,7 @@ mod test { let person_form = PersonInsertForm { actor_id: Some(actor_id.clone()), private_key: (Some(actor_keypair.private_key)), - inbox_url: Some(generate_inbox_url(&actor_id)?), - shared_inbox_url: Some(generate_shared_inbox_url(context.settings())?), + inbox_url: Some(generate_inbox_url()?), ..PersonInsertForm::new("alice".to_string(), actor_keypair.public_key, instance.id) }; let person = Person::create(&mut context.pool(), &person_form).await?; diff --git a/migrations/2024-10-18-074533_no-individual-inboxes/down.sql b/migrations/2024-10-18-074533_no-individual-inboxes/down.sql new file mode 100644 index 000000000..6da025919 --- /dev/null +++ b/migrations/2024-10-18-074533_no-individual-inboxes/down.sql @@ -0,0 +1,6 @@ +ALTER TABLE person + ADD COLUMN shared_inbox_url varchar(255); + +ALTER TABLE community + ADD COLUMN shared_inbox_url varchar(255); + diff --git a/migrations/2024-10-18-074533_no-individual-inboxes/up.sql b/migrations/2024-10-18-074533_no-individual-inboxes/up.sql new file mode 100644 index 000000000..98cefcee0 --- /dev/null +++ b/migrations/2024-10-18-074533_no-individual-inboxes/up.sql @@ -0,0 +1,33 @@ +-- replace value of inbox_url with shared_inbox_url and the drop shared inbox +UPDATE + person +SET + inbox_url = subquery.inbox_url +FROM ( + SELECT + id, + coalesce(shared_inbox_url, inbox_url) AS inbox_url + FROM + person) AS subquery +WHERE + person.id = subquery.id; + +ALTER TABLE person + DROP COLUMN shared_inbox_url; + +UPDATE + community +SET + inbox_url = subquery.inbox_url +FROM ( + SELECT + id, + coalesce(shared_inbox_url, inbox_url) AS inbox_url + FROM + community) AS subquery +WHERE + community.id = subquery.id; + +ALTER TABLE community + DROP COLUMN shared_inbox_url; + diff --git a/src/code_migrations.rs b/src/code_migrations.rs index e78f8bf0b..84af43ea7 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -10,13 +10,7 @@ use diesel::{ use diesel_async::RunQueryDsl; use lemmy_api_common::{ lemmy_db_views::structs::SiteView, - utils::{ - generate_followers_url, - generate_inbox_url, - generate_local_apub_endpoint, - generate_shared_inbox_url, - EndpointType, - }, + utils::{generate_followers_url, generate_inbox_url, generate_local_apub_endpoint, EndpointType}, }; use lemmy_db_schema::{ source::{ @@ -49,8 +43,8 @@ pub async fn run_advanced_migrations( comment_updates_2020_04_03(pool, protocol_and_hostname).await?; private_message_updates_2020_05_05(pool, protocol_and_hostname).await?; post_thumbnail_url_updates_2020_07_27(pool, protocol_and_hostname).await?; - apub_columns_2021_02_02(pool, settings).await?; - instance_actor_2022_01_28(pool, protocol_and_hostname, settings).await?; + apub_columns_2021_02_02(pool).await?; + instance_actor_2022_01_28(pool, protocol_and_hostname).await?; regenerate_public_keys_2022_07_05(pool).await?; initialize_local_site_2022_10_10(pool, settings).await?; @@ -282,36 +276,27 @@ async fn post_thumbnail_url_updates_2020_07_27( /// We are setting inbox and follower URLs for local and remote actors alike, because for now /// all federated instances are also Lemmy and use the same URL scheme. -async fn apub_columns_2021_02_02(pool: &mut DbPool<'_>, settings: &Settings) -> LemmyResult<()> { +async fn apub_columns_2021_02_02(pool: &mut DbPool<'_>) -> LemmyResult<()> { let conn = &mut get_conn(pool).await?; info!("Running apub_columns_2021_02_02"); { - use lemmy_db_schema::schema::person::dsl::{inbox_url, person, shared_inbox_url}; + use lemmy_db_schema::schema::person::dsl::{inbox_url, person}; let persons = person .filter(inbox_url.like("http://changeme%")) .load::(conn) .await?; for p in &persons { - let inbox_url_ = generate_inbox_url(&p.actor_id)?; - let shared_inbox_url_ = generate_shared_inbox_url(settings)?; + let inbox_url_ = generate_inbox_url()?; diesel::update(person.find(p.id)) - .set(( - inbox_url.eq(inbox_url_), - shared_inbox_url.eq(shared_inbox_url_), - )) + .set((inbox_url.eq(inbox_url_),)) .get_result::(conn) .await?; } } { - use lemmy_db_schema::schema::community::dsl::{ - community, - followers_url, - inbox_url, - shared_inbox_url, - }; + use lemmy_db_schema::schema::community::dsl::{community, followers_url, inbox_url}; let communities = community .filter(inbox_url.like("http://changeme%")) .load::(conn) @@ -319,14 +304,9 @@ async fn apub_columns_2021_02_02(pool: &mut DbPool<'_>, settings: &Settings) -> for c in &communities { let followers_url_ = generate_followers_url(&c.actor_id)?; - let inbox_url_ = generate_inbox_url(&c.actor_id)?; - let shared_inbox_url_ = generate_shared_inbox_url(settings)?; + let inbox_url_ = generate_inbox_url()?; diesel::update(community.find(c.id)) - .set(( - followers_url.eq(followers_url_), - inbox_url.eq(inbox_url_), - shared_inbox_url.eq(shared_inbox_url_), - )) + .set((followers_url.eq(followers_url_), inbox_url.eq(inbox_url_))) .get_result::(conn) .await?; } @@ -342,7 +322,6 @@ async fn apub_columns_2021_02_02(pool: &mut DbPool<'_>, settings: &Settings) -> async fn instance_actor_2022_01_28( pool: &mut DbPool<'_>, protocol_and_hostname: &str, - settings: &Settings, ) -> LemmyResult<()> { info!("Running instance_actor_2021_09_29"); if let Ok(site_view) = SiteView::read_local(pool).await { @@ -356,7 +335,7 @@ async fn instance_actor_2022_01_28( let site_form = SiteUpdateForm { actor_id: Some(actor_id.clone().into()), last_refreshed_at: Some(naive_now()), - inbox_url: Some(generate_shared_inbox_url(settings)?), + inbox_url: Some(generate_inbox_url()?), private_key: Some(Some(key_pair.private_key)), public_key: Some(key_pair.public_key), ..Default::default() @@ -457,8 +436,7 @@ async fn initialize_local_site_2022_10_10( // Register the user if there's a site setup let person_form = PersonInsertForm { actor_id: Some(person_actor_id.clone()), - inbox_url: Some(generate_inbox_url(&person_actor_id)?), - shared_inbox_url: Some(generate_shared_inbox_url(settings)?), + inbox_url: Some(generate_inbox_url()?), private_key: Some(person_keypair.private_key), ..PersonInsertForm::new( setup.admin_username.clone(), @@ -488,7 +466,7 @@ async fn initialize_local_site_2022_10_10( let site_form = SiteInsertForm { actor_id: Some(site_actor_id.clone().into()), last_refreshed_at: Some(naive_now()), - inbox_url: Some(generate_shared_inbox_url(settings)?), + inbox_url: Some(generate_inbox_url()?), private_key: Some(site_key_pair.private_key), public_key: Some(site_key_pair.public_key),