get_user_from_jwt_opt,
is_mod_or_admin,
APIError,
- Oper,
Perform,
},
apub::{ApubLikeableType, ApubObjectType},
DbPool,
LemmyError,
};
+use actix_web::client::Client;
use lemmy_db::{
comment::*,
comment_view::*,
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<CreateComment> {
+impl Perform for CreateComment {
type Response = CommentResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<CommentResponse, LemmyError> {
- let data: &CreateComment = &self.data;
+ let data: &CreateComment = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let content_slurs_removed = remove_slurs(&data.content.to_owned());
Err(_e) => return Err(APIError::err("couldnt_create_comment").into()),
};
- updated_comment
- .send_create(&user, &self.client, pool)
- .await?;
+ updated_comment.send_create(&user, &client, pool).await?;
// Scan the comment for user mentions, add those rows
let mentions = scrape_text_for_mentions(&comment_form.content);
return Err(APIError::err("couldnt_like_comment").into());
}
- updated_comment.send_like(&user, &self.client, pool).await?;
+ updated_comment.send_like(&user, &client, pool).await?;
let user_id = user.id;
let comment_view = blocking(pool, move |conn| {
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<EditComment> {
+impl Perform for EditComment {
type Response = CommentResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<CommentResponse, LemmyError> {
- let data: &EditComment = &self.data;
+ let data: &EditComment = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let edit_id = data.edit_id;
};
// Send the apub update
- updated_comment
- .send_update(&user, &self.client, pool)
- .await?;
+ updated_comment.send_update(&user, &client, pool).await?;
// Do the mentions / recipients
let post_id = orig_comment.post_id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<DeleteComment> {
+impl Perform for DeleteComment {
type Response = CommentResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<CommentResponse, LemmyError> {
- let data: &DeleteComment = &self.data;
+ let data: &DeleteComment = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let edit_id = data.edit_id;
// Send the apub message
if deleted {
- updated_comment
- .send_delete(&user, &self.client, pool)
- .await?;
+ updated_comment.send_delete(&user, &client, pool).await?;
} else {
updated_comment
- .send_undo_delete(&user, &self.client, pool)
+ .send_undo_delete(&user, &client, pool)
.await?;
}
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<RemoveComment> {
+impl Perform for RemoveComment {
type Response = CommentResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<CommentResponse, LemmyError> {
- let data: &RemoveComment = &self.data;
+ let data: &RemoveComment = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let edit_id = data.edit_id;
// Send the apub message
if removed {
- updated_comment
- .send_remove(&user, &self.client, pool)
- .await?;
+ updated_comment.send_remove(&user, &client, pool).await?;
} else {
updated_comment
- .send_undo_remove(&user, &self.client, pool)
+ .send_undo_remove(&user, &client, pool)
.await?;
}
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<MarkCommentAsRead> {
+impl Perform for MarkCommentAsRead {
type Response = CommentResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<CommentResponse, LemmyError> {
- let data: &MarkCommentAsRead = &self.data;
+ let data: &MarkCommentAsRead = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let edit_id = data.edit_id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<SaveComment> {
+impl Perform for SaveComment {
type Response = CommentResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<CommentResponse, LemmyError> {
- let data: &SaveComment = &self.data;
+ let data: &SaveComment = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let comment_saved_form = CommentSavedForm {
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<CreateCommentLike> {
+impl Perform for CreateCommentLike {
type Response = CommentResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<CommentResponse, LemmyError> {
- let data: &CreateCommentLike = &self.data;
+ let data: &CreateCommentLike = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let mut recipient_ids = Vec::new();
}
if like_form.score == 1 {
- comment.send_like(&user, &self.client, pool).await?;
+ comment.send_like(&user, &client, pool).await?;
} else if like_form.score == -1 {
- comment.send_dislike(&user, &self.client, pool).await?;
+ comment.send_dislike(&user, &client, pool).await?;
}
} else {
- comment.send_undo_like(&user, &self.client, pool).await?;
+ comment.send_undo_like(&user, &client, pool).await?;
}
// Have to refetch the comment to get the current state
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetComments> {
+impl Perform for GetComments {
type Response = GetCommentsResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetCommentsResponse, LemmyError> {
- let data: &GetComments = &self.data;
+ let data: &GetComments = &self;
let user = get_user_from_jwt_opt(&data.auth, pool).await?;
let user_id = user.map(|u| u.id);
use super::*;
use crate::{
- api::{is_admin, is_mod_or_admin, APIError, Oper, Perform},
+ api::{is_admin, is_mod_or_admin, APIError, Perform},
apub::ActorType,
blocking,
websocket::{
},
DbPool,
};
+use actix_web::client::Client;
use lemmy_db::{
diesel_option_overwrite,
naive_now,
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetCommunity> {
+impl Perform for GetCommunity {
type Response = GetCommunityResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetCommunityResponse, LemmyError> {
- let data: &GetCommunity = &self.data;
+ let data: &GetCommunity = &self;
let user = get_user_from_jwt_opt(&data.auth, pool).await?;
let user_id = user.map(|u| u.id);
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<CreateCommunity> {
+impl Perform for CreateCommunity {
type Response = CommunityResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<CommunityResponse, LemmyError> {
- let data: &CreateCommunity = &self.data;
+ let data: &CreateCommunity = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
check_slurs(&data.name)?;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<EditCommunity> {
+impl Perform for EditCommunity {
type Response = CommunityResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<CommunityResponse, LemmyError> {
- let data: &EditCommunity = &self.data;
+ let data: &EditCommunity = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
check_slurs(&data.title)?;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<DeleteCommunity> {
+impl Perform for DeleteCommunity {
type Response = CommunityResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<CommunityResponse, LemmyError> {
- let data: &DeleteCommunity = &self.data;
+ let data: &DeleteCommunity = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
// Verify its the creator (only a creator can delete the community)
// Send apub messages
if deleted {
- updated_community
- .send_delete(&user, &self.client, pool)
- .await?;
+ updated_community.send_delete(&user, &client, pool).await?;
} else {
updated_community
- .send_undo_delete(&user, &self.client, pool)
+ .send_undo_delete(&user, &client, pool)
.await?;
}
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<RemoveCommunity> {
+impl Perform for RemoveCommunity {
type Response = CommunityResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<CommunityResponse, LemmyError> {
- let data: &RemoveCommunity = &self.data;
+ let data: &RemoveCommunity = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
// Verify its an admin (only an admin can remove a community)
// Apub messages
if removed {
- updated_community
- .send_remove(&user, &self.client, pool)
- .await?;
+ updated_community.send_remove(&user, &client, pool).await?;
} else {
updated_community
- .send_undo_remove(&user, &self.client, pool)
+ .send_undo_remove(&user, &client, pool)
.await?;
}
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<ListCommunities> {
+impl Perform for ListCommunities {
type Response = ListCommunitiesResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<ListCommunitiesResponse, LemmyError> {
- let data: &ListCommunities = &self.data;
+ let data: &ListCommunities = &self;
let user = get_user_from_jwt_opt(&data.auth, pool).await?;
let user_id = match &user {
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<FollowCommunity> {
+impl Perform for FollowCommunity {
type Response = CommunityResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<CommunityResponse, LemmyError> {
- let data: &FollowCommunity = &self.data;
+ let data: &FollowCommunity = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let community_id = data.community_id;
// Dont actually add to the community followers here, because you need
// to wait for the accept
user
- .send_follow(&community.actor_id()?, &self.client, pool)
+ .send_follow(&community.actor_id()?, &client, pool)
.await?;
} else {
user
- .send_unfollow(&community.actor_id()?, &self.client, pool)
+ .send_unfollow(&community.actor_id()?, &client, pool)
.await?;
let unfollow = move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
if blocking(pool, unfollow).await?.is_err() {
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetFollowedCommunities> {
+impl Perform for GetFollowedCommunities {
type Response = GetFollowedCommunitiesResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetFollowedCommunitiesResponse, LemmyError> {
- let data: &GetFollowedCommunities = &self.data;
+ let data: &GetFollowedCommunities = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let user_id = user.id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<BanFromCommunity> {
+impl Perform for BanFromCommunity {
type Response = BanFromCommunityResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<BanFromCommunityResponse, LemmyError> {
- let data: &BanFromCommunity = &self.data;
+ let data: &BanFromCommunity = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let community_id = data.community_id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<AddModToCommunity> {
+impl Perform for AddModToCommunity {
type Response = AddModToCommunityResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<AddModToCommunityResponse, LemmyError> {
- let data: &AddModToCommunity = &self.data;
+ let data: &AddModToCommunity = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let community_moderator_form = CommunityModeratorForm {
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<TransferCommunity> {
+impl Perform for TransferCommunity {
type Response = GetCommunityResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetCommunityResponse, LemmyError> {
- let data: &TransferCommunity = &self.data;
+ let data: &TransferCommunity = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let community_id = data.community_id;
}
}
-pub struct Oper<T> {
- data: T,
- client: Client,
-}
-
-impl<Data> Oper<Data> {
- pub fn new(data: Data, client: Client) -> Oper<Data> {
- Oper { data, client }
- }
-}
-
#[async_trait::async_trait(?Send)]
pub trait Perform {
type Response: serde::ser::Serialize + Send;
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<Self::Response, LemmyError>;
}
get_user_from_jwt_opt,
is_mod_or_admin,
APIError,
- Oper,
Perform,
},
apub::{ApubLikeableType, ApubObjectType},
DbPool,
LemmyError,
};
+use actix_web::client::Client;
use lemmy_db::{
comment_view::*,
community_view::*,
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<CreatePost> {
+impl Perform for CreatePost {
type Response = PostResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<PostResponse, LemmyError> {
- let data: &CreatePost = &self.data;
+ let data: &CreatePost = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
check_slurs(&data.name)?;
// Fetch Iframely and pictrs cached image
let (iframely_title, iframely_description, iframely_html, pictrs_thumbnail) =
- fetch_iframely_and_pictrs_data(&self.client, data.url.to_owned()).await;
+ fetch_iframely_and_pictrs_data(&client, data.url.to_owned()).await;
let post_form = PostForm {
name: data.name.trim().to_owned(),
Err(_e) => return Err(APIError::err("couldnt_create_post").into()),
};
- updated_post.send_create(&user, &self.client, pool).await?;
+ updated_post.send_create(&user, &client, pool).await?;
// They like their own post by default
let like_form = PostLikeForm {
return Err(APIError::err("couldnt_like_post").into());
}
- updated_post.send_like(&user, &self.client, pool).await?;
+ updated_post.send_like(&user, &client, pool).await?;
// Refetch the view
let inserted_post_id = inserted_post.id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetPost> {
+impl Perform for GetPost {
type Response = GetPostResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetPostResponse, LemmyError> {
- let data: &GetPost = &self.data;
+ let data: &GetPost = &self;
let user = get_user_from_jwt_opt(&data.auth, pool).await?;
let user_id = user.map(|u| u.id);
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetPosts> {
+impl Perform for GetPosts {
type Response = GetPostsResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetPostsResponse, LemmyError> {
- let data: &GetPosts = &self.data;
+ let data: &GetPosts = &self;
let user = get_user_from_jwt_opt(&data.auth, pool).await?;
let user_id = match &user {
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<CreatePostLike> {
+impl Perform for CreatePostLike {
type Response = PostResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<PostResponse, LemmyError> {
- let data: &CreatePostLike = &self.data;
+ let data: &CreatePostLike = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
// Don't do a downvote if site has downvotes disabled
}
if like_form.score == 1 {
- post.send_like(&user, &self.client, pool).await?;
+ post.send_like(&user, &client, pool).await?;
} else if like_form.score == -1 {
- post.send_dislike(&user, &self.client, pool).await?;
+ post.send_dislike(&user, &client, pool).await?;
}
} else {
- post.send_undo_like(&user, &self.client, pool).await?;
+ post.send_undo_like(&user, &client, pool).await?;
}
let post_id = data.post_id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<EditPost> {
+impl Perform for EditPost {
type Response = PostResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<PostResponse, LemmyError> {
- let data: &EditPost = &self.data;
+ let data: &EditPost = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
check_slurs(&data.name)?;
// Fetch Iframely and Pictrs cached image
let (iframely_title, iframely_description, iframely_html, pictrs_thumbnail) =
- fetch_iframely_and_pictrs_data(&self.client, data.url.to_owned()).await;
+ fetch_iframely_and_pictrs_data(&client, data.url.to_owned()).await;
let post_form = PostForm {
name: data.name.trim().to_owned(),
};
// Send apub update
- updated_post.send_update(&user, &self.client, pool).await?;
+ updated_post.send_update(&user, &client, pool).await?;
let edit_id = data.edit_id;
let post_view = blocking(pool, move |conn| {
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<DeletePost> {
+impl Perform for DeletePost {
type Response = PostResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<PostResponse, LemmyError> {
- let data: &DeletePost = &self.data;
+ let data: &DeletePost = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let edit_id = data.edit_id;
// apub updates
if deleted {
- updated_post.send_delete(&user, &self.client, pool).await?;
+ updated_post.send_delete(&user, &client, pool).await?;
} else {
- updated_post
- .send_undo_delete(&user, &self.client, pool)
- .await?;
+ updated_post.send_undo_delete(&user, &client, pool).await?;
}
// Refetch the post
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<RemovePost> {
+impl Perform for RemovePost {
type Response = PostResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<PostResponse, LemmyError> {
- let data: &RemovePost = &self.data;
+ let data: &RemovePost = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let edit_id = data.edit_id;
// apub updates
if removed {
- updated_post.send_remove(&user, &self.client, pool).await?;
+ updated_post.send_remove(&user, &client, pool).await?;
} else {
- updated_post
- .send_undo_remove(&user, &self.client, pool)
- .await?;
+ updated_post.send_undo_remove(&user, &client, pool).await?;
}
// Refetch the post
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<LockPost> {
+impl Perform for LockPost {
type Response = PostResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<PostResponse, LemmyError> {
- let data: &LockPost = &self.data;
+ let data: &LockPost = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let edit_id = data.edit_id;
blocking(pool, move |conn| ModLockPost::create(conn, &form)).await??;
// apub updates
- updated_post.send_update(&user, &self.client, pool).await?;
+ updated_post.send_update(&user, &client, pool).await?;
// Refetch the post
let edit_id = data.edit_id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<StickyPost> {
+impl Perform for StickyPost {
type Response = PostResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<PostResponse, LemmyError> {
- let data: &StickyPost = &self.data;
+ let data: &StickyPost = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let edit_id = data.edit_id;
// Apub updates
// TODO stickied should pry work like locked for ease of use
- updated_post.send_update(&user, &self.client, pool).await?;
+ updated_post.send_update(&user, &client, pool).await?;
// Refetch the post
let edit_id = data.edit_id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<SavePost> {
+impl Perform for SavePost {
type Response = PostResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<PostResponse, LemmyError> {
- let data: &SavePost = &self.data;
+ let data: &SavePost = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let post_saved_form = PostSavedForm {
get_user_from_jwt_opt,
is_admin,
APIError,
- Oper,
Perform,
},
apub::fetcher::search_by_apub_id,
DbPool,
LemmyError,
};
+use actix_web::client::Client;
use lemmy_db::{
category::*,
comment_view::*,
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<ListCategories> {
+impl Perform for ListCategories {
type Response = ListCategoriesResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<ListCategoriesResponse, LemmyError> {
- let _data: &ListCategories = &self.data;
+ let _data: &ListCategories = &self;
let categories = blocking(pool, move |conn| Category::list_all(conn)).await??;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetModlog> {
+impl Perform for GetModlog {
type Response = GetModlogResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetModlogResponse, LemmyError> {
- let data: &GetModlog = &self.data;
+ let data: &GetModlog = &self;
let community_id = data.community_id;
let mod_user_id = data.mod_user_id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<CreateSite> {
+impl Perform for CreateSite {
type Response = SiteResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<SiteResponse, LemmyError> {
- let data: &CreateSite = &self.data;
+ let data: &CreateSite = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<EditSite> {
+impl Perform for EditSite {
type Response = SiteResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<SiteResponse, LemmyError> {
- let data: &EditSite = &self.data;
+ let data: &EditSite = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
check_slurs(&data.name)?;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetSite> {
+impl Perform for GetSite {
type Response = GetSiteResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<GetSiteResponse, LemmyError> {
- let data: &GetSite = &self.data;
+ let data: &GetSite = &self;
// TODO refactor this a little
let res = blocking(pool, move |conn| Site::read(conn, 1)).await?;
captcha_uuid: None,
captcha_answer: None,
};
- let login_response = Oper::new(register, self.client.clone())
- .perform(pool, websocket_info.clone())
+ let login_response = register
+ .perform(pool, websocket_info.clone(), client.clone())
.await?;
info!("Admin {} created", setup.admin_username);
enable_nsfw: true,
auth: login_response.jwt,
};
- Oper::new(create_site, self.client.clone())
- .perform(pool, websocket_info.clone())
+ create_site
+ .perform(pool, websocket_info.clone(), client.clone())
.await?;
info!("Site {} created", setup.site_name);
Some(blocking(pool, move |conn| SiteView::read(conn)).await??)
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<Search> {
+impl Perform for Search {
type Response = SearchResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<SearchResponse, LemmyError> {
- let data: &Search = &self.data;
+ let data: &Search = &self;
dbg!(&data);
- match search_by_apub_id(&data.q, &self.client, pool).await {
+ match search_by_apub_id(&data.q, &client, pool).await {
Ok(r) => return Ok(r),
Err(e) => debug!("Failed to resolve search query as activitypub ID: {}", e),
}
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<TransferSite> {
+impl Perform for TransferSite {
type Response = GetSiteResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetSiteResponse, LemmyError> {
- let data: &TransferSite = &self.data;
+ let data: &TransferSite = &self;
let mut user = get_user_from_jwt(&data.auth, pool).await?;
// TODO add a User_::read_safe() for this.
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetSiteConfig> {
+impl Perform for GetSiteConfig {
type Response = GetSiteConfigResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetSiteConfigResponse, LemmyError> {
- let data: &GetSiteConfig = &self.data;
+ let data: &GetSiteConfig = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
// Only let admins read this
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<SaveSiteConfig> {
+impl Perform for SaveSiteConfig {
type Response = GetSiteConfigResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetSiteConfigResponse, LemmyError> {
- let data: &SaveSiteConfig = &self.data;
+ let data: &SaveSiteConfig = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
// Only let admins read this
get_user_from_jwt_opt,
is_admin,
APIError,
- Oper,
Perform,
},
apub::ApubObjectType,
DbPool,
LemmyError,
};
+use actix_web::client::Client;
use bcrypt::verify;
use captcha::{gen, Difficulty};
use chrono::Duration;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<Login> {
+impl Perform for Login {
type Response = LoginResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<LoginResponse, LemmyError> {
- let data: &Login = &self.data;
+ let data: &Login = &self;
// Fetch that username / email
let username_or_email = data.username_or_email.clone();
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<Register> {
+impl Perform for Register {
type Response = LoginResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<LoginResponse, LemmyError> {
- let data: &Register = &self.data;
+ let data: &Register = &self;
// Make sure site has open registration
if let Ok(site) = blocking(pool, move |conn| SiteView::read(conn)).await? {
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetCaptcha> {
+impl Perform for GetCaptcha {
type Response = GetCaptchaResponse;
async fn perform(
&self,
_pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<Self::Response, LemmyError> {
let captcha_settings = Settings::get().captcha;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<SaveUserSettings> {
+impl Perform for SaveUserSettings {
type Response = LoginResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<LoginResponse, LemmyError> {
- let data: &SaveUserSettings = &self.data;
+ let data: &SaveUserSettings = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let user_id = user.id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetUserDetails> {
+impl Perform for GetUserDetails {
type Response = GetUserDetailsResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetUserDetailsResponse, LemmyError> {
- let data: &GetUserDetails = &self.data;
+ let data: &GetUserDetails = &self;
let user = get_user_from_jwt_opt(&data.auth, pool).await?;
let show_nsfw = match &user {
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<AddAdmin> {
+impl Perform for AddAdmin {
type Response = AddAdminResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<AddAdminResponse, LemmyError> {
- let data: &AddAdmin = &self.data;
+ let data: &AddAdmin = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
// Make sure user is an admin
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<BanUser> {
+impl Perform for BanUser {
type Response = BanUserResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<BanUserResponse, LemmyError> {
- let data: &BanUser = &self.data;
+ let data: &BanUser = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
// Make sure user is an admin
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetReplies> {
+impl Perform for GetReplies {
type Response = GetRepliesResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetRepliesResponse, LemmyError> {
- let data: &GetReplies = &self.data;
+ let data: &GetReplies = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let sort = SortType::from_str(&data.sort)?;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetUserMentions> {
+impl Perform for GetUserMentions {
type Response = GetUserMentionsResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetUserMentionsResponse, LemmyError> {
- let data: &GetUserMentions = &self.data;
+ let data: &GetUserMentions = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let sort = SortType::from_str(&data.sort)?;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<MarkUserMentionAsRead> {
+impl Perform for MarkUserMentionAsRead {
type Response = UserMentionResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<UserMentionResponse, LemmyError> {
- let data: &MarkUserMentionAsRead = &self.data;
+ let data: &MarkUserMentionAsRead = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let user_mention_id = data.user_mention_id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<MarkAllAsRead> {
+impl Perform for MarkAllAsRead {
type Response = GetRepliesResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<GetRepliesResponse, LemmyError> {
- let data: &MarkAllAsRead = &self.data;
+ let data: &MarkAllAsRead = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let user_id = user.id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<DeleteAccount> {
+impl Perform for DeleteAccount {
type Response = LoginResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<LoginResponse, LemmyError> {
- let data: &DeleteAccount = &self.data;
+ let data: &DeleteAccount = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
// Verify the password
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<PasswordReset> {
+impl Perform for PasswordReset {
type Response = PasswordResetResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<PasswordResetResponse, LemmyError> {
- let data: &PasswordReset = &self.data;
+ let data: &PasswordReset = &self;
// Fetch that email
let email = data.email.clone();
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<PasswordChange> {
+impl Perform for PasswordChange {
type Response = LoginResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<LoginResponse, LemmyError> {
- let data: &PasswordChange = &self.data;
+ let data: &PasswordChange = &self;
// Fetch the user_id from the token
let token = data.token.clone();
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<CreatePrivateMessage> {
+impl Perform for CreatePrivateMessage {
type Response = PrivateMessageResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<PrivateMessageResponse, LemmyError> {
- let data: &CreatePrivateMessage = &self.data;
+ let data: &CreatePrivateMessage = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let hostname = &format!("https://{}", Settings::get().hostname);
};
updated_private_message
- .send_create(&user, &self.client, pool)
+ .send_create(&user, &client, pool)
.await?;
// Send notifications to the recipient
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<EditPrivateMessage> {
+impl Perform for EditPrivateMessage {
type Response = PrivateMessageResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<PrivateMessageResponse, LemmyError> {
- let data: &EditPrivateMessage = &self.data;
+ let data: &EditPrivateMessage = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
// Checking permissions
// Send the apub update
updated_private_message
- .send_update(&user, &self.client, pool)
+ .send_update(&user, &client, pool)
.await?;
let edit_id = data.edit_id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<DeletePrivateMessage> {
+impl Perform for DeletePrivateMessage {
type Response = PrivateMessageResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ client: Client,
) -> Result<PrivateMessageResponse, LemmyError> {
- let data: &DeletePrivateMessage = &self.data;
+ let data: &DeletePrivateMessage = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
// Checking permissions
// Send the apub update
if data.deleted {
updated_private_message
- .send_delete(&user, &self.client, pool)
+ .send_delete(&user, &client, pool)
.await?;
} else {
updated_private_message
- .send_undo_delete(&user, &self.client, pool)
+ .send_undo_delete(&user, &client, pool)
.await?;
}
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<MarkPrivateMessageAsRead> {
+impl Perform for MarkPrivateMessageAsRead {
type Response = PrivateMessageResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<PrivateMessageResponse, LemmyError> {
- let data: &MarkPrivateMessageAsRead = &self.data;
+ let data: &MarkPrivateMessageAsRead = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
// Checking permissions
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<GetPrivateMessages> {
+impl Perform for GetPrivateMessages {
type Response = PrivateMessagesResponse;
async fn perform(
&self,
pool: &DbPool,
_websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<PrivateMessagesResponse, LemmyError> {
- let data: &GetPrivateMessages = &self.data;
+ let data: &GetPrivateMessages = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
let user_id = user.id;
}
#[async_trait::async_trait(?Send)]
-impl Perform for Oper<UserJoin> {
+impl Perform for UserJoin {
type Response = UserJoinResponse;
async fn perform(
&self,
pool: &DbPool,
websocket_info: Option<WebsocketInfo>,
+ _client: Client,
) -> Result<UserJoinResponse, LemmyError> {
- let data: &UserJoin = &self.data;
+ let data: &UserJoin = &self;
let user = get_user_from_jwt(&data.auth, pool).await?;
if let Some(ws) = websocket_info {
use crate::{
- api::{comment::*, community::*, post::*, site::*, user::*, Oper, Perform},
+ api::{comment::*, community::*, post::*, site::*, user::*, Perform},
rate_limit::RateLimit,
routes::{ChatServerParam, DbPoolParam},
websocket::WebsocketInfo,
chat_server: ChatServerParam,
) -> Result<HttpResponse, Error>
where
- Oper<Request>: Perform,
+ Request: Perform,
Request: Send + 'static,
{
let ws_info = WebsocketInfo {
id: None,
};
- let oper: Oper<Request> = Oper::new(data, client.clone());
-
- let res = oper
- .perform(&db, Some(ws_info))
+ let res = data
+ .perform(&db, Some(ws_info), client.clone())
.await
.map(|json| HttpResponse::Ok().json(json))
.map_err(ErrorBadRequest)?;
chat_server: ChatServerParam,
) -> Result<HttpResponse, Error>
where
- Data: Serialize + Send + 'static,
- Oper<Data>: Perform,
+ Data: Serialize + Send + 'static + Perform,
{
perform::<Data>(data.0, &client, db, chat_server).await
}
chat_server: ChatServerParam,
) -> Result<HttpResponse, Error>
where
- Data: Serialize + Send + 'static,
- Oper<Data>: Perform,
+ Data: Serialize + Send + 'static + Perform,
{
perform::<Data>(data.0, &client, db, chat_server).await
}
async fn do_user_operation<'a, 'b, Data>(args: Args<'b>) -> Result<String, LemmyError>
where
for<'de> Data: Deserialize<'de> + 'a,
- Oper<Data>: Perform,
+ Data: Perform,
{
let Args {
client,
let fut = async move {
let pool = pool.clone();
let parsed_data: Data = serde_json::from_str(&data)?;
- let res = Oper::new(parsed_data, client)
- .perform(&pool, Some(ws_info))
- .await?;
+ let res = parsed_data.perform(&pool, Some(ws_info), client).await?;
to_json_string(&op, &res)
};