Fixing API tests.

This commit is contained in:
Dessalines 2024-07-07 12:10:14 -04:00
parent fc45266bc3
commit 0b3b711d82
6 changed files with 18 additions and 20 deletions

View file

@ -17,6 +17,7 @@ use lemmy_db_schema::{
actor_language::CommunityLanguage, actor_language::CommunityLanguage,
comment::Comment, comment::Comment,
comment_reply::{CommentReply, CommentReplyInsertForm}, comment_reply::{CommentReply, CommentReplyInsertForm},
person::Person,
person_mention::{PersonMention, PersonMentionInsertForm}, person_mention::{PersonMention, PersonMentionInsertForm},
}, },
traits::Crud, traits::Crud,
@ -96,24 +97,18 @@ pub async fn build_post_response(
pub async fn send_local_notifs( pub async fn send_local_notifs(
mentions: Vec<MentionData>, mentions: Vec<MentionData>,
comment_id: CommentId, comment_id: CommentId,
my_local_user: &LocalUserView, person: &Person,
do_send_email: bool, do_send_email: bool,
context: &LemmyContext, context: &LemmyContext,
) -> LemmyResult<Vec<LocalUserId>> { ) -> LemmyResult<Vec<LocalUserId>> {
let mut recipient_ids = Vec::new(); let mut recipient_ids = Vec::new();
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname()); let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
let person = &my_local_user.person;
// let person = my_local_user.person; // let person = my_local_user.person;
// Read the comment view to get extra info // Read the comment view to get extra info
let comment_view = CommentView::read( let comment_view = CommentView::read(&mut context.pool(), comment_id, None)
&mut context.pool(), .await?
comment_id, .ok_or(LemmyErrorType::CouldntFindComment)?;
Some(&my_local_user.local_user),
)
.await?
.ok_or(LemmyErrorType::CouldntFindComment)?;
let comment = comment_view.comment; let comment = comment_view.comment;
let post = comment_view.post; let post = comment_view.post;
let community = comment_view.community; let community = comment_view.community;

View file

@ -131,7 +131,7 @@ pub async fn create_comment(
let recipient_ids = send_local_notifs( let recipient_ids = send_local_notifs(
mentions, mentions,
inserted_comment_id, inserted_comment_id,
&local_user_view, &local_user_view.person,
true, true,
&context, &context,
) )

View file

@ -60,7 +60,7 @@ pub async fn delete_comment(
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?; .with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
let recipient_ids = let recipient_ids =
send_local_notifs(vec![], comment_id, &local_user_view, false, &context).await?; send_local_notifs(vec![], comment_id, &local_user_view.person, false, &context).await?;
let updated_comment_id = updated_comment.id; let updated_comment_id = updated_comment.id;
ActivityChannel::submit_activity( ActivityChannel::submit_activity(

View file

@ -73,7 +73,7 @@ pub async fn remove_comment(
ModRemoveComment::create(&mut context.pool(), &form).await?; ModRemoveComment::create(&mut context.pool(), &form).await?;
let recipient_ids = let recipient_ids =
send_local_notifs(vec![], comment_id, &local_user_view, false, &context).await?; send_local_notifs(vec![], comment_id, &local_user_view.person, false, &context).await?;
let updated_comment_id = updated_comment.id; let updated_comment_id = updated_comment.id;
ActivityChannel::submit_activity( ActivityChannel::submit_activity(

View file

@ -85,8 +85,14 @@ pub async fn update_comment(
// Do the mentions / recipients // Do the mentions / recipients
let updated_comment_content = updated_comment.content.clone(); let updated_comment_content = updated_comment.content.clone();
let mentions = scrape_text_for_mentions(&updated_comment_content); let mentions = scrape_text_for_mentions(&updated_comment_content);
let recipient_ids = let recipient_ids = send_local_notifs(
send_local_notifs(mentions, comment_id, &local_user_view, false, &context).await?; mentions,
comment_id,
&local_user_view.person,
false,
&context,
)
.await?;
ActivityChannel::submit_activity( ActivityChannel::submit_activity(
SendActivityData::UpdateComment(updated_comment.clone()), SendActivityData::UpdateComment(updated_comment.clone()),

View file

@ -39,7 +39,6 @@ use lemmy_db_schema::{
}, },
traits::{Crud, Likeable}, traits::{Crud, Likeable},
}; };
use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyResult}, error::{LemmyError, LemmyResult},
utils::mention::scrape_text_for_mentions, utils::mention::scrape_text_for_mentions,
@ -179,10 +178,8 @@ impl ActivityHandler for CreateOrUpdateNote {
// anyway. // anyway.
// TODO: for compatibility with other projects, it would be much better to read this from cc or // TODO: for compatibility with other projects, it would be much better to read this from cc or
// tags // tags
if let Some(local_user) = LocalUserView::read_person(&mut context.pool(), actor.id).await? { let mentions = scrape_text_for_mentions(&comment.content);
let mentions = scrape_text_for_mentions(&comment.content); send_local_notifs(mentions, comment.id, &actor, do_send_email, context).await?;
send_local_notifs(mentions, comment.id, &local_user, do_send_email, context).await?;
}
Ok(()) Ok(())
} }
} }