DistinguishComment,
EditComment,
GetComment,
- GetComments,
ListCommentReports,
RemoveComment,
ResolveCommentReport,
DeleteCommunity,
EditCommunity,
FollowCommunity,
- GetCommunity,
HideCommunity,
ListCommunities,
RemoveCommunity,
DeleteAccount,
GetBannedPersons,
GetCaptcha,
- GetPersonDetails,
GetPersonMentions,
GetReplies,
GetReportCount,
VerifyEmail,
},
post::{
- CreatePost,
CreatePostLike,
CreatePostReport,
DeletePost,
EditPost,
FeaturePost,
GetPost,
- GetPosts,
GetSiteMetadata,
ListPostReports,
LockPost,
PurgeCommunity,
PurgePerson,
PurgePost,
- ResolveObject,
- Search,
},
- websocket::structs::{CommunityJoin, ModJoin, PostJoin, UserJoin},
};
-use lemmy_api_crud::PerformCrud;
-use lemmy_apub::{api::PerformApub, SendActivity};
-use lemmy_utils::rate_limit::RateLimitCell;
+use lemmy_api_crud::{post::create::create_post, PerformCrud};
+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, spawn_try_task, SYNCHRONOUS_FEDERATION};
use serde::Deserialize;
pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimitCell) {
.service(
web::resource("/search")
.wrap(rate_limit.search())
- .route(web::get().to(route_get_apub::<Search>)),
+ .route(web::get().to(search)),
)
.service(
web::resource("/resolve_object")
.wrap(rate_limit.message())
- .route(web::get().to(route_get_apub::<ResolveObject>)),
+ .route(web::get().to(resolve_object)),
)
// Community
.service(
.service(
web::scope("/community")
.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("/hide", web::put().to(route_post::<HideCommunity>))
.route("/list", web::get().to(route_get_crud::<ListCommunities>))
)
.route("/transfer", web::post().to(route_post::<TransferCommunity>))
.route("/ban_user", web::post().to(route_post::<BanFromCommunity>))
- .route("/mod", web::post().to(route_post::<AddModToCommunity>))
- .route("/join", web::post().to(route_post::<CommunityJoin>))
- .route("/mod/join", web::post().to(route_post::<ModJoin>)),
+ .route("/mod", web::post().to(route_post::<AddModToCommunity>)),
)
.service(
web::scope("/federated_instances")
web::resource("/post")
.guard(guard::Post())
.wrap(rate_limit.post())
- .route(web::post().to(route_post_crud::<CreatePost>)),
+ .route(web::post().to(create_post)),
)
.service(
web::scope("/post")
)
.route("/lock", web::post().to(route_post::<LockPost>))
.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("/save", web::put().to(route_post::<SavePost>))
- .route("/join", web::post().to(route_post::<PostJoin>))
.route("/report", web::post().to(route_post::<CreatePostReport>))
.route(
"/report/resolve",
)
.route("/like", web::post().to(route_post::<CreateCommentLike>))
.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/resolve",
.service(
web::scope("/user")
.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/mark_as_read",
web::post().to(route_post::<MarkPersonMentionAsRead>),
)
.route("/replies", web::get().to(route_get::<GetReplies>))
- .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>))
.route("/banned", web::get().to(route_get::<GetBannedPersons>))
.route(
"/registration_application/approve",
web::put().to(route_post::<ApproveRegistrationApplication>),
+ )
+ .service(
+ web::scope("/purge")
+ .route("/person", web::post().to(route_post::<PurgePerson>))
+ .route("/community", web::post().to(route_post::<PurgeCommunity>))
+ .route("/post", web::post().to(route_post::<PurgePost>))
+ .route("/comment", web::post().to(route_post::<PurgeComment>)),
),
)
- .service(
- web::scope("/admin/purge")
- .wrap(rate_limit.message())
- .route("/person", web::post().to(route_post::<PurgePerson>))
- .route("/community", web::post().to(route_post::<PurgeCommunity>))
- .route("/post", web::post().to(route_post::<PurgePost>))
- .route("/comment", web::post().to(route_post::<PurgeComment>)),
- )
.service(
web::scope("/custom_emoji")
.wrap(rate_limit.message())
+ Send
+ 'static,
{
- let res = data.perform(&context, None).await?;
- SendActivity::send_activity(&data, &res, &apub_data).await?;
- Ok(HttpResponse::Ok().json(res))
+ let res = data.perform(&context).await?;
+ let res_clone = res.clone();
+ let fed_task = async move { SendActivity::send_activity(&data, &res_clone, &apub_data).await };
+ if *SYNCHRONOUS_FEDERATION {
+ fed_task.await?;
+ } else {
+ spawn_try_task(fed_task);
+ }
+ Ok(HttpResponse::Ok().json(&res))
}
async fn route_get<'a, Data>(
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, None).await?;
- SendActivity::send_activity(&data.0, &res, &context).await?;
- Ok(HttpResponse::Ok().json(res))
-}
-
async fn route_post<'a, Data>(
data: web::Json<Data>,
context: web::Data<LemmyContext>,
+ Send
+ 'static,
{
- let res = data.perform(&context, None).await?;
- SendActivity::send_activity(&data, &res, &apub_data).await?;
- Ok(HttpResponse::Ok().json(res))
+ let res = data.perform(&context).await?;
+ let res_clone = res.clone();
+ let fed_task = async move { SendActivity::send_activity(&data, &res_clone, &apub_data).await };
+ if *SYNCHRONOUS_FEDERATION {
+ fed_task.await?;
+ } else {
+ spawn_try_task(fed_task);
+ }
+ Ok(HttpResponse::Ok().json(&res))
}
async fn route_get_crud<'a, Data>(