mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-20 02:38:05 +00:00
Merge branch 'main' into feature/custom-emoji-and-tagline-views
This commit is contained in:
commit
5cf15a4c8c
|
@ -19,7 +19,6 @@ use lemmy_db_schema::{
|
|||
comment_reply::{CommentReply, CommentReplyInsertForm},
|
||||
person::Person,
|
||||
person_mention::{PersonMention, PersonMentionInsertForm},
|
||||
post::Post,
|
||||
},
|
||||
traits::Crud,
|
||||
};
|
||||
|
@ -91,16 +90,19 @@ pub async fn build_post_response(
|
|||
#[tracing::instrument(skip_all)]
|
||||
pub async fn send_local_notifs(
|
||||
mentions: Vec<MentionData>,
|
||||
comment: &Comment,
|
||||
comment_id: CommentId,
|
||||
person: &Person,
|
||||
post: &Post,
|
||||
do_send_email: bool,
|
||||
context: &LemmyContext,
|
||||
) -> Result<Vec<LocalUserId>, LemmyError> {
|
||||
let mut recipient_ids = Vec::new();
|
||||
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
|
||||
|
||||
let community_id = post.community_id;
|
||||
// Read the comment view to get extra info
|
||||
let comment_view = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||
let comment = comment_view.comment;
|
||||
let post = comment_view.post;
|
||||
let community = comment_view.community;
|
||||
|
||||
// Send the local mentions
|
||||
for mention in mentions
|
||||
|
@ -117,7 +119,7 @@ pub async fn send_local_notifs(
|
|||
|
||||
let user_mention_form = PersonMentionInsertForm {
|
||||
recipient_id: mention_user_view.person.id,
|
||||
comment_id: comment.id,
|
||||
comment_id,
|
||||
read: None,
|
||||
};
|
||||
|
||||
|
@ -152,8 +154,9 @@ pub async fn send_local_notifs(
|
|||
let check_blocks = check_person_instance_community_block(
|
||||
person.id,
|
||||
parent_creator_id,
|
||||
person.instance_id,
|
||||
community_id,
|
||||
// Only block from the community's instance_id
|
||||
community.instance_id,
|
||||
community.id,
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await
|
||||
|
@ -194,11 +197,13 @@ pub async fn send_local_notifs(
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// Use the post creator to check blocks
|
||||
let check_blocks = check_person_instance_community_block(
|
||||
person.id,
|
||||
post.creator_id,
|
||||
person.instance_id,
|
||||
community_id,
|
||||
// Only block from the community's instance_id
|
||||
community.instance_id,
|
||||
community.id,
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await
|
||||
|
|
|
@ -295,12 +295,12 @@ async fn check_instance_block(
|
|||
pub async fn check_person_instance_community_block(
|
||||
my_id: PersonId,
|
||||
potential_blocker_id: PersonId,
|
||||
instance_id: InstanceId,
|
||||
community_instance_id: InstanceId,
|
||||
community_id: CommunityId,
|
||||
pool: &mut DbPool<'_>,
|
||||
) -> Result<(), LemmyError> {
|
||||
check_person_block(my_id, potential_blocker_id, pool).await?;
|
||||
check_instance_block(instance_id, potential_blocker_id, pool).await?;
|
||||
check_instance_block(community_instance_id, potential_blocker_id, pool).await?;
|
||||
check_community_block(community_id, potential_blocker_id, pool).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -138,9 +138,8 @@ pub async fn create_comment(
|
|||
let mentions = scrape_text_for_mentions(&content);
|
||||
let recipient_ids = send_local_notifs(
|
||||
mentions,
|
||||
&updated_comment,
|
||||
inserted_comment_id,
|
||||
&local_user_view.person,
|
||||
&post,
|
||||
true,
|
||||
&context,
|
||||
)
|
||||
|
|
|
@ -8,10 +8,7 @@ use lemmy_api_common::{
|
|||
utils::check_community_user_action,
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
source::{
|
||||
comment::{Comment, CommentUpdateForm},
|
||||
post::Post,
|
||||
},
|
||||
source::comment::{Comment, CommentUpdateForm},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views::structs::{CommentView, LocalUserView};
|
||||
|
@ -56,17 +53,8 @@ pub async fn delete_comment(
|
|||
.await
|
||||
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
|
||||
|
||||
let post_id = updated_comment.post_id;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
let recipient_ids = send_local_notifs(
|
||||
vec![],
|
||||
&updated_comment,
|
||||
&local_user_view.person,
|
||||
&post,
|
||||
false,
|
||||
&context,
|
||||
)
|
||||
.await?;
|
||||
let recipient_ids =
|
||||
send_local_notifs(vec![], comment_id, &local_user_view.person, false, &context).await?;
|
||||
let updated_comment_id = updated_comment.id;
|
||||
|
||||
ActivityChannel::submit_activity(
|
||||
|
|
|
@ -12,7 +12,6 @@ use lemmy_db_schema::{
|
|||
comment::{Comment, CommentUpdateForm},
|
||||
comment_report::CommentReport,
|
||||
moderator::{ModRemoveComment, ModRemoveCommentForm},
|
||||
post::Post,
|
||||
},
|
||||
traits::{Crud, Reportable},
|
||||
};
|
||||
|
@ -61,13 +60,10 @@ pub async fn remove_comment(
|
|||
};
|
||||
ModRemoveComment::create(&mut context.pool(), &form).await?;
|
||||
|
||||
let post_id = updated_comment.post_id;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
let recipient_ids = send_local_notifs(
|
||||
vec![],
|
||||
&updated_comment,
|
||||
comment_id,
|
||||
&local_user_view.person.clone(),
|
||||
&post,
|
||||
false,
|
||||
&context,
|
||||
)
|
||||
|
|
|
@ -79,9 +79,8 @@ pub async fn update_comment(
|
|||
let mentions = scrape_text_for_mentions(&updated_comment_content);
|
||||
let recipient_ids = send_local_notifs(
|
||||
mentions,
|
||||
&updated_comment,
|
||||
comment_id,
|
||||
&local_user_view.person,
|
||||
&orig_comment.post,
|
||||
false,
|
||||
&context,
|
||||
)
|
||||
|
|
|
@ -159,8 +159,6 @@ impl ActivityHandler for CreateOrUpdateNote {
|
|||
CommentAggregates::update_hot_rank(&mut context.pool(), comment.id).await?;
|
||||
|
||||
let do_send_email = self.kind == CreateOrUpdateType::Create;
|
||||
let post_id = comment.post_id;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
let actor = self.actor.dereference(context).await?;
|
||||
|
||||
// Note:
|
||||
|
@ -169,7 +167,7 @@ impl ActivityHandler for CreateOrUpdateNote {
|
|||
// anyway.
|
||||
// TODO: for compatibility with other projects, it would be much better to read this from cc or tags
|
||||
let mentions = scrape_text_for_mentions(&comment.content);
|
||||
send_local_notifs(mentions, &comment.0, &actor, &post, do_send_email, context).await?;
|
||||
send_local_notifs(mentions, comment.id, &actor, do_send_email, context).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,17 @@ use structs::{DatabaseConnection, PictrsConfig, PictrsImageMode, Settings};
|
|||
static DEFAULT_CONFIG_FILE: &str = "config/config.hjson";
|
||||
|
||||
pub static SETTINGS: Lazy<Settings> = Lazy::new(|| {
|
||||
Settings::init().expect("Failed to load settings file, see documentation (https://join-lemmy.org/docs/en/administration/configuration.html)")
|
||||
if env::var("LEMMY_INITIALIZE_WITH_DEFAULT_SETTINGS").is_ok() {
|
||||
println!(
|
||||
"LEMMY_INITIALIZE_WITH_DEFAULT_SETTINGS was set, any configuration file has been ignored."
|
||||
);
|
||||
println!("Use with other environment variables to configure this instance further; e.g. LEMMY_DATABASE_URL.");
|
||||
Settings::default()
|
||||
} else {
|
||||
Settings::init().expect("Failed to load settings file, see documentation (https://join-lemmy.org/docs/en/administration/configuration.html).")
|
||||
}
|
||||
});
|
||||
|
||||
static WEBFINGER_REGEX: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(&format!(
|
||||
"^acct:([a-zA-Z0-9_]{{3,}})@{}$",
|
||||
|
@ -30,9 +39,7 @@ impl Settings {
|
|||
/// `lemmy_db_schema/src/lib.rs::get_database_url_from_env()`
|
||||
/// Warning: Only call this once.
|
||||
pub(crate) fn init() -> Result<Self, LemmyError> {
|
||||
// Read the config file
|
||||
let config = from_str::<Settings>(&Self::read_config_file()?)?;
|
||||
|
||||
if config.hostname == "unset" {
|
||||
Err(anyhow!("Hostname variable is not set!").into())
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue