Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to mention persons from post body. #5162

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/api/src/comment/like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use lemmy_api_common::{
comment::{CommentResponse, CreateCommentLike},
context::LemmyContext,
send_activity::{ActivityChannel, SendActivityData},
utils::{check_bot_account, check_community_user_action, check_local_vote_mode, VoteItem},
utils::{check_bot_account, check_community_user_action, check_local_vote_mode},
};
use lemmy_db_schema::{
newtypes::LocalUserId,
newtypes::{LocalUserId, PostOrCommentId},
source::{
comment::{CommentLike, CommentLikeForm},
comment_reply::CommentReply,
Expand All @@ -33,7 +33,7 @@ pub async fn like_comment(

check_local_vote_mode(
data.score,
VoteItem::Comment(comment_id),
PostOrCommentId::Comment(comment_id),
&local_site,
local_user_view.person.id,
&mut context.pool(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use actix_web::web::{Data, Json, Query};
use lemmy_api_common::{
context::LemmyContext,
person::{GetPersonCommentMentions, GetPersonCommentMentionsResponse},
};
use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::person_comment_mention_view::PersonCommentMentionQuery;
use lemmy_utils::error::LemmyResult;

#[tracing::instrument(skip(context))]
pub async fn list_comment_mentions(
data: Query<GetPersonCommentMentions>,
context: Data<LemmyContext>,
local_user_view: LocalUserView,
) -> LemmyResult<Json<GetPersonCommentMentionsResponse>> {
let sort = data.sort;
let page = data.page;
let limit = data.limit;
let unread_only = data.unread_only.unwrap_or_default();
let person_id = Some(local_user_view.person.id);
let show_bot_accounts = local_user_view.local_user.show_bot_accounts;

let comment_mentions = PersonCommentMentionQuery {
recipient_id: person_id,
my_person_id: person_id,
sort,
unread_only,
show_bot_accounts,
page,
limit,
}
.list(&mut context.pool())
.await?;

Ok(Json(GetPersonCommentMentionsResponse { comment_mentions }))
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
use actix_web::web::{Data, Json, Query};
use lemmy_api_common::{
context::LemmyContext,
person::{GetPersonMentions, GetPersonMentionsResponse},
person::{GetPersonPostMentions, GetPersonPostMentionsResponse},
};
use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::person_mention_view::PersonMentionQuery;
use lemmy_db_views_actor::person_post_mention_view::PersonPostMentionQuery;
use lemmy_utils::error::LemmyResult;

#[tracing::instrument(skip(context))]
pub async fn list_mentions(
data: Query<GetPersonMentions>,
pub async fn list_post_mentions(
data: Query<GetPersonPostMentions>,
context: Data<LemmyContext>,
local_user_view: LocalUserView,
) -> LemmyResult<Json<GetPersonMentionsResponse>> {
) -> LemmyResult<Json<GetPersonPostMentionsResponse>> {
let sort = data.sort;
let page = data.page;
let limit = data.limit;
let unread_only = data.unread_only.unwrap_or_default();
let person_id = Some(local_user_view.person.id);
let show_bot_accounts = local_user_view.local_user.show_bot_accounts;

let mentions = PersonMentionQuery {
let post_mentions = PersonPostMentionQuery {
recipient_id: person_id,
my_person_id: person_id,
sort,
Expand All @@ -32,5 +32,5 @@ pub async fn list_mentions(
.list(&mut context.pool())
.await?;

Ok(Json(GetPersonMentionsResponse { mentions }))
Ok(Json(GetPersonPostMentionsResponse { post_mentions }))
}
6 changes: 3 additions & 3 deletions crates/api/src/local_user/notifications/mark_all_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use actix_web::web::{Data, Json};
use lemmy_api_common::{context::LemmyContext, person::GetRepliesResponse};
use lemmy_db_schema::source::{
comment_reply::CommentReply,
person_mention::PersonMention,
person_comment_mention::PersonCommentMention,
private_message::PrivateMessage,
};
use lemmy_db_views::structs::LocalUserView;
Expand All @@ -20,8 +20,8 @@ pub async fn mark_all_notifications_read(
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;

// Mark all user mentions as read
PersonMention::mark_all_as_read(&mut context.pool(), person_id)
// Mark all comment mentions as read
PersonCommentMention::mark_all_as_read(&mut context.pool(), person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use actix_web::web::{Data, Json};
use lemmy_api_common::{
context::LemmyContext,
person::{MarkPersonCommentMentionAsRead, PersonCommentMentionResponse},
};
use lemmy_db_schema::{
source::person_comment_mention::{PersonCommentMention, PersonCommentMentionUpdateForm},
traits::Crud,
};
use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::PersonCommentMentionView;
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};

#[tracing::instrument(skip(context))]
pub async fn mark_comment_mention_as_read(
data: Json<MarkPersonCommentMentionAsRead>,
context: Data<LemmyContext>,
local_user_view: LocalUserView,
) -> LemmyResult<Json<PersonCommentMentionResponse>> {
let person_comment_mention_id = data.person_comment_mention_id;
let read_person_comment_mention =
PersonCommentMention::read(&mut context.pool(), person_comment_mention_id).await?;

if local_user_view.person.id != read_person_comment_mention.recipient_id {
Err(LemmyErrorType::CouldntUpdateComment)?
}

let person_comment_mention_id = read_person_comment_mention.id;
let read = Some(data.read);
PersonCommentMention::update(
&mut context.pool(),
person_comment_mention_id,
&PersonCommentMentionUpdateForm { read },
)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;

let person_comment_mention_id = read_person_comment_mention.id;
let person_id = local_user_view.person.id;
let person_comment_mention_view = PersonCommentMentionView::read(
&mut context.pool(),
person_comment_mention_id,
Some(person_id),
)
.await?;

Ok(Json(PersonCommentMentionResponse {
person_comment_mention_view,
}))
}
45 changes: 0 additions & 45 deletions crates/api/src/local_user/notifications/mark_mention_read.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use actix_web::web::{Data, Json};
use lemmy_api_common::{
context::LemmyContext,
person::{MarkPersonPostMentionAsRead, PersonPostMentionResponse},
};
use lemmy_db_schema::{
source::person_post_mention::{PersonPostMention, PersonPostMentionUpdateForm},
traits::Crud,
};
use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::PersonPostMentionView;
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorType, LemmyResult};

#[tracing::instrument(skip(context))]
pub async fn mark_post_mention_as_read(
data: Json<MarkPersonPostMentionAsRead>,
context: Data<LemmyContext>,
local_user_view: LocalUserView,
) -> LemmyResult<Json<PersonPostMentionResponse>> {
let person_post_mention_id = data.person_post_mention_id;
let read_person_post_mention =
PersonPostMention::read(&mut context.pool(), person_post_mention_id).await?;

if local_user_view.person.id != read_person_post_mention.recipient_id {
Err(LemmyErrorType::CouldntUpdatePost)?
}

let person_post_mention_id = read_person_post_mention.id;
let read = Some(data.read);
PersonPostMention::update(
&mut context.pool(),
person_post_mention_id,
&PersonPostMentionUpdateForm { read },
)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdatePost)?;

let person_post_mention_id = read_person_post_mention.id;
let person_id = local_user_view.person.id;
let person_post_mention_view =
PersonPostMentionView::read(&mut context.pool(), person_post_mention_id, Some(person_id))
.await?;

Ok(Json(PersonPostMentionResponse {
person_post_mention_view,
}))
}
6 changes: 4 additions & 2 deletions crates/api/src/local_user/notifications/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub mod list_mentions;
pub mod list_comment_mentions;
pub mod list_post_mentions;
pub mod list_replies;
pub mod mark_all_read;
pub mod mark_mention_read;
pub mod mark_comment_mention_read;
pub mod mark_post_mention_read;
pub mod mark_reply_read;
pub mod unread_count;
21 changes: 15 additions & 6 deletions crates/api/src/local_user/notifications/unread_count.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use actix_web::web::{Data, Json};
use lemmy_api_common::{context::LemmyContext, person::GetUnreadCountResponse};
use lemmy_db_views::structs::{LocalUserView, PrivateMessageView};
use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView};
use lemmy_db_views_actor::structs::{
CommentReplyView,
PersonCommentMentionView,
PersonPostMentionView,
};
use lemmy_utils::error::LemmyResult;

#[tracing::instrument(skip(context))]
Expand All @@ -12,18 +16,23 @@ pub async fn unread_count(
let person_id = local_user_view.person.id;

let replies =
CommentReplyView::get_unread_replies(&mut context.pool(), &local_user_view.local_user).await?;
CommentReplyView::get_unread_count(&mut context.pool(), &local_user_view.local_user).await?;

let mentions =
PersonMentionView::get_unread_mentions(&mut context.pool(), &local_user_view.local_user)
let comment_mentions =
PersonCommentMentionView::get_unread_count(&mut context.pool(), &local_user_view.local_user)
.await?;

let post_mentions =
PersonPostMentionView::get_unread_count(&mut context.pool(), &local_user_view.local_user)
.await?;

let private_messages =
PrivateMessageView::get_unread_messages(&mut context.pool(), person_id).await?;
PrivateMessageView::get_unread_count(&mut context.pool(), person_id).await?;

Ok(Json(GetUnreadCountResponse {
replies,
mentions,
comment_mentions,
post_mentions,
private_messages,
}))
}
4 changes: 2 additions & 2 deletions crates/api/src/post/like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use lemmy_api_common::{
check_community_user_action,
check_local_vote_mode,
mark_post_as_read,
VoteItem,
},
};
use lemmy_db_schema::{
newtypes::PostOrCommentId,
source::{
community::Community,
local_site::LocalSite,
Expand All @@ -36,7 +36,7 @@ pub async fn like_post(

check_local_vote_mode(
data.score,
VoteItem::Post(post_id),
PostOrCommentId::Post(post_id),
&local_site,
local_user_view.person.id,
&mut context.pool(),
Expand Down
Loading