mirror of https://github.com/LemmyNet/lemmy.git
Merge branch 'main' into db-traits-refactor
commit
37bf1843c9
21
README.md
21
README.md
|
@ -116,26 +116,7 @@ Each Lemmy server can set its own moderation policy; appointing site-wide admins
|
||||||
|
|
||||||
## Lemmy Projects
|
## Lemmy Projects
|
||||||
|
|
||||||
### Apps
|
- [awesome-lemmy - A community driven list of apps and tools for lemmy](https://github.com/dbeley/awesome-lemmy)
|
||||||
|
|
||||||
- [lemmy-ui - The official web app for lemmy](https://github.com/LemmyNet/lemmy-ui)
|
|
||||||
- [lemmyBB - A Lemmy forum UI based on phpBB](https://github.com/LemmyNet/lemmyBB)
|
|
||||||
- [Jerboa - A native Android app made by Lemmy's developers](https://github.com/dessalines/jerboa)
|
|
||||||
- [Mlem - A Lemmy client for iOS](https://github.com/buresdv/Mlem)
|
|
||||||
- [Lemoa - A Gtk client for Lemmy on Linux](https://github.com/lemmy-gtk/lemoa)
|
|
||||||
- [Liftoff - A Lemmy for Windows , Linux and Android ](https://github.com/liftoff-app/liftoff)
|
|
||||||
|
|
||||||
### Libraries
|
|
||||||
|
|
||||||
- [lemmy-js-client](https://github.com/LemmyNet/lemmy-js-client)
|
|
||||||
- [lemmy-rust-client](https://github.com/LemmyNet/lemmy/tree/main/crates/api_common)
|
|
||||||
- [go-lemmy](https://gitea.arsenm.dev/Arsen6331/go-lemmy)
|
|
||||||
- [Dart API client](https://github.com/LemmurOrg/lemmy_api_client)
|
|
||||||
- [Lemmy-Swift-Client](https://github.com/rrainn/Lemmy-Swift-Client)
|
|
||||||
- [Reddit -> Lemmy Importer](https://github.com/rileynull/RedditLemmyImporter)
|
|
||||||
- [lemmy-bot - Typescript library to make it easier to make bots for Lemmy](https://github.com/SleeplessOne1917/lemmy-bot)
|
|
||||||
- [Reddit API wrapper for Lemmy](https://github.com/derivator/tafkars)
|
|
||||||
- [Pythörhead - Python package for integrating with the Lemmy API](https://pypi.org/project/pythorhead/)
|
|
||||||
|
|
||||||
## Support / Donate
|
## Support / Donate
|
||||||
|
|
||||||
|
|
|
@ -26,24 +26,27 @@ impl Perform for FollowCommunity {
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let community = Community::read(context.conn().await?, community_id).await?;
|
let community = Community::read(context.conn().await?, community_id).await?;
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let mut community_follower_form = CommunityFollowerForm {
|
||||||
community_id: data.community_id,
|
community_id: data.community_id,
|
||||||
person_id: local_user_view.person.id,
|
person_id: local_user_view.person.id,
|
||||||
pending: false,
|
pending: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if community.local && data.follow {
|
if data.follow {
|
||||||
check_community_ban(
|
if community.local {
|
||||||
local_user_view.person.id,
|
check_community_ban(local_user_view.person.id, community_id, context.conn().await?).await?;
|
||||||
community_id,
|
check_community_deleted_or_removed(community_id, context.conn().await?).await?;
|
||||||
context.conn().await?,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
check_community_deleted_or_removed(community_id, context.conn().await?).await?;
|
|
||||||
|
|
||||||
CommunityFollower::follow(context.conn().await?, &community_follower_form)
|
CommunityFollower::follow(context.conn().await?, &community_follower_form)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
||||||
|
} else {
|
||||||
|
// Mark as pending, the actual federation activity is sent via `SendActivity` handler
|
||||||
|
community_follower_form.pending = true;
|
||||||
|
CommunityFollower::follow(context.conn().await?, &community_follower_form)
|
||||||
|
.await
|
||||||
|
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !data.follow {
|
if !data.follow {
|
||||||
CommunityFollower::unfollow(context.conn().await?, &community_follower_form)
|
CommunityFollower::unfollow(context.conn().await?, &community_follower_form)
|
||||||
|
|
|
@ -132,6 +132,7 @@ impl Perform for SaveUserSettings {
|
||||||
.interface_language(data.interface_language.clone())
|
.interface_language(data.interface_language.clone())
|
||||||
.totp_2fa_secret(totp_2fa_secret)
|
.totp_2fa_secret(totp_2fa_secret)
|
||||||
.totp_2fa_url(totp_2fa_url)
|
.totp_2fa_url(totp_2fa_url)
|
||||||
|
.open_links_in_new_tab(data.open_links_in_new_tab)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let local_user_res =
|
let local_user_res =
|
||||||
|
|
|
@ -75,9 +75,9 @@ pub struct GetCaptchaResponse {
|
||||||
#[cfg_attr(feature = "full", ts(export))]
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
/// A captcha response.
|
/// A captcha response.
|
||||||
pub struct CaptchaResponse {
|
pub struct CaptchaResponse {
|
||||||
/// A Base64 encoded png
|
/// A Base64 encoded png
|
||||||
pub png: String,
|
pub png: String,
|
||||||
/// A Base64 encoded wav audio
|
/// A Base64 encoded wav audio
|
||||||
pub wav: String,
|
pub wav: String,
|
||||||
/// The UUID for the captcha item.
|
/// The UUID for the captcha item.
|
||||||
pub uuid: String,
|
pub uuid: String,
|
||||||
|
@ -109,7 +109,7 @@ pub struct SaveUserSettings {
|
||||||
pub email: Option<Sensitive<String>>,
|
pub email: Option<Sensitive<String>>,
|
||||||
/// Your bio / info, in markdown.
|
/// Your bio / info, in markdown.
|
||||||
pub bio: Option<String>,
|
pub bio: Option<String>,
|
||||||
/// Your matrix user id. Ex: @my_user:matrix.org
|
/// Your matrix user id. Ex: @my_user:matrix.org
|
||||||
pub matrix_user_id: Option<String>,
|
pub matrix_user_id: Option<String>,
|
||||||
/// Whether to show or hide avatars.
|
/// Whether to show or hide avatars.
|
||||||
pub show_avatars: Option<bool>,
|
pub show_avatars: Option<bool>,
|
||||||
|
@ -131,6 +131,8 @@ pub struct SaveUserSettings {
|
||||||
/// None leaves it as is, true will generate or regenerate it, false clears it out.
|
/// None leaves it as is, true will generate or regenerate it, false clears it out.
|
||||||
pub generate_totp_2fa: Option<bool>,
|
pub generate_totp_2fa: Option<bool>,
|
||||||
pub auth: Sensitive<String>,
|
pub auth: Sensitive<String>,
|
||||||
|
/// Open links in a new tab
|
||||||
|
pub open_links_in_new_tab: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
|
|
|
@ -121,18 +121,9 @@ impl PerformCrud for CreatePost {
|
||||||
.thumbnail_url(thumbnail_url)
|
.thumbnail_url(thumbnail_url)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let inserted_post = match Post::create(context.conn().await?, &post_form).await {
|
let inserted_post = Post::create(context.conn().await?, &post_form)
|
||||||
Ok(post) => post,
|
.await
|
||||||
Err(e) => {
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;
|
||||||
let err_type = if e.to_string() == "value too long for type character varying(200)" {
|
|
||||||
"post_title_too_long"
|
|
||||||
} else {
|
|
||||||
"couldnt_create_post"
|
|
||||||
};
|
|
||||||
|
|
||||||
return Err(LemmyError::from_error_message(e, err_type));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let inserted_post_id = inserted_post.id;
|
let inserted_post_id = inserted_post.id;
|
||||||
let protocol_and_hostname = context.settings().get_protocol_and_hostname();
|
let protocol_and_hostname = context.settings().get_protocol_and_hostname();
|
||||||
|
|
|
@ -96,16 +96,9 @@ impl PerformCrud for EditPost {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let res = Post::update(context.conn().await?, post_id, &post_form).await;
|
Post::update(context.conn().await?, post_id, &post_form)
|
||||||
if let Err(e) = res {
|
.await
|
||||||
let err_type = if e.to_string() == "value too long for type character varying(200)" {
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;
|
||||||
"post_title_too_long"
|
|
||||||
} else {
|
|
||||||
"couldnt_update_post"
|
|
||||||
};
|
|
||||||
|
|
||||||
return Err(LemmyError::from_error_message(e, err_type));
|
|
||||||
}
|
|
||||||
|
|
||||||
build_post_response(
|
build_post_response(
|
||||||
context,
|
context,
|
||||||
|
|
|
@ -5,8 +5,6 @@ use lemmy_api_common::{
|
||||||
CommentResponse,
|
CommentResponse,
|
||||||
DistinguishComment,
|
DistinguishComment,
|
||||||
GetComment,
|
GetComment,
|
||||||
GetComments,
|
|
||||||
GetCommentsResponse,
|
|
||||||
ListCommentReports,
|
ListCommentReports,
|
||||||
ListCommentReportsResponse,
|
ListCommentReportsResponse,
|
||||||
ResolveCommentReport,
|
ResolveCommentReport,
|
||||||
|
@ -15,7 +13,6 @@ use lemmy_api_common::{
|
||||||
community::{
|
community::{
|
||||||
CommunityResponse,
|
CommunityResponse,
|
||||||
CreateCommunity,
|
CreateCommunity,
|
||||||
GetCommunity,
|
|
||||||
GetCommunityResponse,
|
GetCommunityResponse,
|
||||||
ListCommunities,
|
ListCommunities,
|
||||||
ListCommunitiesResponse,
|
ListCommunitiesResponse,
|
||||||
|
@ -39,8 +36,6 @@ use lemmy_api_common::{
|
||||||
GetBannedPersons,
|
GetBannedPersons,
|
||||||
GetCaptcha,
|
GetCaptcha,
|
||||||
GetCaptchaResponse,
|
GetCaptchaResponse,
|
||||||
GetPersonDetails,
|
|
||||||
GetPersonDetailsResponse,
|
|
||||||
GetPersonMentions,
|
GetPersonMentions,
|
||||||
GetPersonMentionsResponse,
|
GetPersonMentionsResponse,
|
||||||
GetReplies,
|
GetReplies,
|
||||||
|
@ -66,8 +61,6 @@ use lemmy_api_common::{
|
||||||
post::{
|
post::{
|
||||||
GetPost,
|
GetPost,
|
||||||
GetPostResponse,
|
GetPostResponse,
|
||||||
GetPosts,
|
|
||||||
GetPostsResponse,
|
|
||||||
GetSiteMetadata,
|
GetSiteMetadata,
|
||||||
GetSiteMetadataResponse,
|
GetSiteMetadataResponse,
|
||||||
ListPostReports,
|
ListPostReports,
|
||||||
|
@ -110,10 +103,6 @@ use lemmy_api_common::{
|
||||||
PurgePerson,
|
PurgePerson,
|
||||||
PurgePost,
|
PurgePost,
|
||||||
RegistrationApplicationResponse,
|
RegistrationApplicationResponse,
|
||||||
ResolveObject,
|
|
||||||
ResolveObjectResponse,
|
|
||||||
Search,
|
|
||||||
SearchResponse,
|
|
||||||
SiteResponse,
|
SiteResponse,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -122,10 +111,6 @@ impl SendActivity for Register {
|
||||||
type Response = LoginResponse;
|
type Response = LoginResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SendActivity for GetPersonDetails {
|
|
||||||
type Response = GetPersonDetailsResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SendActivity for GetPrivateMessages {
|
impl SendActivity for GetPrivateMessages {
|
||||||
type Response = PrivateMessagesResponse;
|
type Response = PrivateMessagesResponse;
|
||||||
}
|
}
|
||||||
|
@ -142,10 +127,6 @@ impl SendActivity for GetSite {
|
||||||
type Response = GetSiteResponse;
|
type Response = GetSiteResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SendActivity for GetCommunity {
|
|
||||||
type Response = GetCommunityResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SendActivity for ListCommunities {
|
impl SendActivity for ListCommunities {
|
||||||
type Response = ListCommunitiesResponse;
|
type Response = ListCommunitiesResponse;
|
||||||
}
|
}
|
||||||
|
@ -158,18 +139,10 @@ impl SendActivity for GetPost {
|
||||||
type Response = GetPostResponse;
|
type Response = GetPostResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SendActivity for GetPosts {
|
|
||||||
type Response = GetPostsResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SendActivity for GetComment {
|
impl SendActivity for GetComment {
|
||||||
type Response = CommentResponse;
|
type Response = CommentResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SendActivity for GetComments {
|
|
||||||
type Response = GetCommentsResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SendActivity for Login {
|
impl SendActivity for Login {
|
||||||
type Response = LoginResponse;
|
type Response = LoginResponse;
|
||||||
}
|
}
|
||||||
|
@ -286,14 +259,6 @@ impl SendActivity for PurgeComment {
|
||||||
type Response = PurgeItemResponse;
|
type Response = PurgeItemResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SendActivity for Search {
|
|
||||||
type Response = SearchResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SendActivity for ResolveObject {
|
|
||||||
type Response = ResolveObjectResponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SendActivity for TransferCommunity {
|
impl SendActivity for TransferCommunity {
|
||||||
type Response = GetCommunityResponse;
|
type Response = GetCommunityResponse;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{listing_type_with_default, PerformApub},
|
api::listing_type_with_default,
|
||||||
fetcher::resolve_actor_identifier,
|
fetcher::resolve_actor_identifier,
|
||||||
objects::community::ApubCommunity,
|
objects::community::ApubCommunity,
|
||||||
};
|
};
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
|
use actix_web::web::{Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{GetComments, GetCommentsResponse},
|
comment::{GetComments, GetCommentsResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
@ -16,61 +17,58 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views::comment_view::CommentQuery;
|
use lemmy_db_views::comment_view::CommentQuery;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformApub for GetComments {
|
pub async fn list_comments(
|
||||||
type Response = GetCommentsResponse;
|
data: Query<GetComments>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<GetCommentsResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
|
||||||
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
let community_id = if let Some(name) = &data.community_name {
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetCommentsResponse, LemmyError> {
|
resolve_actor_identifier::<ApubCommunity, Community>(name, &context, &None, true)
|
||||||
let data: &GetComments = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
|
||||||
let local_site = LocalSite::read(context.conn().await?).await?;
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
|
||||||
|
|
||||||
let community_id = if let Some(name) = &data.community_name {
|
|
||||||
resolve_actor_identifier::<ApubCommunity, Community>(name, context, &None, true)
|
|
||||||
.await
|
|
||||||
.ok()
|
|
||||||
.map(|c| c.id)
|
|
||||||
} else {
|
|
||||||
data.community_id
|
|
||||||
};
|
|
||||||
let sort = data.sort;
|
|
||||||
let max_depth = data.max_depth;
|
|
||||||
let saved_only = data.saved_only;
|
|
||||||
let page = data.page;
|
|
||||||
let limit = data.limit;
|
|
||||||
let parent_id = data.parent_id;
|
|
||||||
|
|
||||||
let listing_type = listing_type_with_default(data.type_, &local_site, community_id)?;
|
|
||||||
|
|
||||||
// If a parent_id is given, fetch the comment to get the path
|
|
||||||
let parent_path = if let Some(parent_id) = parent_id {
|
|
||||||
Some(Comment::read(context.conn().await?, parent_id).await?.path)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let parent_path_cloned = parent_path.clone();
|
|
||||||
let post_id = data.post_id;
|
|
||||||
let local_user = local_user_view.map(|l| l.local_user);
|
|
||||||
let comments = CommentQuery::builder()
|
|
||||||
.conn(context.conn().await?)
|
|
||||||
.listing_type(Some(listing_type))
|
|
||||||
.sort(sort)
|
|
||||||
.max_depth(max_depth)
|
|
||||||
.saved_only(saved_only)
|
|
||||||
.community_id(community_id)
|
|
||||||
.parent_path(parent_path_cloned)
|
|
||||||
.post_id(post_id)
|
|
||||||
.local_user(local_user.as_ref())
|
|
||||||
.page(page)
|
|
||||||
.limit(limit)
|
|
||||||
.build()
|
|
||||||
.list()
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_get_comments"))?;
|
.ok()
|
||||||
|
.map(|c| c.id)
|
||||||
|
} else {
|
||||||
|
data.community_id
|
||||||
|
};
|
||||||
|
let sort = data.sort;
|
||||||
|
let max_depth = data.max_depth;
|
||||||
|
let saved_only = data.saved_only;
|
||||||
|
let page = data.page;
|
||||||
|
let limit = data.limit;
|
||||||
|
let parent_id = data.parent_id;
|
||||||
|
|
||||||
Ok(GetCommentsResponse { comments })
|
let listing_type = listing_type_with_default(data.type_, &local_site, community_id)?;
|
||||||
}
|
|
||||||
|
// If a parent_id is given, fetch the comment to get the path
|
||||||
|
let parent_path = if let Some(parent_id) = parent_id {
|
||||||
|
Some(Comment::read(context.conn().await?, parent_id).await?.path)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
let parent_path_cloned = parent_path.clone();
|
||||||
|
let post_id = data.post_id;
|
||||||
|
let local_user = local_user_view.map(|l| l.local_user);
|
||||||
|
let comments = CommentQuery::builder()
|
||||||
|
.conn(context.conn().await?)
|
||||||
|
.listing_type(Some(listing_type))
|
||||||
|
.sort(sort)
|
||||||
|
.max_depth(max_depth)
|
||||||
|
.saved_only(saved_only)
|
||||||
|
.community_id(community_id)
|
||||||
|
.parent_path(parent_path_cloned)
|
||||||
|
.post_id(post_id)
|
||||||
|
.local_user(local_user.as_ref())
|
||||||
|
.page(page)
|
||||||
|
.limit(limit)
|
||||||
|
.build()
|
||||||
|
.list()
|
||||||
|
.await
|
||||||
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_get_comments"))?;
|
||||||
|
|
||||||
|
Ok(Json(GetCommentsResponse { comments }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{listing_type_with_default, PerformApub},
|
api::listing_type_with_default,
|
||||||
fetcher::resolve_actor_identifier,
|
fetcher::resolve_actor_identifier,
|
||||||
objects::community::ApubCommunity,
|
objects::community::ApubCommunity,
|
||||||
};
|
};
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
|
use actix_web::web::{Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
post::{GetPosts, GetPostsResponse},
|
post::{GetPosts, GetPostsResponse},
|
||||||
|
@ -13,57 +14,50 @@ use lemmy_db_schema::source::{community::Community, local_site::LocalSite};
|
||||||
use lemmy_db_views::post_view::PostQuery;
|
use lemmy_db_views::post_view::PostQuery;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformApub for GetPosts {
|
pub async fn list_posts(
|
||||||
type Response = GetPostsResponse;
|
data: Query<GetPosts>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<GetPostsResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
|
||||||
|
let local_site = LocalSite::read(context.pool()).await?;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetPostsResponse, LemmyError> {
|
|
||||||
let data: &GetPosts = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
|
||||||
let local_site = LocalSite::read(context.conn().await?).await?;
|
|
||||||
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
let sort = data.sort;
|
||||||
|
|
||||||
let sort = data.sort;
|
let page = data.page;
|
||||||
|
let limit = data.limit;
|
||||||
|
let community_id = if let Some(name) = &data.community_name {
|
||||||
|
resolve_actor_identifier::<ApubCommunity, Community>(name, &context, &None, true)
|
||||||
|
.await
|
||||||
|
.ok()
|
||||||
|
.map(|c| c.id)
|
||||||
|
} else {
|
||||||
|
data.community_id
|
||||||
|
};
|
||||||
|
let saved_only = data.saved_only;
|
||||||
|
|
||||||
let page = data.page;
|
let listing_type = listing_type_with_default(data.type_, &local_site, community_id)?;
|
||||||
let limit = data.limit;
|
|
||||||
let community_id = if let Some(name) = &data.community_name {
|
|
||||||
resolve_actor_identifier::<ApubCommunity, Community>(name, context, &None, true)
|
|
||||||
.await
|
|
||||||
.ok()
|
|
||||||
.map(|c| c.id)
|
|
||||||
} else {
|
|
||||||
data.community_id
|
|
||||||
};
|
|
||||||
let saved_only = data.saved_only;
|
|
||||||
|
|
||||||
let listing_type = listing_type_with_default(data.type_, &local_site, community_id)?;
|
let is_mod_or_admin = is_mod_or_admin_opt(context.pool(), local_user_view.as_ref(), community_id)
|
||||||
|
|
||||||
let is_mod_or_admin = is_mod_or_admin_opt(
|
|
||||||
context.conn().await?,
|
|
||||||
local_user_view.as_ref(),
|
|
||||||
community_id,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.is_ok();
|
.is_ok();
|
||||||
|
|
||||||
let posts = PostQuery::builder()
|
let posts = PostQuery::builder()
|
||||||
.conn(context.conn().await?)
|
.conn(context.conn().await?)
|
||||||
.local_user(local_user_view.map(|l| l.local_user).as_ref())
|
.local_user(local_user_view.map(|l| l.local_user).as_ref())
|
||||||
.listing_type(Some(listing_type))
|
.listing_type(Some(listing_type))
|
||||||
.sort(sort)
|
.sort(sort)
|
||||||
.community_id(community_id)
|
.community_id(community_id)
|
||||||
.saved_only(saved_only)
|
.saved_only(saved_only)
|
||||||
.page(page)
|
.page(page)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.is_mod_or_admin(Some(is_mod_or_admin))
|
.is_mod_or_admin(Some(is_mod_or_admin))
|
||||||
.build()
|
.build()
|
||||||
.list()
|
.list()
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_get_posts"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_get_posts"))?;
|
||||||
|
|
||||||
Ok(GetPostsResponse { posts })
|
Ok(Json(GetPostsResponse { posts }))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,12 @@
|
||||||
use activitypub_federation::config::Data;
|
|
||||||
use lemmy_api_common::context::LemmyContext;
|
|
||||||
use lemmy_db_schema::{newtypes::CommunityId, source::local_site::LocalSite, ListingType};
|
use lemmy_db_schema::{newtypes::CommunityId, source::local_site::LocalSite, ListingType};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
mod list_comments;
|
pub mod list_comments;
|
||||||
mod list_posts;
|
pub mod list_posts;
|
||||||
mod read_community;
|
pub mod read_community;
|
||||||
mod read_person;
|
pub mod read_person;
|
||||||
mod resolve_object;
|
pub mod resolve_object;
|
||||||
mod search;
|
pub mod search;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
|
||||||
pub trait PerformApub {
|
|
||||||
type Response: serde::ser::Serialize + Send;
|
|
||||||
|
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns default listing type, depending if the query is for frontpage or community.
|
/// Returns default listing type, depending if the query is for frontpage or community.
|
||||||
fn listing_type_with_default(
|
fn listing_type_with_default(
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use crate::{
|
use crate::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity};
|
||||||
api::PerformApub,
|
|
||||||
fetcher::resolve_actor_identifier,
|
|
||||||
objects::community::ApubCommunity,
|
|
||||||
};
|
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
|
use actix_web::web::{Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{GetCommunity, GetCommunityResponse},
|
community::{GetCommunity, GetCommunityResponse},
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
@ -18,81 +15,68 @@ use lemmy_db_schema::source::{
|
||||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformApub for GetCommunity {
|
pub async fn read_community(
|
||||||
type Response = GetCommunityResponse;
|
data: Query<GetCommunity>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<GetCommunityResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
|
||||||
|
let local_site = LocalSite::read(context.conn().await?).await?;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
if data.name.is_none() && data.id.is_none() {
|
||||||
async fn perform(
|
return Err(LemmyError::from_message("no_id_given"));
|
||||||
&self,
|
}
|
||||||
context: &Data<LemmyContext>,
|
|
||||||
) -> Result<GetCommunityResponse, LemmyError> {
|
|
||||||
let data: &GetCommunity = self;
|
|
||||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
|
||||||
let local_site = LocalSite::read(context.conn().await?).await?;
|
|
||||||
|
|
||||||
if data.name.is_none() && data.id.is_none() {
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
return Err(LemmyError::from_message("no_id_given"));
|
|
||||||
|
let person_id = local_user_view.as_ref().map(|u| u.person.id);
|
||||||
|
|
||||||
|
let community_id = match data.id {
|
||||||
|
Some(id) => id,
|
||||||
|
None => {
|
||||||
|
let name = data.name.clone().unwrap_or_else(|| "main".to_string());
|
||||||
|
resolve_actor_identifier::<ApubCommunity, Community>(&name, &context, &local_user_view, true)
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.with_message("couldnt_find_community"))?
|
||||||
|
.id
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
let is_mod_or_admin =
|
||||||
|
is_mod_or_admin_opt(context.conn().await?, local_user_view.as_ref(), Some(community_id))
|
||||||
|
.await
|
||||||
|
.is_ok();
|
||||||
|
|
||||||
let person_id = local_user_view.as_ref().map(|u| u.person.id);
|
let community_view = CommunityView::read(
|
||||||
|
context.conn().await?,
|
||||||
|
community_id,
|
||||||
|
person_id,
|
||||||
|
Some(is_mod_or_admin),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
||||||
|
|
||||||
let community_id = match data.id {
|
let moderators = CommunityModeratorView::for_community(context.pool(), community_id)
|
||||||
Some(id) => id,
|
|
||||||
None => {
|
|
||||||
let name = data.name.clone().unwrap_or_else(|| "main".to_string());
|
|
||||||
resolve_actor_identifier::<ApubCommunity, Community>(&name, context, &local_user_view, true)
|
|
||||||
.await
|
|
||||||
.map_err(|e| e.with_message("couldnt_find_community"))?
|
|
||||||
.id
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let is_mod_or_admin = is_mod_or_admin_opt(
|
|
||||||
context.conn().await?,
|
|
||||||
local_user_view.as_ref(),
|
|
||||||
Some(community_id),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.is_ok();
|
|
||||||
|
|
||||||
let community_view = CommunityView::read(
|
|
||||||
context.conn().await?,
|
|
||||||
community_id,
|
|
||||||
person_id,
|
|
||||||
Some(is_mod_or_admin),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
||||||
|
|
||||||
let moderators = CommunityModeratorView::for_community(context.conn().await?, community_id)
|
let site_id = Site::instance_actor_id_from_url(community_view.community.actor_id.clone().into());
|
||||||
.await
|
let mut site = Site::read_from_apub_id(context.conn().await?, &site_id.into()).await?;
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
// no need to include metadata for local site (its already available through other endpoints).
|
||||||
|
// this also prevents us from leaking the federation private key.
|
||||||
let site_id =
|
if let Some(s) = &site {
|
||||||
Site::instance_actor_id_from_url(community_view.community.actor_id.clone().into());
|
if s.actor_id.domain() == Some(context.settings().hostname.as_ref()) {
|
||||||
let mut site = Site::read_from_apub_id(context.conn().await?, &site_id.into()).await?;
|
site = None;
|
||||||
// no need to include metadata for local site (its already available through other endpoints).
|
|
||||||
// this also prevents us from leaking the federation private key.
|
|
||||||
if let Some(s) = &site {
|
|
||||||
if s.actor_id.domain() == Some(context.settings().hostname.as_ref()) {
|
|
||||||
site = None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let community_id = community_view.community.id;
|
|
||||||
let discussion_languages = CommunityLanguage::read(context.conn().await?, community_id).await?;
|
|
||||||
|
|
||||||
let res = GetCommunityResponse {
|
|
||||||
community_view,
|
|
||||||
site,
|
|
||||||
moderators,
|
|
||||||
discussion_languages,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return the jwt
|
|
||||||
Ok(res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let community_id = community_view.community.id;
|
||||||
|
let discussion_languages = CommunityLanguage::read(context.conn().await?, community_id).await?;
|
||||||
|
|
||||||
|
Ok(Json(GetCommunityResponse {
|
||||||
|
community_view,
|
||||||
|
site,
|
||||||
|
moderators,
|
||||||
|
discussion_languages,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{api::PerformApub, fetcher::resolve_actor_identifier, objects::person::ApubPerson};
|
use crate::{fetcher::resolve_actor_identifier, objects::person::ApubPerson};
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
|
use actix_web::web::{Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{GetPersonDetails, GetPersonDetailsResponse},
|
person::{GetPersonDetails, GetPersonDetailsResponse},
|
||||||
|
@ -13,109 +14,101 @@ use lemmy_db_views::{comment_view::CommentQuery, post_view::PostQuery};
|
||||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonView};
|
use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonView};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformApub for GetPersonDetails {
|
pub async fn read_person(
|
||||||
type Response = GetPersonDetailsResponse;
|
data: Query<GetPersonDetails>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
#[tracing::instrument(skip(self, context))]
|
) -> Result<Json<GetPersonDetailsResponse>, LemmyError> {
|
||||||
async fn perform(
|
// Check to make sure a person name or an id is given
|
||||||
&self,
|
if data.username.is_none() && data.person_id.is_none() {
|
||||||
context: &Data<LemmyContext>,
|
return Err(LemmyError::from_message("no_id_given"));
|
||||||
) -> Result<GetPersonDetailsResponse, LemmyError> {
|
|
||||||
let data: &GetPersonDetails = self;
|
|
||||||
|
|
||||||
// Check to make sure a person name or an id is given
|
|
||||||
if data.username.is_none() && data.person_id.is_none() {
|
|
||||||
return Err(LemmyError::from_message("no_id_given"));
|
|
||||||
}
|
|
||||||
|
|
||||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
|
||||||
let local_site = LocalSite::read(context.conn().await?).await?;
|
|
||||||
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
|
||||||
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
|
||||||
|
|
||||||
let person_details_id = match data.person_id {
|
|
||||||
Some(id) => id,
|
|
||||||
None => {
|
|
||||||
if let Some(username) = &data.username {
|
|
||||||
resolve_actor_identifier::<ApubPerson, Person>(username, context, &local_user_view, true)
|
|
||||||
.await
|
|
||||||
.map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?
|
|
||||||
.id
|
|
||||||
} else {
|
|
||||||
return Err(LemmyError::from_message(
|
|
||||||
"couldnt_find_that_username_or_email",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// You don't need to return settings for the user, since this comes back with GetSite
|
|
||||||
// `my_user`
|
|
||||||
let person_view = PersonView::read(context.conn().await?, person_details_id).await?;
|
|
||||||
|
|
||||||
let sort = data.sort;
|
|
||||||
let page = data.page;
|
|
||||||
let limit = data.limit;
|
|
||||||
let saved_only = data.saved_only;
|
|
||||||
let community_id = data.community_id;
|
|
||||||
let local_user = local_user_view.map(|l| l.local_user);
|
|
||||||
let local_user_clone = local_user.clone();
|
|
||||||
|
|
||||||
let posts_query = PostQuery::builder()
|
|
||||||
.conn(context.conn().await?)
|
|
||||||
.sort(sort)
|
|
||||||
.saved_only(saved_only)
|
|
||||||
.local_user(local_user.as_ref())
|
|
||||||
.community_id(community_id)
|
|
||||||
.is_mod_or_admin(is_admin)
|
|
||||||
.page(page)
|
|
||||||
.limit(limit);
|
|
||||||
|
|
||||||
// If its saved only, you don't care what creator it was
|
|
||||||
// Or, if its not saved, then you only want it for that specific creator
|
|
||||||
let posts = if !saved_only.unwrap_or(false) {
|
|
||||||
posts_query
|
|
||||||
.creator_id(Some(person_details_id))
|
|
||||||
.build()
|
|
||||||
.list()
|
|
||||||
} else {
|
|
||||||
posts_query.build().list()
|
|
||||||
}
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let comments_query = CommentQuery::builder()
|
|
||||||
.conn(context.conn().await?)
|
|
||||||
.local_user(local_user_clone.as_ref())
|
|
||||||
.sort(sort.map(post_to_comment_sort_type))
|
|
||||||
.saved_only(saved_only)
|
|
||||||
.show_deleted_and_removed(Some(false))
|
|
||||||
.community_id(community_id)
|
|
||||||
.page(page)
|
|
||||||
.limit(limit);
|
|
||||||
|
|
||||||
// If its saved only, you don't care what creator it was
|
|
||||||
// Or, if its not saved, then you only want it for that specific creator
|
|
||||||
let comments = if !saved_only.unwrap_or(false) {
|
|
||||||
comments_query
|
|
||||||
.creator_id(Some(person_details_id))
|
|
||||||
.build()
|
|
||||||
.list()
|
|
||||||
} else {
|
|
||||||
comments_query.build().list()
|
|
||||||
}
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let moderates =
|
|
||||||
CommunityModeratorView::for_person(context.conn().await?, person_details_id).await?;
|
|
||||||
|
|
||||||
// Return the jwt
|
|
||||||
Ok(GetPersonDetailsResponse {
|
|
||||||
person_view,
|
|
||||||
moderates,
|
|
||||||
comments,
|
|
||||||
posts,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
|
||||||
|
let local_site = LocalSite::read(context.conn().await?).await?;
|
||||||
|
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
||||||
|
|
||||||
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
|
|
||||||
|
let person_details_id = match data.person_id {
|
||||||
|
Some(id) => id,
|
||||||
|
None => {
|
||||||
|
if let Some(username) = &data.username {
|
||||||
|
resolve_actor_identifier::<ApubPerson, Person>(username, &context, &local_user_view, true)
|
||||||
|
.await
|
||||||
|
.map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?
|
||||||
|
.id
|
||||||
|
} else {
|
||||||
|
return Err(LemmyError::from_message(
|
||||||
|
"couldnt_find_that_username_or_email",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// You don't need to return settings for the user, since this comes back with GetSite
|
||||||
|
// `my_user`
|
||||||
|
let person_view = PersonView::read(context.conn().await?, person_details_id).await?;
|
||||||
|
|
||||||
|
let sort = data.sort;
|
||||||
|
let page = data.page;
|
||||||
|
let limit = data.limit;
|
||||||
|
let saved_only = data.saved_only;
|
||||||
|
let community_id = data.community_id;
|
||||||
|
let local_user = local_user_view.map(|l| l.local_user);
|
||||||
|
let local_user_clone = local_user.clone();
|
||||||
|
|
||||||
|
let posts_query = PostQuery::builder()
|
||||||
|
.conn(context.conn().await?)
|
||||||
|
.sort(sort)
|
||||||
|
.saved_only(saved_only)
|
||||||
|
.local_user(local_user.as_ref())
|
||||||
|
.community_id(community_id)
|
||||||
|
.is_mod_or_admin(is_admin)
|
||||||
|
.page(page)
|
||||||
|
.limit(limit);
|
||||||
|
|
||||||
|
// If its saved only, you don't care what creator it was
|
||||||
|
// Or, if its not saved, then you only want it for that specific creator
|
||||||
|
let posts = if !saved_only.unwrap_or(false) {
|
||||||
|
posts_query
|
||||||
|
.creator_id(Some(person_details_id))
|
||||||
|
.build()
|
||||||
|
.list()
|
||||||
|
} else {
|
||||||
|
posts_query.build().list()
|
||||||
|
}
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let comments_query = CommentQuery::builder()
|
||||||
|
.conn(context.conn().await?)
|
||||||
|
.local_user(local_user_clone.as_ref())
|
||||||
|
.sort(sort.map(post_to_comment_sort_type))
|
||||||
|
.saved_only(saved_only)
|
||||||
|
.show_deleted_and_removed(Some(false))
|
||||||
|
.community_id(community_id)
|
||||||
|
.page(page)
|
||||||
|
.limit(limit);
|
||||||
|
|
||||||
|
// If its saved only, you don't care what creator it was
|
||||||
|
// Or, if its not saved, then you only want it for that specific creator
|
||||||
|
let comments = if !saved_only.unwrap_or(false) {
|
||||||
|
comments_query
|
||||||
|
.creator_id(Some(person_details_id))
|
||||||
|
.build()
|
||||||
|
.list()
|
||||||
|
} else {
|
||||||
|
comments_query.build().list()
|
||||||
|
}
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let moderates = CommunityModeratorView::for_person(context.conn().await?, person_details_id).await?;
|
||||||
|
|
||||||
|
// Return the jwt
|
||||||
|
Ok(Json(GetPersonDetailsResponse {
|
||||||
|
person_view,
|
||||||
|
moderates,
|
||||||
|
comments,
|
||||||
|
posts,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use crate::{
|
use crate::fetcher::search::{search_query_to_object_id, SearchableObjects};
|
||||||
api::PerformApub,
|
|
||||||
fetcher::search::{search_query_to_object_id, SearchableObjects},
|
|
||||||
};
|
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
|
use actix_web::web::{Json, Query};
|
||||||
use diesel::NotFound;
|
use diesel::NotFound;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
|
@ -14,34 +12,29 @@ use lemmy_db_views::structs::{CommentView, PostView};
|
||||||
use lemmy_db_views_actor::structs::{CommunityView, PersonView};
|
use lemmy_db_views_actor::structs::{CommunityView, PersonView};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformApub for ResolveObject {
|
pub async fn resolve_object(
|
||||||
type Response = ResolveObjectResponse;
|
data: Query<ResolveObject>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<ResolveObjectResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
|
||||||
|
let local_site = LocalSite::read(context.conn().await?).await?;
|
||||||
|
let person_id = local_user_view.person.id;
|
||||||
|
check_private_instance(&Some(local_user_view), &local_site)?;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
let res = search_query_to_object_id(&data.q, &context)
|
||||||
async fn perform(
|
.await
|
||||||
&self,
|
.map_err(|e| e.with_message("couldnt_find_object"))?;
|
||||||
context: &Data<LemmyContext>,
|
convert_response(res, person_id, context.conn().await?)
|
||||||
) -> Result<ResolveObjectResponse, LemmyError> {
|
.await
|
||||||
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
|
.map_err(|e| e.with_message("couldnt_find_object"))
|
||||||
let local_site = LocalSite::read(context.conn().await?).await?;
|
|
||||||
let person_id = local_user_view.person.id;
|
|
||||||
check_private_instance(&Some(local_user_view), &local_site)?;
|
|
||||||
|
|
||||||
let res = search_query_to_object_id(&self.q, context)
|
|
||||||
.await
|
|
||||||
.map_err(|e| e.with_message("couldnt_find_object"))?;
|
|
||||||
convert_response(res, person_id, context.conn().await?)
|
|
||||||
.await
|
|
||||||
.map_err(|e| e.with_message("couldnt_find_object"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn convert_response(
|
async fn convert_response(
|
||||||
object: SearchableObjects,
|
object: SearchableObjects,
|
||||||
user_id: PersonId,
|
user_id: PersonId,
|
||||||
mut conn: impl DbConn,
|
mut conn: impl DbConn,
|
||||||
) -> Result<ResolveObjectResponse, LemmyError> {
|
) -> Result<Json<ResolveObjectResponse>, LemmyError> {
|
||||||
use SearchableObjects::*;
|
use SearchableObjects::*;
|
||||||
let removed_or_deleted;
|
let removed_or_deleted;
|
||||||
let mut res = ResolveObjectResponse::default();
|
let mut res = ResolveObjectResponse::default();
|
||||||
|
@ -67,5 +60,5 @@ async fn convert_response(
|
||||||
if removed_or_deleted {
|
if removed_or_deleted {
|
||||||
return Err(NotFound {}.into());
|
return Err(NotFound {}.into());
|
||||||
}
|
}
|
||||||
Ok(res)
|
Ok(Json(res))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
use crate::{
|
use crate::{fetcher::resolve_actor_identifier, objects::community::ApubCommunity};
|
||||||
api::PerformApub,
|
|
||||||
fetcher::resolve_actor_identifier,
|
|
||||||
objects::community::ApubCommunity,
|
|
||||||
};
|
|
||||||
use activitypub_federation::config::Data;
|
use activitypub_federation::config::Data;
|
||||||
|
use actix_web::web::{Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
site::{Search, SearchResponse},
|
site::{Search, SearchResponse},
|
||||||
|
@ -18,78 +15,142 @@ use lemmy_db_views::{comment_view::CommentQuery, post_view::PostQuery};
|
||||||
use lemmy_db_views_actor::{community_view::CommunityQuery, person_view::PersonQuery};
|
use lemmy_db_views_actor::{community_view::CommunityQuery, person_view::PersonQuery};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[tracing::instrument(skip(context))]
|
||||||
impl PerformApub for Search {
|
pub async fn search(
|
||||||
type Response = SearchResponse;
|
data: Query<Search>,
|
||||||
|
context: Data<LemmyContext>,
|
||||||
|
) -> Result<Json<SearchResponse>, LemmyError> {
|
||||||
|
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
|
||||||
|
let local_site = LocalSite::read(context.conn().await?).await?;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
check_private_instance(&local_user_view, &local_site)?;
|
||||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<SearchResponse, LemmyError> {
|
|
||||||
let data: &Search = self;
|
|
||||||
|
|
||||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
||||||
let local_site = LocalSite::read(context.conn().await?).await?;
|
|
||||||
|
|
||||||
check_private_instance(&local_user_view, &local_site)?;
|
let mut posts = Vec::new();
|
||||||
|
let mut comments = Vec::new();
|
||||||
|
let mut communities = Vec::new();
|
||||||
|
let mut users = Vec::new();
|
||||||
|
|
||||||
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
// TODO no clean / non-nsfw searching rn
|
||||||
|
|
||||||
let mut posts = Vec::new();
|
let q = data.q.clone();
|
||||||
let mut comments = Vec::new();
|
let page = data.page;
|
||||||
let mut communities = Vec::new();
|
let limit = data.limit;
|
||||||
let mut users = Vec::new();
|
let sort = data.sort;
|
||||||
|
let listing_type = data.listing_type;
|
||||||
|
let search_type = data.type_.unwrap_or(SearchType::All);
|
||||||
|
let community_id = if let Some(name) = &data.community_name {
|
||||||
|
resolve_actor_identifier::<ApubCommunity, Community>(name, &context, &local_user_view, false)
|
||||||
|
.await
|
||||||
|
.ok()
|
||||||
|
.map(|c| c.id)
|
||||||
|
} else {
|
||||||
|
data.community_id
|
||||||
|
};
|
||||||
|
let creator_id = data.creator_id;
|
||||||
|
let local_user = local_user_view.map(|l| l.local_user);
|
||||||
|
match search_type {
|
||||||
|
SearchType::Posts => {
|
||||||
|
posts = PostQuery::builder()
|
||||||
|
.conn(context.conn().await?)
|
||||||
|
.sort(sort)
|
||||||
|
.listing_type(listing_type)
|
||||||
|
.community_id(community_id)
|
||||||
|
.creator_id(creator_id)
|
||||||
|
.local_user(local_user.as_ref())
|
||||||
|
.search_term(Some(q))
|
||||||
|
.is_mod_or_admin(is_admin)
|
||||||
|
.page(page)
|
||||||
|
.limit(limit)
|
||||||
|
.build()
|
||||||
|
.list()
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
SearchType::Comments => {
|
||||||
|
comments = CommentQuery::builder()
|
||||||
|
.conn(context.conn().await?)
|
||||||
|
.sort(sort.map(post_to_comment_sort_type))
|
||||||
|
.listing_type(listing_type)
|
||||||
|
.search_term(Some(q))
|
||||||
|
.community_id(community_id)
|
||||||
|
.creator_id(creator_id)
|
||||||
|
.local_user(local_user.as_ref())
|
||||||
|
.page(page)
|
||||||
|
.limit(limit)
|
||||||
|
.build()
|
||||||
|
.list()
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
SearchType::Communities => {
|
||||||
|
communities = CommunityQuery::builder()
|
||||||
|
.conn(context.conn().await?)
|
||||||
|
.sort(sort)
|
||||||
|
.listing_type(listing_type)
|
||||||
|
.search_term(Some(q))
|
||||||
|
.local_user(local_user.as_ref())
|
||||||
|
.is_mod_or_admin(is_admin)
|
||||||
|
.page(page)
|
||||||
|
.limit(limit)
|
||||||
|
.build()
|
||||||
|
.list()
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
SearchType::Users => {
|
||||||
|
users = PersonQuery::builder()
|
||||||
|
.conn(context.conn().await?)
|
||||||
|
.sort(sort)
|
||||||
|
.search_term(Some(q))
|
||||||
|
.page(page)
|
||||||
|
.limit(limit)
|
||||||
|
.build()
|
||||||
|
.list()
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
SearchType::All => {
|
||||||
|
// If the community or creator is included, dont search communities or users
|
||||||
|
let community_or_creator_included =
|
||||||
|
data.community_id.is_some() || data.community_name.is_some() || data.creator_id.is_some();
|
||||||
|
|
||||||
// TODO no clean / non-nsfw searching rn
|
let local_user_ = local_user.clone();
|
||||||
|
posts = PostQuery::builder()
|
||||||
|
.conn(context.conn().await?)
|
||||||
|
.sort(sort)
|
||||||
|
.listing_type(listing_type)
|
||||||
|
.community_id(community_id)
|
||||||
|
.creator_id(creator_id)
|
||||||
|
.local_user(local_user_.as_ref())
|
||||||
|
.search_term(Some(q))
|
||||||
|
.is_mod_or_admin(is_admin)
|
||||||
|
.page(page)
|
||||||
|
.limit(limit)
|
||||||
|
.build()
|
||||||
|
.list()
|
||||||
|
.await?;
|
||||||
|
|
||||||
let q = data.q.clone();
|
let q = data.q.clone();
|
||||||
let page = data.page;
|
|
||||||
let limit = data.limit;
|
let local_user_ = local_user.clone();
|
||||||
let sort = data.sort;
|
comments = CommentQuery::builder()
|
||||||
let listing_type = data.listing_type;
|
.conn(context.conn().await?)
|
||||||
let search_type = data.type_.unwrap_or(SearchType::All);
|
.sort(sort.map(post_to_comment_sort_type))
|
||||||
let community_id = if let Some(name) = &data.community_name {
|
.listing_type(listing_type)
|
||||||
resolve_actor_identifier::<ApubCommunity, Community>(name, context, &local_user_view, false)
|
.search_term(Some(q))
|
||||||
.await
|
.community_id(community_id)
|
||||||
.ok()
|
.creator_id(creator_id)
|
||||||
.map(|c| c.id)
|
.local_user(local_user_.as_ref())
|
||||||
} else {
|
.page(page)
|
||||||
data.community_id
|
.limit(limit)
|
||||||
};
|
.build()
|
||||||
let creator_id = data.creator_id;
|
.list()
|
||||||
let local_user = local_user_view.map(|l| l.local_user);
|
.await?;
|
||||||
match search_type {
|
|
||||||
SearchType::Posts => {
|
let q = data.q.clone();
|
||||||
posts = PostQuery::builder()
|
|
||||||
.conn(context.conn().await?)
|
communities = if community_or_creator_included {
|
||||||
.sort(sort)
|
vec![]
|
||||||
.listing_type(listing_type)
|
} else {
|
||||||
.community_id(community_id)
|
CommunityQuery::builder()
|
||||||
.creator_id(creator_id)
|
|
||||||
.local_user(local_user.as_ref())
|
|
||||||
.search_term(Some(q))
|
|
||||||
.is_mod_or_admin(is_admin)
|
|
||||||
.page(page)
|
|
||||||
.limit(limit)
|
|
||||||
.build()
|
|
||||||
.list()
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
SearchType::Comments => {
|
|
||||||
comments = CommentQuery::builder()
|
|
||||||
.conn(context.conn().await?)
|
|
||||||
.sort(sort.map(post_to_comment_sort_type))
|
|
||||||
.listing_type(listing_type)
|
|
||||||
.search_term(Some(q))
|
|
||||||
.community_id(community_id)
|
|
||||||
.creator_id(creator_id)
|
|
||||||
.local_user(local_user.as_ref())
|
|
||||||
.page(page)
|
|
||||||
.limit(limit)
|
|
||||||
.build()
|
|
||||||
.list()
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
SearchType::Communities => {
|
|
||||||
communities = CommunityQuery::builder()
|
|
||||||
.conn(context.conn().await?)
|
.conn(context.conn().await?)
|
||||||
.sort(sort)
|
.sort(sort)
|
||||||
.listing_type(listing_type)
|
.listing_type(listing_type)
|
||||||
|
@ -100,10 +161,15 @@ impl PerformApub for Search {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.build()
|
.build()
|
||||||
.list()
|
.list()
|
||||||
.await?;
|
.await?
|
||||||
}
|
};
|
||||||
SearchType::Users => {
|
|
||||||
users = PersonQuery::builder()
|
let q = data.q.clone();
|
||||||
|
|
||||||
|
users = if community_or_creator_included {
|
||||||
|
vec![]
|
||||||
|
} else {
|
||||||
|
PersonQuery::builder()
|
||||||
.conn(context.conn().await?)
|
.conn(context.conn().await?)
|
||||||
.sort(sort)
|
.sort(sort)
|
||||||
.search_term(Some(q))
|
.search_term(Some(q))
|
||||||
|
@ -111,105 +177,32 @@ impl PerformApub for Search {
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.build()
|
.build()
|
||||||
.list()
|
.list()
|
||||||
.await?;
|
.await?
|
||||||
}
|
};
|
||||||
SearchType::All => {
|
}
|
||||||
// If the community or creator is included, dont search communities or users
|
SearchType::Url => {
|
||||||
let community_or_creator_included =
|
posts = PostQuery::builder()
|
||||||
data.community_id.is_some() || data.community_name.is_some() || data.creator_id.is_some();
|
.conn(context.conn().await?)
|
||||||
|
.sort(sort)
|
||||||
|
.listing_type(listing_type)
|
||||||
|
.community_id(community_id)
|
||||||
|
.creator_id(creator_id)
|
||||||
|
.url_search(Some(q))
|
||||||
|
.is_mod_or_admin(is_admin)
|
||||||
|
.page(page)
|
||||||
|
.limit(limit)
|
||||||
|
.build()
|
||||||
|
.list()
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let local_user_ = local_user.clone();
|
// Return the jwt
|
||||||
posts = PostQuery::builder()
|
Ok(Json(SearchResponse {
|
||||||
.conn(context.conn().await?)
|
type_: search_type,
|
||||||
.sort(sort)
|
comments,
|
||||||
.listing_type(listing_type)
|
posts,
|
||||||
.community_id(community_id)
|
communities,
|
||||||
.creator_id(creator_id)
|
users,
|
||||||
.local_user(local_user_.as_ref())
|
}))
|
||||||
.search_term(Some(q))
|
|
||||||
.is_mod_or_admin(is_admin)
|
|
||||||
.page(page)
|
|
||||||
.limit(limit)
|
|
||||||
.build()
|
|
||||||
.list()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let q = data.q.clone();
|
|
||||||
|
|
||||||
let local_user_ = local_user.clone();
|
|
||||||
comments = CommentQuery::builder()
|
|
||||||
.conn(context.conn().await?)
|
|
||||||
.sort(sort.map(post_to_comment_sort_type))
|
|
||||||
.listing_type(listing_type)
|
|
||||||
.search_term(Some(q))
|
|
||||||
.community_id(community_id)
|
|
||||||
.creator_id(creator_id)
|
|
||||||
.local_user(local_user_.as_ref())
|
|
||||||
.page(page)
|
|
||||||
.limit(limit)
|
|
||||||
.build()
|
|
||||||
.list()
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let q = data.q.clone();
|
|
||||||
|
|
||||||
communities = if community_or_creator_included {
|
|
||||||
vec![]
|
|
||||||
} else {
|
|
||||||
CommunityQuery::builder()
|
|
||||||
.conn(context.conn().await?)
|
|
||||||
.sort(sort)
|
|
||||||
.listing_type(listing_type)
|
|
||||||
.search_term(Some(q))
|
|
||||||
.local_user(local_user.as_ref())
|
|
||||||
.is_mod_or_admin(is_admin)
|
|
||||||
.page(page)
|
|
||||||
.limit(limit)
|
|
||||||
.build()
|
|
||||||
.list()
|
|
||||||
.await?
|
|
||||||
};
|
|
||||||
|
|
||||||
let q = data.q.clone();
|
|
||||||
|
|
||||||
users = if community_or_creator_included {
|
|
||||||
vec![]
|
|
||||||
} else {
|
|
||||||
PersonQuery::builder()
|
|
||||||
.conn(context.conn().await?)
|
|
||||||
.sort(sort)
|
|
||||||
.search_term(Some(q))
|
|
||||||
.page(page)
|
|
||||||
.limit(limit)
|
|
||||||
.build()
|
|
||||||
.list()
|
|
||||||
.await?
|
|
||||||
};
|
|
||||||
}
|
|
||||||
SearchType::Url => {
|
|
||||||
posts = PostQuery::builder()
|
|
||||||
.conn(context.conn().await?)
|
|
||||||
.sort(sort)
|
|
||||||
.listing_type(listing_type)
|
|
||||||
.community_id(community_id)
|
|
||||||
.creator_id(creator_id)
|
|
||||||
.url_search(Some(q))
|
|
||||||
.is_mod_or_admin(is_admin)
|
|
||||||
.page(page)
|
|
||||||
.limit(limit)
|
|
||||||
.build()
|
|
||||||
.list()
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return the jwt
|
|
||||||
Ok(SearchResponse {
|
|
||||||
type_: search_type,
|
|
||||||
comments,
|
|
||||||
posts,
|
|
||||||
communities,
|
|
||||||
users,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,6 +406,7 @@ diesel::table! {
|
||||||
accepted_application -> Bool,
|
accepted_application -> Bool,
|
||||||
totp_2fa_secret -> Nullable<Text>,
|
totp_2fa_secret -> Nullable<Text>,
|
||||||
totp_2fa_url -> Nullable<Text>,
|
totp_2fa_url -> Nullable<Text>,
|
||||||
|
open_links_in_new_tab -> Bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use crate::newtypes::{CommunityId, DbUrl, InstanceId, PersonId};
|
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
use crate::schema::{community, community_follower, community_moderator, community_person_ban};
|
use crate::schema::{community, community_follower, community_moderator, community_person_ban};
|
||||||
|
use crate::{
|
||||||
|
newtypes::{CommunityId, DbUrl, InstanceId, PersonId},
|
||||||
|
source::placeholder_apub_url,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
@ -42,9 +45,9 @@ pub struct Community {
|
||||||
pub icon: Option<DbUrl>,
|
pub icon: Option<DbUrl>,
|
||||||
/// A URL for a banner.
|
/// A URL for a banner.
|
||||||
pub banner: Option<DbUrl>,
|
pub banner: Option<DbUrl>,
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip, default = "placeholder_apub_url")]
|
||||||
pub followers_url: DbUrl,
|
pub followers_url: DbUrl,
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip, default = "placeholder_apub_url")]
|
||||||
pub inbox_url: DbUrl,
|
pub inbox_url: DbUrl,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub shared_inbox_url: Option<DbUrl>,
|
pub shared_inbox_url: Option<DbUrl>,
|
||||||
|
|
|
@ -51,6 +51,8 @@ pub struct LocalUser {
|
||||||
pub totp_2fa_secret: Option<String>,
|
pub totp_2fa_secret: Option<String>,
|
||||||
/// A URL to add their 2-factor auth.
|
/// A URL to add their 2-factor auth.
|
||||||
pub totp_2fa_url: Option<String>,
|
pub totp_2fa_url: Option<String>,
|
||||||
|
/// Open links in a new tab.
|
||||||
|
pub open_links_in_new_tab: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, TypedBuilder)]
|
#[derive(Clone, TypedBuilder)]
|
||||||
|
@ -78,6 +80,7 @@ pub struct LocalUserInsertForm {
|
||||||
pub accepted_application: Option<bool>,
|
pub accepted_application: Option<bool>,
|
||||||
pub totp_2fa_secret: Option<Option<String>>,
|
pub totp_2fa_secret: Option<Option<String>>,
|
||||||
pub totp_2fa_url: Option<Option<String>>,
|
pub totp_2fa_url: Option<Option<String>>,
|
||||||
|
pub open_links_in_new_tab: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, TypedBuilder)]
|
#[derive(Clone, TypedBuilder)]
|
||||||
|
@ -102,4 +105,5 @@ pub struct LocalUserUpdateForm {
|
||||||
pub accepted_application: Option<bool>,
|
pub accepted_application: Option<bool>,
|
||||||
pub totp_2fa_secret: Option<Option<String>>,
|
pub totp_2fa_secret: Option<Option<String>>,
|
||||||
pub totp_2fa_url: Option<Option<String>>,
|
pub totp_2fa_url: Option<Option<String>>,
|
||||||
|
pub open_links_in_new_tab: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
use crate::newtypes::DbUrl;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod activity;
|
pub mod activity;
|
||||||
pub mod actor_language;
|
pub mod actor_language;
|
||||||
|
@ -30,3 +33,13 @@ pub mod registration_application;
|
||||||
pub mod secret;
|
pub mod secret;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
pub mod tagline;
|
pub mod tagline;
|
||||||
|
|
||||||
|
/// Default value for columns like [community::Community.inbox_url] which are marked as serde(skip).
|
||||||
|
///
|
||||||
|
/// This is necessary so they can be successfully deserialized from API responses, even though the
|
||||||
|
/// value is not sent by Lemmy. Necessary for crates which rely on Rust API such as lemmy-stats-crawler.
|
||||||
|
fn placeholder_apub_url() -> DbUrl {
|
||||||
|
DbUrl(Box::new(
|
||||||
|
Url::parse("http://example.com").expect("parse placeholer url"),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use crate::newtypes::{DbUrl, InstanceId, PersonId};
|
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
use crate::schema::{person, person_follower};
|
use crate::schema::{person, person_follower};
|
||||||
|
use crate::{
|
||||||
|
newtypes::{DbUrl, InstanceId, PersonId},
|
||||||
|
source::placeholder_apub_url,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
|
@ -40,7 +43,7 @@ pub struct Person {
|
||||||
pub banner: Option<DbUrl>,
|
pub banner: Option<DbUrl>,
|
||||||
/// Whether the person is deleted.
|
/// Whether the person is deleted.
|
||||||
pub deleted: bool,
|
pub deleted: bool,
|
||||||
#[serde(skip_serializing)]
|
#[serde(skip, default = "placeholder_apub_url")]
|
||||||
pub inbox_url: DbUrl,
|
pub inbox_url: DbUrl,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub shared_inbox_url: Option<DbUrl>,
|
pub shared_inbox_url: Option<DbUrl>,
|
||||||
|
|
|
@ -295,6 +295,7 @@ mod tests {
|
||||||
totp_2fa_secret: inserted_sara_local_user.totp_2fa_secret,
|
totp_2fa_secret: inserted_sara_local_user.totp_2fa_secret,
|
||||||
totp_2fa_url: inserted_sara_local_user.totp_2fa_url,
|
totp_2fa_url: inserted_sara_local_user.totp_2fa_url,
|
||||||
password_encrypted: inserted_sara_local_user.password_encrypted,
|
password_encrypted: inserted_sara_local_user.password_encrypted,
|
||||||
|
open_links_in_new_tab: inserted_sara_local_user.open_links_in_new_tab,
|
||||||
},
|
},
|
||||||
creator: Person {
|
creator: Person {
|
||||||
id: inserted_sara_person.id,
|
id: inserted_sara_person.id,
|
||||||
|
|
|
@ -195,7 +195,9 @@ impl RateLimitStorage {
|
||||||
/// Remove buckets older than the given duration
|
/// Remove buckets older than the given duration
|
||||||
pub(super) fn remove_older_than(&mut self, duration: Duration, now: InstantSecs) {
|
pub(super) fn remove_older_than(&mut self, duration: Duration, now: InstantSecs) {
|
||||||
// Only retain buckets that were last used after `instant`
|
// Only retain buckets that were last used after `instant`
|
||||||
let Some(instant) = now.to_instant().checked_sub(duration) else { return };
|
let Some(instant) = now.to_instant().checked_sub(duration) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let is_recently_used = |group: &RateLimitedGroup<_>| {
|
let is_recently_used = |group: &RateLimitedGroup<_>| {
|
||||||
group
|
group
|
||||||
|
|
|
@ -8,7 +8,7 @@ use url::Url;
|
||||||
static VALID_ACTOR_NAME_REGEX: Lazy<Regex> =
|
static VALID_ACTOR_NAME_REGEX: Lazy<Regex> =
|
||||||
Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex"));
|
Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex"));
|
||||||
static VALID_POST_TITLE_REGEX: Lazy<Regex> =
|
static VALID_POST_TITLE_REGEX: Lazy<Regex> =
|
||||||
Lazy::new(|| Regex::new(r".*\S{3,}.*").expect("compile regex"));
|
Lazy::new(|| Regex::new(r".*\S{3,200}.*").expect("compile regex"));
|
||||||
static VALID_MATRIX_ID_REGEX: Lazy<Regex> = Lazy::new(|| {
|
static VALID_MATRIX_ID_REGEX: Lazy<Regex> = Lazy::new(|| {
|
||||||
Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex")
|
Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex")
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,7 +4,7 @@ x-logging: &default-logging
|
||||||
driver: "json-file"
|
driver: "json-file"
|
||||||
options:
|
options:
|
||||||
max-size: "50m"
|
max-size: "50m"
|
||||||
max-file: 4
|
max-file: "4"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
proxy:
|
proxy:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
alter table local_user drop column open_links_in_new_tab;
|
|
@ -0,0 +1 @@
|
||||||
|
alter table local_user add column open_links_in_new_tab boolean default false not null;
|
|
@ -9,7 +9,6 @@ use lemmy_api_common::{
|
||||||
DistinguishComment,
|
DistinguishComment,
|
||||||
EditComment,
|
EditComment,
|
||||||
GetComment,
|
GetComment,
|
||||||
GetComments,
|
|
||||||
ListCommentReports,
|
ListCommentReports,
|
||||||
RemoveComment,
|
RemoveComment,
|
||||||
ResolveCommentReport,
|
ResolveCommentReport,
|
||||||
|
@ -23,7 +22,6 @@ use lemmy_api_common::{
|
||||||
DeleteCommunity,
|
DeleteCommunity,
|
||||||
EditCommunity,
|
EditCommunity,
|
||||||
FollowCommunity,
|
FollowCommunity,
|
||||||
GetCommunity,
|
|
||||||
HideCommunity,
|
HideCommunity,
|
||||||
ListCommunities,
|
ListCommunities,
|
||||||
RemoveCommunity,
|
RemoveCommunity,
|
||||||
|
@ -39,7 +37,6 @@ use lemmy_api_common::{
|
||||||
DeleteAccount,
|
DeleteAccount,
|
||||||
GetBannedPersons,
|
GetBannedPersons,
|
||||||
GetCaptcha,
|
GetCaptcha,
|
||||||
GetPersonDetails,
|
|
||||||
GetPersonMentions,
|
GetPersonMentions,
|
||||||
GetReplies,
|
GetReplies,
|
||||||
GetReportCount,
|
GetReportCount,
|
||||||
|
@ -62,7 +59,6 @@ use lemmy_api_common::{
|
||||||
EditPost,
|
EditPost,
|
||||||
FeaturePost,
|
FeaturePost,
|
||||||
GetPost,
|
GetPost,
|
||||||
GetPosts,
|
|
||||||
GetSiteMetadata,
|
GetSiteMetadata,
|
||||||
ListPostReports,
|
ListPostReports,
|
||||||
LockPost,
|
LockPost,
|
||||||
|
@ -95,12 +91,20 @@ use lemmy_api_common::{
|
||||||
PurgeCommunity,
|
PurgeCommunity,
|
||||||
PurgePerson,
|
PurgePerson,
|
||||||
PurgePost,
|
PurgePost,
|
||||||
ResolveObject,
|
|
||||||
Search,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use lemmy_api_crud::PerformCrud;
|
use lemmy_api_crud::PerformCrud;
|
||||||
use lemmy_apub::{api::PerformApub, SendActivity};
|
use lemmy_apub::{
|
||||||
|
api::{
|
||||||
|
list_comments::list_comments,
|
||||||
|
list_posts::list_posts,
|
||||||
|
read_community::read_community,
|
||||||
|
read_person::read_person,
|
||||||
|
resolve_object::resolve_object,
|
||||||
|
search::search,
|
||||||
|
},
|
||||||
|
SendActivity,
|
||||||
|
};
|
||||||
use lemmy_utils::rate_limit::RateLimitCell;
|
use lemmy_utils::rate_limit::RateLimitCell;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
@ -124,12 +128,12 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
.service(
|
.service(
|
||||||
web::resource("/search")
|
web::resource("/search")
|
||||||
.wrap(rate_limit.search())
|
.wrap(rate_limit.search())
|
||||||
.route(web::get().to(route_get_apub::<Search>)),
|
.route(web::get().to(search)),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("/resolve_object")
|
web::resource("/resolve_object")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route(web::get().to(route_get_apub::<ResolveObject>)),
|
.route(web::get().to(resolve_object)),
|
||||||
)
|
)
|
||||||
// Community
|
// Community
|
||||||
.service(
|
.service(
|
||||||
|
@ -141,7 +145,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
.service(
|
.service(
|
||||||
web::scope("/community")
|
web::scope("/community")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("", web::get().to(route_get_apub::<GetCommunity>))
|
.route("", web::get().to(read_community))
|
||||||
.route("", web::put().to(route_post_crud::<EditCommunity>))
|
.route("", web::put().to(route_post_crud::<EditCommunity>))
|
||||||
.route("/hide", web::put().to(route_post::<HideCommunity>))
|
.route("/hide", web::put().to(route_post::<HideCommunity>))
|
||||||
.route("/list", web::get().to(route_get_crud::<ListCommunities>))
|
.route("/list", web::get().to(route_get_crud::<ListCommunities>))
|
||||||
|
@ -186,7 +190,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
)
|
)
|
||||||
.route("/lock", web::post().to(route_post::<LockPost>))
|
.route("/lock", web::post().to(route_post::<LockPost>))
|
||||||
.route("/feature", web::post().to(route_post::<FeaturePost>))
|
.route("/feature", web::post().to(route_post::<FeaturePost>))
|
||||||
.route("/list", web::get().to(route_get_apub::<GetPosts>))
|
.route("/list", web::get().to(list_posts))
|
||||||
.route("/like", web::post().to(route_post::<CreatePostLike>))
|
.route("/like", web::post().to(route_post::<CreatePostLike>))
|
||||||
.route("/save", web::put().to(route_post::<SavePost>))
|
.route("/save", web::put().to(route_post::<SavePost>))
|
||||||
.route("/report", web::post().to(route_post::<CreatePostReport>))
|
.route("/report", web::post().to(route_post::<CreatePostReport>))
|
||||||
|
@ -225,7 +229,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
)
|
)
|
||||||
.route("/like", web::post().to(route_post::<CreateCommentLike>))
|
.route("/like", web::post().to(route_post::<CreateCommentLike>))
|
||||||
.route("/save", web::put().to(route_post::<SaveComment>))
|
.route("/save", web::put().to(route_post::<SaveComment>))
|
||||||
.route("/list", web::get().to(route_get_apub::<GetComments>))
|
.route("/list", web::get().to(list_comments))
|
||||||
.route("/report", web::post().to(route_post::<CreateCommentReport>))
|
.route("/report", web::post().to(route_post::<CreateCommentReport>))
|
||||||
.route(
|
.route(
|
||||||
"/report/resolve",
|
"/report/resolve",
|
||||||
|
@ -283,7 +287,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
|
||||||
.service(
|
.service(
|
||||||
web::scope("/user")
|
web::scope("/user")
|
||||||
.wrap(rate_limit.message())
|
.wrap(rate_limit.message())
|
||||||
.route("", web::get().to(route_get_apub::<GetPersonDetails>))
|
.route("", web::get().to(read_person))
|
||||||
.route("/mention", web::get().to(route_get::<GetPersonMentions>))
|
.route("/mention", web::get().to(route_get::<GetPersonMentions>))
|
||||||
.route(
|
.route(
|
||||||
"/mention/mark_as_read",
|
"/mention/mark_as_read",
|
||||||
|
@ -398,23 +402,6 @@ where
|
||||||
perform::<Data>(data.0, context, apub_data).await
|
perform::<Data>(data.0, context, apub_data).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn route_get_apub<'a, Data>(
|
|
||||||
data: web::Query<Data>,
|
|
||||||
context: activitypub_federation::config::Data<LemmyContext>,
|
|
||||||
) -> Result<HttpResponse, Error>
|
|
||||||
where
|
|
||||||
Data: PerformApub
|
|
||||||
+ SendActivity<Response = <Data as PerformApub>::Response>
|
|
||||||
+ Clone
|
|
||||||
+ Deserialize<'a>
|
|
||||||
+ Send
|
|
||||||
+ 'static,
|
|
||||||
{
|
|
||||||
let res = data.perform(&context).await?;
|
|
||||||
SendActivity::send_activity(&data.0, &res, &context).await?;
|
|
||||||
Ok(HttpResponse::Ok().json(res))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn route_post<'a, Data>(
|
async fn route_post<'a, Data>(
|
||||||
data: web::Json<Data>,
|
data: web::Json<Data>,
|
||||||
context: web::Data<LemmyContext>,
|
context: web::Data<LemmyContext>,
|
||||||
|
|
Loading…
Reference in New Issue