Moving blocked and follows to MyUserInfo

This commit is contained in:
Dessalines 2021-08-10 18:55:45 -04:00
parent 99158b88d7
commit d90d569457
10 changed files with 60 additions and 178 deletions

View file

@ -45,9 +45,6 @@ pub async fn match_websocket_operation(
UserOperation::GetPersonMentions => { UserOperation::GetPersonMentions => {
do_websocket_operation::<GetPersonMentions>(context, id, op, data).await do_websocket_operation::<GetPersonMentions>(context, id, op, data).await
} }
UserOperation::GetBlockedPersons => {
do_websocket_operation::<GetBlockedPersons>(context, id, op, data).await
}
UserOperation::MarkPersonMentionAsRead => { UserOperation::MarkPersonMentionAsRead => {
do_websocket_operation::<MarkPersonMentionAsRead>(context, id, op, data).await do_websocket_operation::<MarkPersonMentionAsRead>(context, id, op, data).await
} }
@ -104,12 +101,6 @@ pub async fn match_websocket_operation(
UserOperation::BlockCommunity => { UserOperation::BlockCommunity => {
do_websocket_operation::<BlockCommunity>(context, id, op, data).await do_websocket_operation::<BlockCommunity>(context, id, op, data).await
} }
UserOperation::GetFollowedCommunities => {
do_websocket_operation::<GetFollowedCommunities>(context, id, op, data).await
}
UserOperation::GetBlockedCommunities => {
do_websocket_operation::<GetBlockedCommunities>(context, id, op, data).await
}
UserOperation::BanFromCommunity => { UserOperation::BanFromCommunity => {
do_websocket_operation::<BanFromCommunity>(context, id, op, data).await do_websocket_operation::<BanFromCommunity>(context, id, op, data).await
} }

View file

@ -7,12 +7,6 @@ use chrono::Duration;
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
collect_moderated_communities, collect_moderated_communities,
community::{
GetBlockedCommunities,
GetBlockedCommunitiesResponse,
GetFollowedCommunities,
GetFollowedCommunitiesResponse,
},
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
is_admin, is_admin,
password_length_check, password_length_check,
@ -59,10 +53,7 @@ use lemmy_db_views::{
post_report_view::PostReportView, post_report_view::PostReportView,
}; };
use lemmy_db_views_actor::{ use lemmy_db_views_actor::{
community_block_view::CommunityBlockView,
community_follower_view::CommunityFollowerView,
community_moderator_view::CommunityModeratorView, community_moderator_view::CommunityModeratorView,
person_block_view::PersonBlockView,
person_mention_view::{PersonMentionQueryBuilder, PersonMentionView}, person_mention_view::{PersonMentionQueryBuilder, PersonMentionView},
person_view::PersonViewSafe, person_view::PersonViewSafe,
}; };
@ -840,75 +831,3 @@ impl Perform for GetReportCount {
Ok(res) Ok(res)
} }
} }
#[async_trait::async_trait(?Send)]
impl Perform for GetFollowedCommunities {
type Response = GetFollowedCommunitiesResponse;
async fn perform(
&self,
context: &Data<LemmyContext>,
_websocket_id: Option<ConnectionId>,
) -> Result<GetFollowedCommunitiesResponse, LemmyError> {
let data: &GetFollowedCommunities = self;
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
let person_id = local_user_view.person.id;
let communities = blocking(context.pool(), move |conn| {
CommunityFollowerView::for_person(conn, person_id)
})
.await?
.map_err(|_| ApiError::err("system_err_login"))?;
// Return the jwt
Ok(GetFollowedCommunitiesResponse { communities })
}
}
#[async_trait::async_trait(?Send)]
impl Perform for GetBlockedCommunities {
type Response = GetBlockedCommunitiesResponse;
async fn perform(
&self,
context: &Data<LemmyContext>,
_websocket_id: Option<ConnectionId>,
) -> Result<GetBlockedCommunitiesResponse, LemmyError> {
let data: &GetBlockedCommunities = self;
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
let person_id = local_user_view.person.id;
let communities = blocking(context.pool(), move |conn| {
CommunityBlockView::for_person(conn, person_id)
})
.await?
.map_err(|_| ApiError::err("system_err_login"))?;
// Return the jwt
Ok(GetBlockedCommunitiesResponse { communities })
}
}
#[async_trait::async_trait(?Send)]
impl Perform for GetBlockedPersons {
type Response = GetBlockedPersonsResponse;
async fn perform(
&self,
context: &Data<LemmyContext>,
_websocket_id: Option<ConnectionId>,
) -> Result<GetBlockedPersonsResponse, LemmyError> {
let data: &GetBlockedPersons = self;
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
let person_id = local_user_view.person.id;
let persons = blocking(context.pool(), move |conn| {
PersonBlockView::for_person(conn, person_id)
})
.await?
.map_err(|_| ApiError::err("system_err_login"))?;
// Return the jwt
Ok(GetBlockedPersonsResponse { persons })
}
}

