5 pub mod private_message;
6 #[cfg(feature = "full")]
10 #[cfg(feature = "full")]
15 extern crate strum_macros;
16 pub extern crate lemmy_db_schema;
17 pub extern crate lemmy_db_views;
18 pub extern crate lemmy_db_views_actor;
19 pub extern crate lemmy_db_views_moderator;
21 use crate::websocket::chat_server::ChatServer;
24 use lemmy_db_schema::{newtypes::DbUrl, source::secret::Secret, utils::DbPool};
28 rate_limit::RateLimitCell,
29 settings::{structs::Settings, SETTINGS},
31 use reqwest_middleware::ClientWithMiddleware;
32 use url::{ParseError, Url};
34 pub struct LemmyContext {
36 chat_server: Addr<ChatServer>,
37 client: ClientWithMiddleware,
40 rate_limit_cell: RateLimitCell,
46 chat_server: Addr<ChatServer>,
47 client: ClientWithMiddleware,
50 settings_updated_channel: RateLimitCell,
58 rate_limit_cell: settings_updated_channel,
61 pub fn pool(&self) -> &DbPool {
64 pub fn chat_server(&self) -> &Addr<ChatServer> {
67 pub fn client(&self) -> &ClientWithMiddleware {
70 pub fn settings(&self) -> &'static Settings {
73 pub fn secret(&self) -> &Secret {
76 pub fn settings_updated_channel(&self) -> &RateLimitCell {
81 impl Clone for LemmyContext {
82 fn clone(&self) -> Self {
84 pool: self.pool.clone(),
85 chat_server: self.chat_server.clone(),
86 client: self.client.clone(),
87 settings: self.settings.clone(),
88 secret: self.secret.clone(),
89 rate_limit_cell: self.rate_limit_cell.clone(),
94 pub enum EndpointType {
102 /// Generates an apub endpoint for a given domain, IE xyz.tld
103 pub fn generate_local_apub_endpoint(
104 endpoint_type: EndpointType,
107 ) -> Result<DbUrl, ParseError> {
108 let point = match endpoint_type {
109 EndpointType::Community => "c",
110 EndpointType::Person => "u",
111 EndpointType::Post => "post",
112 EndpointType::Comment => "comment",
113 EndpointType::PrivateMessage => "private_message",
116 Ok(Url::parse(&format!("{}/{}/{}", domain, point, name))?.into())
119 pub fn generate_followers_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
120 Ok(Url::parse(&format!("{}/followers", actor_id))?.into())
123 pub fn generate_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
124 Ok(Url::parse(&format!("{}/inbox", actor_id))?.into())
127 pub fn generate_site_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
128 let mut actor_id: Url = actor_id.clone().into();
129 actor_id.set_path("site_inbox");
133 pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, LemmyError> {
134 let actor_id: Url = actor_id.clone().into();
138 &actor_id.host_str().context(location_info!())?,
139 if let Some(port) = actor_id.port() {
145 Ok(Url::parse(&url)?.into())
148 pub fn generate_outbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
149 Ok(Url::parse(&format!("{}/outbox", actor_id))?.into())
152 pub fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
153 Ok(Url::parse(&format!("{}/moderators", community_id))?.into())