use crate::PerformCrud;
use actix_web::web::Data;
-use lemmy_api_common::{blocking, get_local_user_view_from_jwt_opt, mark_post_as_read, post::*};
+use lemmy_api_common::{
+ blocking,
+ check_private_instance,
+ get_local_user_view_from_jwt_opt,
+ mark_post_as_read,
+ post::*,
+};
use lemmy_apub::{
fetcher::webfinger::webfinger_resolve,
objects::community::ApubCommunity,
community_moderator_view::CommunityModeratorView,
community_view::CommunityView,
};
-use lemmy_utils::{ApiError, ConnectionId, LemmyError};
+use lemmy_utils::{ConnectionId, LemmyError};
use lemmy_websocket::{messages::GetPostUsersOnline, LemmyContext};
#[async_trait::async_trait(?Send)]
impl PerformCrud for GetPost {
type Response = GetPostResponse;
+ #[tracing::instrument(skip(context, _websocket_id))]
async fn perform(
&self,
context: &Data<LemmyContext>,
) -> Result<GetPostResponse, LemmyError> {
let data: &GetPost = self;
let local_user_view =
- get_local_user_view_from_jwt_opt(&data.auth, context.pool(), context.secret()).await?;
+ get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
+ .await?;
+
+ check_private_instance(&local_user_view, context.pool()).await?;
let show_bot_accounts = local_user_view
.as_ref()
PostView::read(conn, id, person_id)
})
.await?
- .map_err(|e| ApiError::err("couldnt_find_post", e))?;
+ .map_err(LemmyError::from)
+ .map_err(|e| e.with_message("couldnt_find_post"))?;
// Mark the post as read
if let Some(person_id) = person_id {
CommunityView::read(conn, community_id, person_id)
})
.await?
- .map_err(|e| ApiError::err("couldnt_find_community", e))?;
+ .map_err(LemmyError::from)
+ .map_err(|e| e.with_message("couldnt_find_community"))?;
// Blank out deleted or removed info for non-logged in users
if person_id.is_none() {
impl PerformCrud for GetPosts {
type Response = GetPostsResponse;
+ #[tracing::instrument(skip(context, _websocket_id))]
async fn perform(
&self,
context: &Data<LemmyContext>,
) -> Result<GetPostsResponse, LemmyError> {
let data: &GetPosts = self;
let local_user_view =
- get_local_user_view_from_jwt_opt(&data.auth, context.pool(), context.secret()).await?;
+ get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
+ .await?;
+
+ check_private_instance(&local_user_view, context.pool()).await?;
let person_id = local_user_view.to_owned().map(|l| l.person.id);
.list()
})
.await?
- .map_err(|e| ApiError::err("couldnt_get_posts", e))?;
+ .map_err(LemmyError::from)
+ .map_err(|e| e.with_message("couldnt_get_posts"))?;
// Blank out deleted or removed info for non-logged in users
if person_id.is_none() {