Merge pull request 'Dont send email notifications to banned users (fixes #1251)' (#126) from dont-email-banned-user into main
Reviewed-on: https://yerbamate.dev/LemmyNet/lemmy/pulls/126
This commit is contained in:
commit
60517f8471
2 changed files with 41 additions and 53 deletions
|
@ -38,7 +38,7 @@ use lemmy_db::{
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use lemmy_structs::{blocking, user::*};
|
use lemmy_structs::{blocking, send_email_to_user, user::*};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
|
apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
|
||||||
email::send_email,
|
email::send_email,
|
||||||
|
@ -61,7 +61,6 @@ use lemmy_websocket::{
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
UserOperation,
|
UserOperation,
|
||||||
};
|
};
|
||||||
use log::error;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
|
@ -1041,23 +1040,12 @@ impl Perform for CreatePrivateMessage {
|
||||||
let recipient_user =
|
let recipient_user =
|
||||||
blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
|
blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
|
||||||
if recipient_user.send_notifications_to_email {
|
if recipient_user.send_notifications_to_email {
|
||||||
if let Some(email) = recipient_user.email {
|
send_email_to_user(
|
||||||
let subject = &format!(
|
recipient_user,
|
||||||
"{} - Private Message from {}",
|
"Private Message from",
|
||||||
Settings::get().hostname,
|
"Private Message",
|
||||||
user.name,
|
|
||||||
);
|
|
||||||
let html = &format!(
|
|
||||||
"<h1>Private Message</h1><br><div>{} - {}</div><br><a href={}/inbox>inbox</a>",
|
|
||||||
user.name,
|
|
||||||
&content_slurs_removed,
|
&content_slurs_removed,
|
||||||
Settings::get().get_protocol_and_hostname()
|
|
||||||
);
|
);
|
||||||
match send_email(subject, &email, &recipient_user.name, html) {
|
|
||||||
Ok(_o) => _o,
|
|
||||||
Err(e) => error!("{}", e),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let message = blocking(context.pool(), move |conn| {
|
let message = blocking(context.pool(), move |conn| {
|
||||||
|
|
|
@ -77,7 +77,6 @@ fn do_send_local_notifs(
|
||||||
do_send_email: bool,
|
do_send_email: bool,
|
||||||
) -> Vec<i32> {
|
) -> Vec<i32> {
|
||||||
let mut recipient_ids = Vec::new();
|
let mut recipient_ids = Vec::new();
|
||||||
let hostname = &Settings::get().get_protocol_and_hostname();
|
|
||||||
|
|
||||||
// Send the local mentions
|
// Send the local mentions
|
||||||
for mention in mentions
|
for mention in mentions
|
||||||
|
@ -106,17 +105,12 @@ fn do_send_local_notifs(
|
||||||
|
|
||||||
// Send an email to those users that have notifications on
|
// Send an email to those users that have notifications on
|
||||||
if do_send_email && mention_user.send_notifications_to_email {
|
if do_send_email && mention_user.send_notifications_to_email {
|
||||||
if let Some(mention_email) = mention_user.email {
|
send_email_to_user(
|
||||||
let subject = &format!("{} - Mentioned by {}", Settings::get().hostname, user.name,);
|
mention_user,
|
||||||
let html = &format!(
|
"Mentioned by",
|
||||||
"<h1>User Mention</h1><br><div>{} - {}</div><br><a href={}/inbox>inbox</a>",
|
"User Mention",
|
||||||
user.name, comment.content, hostname
|
&comment.content,
|
||||||
);
|
)
|
||||||
match send_email(subject, &mention_email, &mention_user.name, html) {
|
|
||||||
Ok(_o) => _o,
|
|
||||||
Err(e) => error!("{}", e),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,17 +124,7 @@ fn do_send_local_notifs(
|
||||||
recipient_ids.push(parent_user.id);
|
recipient_ids.push(parent_user.id);
|
||||||
|
|
||||||
if do_send_email && parent_user.send_notifications_to_email {
|
if do_send_email && parent_user.send_notifications_to_email {
|
||||||
if let Some(comment_reply_email) = parent_user.email {
|
send_email_to_user(parent_user, "Reply from", "Comment Reply", &comment.content)
|
||||||
let subject = &format!("{} - Reply from {}", Settings::get().hostname, user.name,);
|
|
||||||
let html = &format!(
|
|
||||||
"<h1>Comment Reply</h1><br><div>{} - {}</div><br><a href={}/inbox>inbox</a>",
|
|
||||||
user.name, comment.content, hostname
|
|
||||||
);
|
|
||||||
match send_email(subject, &comment_reply_email, &parent_user.name, html) {
|
|
||||||
Ok(_o) => _o,
|
|
||||||
Err(e) => error!("{}", e),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,17 +137,7 @@ fn do_send_local_notifs(
|
||||||
recipient_ids.push(parent_user.id);
|
recipient_ids.push(parent_user.id);
|
||||||
|
|
||||||
if do_send_email && parent_user.send_notifications_to_email {
|
if do_send_email && parent_user.send_notifications_to_email {
|
||||||
if let Some(post_reply_email) = parent_user.email {
|
send_email_to_user(parent_user, "Reply from", "Post Reply", &comment.content)
|
||||||
let subject = &format!("{} - Reply from {}", Settings::get().hostname, user.name,);
|
|
||||||
let html = &format!(
|
|
||||||
"<h1>Post Reply</h1><br><div>{} - {}</div><br><a href={}/inbox>inbox</a>",
|
|
||||||
user.name, comment.content, hostname
|
|
||||||
);
|
|
||||||
match send_email(subject, &post_reply_email, &parent_user.name, html) {
|
|
||||||
Ok(_o) => _o,
|
|
||||||
Err(e) => error!("{}", e),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,3 +145,29 @@ fn do_send_local_notifs(
|
||||||
};
|
};
|
||||||
recipient_ids
|
recipient_ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn send_email_to_user(user: User_, subject_text: &str, body_text: &str, comment_content: &str) {
|
||||||
|
if user.banned {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(user_email) = user.email {
|
||||||
|
let subject = &format!(
|
||||||
|
"{} - {} {}",
|
||||||
|
subject_text,
|
||||||
|
Settings::get().hostname,
|
||||||
|
user.name,
|
||||||
|
);
|
||||||
|
let html = &format!(
|
||||||
|
"<h1>{}</h1><br><div>{} - {}</div><br><a href={}/inbox>inbox</a>",
|
||||||
|
body_text,
|
||||||
|
user.name,
|
||||||
|
comment_content,
|
||||||
|
Settings::get().get_protocol_and_hostname()
|
||||||
|
);
|
||||||
|
match send_email(subject, &user_email, &user.name, html) {
|
||||||
|
Ok(_o) => _o,
|
||||||
|
Err(e) => error!("{}", e),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue