source::{
community::{CommunityModerator_, Community_},
person_block::PersonBlock_,
- secret::SecretSingleton,
site::Site_,
},
Crud,
use lemmy_utils::{
claims::Claims,
email::send_email,
- settings::structs::Settings,
+ settings::structs::{FederationConfig, Settings},
utils::MentionData,
ApiError,
LemmyError,
post: Post,
pool: &DbPool,
do_send_email: bool,
+ settings: &Settings,
) -> Result<Vec<LocalUserId>, LemmyError> {
+ let settings = settings.to_owned();
let ids = blocking(pool, move |conn| {
- do_send_local_notifs(conn, &mentions, &comment, &person, &post, do_send_email)
+ do_send_local_notifs(
+ conn,
+ &mentions,
+ &comment,
+ &person,
+ &post,
+ do_send_email,
+ &settings,
+ )
})
.await?;
person: &Person,
post: &Post,
do_send_email: bool,
+ settings: &Settings,
) -> Vec<LocalUserId> {
let mut recipient_ids = Vec::new();
// Send the local mentions
for mention in mentions
.iter()
- .filter(|m| m.is_local() && m.name.ne(&person.name))
+ .filter(|m| m.is_local(&settings.hostname) && m.name.ne(&person.name))
.collect::<Vec<&MentionData>>()
{
if let Ok(mention_user_view) = LocalUserView::read_from_name(conn, &mention.name) {
"Mentioned by",
"Person Mention",
&comment.content,
+ settings,
)
}
}
"Reply from",
"Comment Reply",
&comment.content,
+ settings,
)
}
}
"Reply from",
"Post Reply",
&comment.content,
+ settings,
)
}
}
subject_text: &str,
body_text: &str,
comment_content: &str,
+ settings: &Settings,
) {
if local_user_view.person.banned || !local_user_view.local_user.send_notifications_to_email {
return;
if let Some(user_email) = &local_user_view.local_user.email {
let subject = &format!(
"{} - {} {}",
- subject_text,
- Settings::get().hostname,
- local_user_view.person.name,
+ subject_text, settings.hostname, local_user_view.person.name,
);
let html = &format!(
"<h1>{}</h1><br><div>{} - {}</div><br><a href={}/inbox>inbox</a>",
body_text,
local_user_view.person.name,
comment_content,
- Settings::get().get_protocol_and_hostname()
+ settings.get_protocol_and_hostname()
);
- match send_email(subject, user_email, &local_user_view.person.name, html) {
+ match send_email(
+ subject,
+ user_email,
+ &local_user_view.person.name,
+ html,
+ settings,
+ ) {
Ok(_o) => _o,
Err(e) => error!("{}", e),
};
pub async fn get_local_user_view_from_jwt(
jwt: &str,
pool: &DbPool,
+ secret: &Secret,
) -> Result<LocalUserView, LemmyError> {
- let jwt_secret = Secret::get().jwt_secret;
- let claims = Claims::decode(jwt, &jwt_secret)
+ let claims = Claims::decode(jwt, &secret.jwt_secret)
.map_err(|_| ApiError::err("not_logged_in"))?
.claims;
let local_user_id = LocalUserId(claims.sub);
pub async fn get_local_user_view_from_jwt_opt(
jwt: &Option<String>,
pool: &DbPool,
+ secret: &Secret,
) -> Result<Option<LocalUserView>, LemmyError> {
match jwt {
- Some(jwt) => Ok(Some(get_local_user_view_from_jwt(jwt, pool).await?)),
+ Some(jwt) => Ok(Some(get_local_user_view_from_jwt(jwt, pool, secret).await?)),
None => Ok(None),
}
}
pub async fn get_local_user_settings_view_from_jwt(
jwt: &str,
pool: &DbPool,
+ secret: &Secret,
) -> Result<LocalUserSettingsView, LemmyError> {
- let jwt_secret = Secret::get().jwt_secret;
- let claims = Claims::decode(jwt, &jwt_secret)
+ let claims = Claims::decode(jwt, &secret.jwt_secret)
.map_err(|_| ApiError::err("not_logged_in"))?
.claims;
let local_user_id = LocalUserId(claims.sub);
pub async fn get_local_user_settings_view_from_jwt_opt(
jwt: &Option<String>,
pool: &DbPool,
+ secret: &Secret,
) -> Result<Option<LocalUserSettingsView>, LemmyError> {
match jwt {
Some(jwt) => Ok(Some(
- get_local_user_settings_view_from_jwt(jwt, pool).await?,
+ get_local_user_settings_view_from_jwt(jwt, pool, secret).await?,
)),
None => Ok(None),
}
pub async fn build_federated_instances(
pool: &DbPool,
+ federation_config: &FederationConfig,
+ hostname: &str,
) -> Result<Option<FederatedInstances>, LemmyError> {
- if Settings::get().federation.enabled {
+ let federation = federation_config.to_owned();
+ if federation.enabled {
let distinct_communities = blocking(pool, move |conn| {
Community::distinct_federated_communities(conn)
})
.await??;
- let allowed = Settings::get().federation.allowed_instances;
- let blocked = Settings::get().federation.blocked_instances;
+ let allowed = federation.allowed_instances;
+ let blocked = federation.blocked_instances;
let mut linked = distinct_communities
.iter()
}
if let Some(blocked) = blocked.as_ref() {
- linked.retain(|a| !blocked.contains(a) && !a.eq(&Settings::get().hostname));
+ linked.retain(|a| !blocked.contains(a) && !a.eq(hostname));
}
// Sort and remove dupes