mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
Moving blocked and follows to MyUserInfo
This commit is contained in:
parent
99158b88d7
commit
d90d569457
10 changed files with 60 additions and 178 deletions
|
@ -45,9 +45,6 @@ pub async fn match_websocket_operation(
|
|||
UserOperation::GetPersonMentions => {
|
||||
do_websocket_operation::<GetPersonMentions>(context, id, op, data).await
|
||||
}
|
||||
UserOperation::GetBlockedPersons => {
|
||||
do_websocket_operation::<GetBlockedPersons>(context, id, op, data).await
|
||||
}
|
||||
UserOperation::MarkPersonMentionAsRead => {
|
||||
do_websocket_operation::<MarkPersonMentionAsRead>(context, id, op, data).await
|
||||
}
|
||||
|
@ -104,12 +101,6 @@ pub async fn match_websocket_operation(
|
|||
UserOperation::BlockCommunity => {
|
||||
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 => {
|
||||
do_websocket_operation::<BanFromCommunity>(context, id, op, data).await
|
||||
}
|
||||
|
|
|
@ -7,12 +7,6 @@ use chrono::Duration;
|
|||
use lemmy_api_common::{
|
||||
blocking,
|
||||
collect_moderated_communities,
|
||||
community::{
|
||||
GetBlockedCommunities,
|
||||
GetBlockedCommunitiesResponse,
|
||||
GetFollowedCommunities,
|
||||
GetFollowedCommunitiesResponse,
|
||||
},
|
||||
get_local_user_view_from_jwt,
|
||||
is_admin,
|
||||
password_length_check,
|
||||
|
@ -59,10 +53,7 @@ use lemmy_db_views::{
|
|||
post_report_view::PostReportView,
|
||||
};
|
||||
use lemmy_db_views_actor::{
|
||||
community_block_view::CommunityBlockView,
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
person_block_view::PersonBlockView,
|
||||
person_mention_view::{PersonMentionQueryBuilder, PersonMentionView},
|
||||
person_view::PersonViewSafe,
|
||||
};
|
||||
|
@ -840,75 +831,3 @@ impl Perform for GetReportCount {
|
|||
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 })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ use anyhow::Context;
|
|||
use lemmy_api_common::{
|
||||
blocking,
|
||||
build_federated_instances,
|
||||
get_local_user_settings_view_from_jwt,
|
||||
get_local_user_view_from_jwt,
|
||||
get_local_user_view_from_jwt_opt,
|
||||
is_admin,
|
||||
|
@ -422,15 +421,13 @@ impl Perform for TransferSite {
|
|||
let banned = blocking(context.pool(), move |conn| PersonViewSafe::banned(conn)).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 {
|
||||
site_view: Some(site_view),
|
||||
admins,
|
||||
banned,
|
||||
online: 0,
|
||||
version: version::VERSION.to_string(),
|
||||
my_user,
|
||||
my_user: None,
|
||||
federated_instances,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use lemmy_db_schema::{CommunityId, PersonId};
|
||||
use lemmy_db_views_actor::{
|
||||
community_block_view::CommunityBlockView,
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
community_view::CommunityView,
|
||||
person_view::PersonViewSafe,
|
||||
|
@ -124,26 +122,6 @@ pub struct BlockCommunity {
|
|||
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)]
|
||||
pub struct TransferCommunity {
|
||||
pub community_id: CommunityId,
|
||||
|
|
|
@ -4,10 +4,7 @@ use lemmy_db_views::{
|
|||
private_message_view::PrivateMessageView,
|
||||
};
|
||||
use lemmy_db_views_actor::{
|
||||
community_block_view::CommunityBlockView,
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
person_block_view::PersonBlockView,
|
||||
person_mention_view::PersonMentionView,
|
||||
person_view::PersonViewSafe,
|
||||
};
|
||||
|
@ -98,12 +95,9 @@ pub struct GetPersonDetails {
|
|||
#[derive(Serialize)]
|
||||
pub struct GetPersonDetailsResponse {
|
||||
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 posts: Vec<PostView>,
|
||||
pub moderates: Vec<CommunityModeratorView>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
@ -271,13 +265,3 @@ pub struct GetReportCountResponse {
|
|||
pub comment_reports: i64,
|
||||
pub post_reports: i64,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct GetBlockedPersons {
|
||||
pub auth: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct GetBlockedPersonsResponse {
|
||||
pub persons: Vec<PersonBlockView>,
|
||||
}
|
||||
|
|
|
@ -5,7 +5,13 @@ use lemmy_db_views::{
|
|||
post_view::PostView,
|
||||
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::{
|
||||
mod_add_community_view::ModAddCommunityView,
|
||||
mod_add_view::ModAddView,
|
||||
|
@ -110,10 +116,18 @@ pub struct GetSiteResponse {
|
|||
pub banned: Vec<PersonViewSafe>,
|
||||
pub online: usize,
|
||||
pub version: String,
|
||||
pub my_user: Option<LocalUserSettingsView>,
|
||||
pub my_user: Option<MyUserInfo>,
|
||||
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)]
|
||||
pub struct TransferSite {
|
||||
pub person_id: PersonId,
|
||||
|
|
|
@ -8,8 +8,13 @@ use lemmy_api_common::{
|
|||
site::*,
|
||||
};
|
||||
use lemmy_db_views::site_view::SiteView;
|
||||
use lemmy_db_views_actor::person_view::PersonViewSafe;
|
||||
use lemmy_utils::{settings::structs::Settings, version, ConnectionId, LemmyError};
|
||||
use lemmy_db_views_actor::{
|
||||
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 log::info;
|
||||
|
||||
|
@ -83,7 +88,41 @@ impl PerformCrud for GetSite {
|
|||
.await
|
||||
.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?;
|
||||
|
||||
Ok(GetSiteResponse {
|
||||
|
|
|
@ -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_views::{comment_view::CommentQueryBuilder, post_view::PostQueryBuilder};
|
||||
use lemmy_db_views_actor::{
|
||||
community_block_view::CommunityBlockView,
|
||||
community_follower_view::CommunityFollowerView,
|
||||
community_moderator_view::CommunityModeratorView,
|
||||
person_block_view::PersonBlockView,
|
||||
person_view::PersonViewSafe,
|
||||
};
|
||||
use lemmy_utils::{ApiError, ConnectionId, LemmyError};
|
||||
|
@ -105,28 +102,6 @@ impl PerformCrud for GetPersonDetails {
|
|||
})
|
||||
.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| {
|
||||
CommunityModeratorView::for_person(conn, person_details_id)
|
||||
})
|
||||
|
@ -135,9 +110,6 @@ impl PerformCrud for GetPersonDetails {
|
|||
// Return the jwt
|
||||
Ok(GetPersonDetailsResponse {
|
||||
person_view,
|
||||
follows,
|
||||
community_blocks,
|
||||
person_blocks,
|
||||
moderates,
|
||||
comments,
|
||||
posts,
|
||||
|
|
|
@ -101,7 +101,6 @@ pub enum UserOperation {
|
|||
ListPostReports,
|
||||
GetReportCount,
|
||||
FollowCommunity,
|
||||
GetFollowedCommunities,
|
||||
GetReplies,
|
||||
GetPersonMentions,
|
||||
MarkPersonMentionAsRead,
|
||||
|
@ -128,8 +127,6 @@ pub enum UserOperation {
|
|||
GetSiteMetadata,
|
||||
BlockCommunity,
|
||||
BlockPerson,
|
||||
GetBlockedCommunities,
|
||||
GetBlockedPersons,
|
||||
}
|
||||
|
||||
#[derive(EnumString, ToString, Debug, Clone)]
|
||||
|
|
|
@ -151,20 +151,11 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
|
|||
.wrap(rate_limit.message())
|
||||
.route("", web::get().to(route_get_crud::<GetPersonDetails>))
|
||||
.route("/mention", web::get().to(route_get::<GetPersonMentions>))
|
||||
.route("/block", web::get().to(route_get::<GetBlockedPersons>))
|
||||
.route(
|
||||
"/mention/mark_as_read",
|
||||
web::post().to(route_post::<MarkPersonMentionAsRead>),
|
||||
)
|
||||
.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>))
|
||||
// Admin action. I don't like that it's in /user
|
||||
.route("/ban", web::post().to(route_post::<BanPerson>))
|
||||
|
|
Loading…
Reference in a new issue