forked from LemmyNet/lemmy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #222 from LemmyNet/main
[pull] master from LemmyNet:main
- Loading branch information
Showing
34 changed files
with
1,493 additions
and
310 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use activitypub_federation::config::Data; | ||
use actix_web::web::{Json, Query}; | ||
use lemmy_api_common::{ | ||
context::LemmyContext, | ||
person::{ListPersonSaved, ListPersonSavedResponse}, | ||
utils::check_private_instance, | ||
}; | ||
use lemmy_db_views::{ | ||
person_saved_combined_view::PersonSavedCombinedQuery, | ||
structs::{LocalUserView, SiteView}, | ||
}; | ||
use lemmy_utils::error::LemmyResult; | ||
|
||
#[tracing::instrument(skip(context))] | ||
pub async fn list_person_saved( | ||
data: Query<ListPersonSaved>, | ||
context: Data<LemmyContext>, | ||
local_user_view: LocalUserView, | ||
) -> LemmyResult<Json<ListPersonSavedResponse>> { | ||
let local_site = SiteView::read_local(&mut context.pool()).await?; | ||
|
||
check_private_instance(&Some(local_user_view.clone()), &local_site.local_site)?; | ||
|
||
// parse pagination token | ||
let page_after = if let Some(pa) = &data.page_cursor { | ||
Some(pa.read(&mut context.pool()).await?) | ||
} else { | ||
None | ||
}; | ||
let page_back = data.page_back; | ||
let type_ = data.type_; | ||
|
||
let saved = PersonSavedCombinedQuery { | ||
type_, | ||
page_after, | ||
page_back, | ||
} | ||
.list(&mut context.pool(), &local_user_view) | ||
.await?; | ||
|
||
Ok(Json(ListPersonSavedResponse { saved })) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,16 @@ use lemmy_db_schema::{ | |
source::{login_token::LoginToken, site::Site}, | ||
CommentSortType, | ||
ListingType, | ||
PersonContentType, | ||
PostListingMode, | ||
PostSortType, | ||
}; | ||
use lemmy_db_views::structs::{CommentView, LocalImageView, PostView}; | ||
use lemmy_db_views::structs::{ | ||
LocalImageView, | ||
PersonContentCombinedPaginationCursor, | ||
PersonContentCombinedView, | ||
PersonSavedCombinedPaginationCursor, | ||
}; | ||
use lemmy_db_views_actor::structs::{ | ||
CommentReplyView, | ||
CommunityModeratorView, | ||
|
@@ -222,16 +228,6 @@ pub struct GetPersonDetails { | |
/// Example: dessalines , or [email protected] | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub username: Option<String>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub sort: Option<PostSortType>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub page: Option<i64>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub limit: Option<i64>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub community_id: Option<CommunityId>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub saved_only: Option<bool>, | ||
} | ||
|
||
#[skip_serializing_none] | ||
|
@@ -243,11 +239,62 @@ pub struct GetPersonDetailsResponse { | |
pub person_view: PersonView, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub site: Option<Site>, | ||
pub comments: Vec<CommentView>, | ||
pub posts: Vec<PostView>, | ||
pub moderates: Vec<CommunityModeratorView>, | ||
} | ||
|
||
#[skip_serializing_none] | ||
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "full", derive(TS))] | ||
#[cfg_attr(feature = "full", ts(export))] | ||
/// Gets a person's content (posts and comments) | ||
/// | ||
/// Either person_id, or username are required. | ||
pub struct ListPersonContent { | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub type_: Option<PersonContentType>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub person_id: Option<PersonId>, | ||
/// Example: dessalines , or [email protected] | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub username: Option<String>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub page_cursor: Option<PersonContentCombinedPaginationCursor>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub page_back: Option<bool>, | ||
} | ||
|
||
#[skip_serializing_none] | ||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
#[cfg_attr(feature = "full", derive(TS))] | ||
#[cfg_attr(feature = "full", ts(export))] | ||
/// A person's content response. | ||
pub struct ListPersonContentResponse { | ||
pub content: Vec<PersonContentCombinedView>, | ||
} | ||
|
||
#[skip_serializing_none] | ||
#[derive(Debug, Serialize, Deserialize, Clone, Default, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "full", derive(TS))] | ||
#[cfg_attr(feature = "full", ts(export))] | ||
/// Gets your saved posts and comments | ||
pub struct ListPersonSaved { | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub type_: Option<PersonContentType>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub page_cursor: Option<PersonSavedCombinedPaginationCursor>, | ||
#[cfg_attr(feature = "full", ts(optional))] | ||
pub page_back: Option<bool>, | ||
} | ||
|
||
#[skip_serializing_none] | ||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
#[cfg_attr(feature = "full", derive(TS))] | ||
#[cfg_attr(feature = "full", ts(export))] | ||
/// A person's saved content response. | ||
pub struct ListPersonSavedResponse { | ||
pub saved: Vec<PersonContentCombinedView>, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq)] | ||
#[cfg_attr(feature = "full", derive(TS))] | ||
#[cfg_attr(feature = "full", ts(export))] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use super::resolve_person_id_from_id_or_username; | ||
use activitypub_federation::config::Data; | ||
use actix_web::web::{Json, Query}; | ||
use lemmy_api_common::{ | ||
context::LemmyContext, | ||
person::{ListPersonContent, ListPersonContentResponse}, | ||
utils::check_private_instance, | ||
}; | ||
use lemmy_db_views::{ | ||
person_content_combined_view::PersonContentCombinedQuery, | ||
structs::{LocalUserView, SiteView}, | ||
}; | ||
use lemmy_utils::error::LemmyResult; | ||
|
||
#[tracing::instrument(skip(context))] | ||
pub async fn list_person_content( | ||
data: Query<ListPersonContent>, | ||
context: Data<LemmyContext>, | ||
local_user_view: Option<LocalUserView>, | ||
) -> LemmyResult<Json<ListPersonContentResponse>> { | ||
let local_site = SiteView::read_local(&mut context.pool()).await?; | ||
|
||
check_private_instance(&local_user_view, &local_site.local_site)?; | ||
|
||
let person_details_id = resolve_person_id_from_id_or_username( | ||
&data.person_id, | ||
&data.username, | ||
&context, | ||
&local_user_view, | ||
) | ||
.await?; | ||
|
||
// parse pagination token | ||
let page_after = if let Some(pa) = &data.page_cursor { | ||
Some(pa.read(&mut context.pool()).await?) | ||
} else { | ||
None | ||
}; | ||
let page_back = data.page_back; | ||
let type_ = data.type_; | ||
|
||
let content = PersonContentCombinedQuery { | ||
creator_id: person_details_id, | ||
type_, | ||
page_after, | ||
page_back, | ||
} | ||
.list(&mut context.pool(), &local_user_view) | ||
.await?; | ||
|
||
Ok(Json(ListPersonContentResponse { content })) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.