View file

@ -4,7 +4,6 @@ use anyhow::Context;
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
build_federated_instances, build_federated_instances,
get_local_user_settings_view_from_jwt,
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
get_local_user_view_from_jwt_opt, get_local_user_view_from_jwt_opt,
is_admin, is_admin,
@ -422,15 +421,13 @@ impl Perform for TransferSite {
let banned = blocking(context.pool(), move |conn| PersonViewSafe::banned(conn)).await??; let banned = blocking(context.pool(), move |conn| PersonViewSafe::banned(conn)).await??;
let federated_instances = build_federated_instances(context.pool()).await?; let federated_instances = build_federated_instances(context.pool()).await?;
let my_user = Some(get_local_user_settings_view_from_jwt(&data.auth, context.pool()).await?);
Ok(GetSiteResponse { Ok(GetSiteResponse {
site_view: Some(site_view), site_view: Some(site_view),
admins, admins,
banned, banned,
online: 0, online: 0,
version: version::VERSION.to_string(), version: version::VERSION.to_string(),
my_user, my_user: None,
federated_instances, federated_instances,
}) })
} }

View file

@ -1,7 +1,5 @@
use lemmy_db_schema::{CommunityId, PersonId}; use lemmy_db_schema::{CommunityId, PersonId};
use lemmy_db_views_actor::{ use lemmy_db_views_actor::{
community_block_view::CommunityBlockView,
community_follower_view::CommunityFollowerView,
community_moderator_view::CommunityModeratorView, community_moderator_view::CommunityModeratorView,
community_view::CommunityView, community_view::CommunityView,
person_view::PersonViewSafe, person_view::PersonViewSafe,
@ -124,26 +122,6 @@ pub struct BlockCommunity {
pub auth: String, pub auth: String,
} }
#[derive(Deserialize)]
pub struct GetFollowedCommunities {
pub auth: String,
}
#[derive(Serialize)]
pub struct GetFollowedCommunitiesResponse {
pub communities: Vec<CommunityFollowerView>,
}
#[derive(Deserialize)]
pub struct GetBlockedCommunities {
pub auth: String,
}
#[derive(Serialize)]
pub struct GetBlockedCommunitiesResponse {
pub communities: Vec<CommunityBlockView>,
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct TransferCommunity { pub struct TransferCommunity {
pub community_id: CommunityId, pub community_id: CommunityId,

View file

@ -4,10 +4,7 @@ use lemmy_db_views::{
private_message_view::PrivateMessageView, private_message_view::PrivateMessageView,
}; };
use lemmy_db_views_actor::{ use lemmy_db_views_actor::{
community_block_view::CommunityBlockView,
community_follower_view::CommunityFollowerView,
community_moderator_view::CommunityModeratorView, community_moderator_view::CommunityModeratorView,
person_block_view::PersonBlockView,
person_mention_view::PersonMentionView, person_mention_view::PersonMentionView,
person_view::PersonViewSafe, person_view::PersonViewSafe,
}; };
@ -98,12 +95,9 @@ pub struct GetPersonDetails {
#[derive(Serialize)] #[derive(Serialize)]
pub struct GetPersonDetailsResponse { pub struct GetPersonDetailsResponse {
pub person_view: PersonViewSafe, pub person_view: PersonViewSafe,
pub follows: Vec<CommunityFollowerView>,
pub community_blocks: Vec<CommunityBlockView>,
pub person_blocks: Vec<PersonBlockView>,
pub moderates: Vec<CommunityModeratorView>,
pub comments: Vec<CommentView>, pub comments: Vec<CommentView>,
pub posts: Vec<PostView>, pub posts: Vec<PostView>,
pub moderates: Vec<CommunityModeratorView>,
} }
#[derive(Serialize)] #[derive(Serialize)]
@ -271,13 +265,3 @@ pub struct GetReportCountResponse {
pub comment_reports: i64, pub comment_reports: i64,
pub post_reports: i64, pub post_reports: i64,
} }
#[derive(Deserialize)]
pub struct GetBlockedPersons {
pub auth: String,
}
#[derive(Serialize)]
pub struct GetBlockedPersonsResponse {
pub persons: Vec<PersonBlockView>,
}

View file

@ -5,7 +5,13 @@ use lemmy_db_views::{
post_view::PostView, post_view::PostView,
site_view::SiteView, site_view::SiteView,
}; };
use lemmy_db_views_actor::{community_view::CommunityView, person_view::PersonViewSafe}; use lemmy_db_views_actor::{
community_block_view::CommunityBlockView,
community_follower_view::CommunityFollowerView,
community_view::CommunityView,
person_block_view::PersonBlockView,
person_view::PersonViewSafe,
};
use lemmy_db_views_moderator::{ use lemmy_db_views_moderator::{
mod_add_community_view::ModAddCommunityView, mod_add_community_view::ModAddCommunityView,
mod_add_view::ModAddView, mod_add_view::ModAddView,
@ -110,10 +116,18 @@ pub struct GetSiteResponse {
pub banned: Vec<PersonViewSafe>, pub banned: Vec<PersonViewSafe>,
pub online: usize, pub online: usize,
pub version: String, pub version: String,
pub my_user: Option<LocalUserSettingsView>, pub my_user: Option<MyUserInfo>,
pub federated_instances: Option<FederatedInstances>, // Federation may be disabled pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
} }
#[derive(Serialize)]
pub struct MyUserInfo {
pub local_user: LocalUserSettingsView,
pub follows: Vec<CommunityFollowerView>,
pub community_blocks: Vec<CommunityBlockView>,
pub person_blocks: Vec<PersonBlockView>,
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct TransferSite { pub struct TransferSite {
pub person_id: PersonId, pub person_id: PersonId,

View file

@ -8,8 +8,13 @@ use lemmy_api_common::{
site::*, site::*,
}; };
use lemmy_db_views::site_view::SiteView; use lemmy_db_views::site_view::SiteView;
use lemmy_db_views_actor::person_view::PersonViewSafe; use lemmy_db_views_actor::{
use lemmy_utils::{settings::structs::Settings, version, ConnectionId, LemmyError}; community_block_view::CommunityBlockView,
community_follower_view::CommunityFollowerView,
person_block_view::PersonBlockView,
person_view::PersonViewSafe,
};
use lemmy_utils::{settings::structs::Settings, version, ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::GetUsersOnline, LemmyContext}; use lemmy_websocket::{messages::GetUsersOnline, LemmyContext};
use log::info; use log::info;
@ -83,7 +88,41 @@ impl PerformCrud for GetSite {
.await .await
.unwrap_or(1); .unwrap_or(1);
let my_user = get_local_user_settings_view_from_jwt_opt(&data.auth, context.pool()).await?; // Build the local user
let my_user = if let Some(local_user_view) =
get_local_user_settings_view_from_jwt_opt(&data.auth, context.pool()).await?
{
let person_id = local_user_view.person.id;
let follows = blocking(context.pool(), move |conn| {
CommunityFollowerView::for_person(conn, person_id)
})
.await?
.map_err(|_| ApiError::err("system_err_login"))?;
let person_id = local_user_view.person.id;
let community_blocks = blocking(context.pool(), move |conn| {
CommunityBlockView::for_person(conn, person_id)
})
.await?
.map_err(|_| ApiError::err("system_err_login"))?;
let person_id = local_user_view.person.id;
let person_blocks = blocking(context.pool(), move |conn| {
PersonBlockView::for_person(conn, person_id)
})
.await?
.map_err(|_| ApiError::err("system_err_login"))?;
Some(MyUserInfo {
local_user: local_user_view,
follows,
community_blocks,
person_blocks,
})
} else {
None
};
let federated_instances = build_federated_instances(context.pool()).await?; let federated_instances = build_federated_instances(context.pool()).await?;
Ok(GetSiteResponse { Ok(GetSiteResponse {

View file

@ -6,10 +6,7 @@ use lemmy_db_queries::{from_opt_str_to_opt_enum, ApubObject, SortType};
use lemmy_db_schema::source::person::*; use lemmy_db_schema::source::person::*;
use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder}; use lemmy_db_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
use lemmy_db_views_actor::{ use lemmy_db_views_actor::{
community_block_view::CommunityBlockView,
community_follower_view::CommunityFollowerView,
community_moderator_view::CommunityModeratorView, community_moderator_view::CommunityModeratorView,
person_block_view::PersonBlockView,
person_view::PersonViewSafe, person_view::PersonViewSafe,
}; };
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
@ -105,28 +102,6 @@ impl PerformCrud for GetPersonDetails {
}) })
.await??; .await??;
let mut follows = vec![];
let mut person_blocks = vec![];
let mut community_blocks = vec![];
// Only show the followers and blocks for that user
if let Some(pid) = person_id {
if pid == person_details_id {
follows = blocking(context.pool(), move |conn| {
CommunityFollowerView::for_person(conn, person_details_id)
})
.await??;
person_blocks = blocking(context.pool(), move |conn| {
PersonBlockView::for_person(conn, person_details_id)
})
.await??;
community_blocks = blocking(context.pool(), move |conn| {
CommunityBlockView::for_person(conn, person_details_id)
})
.await??;
}
};
let moderates = blocking(context.pool(), move |conn| { let moderates = blocking(context.pool(), move |conn| {
CommunityModeratorView::for_person(conn, person_details_id) CommunityModeratorView::for_person(conn, person_details_id)
}) })
@ -135,9 +110,6 @@ impl PerformCrud for GetPersonDetails {
// Return the jwt // Return the jwt
Ok(GetPersonDetailsResponse { Ok(GetPersonDetailsResponse {
person_view, person_view,
follows,
community_blocks,
person_blocks,
moderates, moderates,
comments, comments,
posts, posts,

View file

@ -101,7 +101,6 @@ pub enum UserOperation {
ListPostReports, ListPostReports,
GetReportCount, GetReportCount,
FollowCommunity, FollowCommunity,
GetFollowedCommunities,
GetReplies, GetReplies,
GetPersonMentions, GetPersonMentions,
MarkPersonMentionAsRead, MarkPersonMentionAsRead,
@ -128,8 +127,6 @@ pub enum UserOperation {
GetSiteMetadata, GetSiteMetadata,
BlockCommunity, BlockCommunity,
BlockPerson, BlockPerson,
GetBlockedCommunities,
GetBlockedPersons,
} }
#[derive(EnumString, ToString, Debug, Clone)] #[derive(EnumString, ToString, Debug, Clone)]

View file

@ -151,20 +151,11 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
.wrap(rate_limit.message()) .wrap(rate_limit.message())
.route("", web::get().to(route_get_crud::<GetPersonDetails>)) .route("", web::get().to(route_get_crud::<GetPersonDetails>))
.route("/mention", web::get().to(route_get::<GetPersonMentions>)) .route("/mention", web::get().to(route_get::<GetPersonMentions>))
.route("/block", web::get().to(route_get::<GetBlockedPersons>))
.route( .route(
"/mention/mark_as_read", "/mention/mark_as_read",
web::post().to(route_post::<MarkPersonMentionAsRead>), web::post().to(route_post::<MarkPersonMentionAsRead>),
) )
.route("/replies", web::get().to(route_get::<GetReplies>)) .route("/replies", web::get().to(route_get::<GetReplies>))
.route(
"/followed_communities",
web::get().to(route_get::<GetFollowedCommunities>),
)
.route(
"/blocked_communities",
web::get().to(route_get::<GetBlockedCommunities>),
)
.route("/join", web::post().to(route_post::<UserJoin>)) .route("/join", web::post().to(route_post::<UserJoin>))
// Admin action. I don't like that it's in /user // Admin action. I don't like that it's in /user
.route("/ban", web::post().to(route_post::<BanPerson>)) .route("/ban", web::post().to(route_post::<BanPerson>))