use crate::websocket::chat_server::ChatServer;
use actix::Addr;
-use lemmy_db_schema::{source::secret::Secret, utils::DbPool};
+use anyhow::Context;
+use lemmy_db_schema::{newtypes::DbUrl, source::secret::Secret, utils::DbPool};
use lemmy_utils::{
+ error::LemmyError,
+ location_info,
rate_limit::RateLimitCell,
settings::{structs::Settings, SETTINGS},
};
use reqwest_middleware::ClientWithMiddleware;
+use url::{ParseError, Url};
pub struct LemmyContext {
pool: DbPool,
}
}
}
+
+pub enum EndpointType {
+ Community,
+ Person,
+ Post,
+ Comment,
+ PrivateMessage,
+}
+
+/// Generates an apub endpoint for a given domain, IE xyz.tld
+pub fn generate_local_apub_endpoint(
+ endpoint_type: EndpointType,
+ name: &str,
+ domain: &str,
+) -> Result<DbUrl, ParseError> {
+ let point = match endpoint_type {
+ EndpointType::Community => "c",
+ EndpointType::Person => "u",
+ EndpointType::Post => "post",
+ EndpointType::Comment => "comment",
+ EndpointType::PrivateMessage => "private_message",
+ };
+
+ Ok(Url::parse(&format!("{}/{}/{}", domain, point, name))?.into())
+}
+
+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_site_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
+ let mut actor_id: Url = actor_id.clone().into();
+ actor_id.set_path("site_inbox");
+ Ok(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 {
+ String::new()
+ },
+ );
+ Ok(Url::parse(&url)?.into())
+}
+
+pub fn generate_outbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
+ Ok(Url::parse(&format!("{}/outbox", actor_id))?.into())
+}
+
+pub fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
+ Ok(Url::parse(&format!("{}/moderators", community_id))?.into())
+}
use actix_web::web::Data;
use lemmy_api_common::{
comment::{CommentResponse, CreateComment},
+ generate_local_apub_endpoint,
utils::{
check_community_ban,
check_community_deleted_or_removed,
send::{send_comment_ws_message, send_local_notifs},
UserOperationCrud,
},
+ EndpointType,
LemmyContext,
};
use lemmy_apub::{
- generate_local_apub_endpoint,
objects::comment::ApubComment,
protocol::activities::{create_or_update::note::CreateOrUpdateNote, CreateOrUpdateType},
- EndpointType,
};
use lemmy_db_schema::{
source::{
use actix_web::web::Data;
use lemmy_api_common::{
community::{CommunityResponse, CreateCommunity},
- utils::{get_local_user_view_from_jwt, is_admin, local_site_to_slur_regex},
- LemmyContext,
-};
-use lemmy_apub::{
generate_followers_url,
generate_inbox_url,
generate_local_apub_endpoint,
generate_shared_inbox_url,
- objects::community::ApubCommunity,
+ utils::{get_local_user_view_from_jwt, is_admin, local_site_to_slur_regex},
EndpointType,
+ LemmyContext,
};
+use lemmy_apub::objects::community::ApubCommunity;
use lemmy_db_schema::{
source::community::{
Community,
use crate::PerformCrud;
use actix_web::web::Data;
use lemmy_api_common::{
+ generate_local_apub_endpoint,
post::{CreatePost, PostResponse},
request::fetch_site_data,
utils::{
mark_post_as_read,
},
websocket::{send::send_post_ws_message, UserOperationCrud},
+ EndpointType,
LemmyContext,
};
use lemmy_apub::{
- generate_local_apub_endpoint,
objects::post::ApubPost,
protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
- EndpointType,
};
use lemmy_db_schema::{
impls::actor_language::default_post_language,
use crate::PerformCrud;
use actix_web::web::Data;
use lemmy_api_common::{
+ generate_local_apub_endpoint,
private_message::{CreatePrivateMessage, PrivateMessageResponse},
utils::{
check_person_block,
send_email_to_user,
},
websocket::{send::send_pm_ws_message, UserOperationCrud},
+ EndpointType,
LemmyContext,
};
-use lemmy_apub::{
- generate_local_apub_endpoint,
- protocol::activities::{
- create_or_update::chat_message::CreateOrUpdateChatMessage,
- CreateOrUpdateType,
- },
- EndpointType,
+use lemmy_apub::protocol::activities::{
+ create_or_update::chat_message::CreateOrUpdateChatMessage,
+ CreateOrUpdateType,
};
use lemmy_db_schema::{
source::{
use activitypub_federation::core::signatures::generate_actor_keypair;
use actix_web::web::Data;
use lemmy_api_common::{
+ generate_site_inbox_url,
site::{CreateSite, SiteResponse},
utils::{
get_local_user_view_from_jwt,
},
LemmyContext,
};
-use lemmy_apub::generate_site_inbox_url;
use lemmy_db_schema::{
newtypes::DbUrl,
source::{
use activitypub_federation::core::signatures::generate_actor_keypair;
use actix_web::web::Data;
use lemmy_api_common::{
+ generate_inbox_url,
+ generate_local_apub_endpoint,
+ generate_shared_inbox_url,
person::{LoginResponse, Register},
utils::{
honeypot_check,
send_verification_email,
},
websocket::messages::CheckCaptcha,
- LemmyContext,
-};
-use lemmy_apub::{
- generate_inbox_url,
- generate_local_apub_endpoint,
- generate_shared_inbox_url,
EndpointType,
+ LemmyContext,
};
use lemmy_db_schema::{
aggregates::structs::PersonAggregates,
verify_person_in_community,
},
activity_lists::AnnouncableActivities,
- generate_moderators_url,
local_instance,
objects::{community::ApubCommunity, person::ApubPerson},
protocol::{activities::community::add_mod::AddMod, InCommunity},
traits::{ActivityHandler, Actor},
};
use activitystreams_kinds::{activity::AddType, public};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::{generate_moderators_url, LemmyContext};
use lemmy_db_schema::{
source::{
community::{CommunityModerator, CommunityModeratorForm},
verify_person_in_community,
},
activity_lists::AnnouncableActivities,
- generate_moderators_url,
local_instance,
objects::{community::ApubCommunity, person::ApubPerson},
protocol::{activities::community::remove_mod::RemoveMod, InCommunity},
traits::{ActivityHandler, Actor},
};
use activitystreams_kinds::{activity::RemoveType, public};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::{generate_moderators_url, LemmyContext};
use lemmy_db_schema::{
source::{
community::{CommunityModerator, CommunityModeratorForm},
use crate::{
- generate_moderators_url,
insert_activity,
local_instance,
objects::{community::ApubCommunity, person::ApubPerson},
};
use activitystreams_kinds::public;
use anyhow::anyhow;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::{generate_moderators_url, LemmyContext};
use lemmy_db_schema::{
newtypes::CommunityId,
source::{community::Community, local_site::LocalSite},
use crate::{
collections::CommunityContext,
- generate_moderators_url,
local_instance,
objects::person::ApubPerson,
protocol::collections::group_moderators::GroupModerators,
};
use activitystreams_kinds::collection::OrderedCollectionType;
use chrono::NaiveDateTime;
+use lemmy_api_common::generate_moderators_url;
use lemmy_db_schema::{
source::community::{CommunityModerator, CommunityModeratorForm},
traits::Joinable,
use crate::{
activity_lists::AnnouncableActivities,
collections::CommunityContext,
- generate_outbox_url,
objects::post::ApubPost,
protocol::{
activities::{
use activitystreams_kinds::collection::OrderedCollectionType;
use chrono::NaiveDateTime;
use futures::future::join_all;
+use lemmy_api_common::generate_outbox_url;
use lemmy_db_schema::{
source::{person::Person, post::Post},
traits::Crud,
community_outbox::ApubCommunityOutbox,
CommunityContext,
},
- generate_outbox_url,
http::{create_apub_response, create_apub_tombstone_response, receive_lemmy_activity},
local_instance,
objects::{community::ApubCommunity, person::ApubPerson},
traits::ApubObject,
};
use actix_web::{web, HttpRequest, HttpResponse};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::{generate_outbox_url, LemmyContext};
use lemmy_db_schema::{source::community::Community, traits::ApubActor};
use lemmy_utils::error::LemmyError;
use serde::Deserialize;
use crate::{
activity_lists::PersonInboxActivitiesWithAnnouncable,
fetcher::user_or_community::UserOrCommunity,
- generate_outbox_url,
http::{create_apub_response, create_apub_tombstone_response, receive_lemmy_activity},
objects::person::ApubPerson,
protocol::collections::empty_outbox::EmptyOutbox,
};
use activitypub_federation::{deser::context::WithContext, traits::ApubObject};
use actix_web::{web, HttpRequest, HttpResponse};
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::{generate_outbox_url, LemmyContext};
use lemmy_db_schema::{source::person::Person, traits::ApubActor};
use lemmy_utils::error::LemmyError;
use serde::Deserialize;
LocalInstance,
UrlVerifier,
};
-use anyhow::Context;
use async_trait::async_trait;
use lemmy_api_common::LemmyContext;
use lemmy_db_schema::{
- newtypes::DbUrl,
source::{activity::Activity, instance::Instance, local_site::LocalSite},
utils::DbPool,
};
-use lemmy_utils::{error::LemmyError, location_info, settings::structs::Settings};
+use lemmy_utils::{error::LemmyError, settings::structs::Settings};
use once_cell::sync::Lazy;
use tokio::sync::OnceCell;
-use url::{ParseError, Url};
+use url::Url;
pub mod activities;
pub(crate) mod activity_lists;
Ok(())
}
-pub enum EndpointType {
- Community,
- Person,
- Post,
- Comment,
- PrivateMessage,
-}
-
-/// Generates an apub endpoint for a given domain, IE xyz.tld
-pub fn generate_local_apub_endpoint(
- endpoint_type: EndpointType,
- name: &str,
- domain: &str,
-) -> Result<DbUrl, ParseError> {
- let point = match endpoint_type {
- EndpointType::Community => "c",
- EndpointType::Person => "u",
- EndpointType::Post => "post",
- EndpointType::Comment => "comment",
- EndpointType::PrivateMessage => "private_message",
- };
-
- Ok(Url::parse(&format!("{}/{}/{}", domain, point, name))?.into())
-}
-
-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_site_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
- let mut actor_id: Url = actor_id.clone().into();
- actor_id.set_path("site_inbox");
- Ok(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 {
- String::new()
- },
- );
- Ok(Url::parse(&url)?.into())
-}
-
-pub fn generate_outbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
- Ok(Url::parse(&format!("{}/outbox", actor_id))?.into())
-}
-
-fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
- Ok(Url::parse(&format!("{}/moderators", community_id))?.into())
-}
-
/// Store a sent or received activity in the database, for logging purposes. These records are not
/// persistent.
#[tracing::instrument(skip(pool))]
check_apub_id_valid_with_strictness,
collections::{community_moderators::ApubCommunityModerators, CommunityContext},
fetch_local_site_data,
- generate_moderators_url,
- generate_outbox_url,
local_instance,
objects::instance::fetch_instance_actor_for_object,
protocol::{
use activitystreams_kinds::actor::GroupType;
use chrono::NaiveDateTime;
use itertools::Itertools;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::{generate_moderators_url, generate_outbox_url, LemmyContext};
use lemmy_db_schema::{
source::{
actor_language::CommunityLanguage,
use crate::{
check_apub_id_valid_with_strictness,
fetch_local_site_data,
- generate_outbox_url,
objects::{instance::fetch_instance_actor_for_object, read_from_string_or_source_opt},
protocol::{
objects::{
utils::verify_domains_match,
};
use chrono::NaiveDateTime;
-use lemmy_api_common::{utils::local_site_opt_to_slur_regex, LemmyContext};
+use lemmy_api_common::{generate_outbox_url, utils::local_site_opt_to_slur_regex, LemmyContext};
use lemmy_db_schema::{
source::{
instance::Instance,
-use crate::generate_followers_url;
use activitystreams_kinds::collection::CollectionType;
-use lemmy_api_common::LemmyContext;
+use lemmy_api_common::{generate_followers_url, LemmyContext};
use lemmy_db_schema::source::community::Community;
use lemmy_db_views_actor::structs::CommunityFollowerView;
use lemmy_utils::error::LemmyError;
TextExpressionMethods,
};
use diesel_async::RunQueryDsl;
-use lemmy_api_common::lemmy_db_views::structs::SiteView;
-use lemmy_apub::{
+use lemmy_api_common::{
generate_followers_url,
generate_inbox_url,
generate_local_apub_endpoint,
generate_shared_inbox_url,
generate_site_inbox_url,
+ lemmy_db_views::structs::SiteView,
EndpointType,
};
use lemmy_db_schema::{