Merge pull request #2593 from LemmyNet/refactor-notifications
Refactor crates for parallel build
This commit is contained in:
commit
f02892b23b
188 changed files with 2300 additions and 1588 deletions
49
Cargo.lock
generated
49
Cargo.lock
generated
|
@ -2034,7 +2034,6 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
name = "lemmy_api"
|
name = "lemmy_api"
|
||||||
version = "0.16.5"
|
version = "0.16.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activitypub_federation",
|
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
@ -2044,13 +2043,11 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"diesel",
|
"diesel",
|
||||||
"lemmy_api_common",
|
"lemmy_api_common",
|
||||||
"lemmy_apub",
|
|
||||||
"lemmy_db_schema",
|
"lemmy_db_schema",
|
||||||
"lemmy_db_views",
|
"lemmy_db_views",
|
||||||
"lemmy_db_views_actor",
|
"lemmy_db_views_actor",
|
||||||
"lemmy_db_views_moderator",
|
"lemmy_db_views_moderator",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"lemmy_websocket",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serial_test",
|
"serial_test",
|
||||||
|
@ -2063,8 +2060,12 @@ dependencies = [
|
||||||
name = "lemmy_api_common"
|
name = "lemmy_api_common"
|
||||||
version = "0.16.5"
|
version = "0.16.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"actix",
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
|
"actix-web-actors",
|
||||||
|
"anyhow",
|
||||||
|
"background-jobs",
|
||||||
"chrono",
|
"chrono",
|
||||||
"diesel",
|
"diesel",
|
||||||
"encoding",
|
"encoding",
|
||||||
|
@ -2073,13 +2074,20 @@ dependencies = [
|
||||||
"lemmy_db_views_actor",
|
"lemmy_db_views_actor",
|
||||||
"lemmy_db_views_moderator",
|
"lemmy_db_views_moderator",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
|
"opentelemetry 0.17.0",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
|
"rand 0.8.5",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"reqwest-middleware",
|
"reqwest-middleware",
|
||||||
"rosetta-i18n",
|
"rosetta-i18n",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"strum",
|
||||||
|
"strum_macros",
|
||||||
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"tracing-opentelemetry 0.17.4",
|
||||||
"url",
|
"url",
|
||||||
"webpage",
|
"webpage",
|
||||||
]
|
]
|
||||||
|
@ -2093,12 +2101,10 @@ dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"bcrypt",
|
"bcrypt",
|
||||||
"lemmy_api_common",
|
"lemmy_api_common",
|
||||||
"lemmy_apub",
|
|
||||||
"lemmy_db_schema",
|
"lemmy_db_schema",
|
||||||
"lemmy_db_views",
|
"lemmy_db_views",
|
||||||
"lemmy_db_views_actor",
|
"lemmy_db_views_actor",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"lemmy_websocket",
|
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
@ -2131,7 +2137,6 @@ dependencies = [
|
||||||
"lemmy_db_views",
|
"lemmy_db_views",
|
||||||
"lemmy_db_views_actor",
|
"lemmy_db_views_actor",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"lemmy_websocket",
|
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"reqwest-middleware",
|
"reqwest-middleware",
|
||||||
|
@ -2223,12 +2228,10 @@ dependencies = [
|
||||||
"diesel",
|
"diesel",
|
||||||
"futures",
|
"futures",
|
||||||
"lemmy_api_common",
|
"lemmy_api_common",
|
||||||
"lemmy_apub",
|
|
||||||
"lemmy_db_schema",
|
"lemmy_db_schema",
|
||||||
"lemmy_db_views",
|
"lemmy_db_views",
|
||||||
"lemmy_db_views_actor",
|
"lemmy_db_views_actor",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"lemmy_websocket",
|
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"reqwest-middleware",
|
"reqwest-middleware",
|
||||||
|
@ -2260,7 +2263,6 @@ dependencies = [
|
||||||
"lemmy_db_schema",
|
"lemmy_db_schema",
|
||||||
"lemmy_routes",
|
"lemmy_routes",
|
||||||
"lemmy_utils",
|
"lemmy_utils",
|
||||||
"lemmy_websocket",
|
|
||||||
"opentelemetry 0.17.0",
|
"opentelemetry 0.17.0",
|
||||||
"opentelemetry-otlp",
|
"opentelemetry-otlp",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
@ -2269,6 +2271,7 @@ dependencies = [
|
||||||
"reqwest-retry",
|
"reqwest-retry",
|
||||||
"reqwest-tracing",
|
"reqwest-tracing",
|
||||||
"serde",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-actix-web",
|
"tracing-actix-web",
|
||||||
"tracing-error",
|
"tracing-error",
|
||||||
|
@ -2317,34 +2320,6 @@ dependencies = [
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "lemmy_websocket"
|
|
||||||
version = "0.16.5"
|
|
||||||
dependencies = [
|
|
||||||
"actix",
|
|
||||||
"actix-web",
|
|
||||||
"actix-web-actors",
|
|
||||||
"anyhow",
|
|
||||||
"background-jobs",
|
|
||||||
"chrono",
|
|
||||||
"diesel",
|
|
||||||
"lemmy_api_common",
|
|
||||||
"lemmy_db_schema",
|
|
||||||
"lemmy_db_views",
|
|
||||||
"lemmy_db_views_actor",
|
|
||||||
"lemmy_utils",
|
|
||||||
"opentelemetry 0.17.0",
|
|
||||||
"rand 0.8.5",
|
|
||||||
"reqwest-middleware",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"strum",
|
|
||||||
"strum_macros",
|
|
||||||
"tokio",
|
|
||||||
"tracing",
|
|
||||||
"tracing-opentelemetry 0.17.4",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lettre"
|
name = "lettre"
|
||||||
version = "0.10.1"
|
version = "0.10.1"
|
||||||
|
|
|
@ -45,7 +45,6 @@ members = [
|
||||||
"crates/db_views",
|
"crates/db_views",
|
||||||
"crates/db_views_actor",
|
"crates/db_views_actor",
|
||||||
"crates/db_views_actor",
|
"crates/db_views_actor",
|
||||||
"crates/websocket",
|
|
||||||
"crates/routes"
|
"crates/routes"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -56,7 +55,6 @@ lemmy_apub = { version = "=0.16.5", path = "./crates/apub" }
|
||||||
lemmy_utils = { version = "=0.16.5", path = "./crates/utils" }
|
lemmy_utils = { version = "=0.16.5", path = "./crates/utils" }
|
||||||
lemmy_db_schema = { version = "=0.16.5", path = "./crates/db_schema" }
|
lemmy_db_schema = { version = "=0.16.5", path = "./crates/db_schema" }
|
||||||
lemmy_api_common = { version = "=0.16.5", path = "./crates/api_common" }
|
lemmy_api_common = { version = "=0.16.5", path = "./crates/api_common" }
|
||||||
lemmy_websocket = { version = "=0.16.5", path = "./crates/websocket" }
|
|
||||||
lemmy_routes = { version = "=0.16.5", path = "./crates/routes" }
|
lemmy_routes = { version = "=0.16.5", path = "./crates/routes" }
|
||||||
lemmy_db_views = { version = "=0.16.5", path = "./crates/db_views" }
|
lemmy_db_views = { version = "=0.16.5", path = "./crates/db_views" }
|
||||||
lemmy_db_views_actor = { version = "=0.16.5", path = "./crates/db_views_actor" }
|
lemmy_db_views_actor = { version = "=0.16.5", path = "./crates/db_views_actor" }
|
||||||
|
@ -116,7 +114,6 @@ lemmy_apub = { workspace = true }
|
||||||
lemmy_utils = { workspace = true }
|
lemmy_utils = { workspace = true }
|
||||||
lemmy_db_schema = { workspace = true }
|
lemmy_db_schema = { workspace = true }
|
||||||
lemmy_api_common = { workspace = true }
|
lemmy_api_common = { workspace = true }
|
||||||
lemmy_websocket = { workspace = true }
|
|
||||||
lemmy_routes = { workspace = true }
|
lemmy_routes = { workspace = true }
|
||||||
activitypub_federation = { workspace = true }
|
activitypub_federation = { workspace = true }
|
||||||
diesel = { workspace = true }
|
diesel = { workspace = true }
|
||||||
|
@ -138,6 +135,7 @@ clokwerk = { workspace = true }
|
||||||
doku = { workspace = true }
|
doku = { workspace = true }
|
||||||
parking_lot = { workspace = true }
|
parking_lot = { workspace = true }
|
||||||
reqwest-retry = { workspace = true }
|
reqwest-retry = { workspace = true }
|
||||||
|
serde_json = { workspace = true }
|
||||||
tracing-opentelemetry = { workspace = true, optional = true }
|
tracing-opentelemetry = { workspace = true, optional = true }
|
||||||
opentelemetry = { workspace = true, optional = true }
|
opentelemetry = { workspace = true, optional = true }
|
||||||
console-subscriber = { version = "0.1.8", optional = true }
|
console-subscriber = { version = "0.1.8", optional = true }
|
||||||
|
|
|
@ -187,12 +187,15 @@ test("Admin actions in remote community are not federated to origin", async () =
|
||||||
let gammaCommunity = (
|
let gammaCommunity = (
|
||||||
await resolveCommunity(gamma, communityRes.community.actor_id)
|
await resolveCommunity(gamma, communityRes.community.actor_id)
|
||||||
).community.unwrap();
|
).community.unwrap();
|
||||||
let gammaFollow = await followCommunity(
|
await followCommunity(
|
||||||
gamma,
|
gamma,
|
||||||
true,
|
true,
|
||||||
gammaCommunity.community.id
|
gammaCommunity.community.id
|
||||||
);
|
);
|
||||||
expect(gammaFollow.community_view.subscribed).toBe("Subscribed");
|
gammaCommunity = (
|
||||||
|
await resolveCommunity(gamma, communityRes.community.actor_id)
|
||||||
|
).community.unwrap();
|
||||||
|
expect(gammaCommunity.subscribed).toBe("Subscribed");
|
||||||
let gammaPost = (await createPost(gamma, gammaCommunity.community.id))
|
let gammaPost = (await createPost(gamma, gammaCommunity.community.id))
|
||||||
.post_view;
|
.post_view;
|
||||||
expect(gammaPost.post.id).toBeDefined();
|
expect(gammaPost.post.id).toBeDefined();
|
||||||
|
|
|
@ -20,12 +20,13 @@ afterAll(async () => {
|
||||||
|
|
||||||
test("Follow federated community", async () => {
|
test("Follow federated community", async () => {
|
||||||
let betaCommunity = (await resolveBetaCommunity(alpha)).community.unwrap();
|
let betaCommunity = (await resolveBetaCommunity(alpha)).community.unwrap();
|
||||||
let follow = await followCommunity(alpha, true, betaCommunity.community.id);
|
await followCommunity(alpha, true, betaCommunity.community.id);
|
||||||
|
betaCommunity = (await resolveBetaCommunity(alpha)).community.unwrap();
|
||||||
|
|
||||||
// Make sure the follow response went through
|
// Make sure the follow response went through
|
||||||
expect(follow.community_view.community.local).toBe(false);
|
expect(betaCommunity.community.local).toBe(false);
|
||||||
expect(follow.community_view.community.name).toBe("main");
|
expect(betaCommunity.community.name).toBe("main");
|
||||||
expect(follow.community_view.subscribed).toBe(SubscribedType.Subscribed);
|
expect(betaCommunity.subscribed).toBe(SubscribedType.Subscribed);
|
||||||
|
|
||||||
// Check it from local
|
// Check it from local
|
||||||
let site = await getSite(alpha);
|
let site = await getSite(alpha);
|
||||||
|
|
|
@ -14,15 +14,12 @@ path = "src/lib.rs"
|
||||||
doctest = false
|
doctest = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_apub = { workspace = true }
|
|
||||||
lemmy_utils = { workspace = true }
|
lemmy_utils = { workspace = true }
|
||||||
lemmy_db_schema = { workspace = true, features = ["full"] }
|
lemmy_db_schema = { workspace = true, features = ["full"] }
|
||||||
lemmy_db_views = { workspace = true, features = ["full"] }
|
lemmy_db_views = { workspace = true, features = ["full"] }
|
||||||
lemmy_db_views_moderator = { workspace = true, features = ["full"] }
|
lemmy_db_views_moderator = { workspace = true, features = ["full"] }
|
||||||
lemmy_db_views_actor = { workspace = true, features = ["full"] }
|
lemmy_db_views_actor = { workspace = true, features = ["full"] }
|
||||||
lemmy_api_common = { workspace = true, features = ["full"] }
|
lemmy_api_common = { workspace = true, features = ["full"] }
|
||||||
lemmy_websocket = { workspace = true }
|
|
||||||
activitypub_federation = { workspace = true }
|
|
||||||
diesel = { workspace = true }
|
diesel = { workspace = true }
|
||||||
bcrypt = { workspace = true }
|
bcrypt = { workspace = true }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
|
|
|
@ -2,14 +2,9 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, CreateCommentLike},
|
comment::{CommentResponse, CreateCommentLike},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{check_community_ban, check_downvotes_enabled, get_local_user_view_from_jwt},
|
utils::{check_community_ban, check_downvotes_enabled, get_local_user_view_from_jwt},
|
||||||
};
|
websocket::{send::send_comment_ws_message, UserOperation},
|
||||||
use lemmy_apub::{
|
|
||||||
fetcher::post_or_comment::PostOrComment,
|
|
||||||
protocol::activities::voting::{
|
|
||||||
undo_vote::UndoVote,
|
|
||||||
vote::{Vote, VoteType},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::LocalUserId,
|
newtypes::LocalUserId,
|
||||||
|
@ -22,8 +17,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{CommentView, LocalUserView};
|
use lemmy_db_views::structs::{CommentView, LocalUserView};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperation};
|
|
||||||
use std::convert::TryInto;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for CreateCommentLike {
|
impl Perform for CreateCommentLike {
|
||||||
|
@ -77,33 +70,12 @@ impl Perform for CreateCommentLike {
|
||||||
CommentLike::remove(context.pool(), person_id, comment_id).await?;
|
CommentLike::remove(context.pool(), person_id, comment_id).await?;
|
||||||
|
|
||||||
// Only add the like if the score isnt 0
|
// Only add the like if the score isnt 0
|
||||||
let comment = orig_comment.comment;
|
|
||||||
let object = PostOrComment::Comment(Box::new(comment.into()));
|
|
||||||
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
|
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
|
||||||
if do_add {
|
if do_add {
|
||||||
let like_form2 = like_form.clone();
|
let like_form2 = like_form.clone();
|
||||||
CommentLike::like(context.pool(), &like_form2)
|
CommentLike::like(context.pool(), &like_form2)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
|
||||||
|
|
||||||
Vote::send(
|
|
||||||
&object,
|
|
||||||
&local_user_view.person.clone().into(),
|
|
||||||
orig_comment.community.id,
|
|
||||||
like_form.score.try_into()?,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
} else {
|
|
||||||
// API doesn't distinguish between Undo/Like and Undo/Dislike
|
|
||||||
UndoVote::send(
|
|
||||||
&object,
|
|
||||||
&local_user_view.person.clone().into(),
|
|
||||||
orig_comment.community.id,
|
|
||||||
VoteType::Like,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
send_comment_ws_message(
|
send_comment_ws_message(
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, SaveComment},
|
comment::{CommentResponse, SaveComment},
|
||||||
|
context::LemmyContext,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -10,7 +11,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::CommentView;
|
use lemmy_db_views::structs::CommentView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for SaveComment {
|
impl Perform for SaveComment {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use crate::{check_report_reason, Perform};
|
use crate::{check_report_reason, Perform};
|
||||||
use activitypub_federation::core::object_id::ObjectId;
|
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, CreateCommentReport},
|
comment::{CommentReportResponse, CreateCommentReport},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{check_community_ban, get_local_user_view_from_jwt},
|
utils::{check_community_ban, get_local_user_view_from_jwt},
|
||||||
|
websocket::{messages::SendModRoomMessage, UserOperation},
|
||||||
};
|
};
|
||||||
use lemmy_apub::protocol::activities::community::report::Report;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
comment_report::{CommentReport, CommentReportForm},
|
comment_report::{CommentReport, CommentReportForm},
|
||||||
|
@ -15,7 +15,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{CommentReportView, CommentView};
|
use lemmy_db_views::structs::{CommentReportView, CommentView};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
/// Creates a comment report and notifies the moderators of the community
|
/// Creates a comment report and notifies the moderators of the community
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
|
@ -66,15 +65,6 @@ impl Perform for CreateCommentReport {
|
||||||
websocket_id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
Report::send(
|
|
||||||
ObjectId::new(comment_view.comment.ap_id),
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
ObjectId::new(comment_view.community.actor_id),
|
|
||||||
reason.to_string(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{ListCommentReports, ListCommentReportsResponse},
|
comment::{ListCommentReports, ListCommentReportsResponse},
|
||||||
|
context::LemmyContext,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::comment_report_view::CommentReportQuery;
|
use lemmy_db_views::comment_report_view::CommentReportQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
/// Lists comment reports for a community if an id is supplied
|
/// Lists comment reports for a community if an id is supplied
|
||||||
/// or returns all comment reports for communities a user moderates
|
/// or returns all comment reports for communities a user moderates
|
||||||
|
|
|
@ -2,12 +2,13 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentReportResponse, ResolveCommentReport},
|
comment::{CommentReportResponse, ResolveCommentReport},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{get_local_user_view_from_jwt, is_mod_or_admin},
|
utils::{get_local_user_view_from_jwt, is_mod_or_admin},
|
||||||
|
websocket::{messages::SendModRoomMessage, UserOperation},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
|
use lemmy_db_schema::{source::comment_report::CommentReport, traits::Reportable};
|
||||||
use lemmy_db_views::structs::CommentReportView;
|
use lemmy_db_views::structs::CommentReportView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
/// Resolves or unresolves a comment report and notifies the moderators of the community
|
/// Resolves or unresolves a comment report and notifies the moderators of the community
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
|
|
|
@ -2,23 +2,19 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{AddModToCommunity, AddModToCommunityResponse},
|
community::{AddModToCommunity, AddModToCommunityResponse},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{get_local_user_view_from_jwt, is_mod_or_admin},
|
utils::{get_local_user_view_from_jwt, is_mod_or_admin},
|
||||||
};
|
websocket::{messages::SendCommunityRoomMessage, UserOperation},
|
||||||
use lemmy_apub::{
|
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
|
||||||
protocol::activities::community::{add_mod::AddMod, remove_mod::RemoveMod},
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunityModerator, CommunityModeratorForm},
|
community::{Community, CommunityModerator, CommunityModeratorForm},
|
||||||
moderator::{ModAddCommunity, ModAddCommunityForm},
|
moderator::{ModAddCommunity, ModAddCommunityForm},
|
||||||
person::Person,
|
|
||||||
},
|
},
|
||||||
traits::{Crud, Joinable},
|
traits::{Crud, Joinable},
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for AddModToCommunity {
|
impl Perform for AddModToCommunity {
|
||||||
|
@ -68,28 +64,6 @@ impl Perform for AddModToCommunity {
|
||||||
|
|
||||||
ModAddCommunity::create(context.pool(), &form).await?;
|
ModAddCommunity::create(context.pool(), &form).await?;
|
||||||
|
|
||||||
// Send to federated instances
|
|
||||||
let updated_mod_id = data.person_id;
|
|
||||||
let updated_mod: ApubPerson = Person::read(context.pool(), updated_mod_id).await?.into();
|
|
||||||
let community: ApubCommunity = community.into();
|
|
||||||
if data.added {
|
|
||||||
AddMod::send(
|
|
||||||
&community,
|
|
||||||
&updated_mod,
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
} else {
|
|
||||||
RemoveMod::send(
|
|
||||||
&community,
|
|
||||||
&updated_mod,
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: in case a remote mod is added, this returns the old moderators list, it will only get
|
// Note: in case a remote mod is added, this returns the old moderators list, it will only get
|
||||||
// updated once we receive an activity from the community (like `Announce/Add/Moderator`)
|
// updated once we receive an activity from the community (like `Announce/Add/Moderator`)
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
|
|
@ -2,30 +2,24 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{BanFromCommunity, BanFromCommunityResponse},
|
community::{BanFromCommunity, BanFromCommunityResponse},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{get_local_user_view_from_jwt, is_mod_or_admin, remove_user_data_in_community},
|
utils::{get_local_user_view_from_jwt, is_mod_or_admin, remove_user_data_in_community},
|
||||||
};
|
websocket::{messages::SendCommunityRoomMessage, UserOperation},
|
||||||
use lemmy_apub::{
|
|
||||||
activities::block::SiteOrCommunity,
|
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
|
||||||
protocol::activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
community::{
|
community::{
|
||||||
Community,
|
|
||||||
CommunityFollower,
|
CommunityFollower,
|
||||||
CommunityFollowerForm,
|
CommunityFollowerForm,
|
||||||
CommunityPersonBan,
|
CommunityPersonBan,
|
||||||
CommunityPersonBanForm,
|
CommunityPersonBanForm,
|
||||||
},
|
},
|
||||||
moderator::{ModBanFromCommunity, ModBanFromCommunityForm},
|
moderator::{ModBanFromCommunity, ModBanFromCommunityForm},
|
||||||
person::Person,
|
|
||||||
},
|
},
|
||||||
traits::{Bannable, Crud, Followable},
|
traits::{Bannable, Crud, Followable},
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||||
use lemmy_utils::{error::LemmyError, utils::naive_from_unix, ConnectionId};
|
use lemmy_utils::{error::LemmyError, utils::naive_from_unix, ConnectionId};
|
||||||
use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for BanFromCommunity {
|
impl Perform for BanFromCommunity {
|
||||||
|
@ -55,9 +49,6 @@ impl Perform for BanFromCommunity {
|
||||||
expires: Some(expires),
|
expires: Some(expires),
|
||||||
};
|
};
|
||||||
|
|
||||||
let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
|
|
||||||
let banned_person: ApubPerson = Person::read(context.pool(), banned_person_id).await?.into();
|
|
||||||
|
|
||||||
if data.ban {
|
if data.ban {
|
||||||
CommunityPersonBan::ban(context.pool(), &community_user_ban_form)
|
CommunityPersonBan::ban(context.pool(), &community_user_ban_form)
|
||||||
.await
|
.await
|
||||||
|
@ -73,29 +64,10 @@ impl Perform for BanFromCommunity {
|
||||||
CommunityFollower::unfollow(context.pool(), &community_follower_form)
|
CommunityFollower::unfollow(context.pool(), &community_follower_form)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.ok();
|
||||||
|
|
||||||
BlockUser::send(
|
|
||||||
&SiteOrCommunity::Community(community),
|
|
||||||
&banned_person,
|
|
||||||
&local_user_view.person.clone().into(),
|
|
||||||
remove_data,
|
|
||||||
data.reason.clone(),
|
|
||||||
expires,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
} else {
|
} else {
|
||||||
CommunityPersonBan::unban(context.pool(), &community_user_ban_form)
|
CommunityPersonBan::unban(context.pool(), &community_user_ban_form)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
|
||||||
UndoBlockUser::send(
|
|
||||||
&SiteOrCommunity::Community(community),
|
|
||||||
&banned_person,
|
|
||||||
&local_user_view.person.clone().into(),
|
|
||||||
data.reason.clone(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove/Restore their data if that's desired
|
// Remove/Restore their data if that's desired
|
||||||
|
|
|
@ -2,19 +2,18 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{BlockCommunity, BlockCommunityResponse},
|
community::{BlockCommunity, BlockCommunityResponse},
|
||||||
|
context::LemmyContext,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_apub::protocol::activities::following::undo_follow::UndoFollow;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunityFollower, CommunityFollowerForm},
|
community::{CommunityFollower, CommunityFollowerForm},
|
||||||
community_block::{CommunityBlock, CommunityBlockForm},
|
community_block::{CommunityBlock, CommunityBlockForm},
|
||||||
},
|
},
|
||||||
traits::{Blockable, Crud, Followable},
|
traits::{Blockable, Followable},
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::CommunityView;
|
use lemmy_db_views_actor::structs::CommunityView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for BlockCommunity {
|
impl Perform for BlockCommunity {
|
||||||
|
@ -52,8 +51,6 @@ impl Perform for BlockCommunity {
|
||||||
CommunityFollower::unfollow(context.pool(), &community_follower_form)
|
CommunityFollower::unfollow(context.pool(), &community_follower_form)
|
||||||
.await
|
.await
|
||||||
.ok();
|
.ok();
|
||||||
let community = Community::read(context.pool(), community_id).await?;
|
|
||||||
UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await?;
|
|
||||||
} else {
|
} else {
|
||||||
CommunityBlock::unblock(context.pool(), &community_block_form)
|
CommunityBlock::unblock(context.pool(), &community_block_form)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -2,22 +2,15 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, FollowCommunity},
|
community::{CommunityResponse, FollowCommunity},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt},
|
utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt},
|
||||||
};
|
};
|
||||||
use lemmy_apub::{
|
|
||||||
objects::community::ApubCommunity,
|
|
||||||
protocol::activities::following::{
|
|
||||||
follow::Follow as FollowCommunityApub,
|
|
||||||
undo_follow::UndoFollow,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{Community, CommunityFollower, CommunityFollowerForm},
|
source::community::{Community, CommunityFollower, CommunityFollowerForm},
|
||||||
traits::{Crud, Followable},
|
traits::{Crud, Followable},
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::CommunityView;
|
use lemmy_db_views_actor::structs::CommunityView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for FollowCommunity {
|
impl Perform for FollowCommunity {
|
||||||
|
@ -34,33 +27,22 @@ impl Perform for FollowCommunity {
|
||||||
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
|
let community = Community::read(context.pool(), community_id).await?;
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let 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 {
|
if community.local && data.follow {
|
||||||
if data.follow {
|
check_community_ban(local_user_view.person.id, community_id, context.pool()).await?;
|
||||||
check_community_ban(local_user_view.person.id, community_id, context.pool()).await?;
|
check_community_deleted_or_removed(community_id, context.pool()).await?;
|
||||||
check_community_deleted_or_removed(community_id, context.pool()).await?;
|
|
||||||
|
|
||||||
CommunityFollower::follow(context.pool(), &community_follower_form)
|
CommunityFollower::follow(context.pool(), &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 {
|
}
|
||||||
CommunityFollower::unfollow(context.pool(), &community_follower_form)
|
if !data.follow {
|
||||||
.await
|
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
|
||||||
}
|
|
||||||
} else if data.follow {
|
|
||||||
// Dont actually add to the community followers here, because you need
|
|
||||||
// to wait for the accept
|
|
||||||
FollowCommunityApub::send(&local_user_view.person.clone().into(), &community, context)
|
|
||||||
.await?;
|
|
||||||
} else {
|
|
||||||
UndoFollow::send(&local_user_view.person.clone().into(), &community, context).await?;
|
|
||||||
CommunityFollower::unfollow(context.pool(), &community_follower_form)
|
CommunityFollower::unfollow(context.pool(), &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"))?;
|
||||||
|
|
|
@ -2,9 +2,10 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, HideCommunity},
|
community::{CommunityResponse, HideCommunity},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{get_local_user_view_from_jwt, is_admin},
|
||||||
|
websocket::{send::send_community_ws_message, UserOperationCrud},
|
||||||
};
|
};
|
||||||
use lemmy_apub::protocol::activities::community::update::UpdateCommunity;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunityUpdateForm},
|
community::{Community, CommunityUpdateForm},
|
||||||
|
@ -13,7 +14,6 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for HideCommunity {
|
impl Perform for HideCommunity {
|
||||||
|
@ -44,19 +44,12 @@ impl Perform for HideCommunity {
|
||||||
};
|
};
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let updated_community = Community::update(context.pool(), community_id, &community_form)
|
Community::update(context.pool(), community_id, &community_form)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community_hidden_status"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community_hidden_status"))?;
|
||||||
|
|
||||||
ModHideCommunity::create(context.pool(), &mod_hide_community_form).await?;
|
ModHideCommunity::create(context.pool(), &mod_hide_community_form).await?;
|
||||||
|
|
||||||
UpdateCommunity::send(
|
|
||||||
updated_community.into(),
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let op = UserOperationCrud::EditCommunity;
|
let op = UserOperationCrud::EditCommunity;
|
||||||
send_community_ws_message(data.community_id, op, websocket_id, None, context).await
|
send_community_ws_message(data.community_id, op, websocket_id, None, context).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use actix_web::web::Data;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{GetCommunityResponse, TransferCommunity},
|
community::{GetCommunityResponse, TransferCommunity},
|
||||||
|
context::LemmyContext,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -14,7 +15,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonViewSafe};
|
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonViewSafe};
|
||||||
use lemmy_utils::{error::LemmyError, location_info, ConnectionId};
|
use lemmy_utils::{error::LemmyError, location_info, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
// TODO: we dont do anything for federation here, it should be updated the next time the community
|
// TODO: we dont do anything for federation here, it should be updated the next time the community
|
||||||
// gets fetched. i hope we can get rid of the community creator role soon.
|
// gets fetched. i hope we can get rid of the community creator role soon.
|
||||||
|
|
|
@ -1,77 +1,8 @@
|
||||||
use actix_web::{web, web::Data};
|
use actix_web::web::Data;
|
||||||
use captcha::Captcha;
|
use captcha::Captcha;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{context::LemmyContext, utils::local_site_to_slur_regex};
|
||||||
comment::{
|
|
||||||
CreateCommentLike,
|
|
||||||
CreateCommentReport,
|
|
||||||
ListCommentReports,
|
|
||||||
ResolveCommentReport,
|
|
||||||
SaveComment,
|
|
||||||
},
|
|
||||||
community::{
|
|
||||||
AddModToCommunity,
|
|
||||||
BanFromCommunity,
|
|
||||||
BlockCommunity,
|
|
||||||
FollowCommunity,
|
|
||||||
TransferCommunity,
|
|
||||||
},
|
|
||||||
person::{
|
|
||||||
AddAdmin,
|
|
||||||
BanPerson,
|
|
||||||
BlockPerson,
|
|
||||||
ChangePassword,
|
|
||||||
GetBannedPersons,
|
|
||||||
GetCaptcha,
|
|
||||||
GetPersonMentions,
|
|
||||||
GetReplies,
|
|
||||||
GetReportCount,
|
|
||||||
GetUnreadCount,
|
|
||||||
Login,
|
|
||||||
MarkAllAsRead,
|
|
||||||
MarkCommentReplyAsRead,
|
|
||||||
MarkPersonMentionAsRead,
|
|
||||||
PasswordChangeAfterReset,
|
|
||||||
PasswordReset,
|
|
||||||
SaveUserSettings,
|
|
||||||
VerifyEmail,
|
|
||||||
},
|
|
||||||
post::{
|
|
||||||
CreatePostLike,
|
|
||||||
CreatePostReport,
|
|
||||||
GetSiteMetadata,
|
|
||||||
ListPostReports,
|
|
||||||
LockPost,
|
|
||||||
MarkPostAsRead,
|
|
||||||
ResolvePostReport,
|
|
||||||
SavePost,
|
|
||||||
StickyPost,
|
|
||||||
},
|
|
||||||
private_message::{
|
|
||||||
CreatePrivateMessageReport,
|
|
||||||
ListPrivateMessageReports,
|
|
||||||
MarkPrivateMessageAsRead,
|
|
||||||
ResolvePrivateMessageReport,
|
|
||||||
},
|
|
||||||
site::{
|
|
||||||
ApproveRegistrationApplication,
|
|
||||||
GetModlog,
|
|
||||||
GetUnreadRegistrationApplicationCount,
|
|
||||||
LeaveAdmin,
|
|
||||||
ListRegistrationApplications,
|
|
||||||
PurgeComment,
|
|
||||||
PurgeCommunity,
|
|
||||||
PurgePerson,
|
|
||||||
PurgePost,
|
|
||||||
ResolveObject,
|
|
||||||
Search,
|
|
||||||
},
|
|
||||||
utils::local_site_to_slur_regex,
|
|
||||||
websocket::{CommunityJoin, ModJoin, PostJoin, UserJoin},
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::source::local_site::LocalSite;
|
use lemmy_db_schema::source::local_site::LocalSite;
|
||||||
use lemmy_utils::{error::LemmyError, utils::check_slurs, ConnectionId};
|
use lemmy_utils::{error::LemmyError, utils::check_slurs, ConnectionId};
|
||||||
use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
mod comment;
|
mod comment;
|
||||||
mod comment_report;
|
mod comment_report;
|
||||||
|
@ -95,182 +26,6 @@ pub trait Perform {
|
||||||
) -> Result<Self::Response, LemmyError>;
|
) -> Result<Self::Response, LemmyError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn match_websocket_operation(
|
|
||||||
context: LemmyContext,
|
|
||||||
id: ConnectionId,
|
|
||||||
op: UserOperation,
|
|
||||||
data: &str,
|
|
||||||
) -> Result<String, LemmyError> {
|
|
||||||
match op {
|
|
||||||
// User ops
|
|
||||||
UserOperation::Login => do_websocket_operation::<Login>(context, id, op, data).await,
|
|
||||||
UserOperation::GetCaptcha => do_websocket_operation::<GetCaptcha>(context, id, op, data).await,
|
|
||||||
UserOperation::GetReplies => do_websocket_operation::<GetReplies>(context, id, op, data).await,
|
|
||||||
UserOperation::AddAdmin => do_websocket_operation::<AddAdmin>(context, id, op, data).await,
|
|
||||||
UserOperation::GetUnreadRegistrationApplicationCount => {
|
|
||||||
do_websocket_operation::<GetUnreadRegistrationApplicationCount>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::ListRegistrationApplications => {
|
|
||||||
do_websocket_operation::<ListRegistrationApplications>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::ApproveRegistrationApplication => {
|
|
||||||
do_websocket_operation::<ApproveRegistrationApplication>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::BanPerson => do_websocket_operation::<BanPerson>(context, id, op, data).await,
|
|
||||||
UserOperation::GetBannedPersons => {
|
|
||||||
do_websocket_operation::<GetBannedPersons>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::BlockPerson => {
|
|
||||||
do_websocket_operation::<BlockPerson>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::GetPersonMentions => {
|
|
||||||
do_websocket_operation::<GetPersonMentions>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::MarkPersonMentionAsRead => {
|
|
||||||
do_websocket_operation::<MarkPersonMentionAsRead>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::MarkCommentReplyAsRead => {
|
|
||||||
do_websocket_operation::<MarkCommentReplyAsRead>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::MarkAllAsRead => {
|
|
||||||
do_websocket_operation::<MarkAllAsRead>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::PasswordReset => {
|
|
||||||
do_websocket_operation::<PasswordReset>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::PasswordChange => {
|
|
||||||
do_websocket_operation::<PasswordChangeAfterReset>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::UserJoin => do_websocket_operation::<UserJoin>(context, id, op, data).await,
|
|
||||||
UserOperation::PostJoin => do_websocket_operation::<PostJoin>(context, id, op, data).await,
|
|
||||||
UserOperation::CommunityJoin => {
|
|
||||||
do_websocket_operation::<CommunityJoin>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::ModJoin => do_websocket_operation::<ModJoin>(context, id, op, data).await,
|
|
||||||
UserOperation::SaveUserSettings => {
|
|
||||||
do_websocket_operation::<SaveUserSettings>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::ChangePassword => {
|
|
||||||
do_websocket_operation::<ChangePassword>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::GetReportCount => {
|
|
||||||
do_websocket_operation::<GetReportCount>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::GetUnreadCount => {
|
|
||||||
do_websocket_operation::<GetUnreadCount>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::VerifyEmail => {
|
|
||||||
do_websocket_operation::<VerifyEmail>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
|
|
||||||
// Private Message ops
|
|
||||||
UserOperation::MarkPrivateMessageAsRead => {
|
|
||||||
do_websocket_operation::<MarkPrivateMessageAsRead>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::CreatePrivateMessageReport => {
|
|
||||||
do_websocket_operation::<CreatePrivateMessageReport>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::ResolvePrivateMessageReport => {
|
|
||||||
do_websocket_operation::<ResolvePrivateMessageReport>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::ListPrivateMessageReports => {
|
|
||||||
do_websocket_operation::<ListPrivateMessageReports>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
|
|
||||||
// Site ops
|
|
||||||
UserOperation::GetModlog => do_websocket_operation::<GetModlog>(context, id, op, data).await,
|
|
||||||
UserOperation::PurgePerson => {
|
|
||||||
do_websocket_operation::<PurgePerson>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::PurgeCommunity => {
|
|
||||||
do_websocket_operation::<PurgeCommunity>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::PurgePost => do_websocket_operation::<PurgePost>(context, id, op, data).await,
|
|
||||||
UserOperation::PurgeComment => {
|
|
||||||
do_websocket_operation::<PurgeComment>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::Search => do_websocket_operation::<Search>(context, id, op, data).await,
|
|
||||||
UserOperation::ResolveObject => {
|
|
||||||
do_websocket_operation::<ResolveObject>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::TransferCommunity => {
|
|
||||||
do_websocket_operation::<TransferCommunity>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::LeaveAdmin => do_websocket_operation::<LeaveAdmin>(context, id, op, data).await,
|
|
||||||
|
|
||||||
// Community ops
|
|
||||||
UserOperation::FollowCommunity => {
|
|
||||||
do_websocket_operation::<FollowCommunity>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::BlockCommunity => {
|
|
||||||
do_websocket_operation::<BlockCommunity>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::BanFromCommunity => {
|
|
||||||
do_websocket_operation::<BanFromCommunity>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::AddModToCommunity => {
|
|
||||||
do_websocket_operation::<AddModToCommunity>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
|
|
||||||
// Post ops
|
|
||||||
UserOperation::LockPost => do_websocket_operation::<LockPost>(context, id, op, data).await,
|
|
||||||
UserOperation::StickyPost => do_websocket_operation::<StickyPost>(context, id, op, data).await,
|
|
||||||
UserOperation::CreatePostLike => {
|
|
||||||
do_websocket_operation::<CreatePostLike>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::MarkPostAsRead => {
|
|
||||||
do_websocket_operation::<MarkPostAsRead>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::SavePost => do_websocket_operation::<SavePost>(context, id, op, data).await,
|
|
||||||
UserOperation::CreatePostReport => {
|
|
||||||
do_websocket_operation::<CreatePostReport>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::ListPostReports => {
|
|
||||||
do_websocket_operation::<ListPostReports>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::ResolvePostReport => {
|
|
||||||
do_websocket_operation::<ResolvePostReport>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::GetSiteMetadata => {
|
|
||||||
do_websocket_operation::<GetSiteMetadata>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comment ops
|
|
||||||
UserOperation::SaveComment => {
|
|
||||||
do_websocket_operation::<SaveComment>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::CreateCommentLike => {
|
|
||||||
do_websocket_operation::<CreateCommentLike>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::CreateCommentReport => {
|
|
||||||
do_websocket_operation::<CreateCommentReport>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::ListCommentReports => {
|
|
||||||
do_websocket_operation::<ListCommentReports>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperation::ResolveCommentReport => {
|
|
||||||
do_websocket_operation::<ResolveCommentReport>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn do_websocket_operation<'a, 'b, Data>(
|
|
||||||
context: LemmyContext,
|
|
||||||
id: ConnectionId,
|
|
||||||
op: UserOperation,
|
|
||||||
data: &str,
|
|
||||||
) -> Result<String, LemmyError>
|
|
||||||
where
|
|
||||||
for<'de> Data: Deserialize<'de> + 'a,
|
|
||||||
Data: Perform,
|
|
||||||
{
|
|
||||||
let parsed_data: Data = serde_json::from_str(data)?;
|
|
||||||
let res = parsed_data
|
|
||||||
.perform(&web::Data::new(context), Some(id))
|
|
||||||
.await?;
|
|
||||||
serialize_websocket_message(&op, &res)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Converts the captcha to a base64 encoded wav audio file
|
/// Converts the captcha to a base64 encoded wav audio file
|
||||||
pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> String {
|
pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> String {
|
||||||
let letters = captcha.as_wav();
|
let letters = captcha.as_wav();
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{AddAdmin, AddAdminResponse},
|
person::{AddAdmin, AddAdminResponse},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{get_local_user_view_from_jwt, is_admin},
|
||||||
|
websocket::{messages::SendAllMessage, UserOperation},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -13,7 +15,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{messages::SendAllMessage, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for AddAdmin {
|
impl Perform for AddAdmin {
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{BanPerson, BanPersonResponse},
|
person::{BanPerson, BanPersonResponse},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin, remove_user_data},
|
utils::{get_local_user_view_from_jwt, is_admin, remove_user_data},
|
||||||
};
|
websocket::{messages::SendAllMessage, UserOperation},
|
||||||
use lemmy_apub::{
|
|
||||||
activities::block::SiteOrCommunity,
|
|
||||||
protocol::activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser},
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -15,10 +13,8 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::SiteView;
|
|
||||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||||
use lemmy_utils::{error::LemmyError, utils::naive_from_unix, ConnectionId};
|
use lemmy_utils::{error::LemmyError, utils::naive_from_unix, ConnectionId};
|
||||||
use lemmy_websocket::{messages::SendAllMessage, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for BanPerson {
|
impl Perform for BanPerson {
|
||||||
|
@ -78,32 +74,6 @@ impl Perform for BanPerson {
|
||||||
let person_id = data.person_id;
|
let person_id = data.person_id;
|
||||||
let person_view = PersonViewSafe::read(context.pool(), person_id).await?;
|
let person_view = PersonViewSafe::read(context.pool(), person_id).await?;
|
||||||
|
|
||||||
let site = SiteOrCommunity::Site(SiteView::read_local(context.pool()).await?.site.into());
|
|
||||||
// if the action affects a local user, federate to other instances
|
|
||||||
if person.local {
|
|
||||||
if ban {
|
|
||||||
BlockUser::send(
|
|
||||||
&site,
|
|
||||||
&person.into(),
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
remove_data,
|
|
||||||
data.reason.clone(),
|
|
||||||
expires,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
} else {
|
|
||||||
UndoBlockUser::send(
|
|
||||||
&site,
|
|
||||||
&person.into(),
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
data.reason.clone(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let res = BanPersonResponse {
|
let res = BanPersonResponse {
|
||||||
person_view,
|
person_view,
|
||||||
banned: data.ban,
|
banned: data.ban,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{BlockPerson, BlockPersonResponse},
|
person::{BlockPerson, BlockPersonResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
|
@ -10,7 +11,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for BlockPerson {
|
impl Perform for BlockPerson {
|
||||||
|
|
|
@ -2,12 +2,12 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use bcrypt::verify;
|
use bcrypt::verify;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{ChangePassword, LoginResponse},
|
person::{ChangePassword, LoginResponse},
|
||||||
utils::{get_local_user_view_from_jwt, password_length_check},
|
utils::{get_local_user_view_from_jwt, password_length_check},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::local_user::LocalUser;
|
use lemmy_db_schema::source::local_user::LocalUser;
|
||||||
use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
|
use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for ChangePassword {
|
impl Perform for ChangePassword {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{LoginResponse, PasswordChangeAfterReset},
|
person::{LoginResponse, PasswordChangeAfterReset},
|
||||||
utils::password_length_check,
|
utils::password_length_check,
|
||||||
};
|
};
|
||||||
|
@ -10,7 +11,6 @@ use lemmy_db_schema::source::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::SiteView;
|
use lemmy_db_views::structs::SiteView;
|
||||||
use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
|
use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for PasswordChangeAfterReset {
|
impl Perform for PasswordChangeAfterReset {
|
||||||
|
|
|
@ -2,10 +2,13 @@ use crate::{captcha_as_wav_base64, Perform};
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use captcha::{gen, Difficulty};
|
use captcha::{gen, Difficulty};
|
||||||
use chrono::Duration;
|
use chrono::Duration;
|
||||||
use lemmy_api_common::person::{CaptchaResponse, GetCaptcha, GetCaptchaResponse};
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
|
person::{CaptchaResponse, GetCaptcha, GetCaptchaResponse},
|
||||||
|
websocket::messages::CaptchaItem,
|
||||||
|
};
|
||||||
use lemmy_db_schema::{source::local_site::LocalSite, utils::naive_now};
|
use lemmy_db_schema::{source::local_site::LocalSite, utils::naive_now};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{messages::CaptchaItem, LemmyContext};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for GetCaptcha {
|
impl Perform for GetCaptcha {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{BannedPersonsResponse, GetBannedPersons},
|
person::{BannedPersonsResponse, GetBannedPersons},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{get_local_user_view_from_jwt, is_admin},
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for GetBannedPersons {
|
impl Perform for GetBannedPersons {
|
||||||
|
|
|
@ -2,13 +2,13 @@ use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use bcrypt::verify;
|
use bcrypt::verify;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{Login, LoginResponse},
|
person::{Login, LoginResponse},
|
||||||
utils::{check_registration_application, check_user_valid},
|
utils::{check_registration_application, check_user_valid},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::local_site::LocalSite;
|
use lemmy_db_schema::source::local_site::LocalSite;
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
|
use lemmy_utils::{claims::Claims, error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for Login {
|
impl Perform for Login {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{GetPersonMentions, GetPersonMentionsResponse},
|
person::{GetPersonMentions, GetPersonMentionsResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::person_mention_view::PersonMentionQuery;
|
use lemmy_db_views_actor::person_mention_view::PersonMentionQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for GetPersonMentions {
|
impl Perform for GetPersonMentions {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{GetReplies, GetRepliesResponse},
|
person::{GetReplies, GetRepliesResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::comment_reply_view::CommentReplyQuery;
|
use lemmy_db_views_actor::comment_reply_view::CommentReplyQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for GetReplies {
|
impl Perform for GetReplies {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{GetRepliesResponse, MarkAllAsRead},
|
person::{GetRepliesResponse, MarkAllAsRead},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
|
@ -10,7 +11,6 @@ use lemmy_db_schema::source::{
|
||||||
private_message::PrivateMessage,
|
private_message::PrivateMessage,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for MarkAllAsRead {
|
impl Perform for MarkAllAsRead {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{MarkPersonMentionAsRead, PersonMentionResponse},
|
person::{MarkPersonMentionAsRead, PersonMentionResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
|
@ -10,7 +11,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::PersonMentionView;
|
use lemmy_db_views_actor::structs::PersonMentionView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for MarkPersonMentionAsRead {
|
impl Perform for MarkPersonMentionAsRead {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{CommentReplyResponse, MarkCommentReplyAsRead},
|
person::{CommentReplyResponse, MarkCommentReplyAsRead},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
|
@ -10,7 +11,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::CommentReplyView;
|
use lemmy_db_views_actor::structs::CommentReplyView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for MarkCommentReplyAsRead {
|
impl Perform for MarkCommentReplyAsRead {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{GetUnreadCount, GetUnreadCountResponse},
|
person::{GetUnreadCount, GetUnreadCountResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::PrivateMessageView;
|
use lemmy_db_views::structs::PrivateMessageView;
|
||||||
use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView};
|
use lemmy_db_views_actor::structs::{CommentReplyView, PersonMentionView};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for GetUnreadCount {
|
impl Perform for GetUnreadCount {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{GetReportCount, GetReportCountResponse},
|
person::{GetReportCount, GetReportCountResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{CommentReportView, PostReportView, PrivateMessageReportView};
|
use lemmy_db_views::structs::{CommentReportView, PostReportView, PrivateMessageReportView};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for GetReportCount {
|
impl Perform for GetReportCount {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{PasswordReset, PasswordResetResponse},
|
person::{PasswordReset, PasswordResetResponse},
|
||||||
utils::send_password_reset_email,
|
utils::send_password_reset_email,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for PasswordReset {
|
impl Perform for PasswordReset {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{LoginResponse, SaveUserSettings},
|
person::{LoginResponse, SaveUserSettings},
|
||||||
utils::{get_local_user_view_from_jwt, send_verification_email},
|
utils::{get_local_user_view_from_jwt, send_verification_email},
|
||||||
};
|
};
|
||||||
|
@ -20,7 +21,6 @@ use lemmy_utils::{
|
||||||
utils::{is_valid_display_name, is_valid_matrix_id},
|
utils::{is_valid_display_name, is_valid_matrix_id},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for SaveUserSettings {
|
impl Perform for SaveUserSettings {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{VerifyEmail, VerifyEmailResponse},
|
person::{VerifyEmail, VerifyEmailResponse},
|
||||||
utils::send_email_verification_success,
|
utils::send_email_verification_success,
|
||||||
};
|
};
|
||||||
|
@ -13,7 +14,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for VerifyEmail {
|
impl Perform for VerifyEmail {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{GetSiteMetadata, GetSiteMetadataResponse},
|
post::{GetSiteMetadata, GetSiteMetadataResponse},
|
||||||
request::fetch_site_metadata,
|
request::fetch_site_metadata,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for GetSiteMetadata {
|
impl Perform for GetSiteMetadata {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{CreatePostLike, PostResponse},
|
post::{CreatePostLike, PostResponse},
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
|
@ -9,14 +10,7 @@ use lemmy_api_common::{
|
||||||
get_local_user_view_from_jwt,
|
get_local_user_view_from_jwt,
|
||||||
mark_post_as_read,
|
mark_post_as_read,
|
||||||
},
|
},
|
||||||
};
|
websocket::{send::send_post_ws_message, UserOperation},
|
||||||
use lemmy_apub::{
|
|
||||||
fetcher::post_or_comment::PostOrComment,
|
|
||||||
objects::post::ApubPost,
|
|
||||||
protocol::activities::voting::{
|
|
||||||
undo_vote::UndoVote,
|
|
||||||
vote::{Vote, VoteType},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -26,7 +20,6 @@ use lemmy_db_schema::{
|
||||||
traits::{Crud, Likeable},
|
traits::{Crud, Likeable},
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for CreatePostLike {
|
impl Perform for CreatePostLike {
|
||||||
|
@ -48,7 +41,7 @@ impl Perform for CreatePostLike {
|
||||||
|
|
||||||
// Check for a community ban
|
// Check for a community ban
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let post: ApubPost = Post::read(context.pool(), post_id).await?.into();
|
let post = Post::read(context.pool(), post_id).await?;
|
||||||
|
|
||||||
check_community_ban(local_user_view.person.id, post.community_id, context.pool()).await?;
|
check_community_ban(local_user_view.person.id, post.community_id, context.pool()).await?;
|
||||||
check_community_deleted_or_removed(post.community_id, context.pool()).await?;
|
check_community_deleted_or_removed(post.community_id, context.pool()).await?;
|
||||||
|
@ -64,9 +57,6 @@ impl Perform for CreatePostLike {
|
||||||
|
|
||||||
PostLike::remove(context.pool(), person_id, post_id).await?;
|
PostLike::remove(context.pool(), person_id, post_id).await?;
|
||||||
|
|
||||||
let community_id = post.community_id;
|
|
||||||
let object = PostOrComment::Post(Box::new(post));
|
|
||||||
|
|
||||||
// Only add the like if the score isnt 0
|
// Only add the like if the score isnt 0
|
||||||
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
|
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
|
||||||
if do_add {
|
if do_add {
|
||||||
|
@ -74,25 +64,6 @@ impl Perform for CreatePostLike {
|
||||||
PostLike::like(context.pool(), &like_form2)
|
PostLike::like(context.pool(), &like_form2)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;
|
||||||
|
|
||||||
Vote::send(
|
|
||||||
&object,
|
|
||||||
&local_user_view.person.clone().into(),
|
|
||||||
community_id,
|
|
||||||
like_form.score.try_into()?,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
} else {
|
|
||||||
// API doesn't distinguish between Undo/Like and Undo/Dislike
|
|
||||||
UndoVote::send(
|
|
||||||
&object,
|
|
||||||
&local_user_view.person.clone().into(),
|
|
||||||
community_id,
|
|
||||||
VoteType::Like,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the post as read
|
// Mark the post as read
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{LockPost, PostResponse},
|
post::{LockPost, PostResponse},
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
|
@ -8,10 +9,7 @@ use lemmy_api_common::{
|
||||||
get_local_user_view_from_jwt,
|
get_local_user_view_from_jwt,
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
},
|
},
|
||||||
};
|
websocket::{send::send_post_ws_message, UserOperation},
|
||||||
use lemmy_apub::{
|
|
||||||
objects::post::ApubPost,
|
|
||||||
protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -21,7 +19,6 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for LockPost {
|
impl Perform for LockPost {
|
||||||
|
@ -59,13 +56,12 @@ impl Perform for LockPost {
|
||||||
// Update the post
|
// Update the post
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let locked = data.locked;
|
let locked = data.locked;
|
||||||
let updated_post: ApubPost = Post::update(
|
Post::update(
|
||||||
context.pool(),
|
context.pool(),
|
||||||
post_id,
|
post_id,
|
||||||
&PostUpdateForm::builder().locked(Some(locked)).build(),
|
&PostUpdateForm::builder().locked(Some(locked)).build(),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.into();
|
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModLockPostForm {
|
let form = ModLockPostForm {
|
||||||
|
@ -75,15 +71,6 @@ impl Perform for LockPost {
|
||||||
};
|
};
|
||||||
ModLockPost::create(context.pool(), &form).await?;
|
ModLockPost::create(context.pool(), &form).await?;
|
||||||
|
|
||||||
// apub updates
|
|
||||||
CreateOrUpdatePage::send(
|
|
||||||
updated_post,
|
|
||||||
&local_user_view.person.clone().into(),
|
|
||||||
CreateOrUpdateType::Update,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
send_post_ws_message(
|
send_post_ws_message(
|
||||||
data.post_id,
|
data.post_id,
|
||||||
UserOperation::LockPost,
|
UserOperation::LockPost,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{MarkPostAsRead, PostResponse},
|
post::{MarkPostAsRead, PostResponse},
|
||||||
utils::{get_local_user_view_from_jwt, mark_post_as_read, mark_post_as_unread},
|
utils::{get_local_user_view_from_jwt, mark_post_as_read, mark_post_as_unread},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::PostView;
|
use lemmy_db_views::structs::PostView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for MarkPostAsRead {
|
impl Perform for MarkPostAsRead {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{PostResponse, SavePost},
|
post::{PostResponse, SavePost},
|
||||||
utils::{get_local_user_view_from_jwt, mark_post_as_read},
|
utils::{get_local_user_view_from_jwt, mark_post_as_read},
|
||||||
};
|
};
|
||||||
|
@ -10,7 +11,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::PostView;
|
use lemmy_db_views::structs::PostView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for SavePost {
|
impl Perform for SavePost {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{PostResponse, StickyPost},
|
post::{PostResponse, StickyPost},
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
|
@ -8,10 +9,7 @@ use lemmy_api_common::{
|
||||||
get_local_user_view_from_jwt,
|
get_local_user_view_from_jwt,
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
},
|
},
|
||||||
};
|
websocket::{send::send_post_ws_message, UserOperation},
|
||||||
use lemmy_apub::{
|
|
||||||
objects::post::ApubPost,
|
|
||||||
protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -21,7 +19,6 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for StickyPost {
|
impl Perform for StickyPost {
|
||||||
|
@ -59,13 +56,12 @@ impl Perform for StickyPost {
|
||||||
// Update the post
|
// Update the post
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let stickied = data.stickied;
|
let stickied = data.stickied;
|
||||||
let updated_post: ApubPost = Post::update(
|
Post::update(
|
||||||
context.pool(),
|
context.pool(),
|
||||||
post_id,
|
post_id,
|
||||||
&PostUpdateForm::builder().stickied(Some(stickied)).build(),
|
&PostUpdateForm::builder().stickied(Some(stickied)).build(),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.into();
|
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModStickyPostForm {
|
let form = ModStickyPostForm {
|
||||||
|
@ -76,16 +72,6 @@ impl Perform for StickyPost {
|
||||||
|
|
||||||
ModStickyPost::create(context.pool(), &form).await?;
|
ModStickyPost::create(context.pool(), &form).await?;
|
||||||
|
|
||||||
// Apub updates
|
|
||||||
// TODO stickied should pry work like locked for ease of use
|
|
||||||
CreateOrUpdatePage::send(
|
|
||||||
updated_post,
|
|
||||||
&local_user_view.person.clone().into(),
|
|
||||||
CreateOrUpdateType::Update,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
send_post_ws_message(
|
send_post_ws_message(
|
||||||
data.post_id,
|
data.post_id,
|
||||||
UserOperation::StickyPost,
|
UserOperation::StickyPost,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use crate::{check_report_reason, Perform};
|
use crate::{check_report_reason, Perform};
|
||||||
use activitypub_federation::core::object_id::ObjectId;
|
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{CreatePostReport, PostReportResponse},
|
post::{CreatePostReport, PostReportResponse},
|
||||||
utils::{check_community_ban, get_local_user_view_from_jwt},
|
utils::{check_community_ban, get_local_user_view_from_jwt},
|
||||||
|
websocket::{messages::SendModRoomMessage, UserOperation},
|
||||||
};
|
};
|
||||||
use lemmy_apub::protocol::activities::community::report::Report;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
local_site::LocalSite,
|
local_site::LocalSite,
|
||||||
|
@ -15,7 +15,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{PostReportView, PostView};
|
use lemmy_db_views::structs::{PostReportView, PostView};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
/// Creates a post report and notifies the moderators of the community
|
/// Creates a post report and notifies the moderators of the community
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
|
@ -66,15 +65,6 @@ impl Perform for CreatePostReport {
|
||||||
websocket_id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
Report::send(
|
|
||||||
ObjectId::new(post_view.post.ap_id),
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
ObjectId::new(post_view.community.actor_id),
|
|
||||||
reason.to_string(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{ListPostReports, ListPostReportsResponse},
|
post::{ListPostReports, ListPostReportsResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::post_report_view::PostReportQuery;
|
use lemmy_db_views::post_report_view::PostReportQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
/// Lists post reports for a community if an id is supplied
|
/// Lists post reports for a community if an id is supplied
|
||||||
/// or returns all post reports for communities a user moderates
|
/// or returns all post reports for communities a user moderates
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{PostReportResponse, ResolvePostReport},
|
post::{PostReportResponse, ResolvePostReport},
|
||||||
utils::{get_local_user_view_from_jwt, is_mod_or_admin},
|
utils::{get_local_user_view_from_jwt, is_mod_or_admin},
|
||||||
|
websocket::{messages::SendModRoomMessage, UserOperation},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
|
use lemmy_db_schema::{source::post_report::PostReport, traits::Reportable};
|
||||||
use lemmy_db_views::structs::PostReportView;
|
use lemmy_db_views::structs::PostReportView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
/// Resolves or unresolves a post report and notifies the moderators of the community
|
/// Resolves or unresolves a post report and notifies the moderators of the community
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse},
|
private_message::{MarkPrivateMessageAsRead, PrivateMessageResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
|
websocket::{send::send_pm_ws_message, UserOperation},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
|
source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for MarkPrivateMessageAsRead {
|
impl Perform for MarkPrivateMessageAsRead {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use crate::{check_report_reason, Perform};
|
use crate::{check_report_reason, Perform};
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse},
|
private_message::{CreatePrivateMessageReport, PrivateMessageReportResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
|
websocket::{messages::SendModRoomMessage, UserOperation},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::CommunityId,
|
newtypes::CommunityId,
|
||||||
|
@ -15,7 +17,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::PrivateMessageReportView;
|
use lemmy_db_views::structs::PrivateMessageReportView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for CreatePrivateMessageReport {
|
impl Perform for CreatePrivateMessageReport {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
private_message::{ListPrivateMessageReports, ListPrivateMessageReportsResponse},
|
private_message::{ListPrivateMessageReports, ListPrivateMessageReportsResponse},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{get_local_user_view_from_jwt, is_admin},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::private_message_report_view::PrivateMessageReportQuery;
|
use lemmy_db_views::private_message_report_view::PrivateMessageReportQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for ListPrivateMessageReports {
|
impl Perform for ListPrivateMessageReports {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
|
private_message::{PrivateMessageReportResponse, ResolvePrivateMessageReport},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{get_local_user_view_from_jwt, is_admin},
|
||||||
|
websocket::{messages::SendModRoomMessage, UserOperation},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::CommunityId,
|
newtypes::CommunityId,
|
||||||
|
@ -11,7 +13,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::PrivateMessageReportView;
|
use lemmy_db_views::structs::PrivateMessageReportView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{messages::SendModRoomMessage, LemmyContext, UserOperation};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for ResolvePrivateMessageReport {
|
impl Perform for ResolvePrivateMessageReport {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
site::{GetSiteResponse, LeaveAdmin},
|
site::{GetSiteResponse, LeaveAdmin},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{get_local_user_view_from_jwt, is_admin},
|
||||||
};
|
};
|
||||||
|
@ -17,7 +18,6 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views::structs::SiteView;
|
use lemmy_db_views::structs::SiteView;
|
||||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||||
use lemmy_utils::{error::LemmyError, version, ConnectionId};
|
use lemmy_utils::{error::LemmyError, version, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for LeaveAdmin {
|
impl Perform for LeaveAdmin {
|
||||||
|
|
|
@ -2,5 +2,3 @@ mod leave_admin;
|
||||||
mod mod_log;
|
mod mod_log;
|
||||||
mod purge;
|
mod purge;
|
||||||
mod registration_applications;
|
mod registration_applications;
|
||||||
mod resolve_object;
|
|
||||||
mod search;
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
site::{GetModlog, GetModlogResponse},
|
site::{GetModlog, GetModlogResponse},
|
||||||
utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_admin, is_mod_or_admin},
|
utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_admin, is_mod_or_admin},
|
||||||
};
|
};
|
||||||
|
@ -28,7 +29,6 @@ use lemmy_db_views_moderator::structs::{
|
||||||
ModlogListParams,
|
ModlogListParams,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
use ModlogActionType::*;
|
use ModlogActionType::*;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
site::{PurgeComment, PurgeItemResponse},
|
site::{PurgeComment, PurgeItemResponse},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{get_local_user_view_from_jwt, is_admin},
|
||||||
};
|
};
|
||||||
|
@ -12,7 +13,6 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for PurgeComment {
|
impl Perform for PurgeComment {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
request::purge_image_from_pictrs,
|
request::purge_image_from_pictrs,
|
||||||
site::{PurgeCommunity, PurgeItemResponse},
|
site::{PurgeCommunity, PurgeItemResponse},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin, purge_image_posts_for_community},
|
utils::{get_local_user_view_from_jwt, is_admin, purge_image_posts_for_community},
|
||||||
|
@ -13,7 +14,6 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for PurgeCommunity {
|
impl Perform for PurgeCommunity {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
request::purge_image_from_pictrs,
|
request::purge_image_from_pictrs,
|
||||||
site::{PurgeItemResponse, PurgePerson},
|
site::{PurgeItemResponse, PurgePerson},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin, purge_image_posts_for_person},
|
utils::{get_local_user_view_from_jwt, is_admin, purge_image_posts_for_person},
|
||||||
|
@ -13,7 +14,6 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for PurgePerson {
|
impl Perform for PurgePerson {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
request::purge_image_from_pictrs,
|
request::purge_image_from_pictrs,
|
||||||
site::{PurgeItemResponse, PurgePost},
|
site::{PurgeItemResponse, PurgePost},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{get_local_user_view_from_jwt, is_admin},
|
||||||
|
@ -13,7 +14,6 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for PurgePost {
|
impl Perform for PurgePost {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
site::{ApproveRegistrationApplication, RegistrationApplicationResponse},
|
site::{ApproveRegistrationApplication, RegistrationApplicationResponse},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin, send_application_approved_email},
|
utils::{get_local_user_view_from_jwt, is_admin, send_application_approved_email},
|
||||||
};
|
};
|
||||||
|
@ -14,7 +15,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
|
use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for ApproveRegistrationApplication {
|
impl Perform for ApproveRegistrationApplication {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
site::{ListRegistrationApplications, ListRegistrationApplicationsResponse},
|
site::{ListRegistrationApplications, ListRegistrationApplicationsResponse},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{get_local_user_view_from_jwt, is_admin},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::local_site::LocalSite;
|
use lemmy_db_schema::source::local_site::LocalSite;
|
||||||
use lemmy_db_views::registration_application_view::RegistrationApplicationQuery;
|
use lemmy_db_views::registration_application_view::RegistrationApplicationQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
/// Lists registration applications, filterable by undenied only.
|
/// Lists registration applications, filterable by undenied only.
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
site::{GetUnreadRegistrationApplicationCount, GetUnreadRegistrationApplicationCountResponse},
|
site::{GetUnreadRegistrationApplicationCount, GetUnreadRegistrationApplicationCountResponse},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{get_local_user_view_from_jwt, is_admin},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::local_site::LocalSite;
|
use lemmy_db_schema::source::local_site::LocalSite;
|
||||||
use lemmy_db_views::structs::RegistrationApplicationView;
|
use lemmy_db_views::structs::RegistrationApplicationView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for GetUnreadRegistrationApplicationCount {
|
impl Perform for GetUnreadRegistrationApplicationCount {
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
use crate::Perform;
|
use crate::Perform;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
websocket::{
|
websocket::{
|
||||||
CommunityJoin,
|
messages::{JoinCommunityRoom, JoinModRoom, JoinPostRoom, JoinUserRoom},
|
||||||
CommunityJoinResponse,
|
structs::{
|
||||||
ModJoin,
|
CommunityJoin,
|
||||||
ModJoinResponse,
|
CommunityJoinResponse,
|
||||||
PostJoin,
|
ModJoin,
|
||||||
PostJoinResponse,
|
ModJoinResponse,
|
||||||
UserJoin,
|
PostJoin,
|
||||||
UserJoinResponse,
|
PostJoinResponse,
|
||||||
|
UserJoin,
|
||||||
|
UserJoinResponse,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{
|
|
||||||
messages::{JoinCommunityRoom, JoinModRoom, JoinPostRoom, JoinUserRoom},
|
|
||||||
LemmyContext,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl Perform for UserJoin {
|
impl Perform for UserJoin {
|
||||||
|
|
|
@ -36,6 +36,17 @@ rosetta-i18n = { workspace = true, optional = true }
|
||||||
percent-encoding = { workspace = true, optional = true }
|
percent-encoding = { workspace = true, optional = true }
|
||||||
webpage = { version = "1.4.0", default-features = false, features = ["serde"], optional = true }
|
webpage = { version = "1.4.0", default-features = false, features = ["serde"], optional = true }
|
||||||
encoding = { version = "0.2.33", optional = true }
|
encoding = { version = "0.2.33", optional = true }
|
||||||
|
rand = { workspace = true }
|
||||||
|
serde_json = { workspace = true }
|
||||||
|
actix = { workspace = true }
|
||||||
|
anyhow = { workspace = true }
|
||||||
|
tokio = { workspace = true }
|
||||||
|
strum = { workspace = true }
|
||||||
|
strum_macros = { workspace = true }
|
||||||
|
opentelemetry = { workspace = true }
|
||||||
|
tracing-opentelemetry = { workspace = true }
|
||||||
|
actix-web-actors = { version = "4.1.0", default-features = false }
|
||||||
|
background-jobs = "0.13.0"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-rt = { workspace = true }
|
actix-rt = { workspace = true }
|
||||||
|
|
68
crates/api_common/src/context.rs
Normal file
68
crates/api_common/src/context.rs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
use crate::websocket::chat_server::ChatServer;
|
||||||
|
use actix::Addr;
|
||||||
|
use lemmy_db_schema::{source::secret::Secret, utils::DbPool};
|
||||||
|
use lemmy_utils::{
|
||||||
|
rate_limit::RateLimitCell,
|
||||||
|
settings::{structs::Settings, SETTINGS},
|
||||||
|
};
|
||||||
|
use reqwest_middleware::ClientWithMiddleware;
|
||||||
|
|
||||||
|
pub struct LemmyContext {
|
||||||
|
pool: DbPool,
|
||||||
|
chat_server: Addr<ChatServer>,
|
||||||
|
client: ClientWithMiddleware,
|
||||||
|
settings: Settings,
|
||||||
|
secret: Secret,
|
||||||
|
rate_limit_cell: RateLimitCell,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LemmyContext {
|
||||||
|
pub fn create(
|
||||||
|
pool: DbPool,
|
||||||
|
chat_server: Addr<ChatServer>,
|
||||||
|
client: ClientWithMiddleware,
|
||||||
|
settings: Settings,
|
||||||
|
secret: Secret,
|
||||||
|
rate_limit_cell: RateLimitCell,
|
||||||
|
) -> LemmyContext {
|
||||||
|
LemmyContext {
|
||||||
|
pool,
|
||||||
|
chat_server,
|
||||||
|
client,
|
||||||
|
settings,
|
||||||
|
secret,
|
||||||
|
rate_limit_cell,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn pool(&self) -> &DbPool {
|
||||||
|
&self.pool
|
||||||
|
}
|
||||||
|
pub fn chat_server(&self) -> &Addr<ChatServer> {
|
||||||
|
&self.chat_server
|
||||||
|
}
|
||||||
|
pub fn client(&self) -> &ClientWithMiddleware {
|
||||||
|
&self.client
|
||||||
|
}
|
||||||
|
pub fn settings(&self) -> &'static Settings {
|
||||||
|
&SETTINGS
|
||||||
|
}
|
||||||
|
pub fn secret(&self) -> &Secret {
|
||||||
|
&self.secret
|
||||||
|
}
|
||||||
|
pub fn settings_updated_channel(&self) -> &RateLimitCell {
|
||||||
|
&self.rate_limit_cell
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clone for LemmyContext {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
LemmyContext {
|
||||||
|
pool: self.pool.clone(),
|
||||||
|
chat_server: self.chat_server.clone(),
|
||||||
|
client: self.client.clone(),
|
||||||
|
settings: self.settings.clone(),
|
||||||
|
secret: self.secret.clone(),
|
||||||
|
rate_limit_cell: self.rate_limit_cell.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
pub mod community;
|
pub mod community;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
pub mod context;
|
||||||
pub mod person;
|
pub mod person;
|
||||||
pub mod post;
|
pub mod post;
|
||||||
pub mod private_message;
|
pub mod private_message;
|
||||||
|
@ -9,8 +11,11 @@ pub mod sensitive;
|
||||||
pub mod site;
|
pub mod site;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
pub mod websocket;
|
pub mod websocket;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate strum_macros;
|
||||||
pub extern crate lemmy_db_schema;
|
pub extern crate lemmy_db_schema;
|
||||||
pub extern crate lemmy_db_views;
|
pub extern crate lemmy_db_views;
|
||||||
pub extern crate lemmy_db_views_actor;
|
pub extern crate lemmy_db_views_actor;
|
||||||
|
|
|
@ -268,7 +268,7 @@ pub struct GetUnreadCountResponse {
|
||||||
pub private_messages: i64,
|
pub private_messages: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Default)]
|
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
|
||||||
pub struct VerifyEmail {
|
pub struct VerifyEmail {
|
||||||
pub token: String,
|
pub token: String,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::{request::purge_image_from_pictrs, sensitive::Sensitive, site::FederatedInstances};
|
use crate::{request::purge_image_from_pictrs, sensitive::Sensitive, site::FederatedInstances};
|
||||||
|
use anyhow::Context;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
impls::person::is_banned,
|
impls::person::is_banned,
|
||||||
newtypes::{CommunityId, LocalUserId, PersonId, PostId},
|
newtypes::{CommunityId, DbUrl, LocalUserId, PersonId, PostId},
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentUpdateForm},
|
comment::{Comment, CommentUpdateForm},
|
||||||
community::{Community, CommunityUpdateForm},
|
community::{Community, CommunityUpdateForm},
|
||||||
|
@ -34,6 +35,7 @@ use lemmy_utils::{
|
||||||
claims::Claims,
|
claims::Claims,
|
||||||
email::{send_email, translations::Lang},
|
email::{send_email, translations::Lang},
|
||||||
error::LemmyError,
|
error::LemmyError,
|
||||||
|
location_info,
|
||||||
rate_limit::RateLimitConfig,
|
rate_limit::RateLimitConfig,
|
||||||
settings::structs::Settings,
|
settings::structs::Settings,
|
||||||
utils::{build_slur_regex, generate_random_string},
|
utils::{build_slur_regex, generate_random_string},
|
||||||
|
@ -43,6 +45,7 @@ use reqwest_middleware::ClientWithMiddleware;
|
||||||
use rosetta_i18n::{Language, LanguageId};
|
use rosetta_i18n::{Language, LanguageId};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
use url::{ParseError, Url};
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn is_mod_or_admin(
|
pub async fn is_mod_or_admin(
|
||||||
|
@ -743,3 +746,65 @@ mod tests {
|
||||||
assert!(honeypot_check(&Some("message".to_string())).is_err());
|
assert!(honeypot_check(&Some("message".to_string())).is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum EndpointType {
|
||||||
|
Community,
|
||||||
|
Person,
|
||||||
|
Post,
|
||||||
|
Comment,
|
||||||
|
PrivateMessage,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generates an apub endpoint for a given domain, IE xyz.tld
|
||||||
|
pub fn generate_local_apub_endpoint(
|
||||||
|
endpoint_type: EndpointType,
|
||||||
|
name: &str,
|
||||||
|
domain: &str,
|
||||||
|
) -> Result<DbUrl, ParseError> {
|
||||||
|
let point = match endpoint_type {
|
||||||
|
EndpointType::Community => "c",
|
||||||
|
EndpointType::Person => "u",
|
||||||
|
EndpointType::Post => "post",
|
||||||
|
EndpointType::Comment => "comment",
|
||||||
|
EndpointType::PrivateMessage => "private_message",
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Url::parse(&format!("{}/{}/{}", domain, point, name))?.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_followers_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
|
||||||
|
Ok(Url::parse(&format!("{}/followers", actor_id))?.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
|
||||||
|
Ok(Url::parse(&format!("{}/inbox", actor_id))?.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_site_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
|
||||||
|
let mut actor_id: Url = actor_id.clone().into();
|
||||||
|
actor_id.set_path("site_inbox");
|
||||||
|
Ok(actor_id.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, LemmyError> {
|
||||||
|
let actor_id: Url = actor_id.clone().into();
|
||||||
|
let url = format!(
|
||||||
|
"{}://{}{}/inbox",
|
||||||
|
&actor_id.scheme(),
|
||||||
|
&actor_id.host_str().context(location_info!())?,
|
||||||
|
if let Some(port) = actor_id.port() {
|
||||||
|
format!(":{}", port)
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Ok(Url::parse(&url)?.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_outbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
|
||||||
|
Ok(Url::parse(&format!("{}/outbox", actor_id))?.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
|
||||||
|
Ok(Url::parse(&format!("{}/moderators", community_id))?.into())
|
||||||
|
}
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
messages::{CaptchaItem, StandardMessage, WsMessage},
|
comment::CommentResponse,
|
||||||
serialize_websocket_message,
|
context::LemmyContext,
|
||||||
LemmyContext,
|
post::PostResponse,
|
||||||
OperationType,
|
websocket::{
|
||||||
UserOperation,
|
messages::{CaptchaItem, StandardMessage, WsMessage},
|
||||||
UserOperationCrud,
|
serialize_websocket_message,
|
||||||
|
OperationType,
|
||||||
|
UserOperation,
|
||||||
|
UserOperationApub,
|
||||||
|
UserOperationCrud,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use anyhow::Context as acontext;
|
use anyhow::Context as acontext;
|
||||||
use lemmy_api_common::{comment::CommentResponse, post::PostResponse};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, LocalUserId, PostId},
|
newtypes::{CommunityId, LocalUserId, PostId},
|
||||||
source::secret::Secret,
|
source::secret::Secret,
|
||||||
|
@ -47,6 +51,13 @@ type MessageHandlerCrudType = fn(
|
||||||
data: &str,
|
data: &str,
|
||||||
) -> Pin<Box<dyn Future<Output = Result<String, LemmyError>> + '_>>;
|
) -> Pin<Box<dyn Future<Output = Result<String, LemmyError>> + '_>>;
|
||||||
|
|
||||||
|
type MessageHandlerApubType = fn(
|
||||||
|
context: LemmyContext,
|
||||||
|
id: ConnectionId,
|
||||||
|
op: UserOperationApub,
|
||||||
|
data: &str,
|
||||||
|
) -> Pin<Box<dyn Future<Output = Result<String, LemmyError>> + '_>>;
|
||||||
|
|
||||||
/// `ChatServer` manages chat rooms and responsible for coordinating chat
|
/// `ChatServer` manages chat rooms and responsible for coordinating chat
|
||||||
/// session.
|
/// session.
|
||||||
pub struct ChatServer {
|
pub struct ChatServer {
|
||||||
|
@ -81,6 +92,7 @@ pub struct ChatServer {
|
||||||
|
|
||||||
message_handler: MessageHandlerType,
|
message_handler: MessageHandlerType,
|
||||||
message_handler_crud: MessageHandlerCrudType,
|
message_handler_crud: MessageHandlerCrudType,
|
||||||
|
message_handler_apub: MessageHandlerApubType,
|
||||||
|
|
||||||
/// An HTTP Client
|
/// An HTTP Client
|
||||||
client: ClientWithMiddleware,
|
client: ClientWithMiddleware,
|
||||||
|
@ -102,6 +114,7 @@ impl ChatServer {
|
||||||
pool: DbPool,
|
pool: DbPool,
|
||||||
message_handler: MessageHandlerType,
|
message_handler: MessageHandlerType,
|
||||||
message_handler_crud: MessageHandlerCrudType,
|
message_handler_crud: MessageHandlerCrudType,
|
||||||
|
message_handler_apub: MessageHandlerApubType,
|
||||||
client: ClientWithMiddleware,
|
client: ClientWithMiddleware,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
secret: Secret,
|
secret: Secret,
|
||||||
|
@ -118,6 +131,7 @@ impl ChatServer {
|
||||||
captchas: Vec::new(),
|
captchas: Vec::new(),
|
||||||
message_handler,
|
message_handler,
|
||||||
message_handler_crud,
|
message_handler_crud,
|
||||||
|
message_handler_apub,
|
||||||
client,
|
client,
|
||||||
settings,
|
settings,
|
||||||
secret,
|
secret,
|
||||||
|
@ -450,16 +464,17 @@ impl ChatServer {
|
||||||
None => IpAddr("blank_ip".to_string()),
|
None => IpAddr("blank_ip".to_string()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let context = LemmyContext {
|
let context = LemmyContext::create(
|
||||||
pool: self.pool.clone(),
|
self.pool.clone(),
|
||||||
chat_server: ctx.address(),
|
ctx.address(),
|
||||||
client: self.client.clone(),
|
self.client.clone(),
|
||||||
settings: self.settings.clone(),
|
self.settings.clone(),
|
||||||
secret: self.secret.clone(),
|
self.secret.clone(),
|
||||||
rate_limit_cell: self.rate_limit_cell.clone(),
|
self.rate_limit_cell.clone(),
|
||||||
};
|
);
|
||||||
let message_handler_crud = self.message_handler_crud;
|
let message_handler_crud = self.message_handler_crud;
|
||||||
let message_handler = self.message_handler;
|
let message_handler = self.message_handler;
|
||||||
|
let message_handler_apub = self.message_handler_apub;
|
||||||
let rate_limiter = self.rate_limit_cell.clone();
|
let rate_limiter = self.rate_limit_cell.clone();
|
||||||
async move {
|
async move {
|
||||||
let json: Value = serde_json::from_str(&msg.msg)?;
|
let json: Value = serde_json::from_str(&msg.msg)?;
|
||||||
|
@ -479,15 +494,21 @@ impl ChatServer {
|
||||||
};
|
};
|
||||||
let fut = (message_handler_crud)(context, msg.id, user_operation_crud, data);
|
let fut = (message_handler_crud)(context, msg.id, user_operation_crud, data);
|
||||||
(passed, fut)
|
(passed, fut)
|
||||||
} else {
|
} else if let Ok(user_operation) = UserOperation::from_str(op) {
|
||||||
let user_operation = UserOperation::from_str(op)?;
|
|
||||||
let passed = match user_operation {
|
let passed = match user_operation {
|
||||||
UserOperation::GetCaptcha => rate_limiter.post().check(ip),
|
UserOperation::GetCaptcha => rate_limiter.post().check(ip),
|
||||||
UserOperation::Search => rate_limiter.search().check(ip),
|
|
||||||
_ => rate_limiter.message().check(ip),
|
_ => rate_limiter.message().check(ip),
|
||||||
};
|
};
|
||||||
let fut = (message_handler)(context, msg.id, user_operation, data);
|
let fut = (message_handler)(context, msg.id, user_operation, data);
|
||||||
(passed, fut)
|
(passed, fut)
|
||||||
|
} else {
|
||||||
|
let user_operation = UserOperationApub::from_str(op)?;
|
||||||
|
let passed = match user_operation {
|
||||||
|
UserOperationApub::Search => rate_limiter.search().check(ip),
|
||||||
|
_ => rate_limiter.message().check(ip),
|
||||||
|
};
|
||||||
|
let fut = (message_handler_apub)(context, msg.id, user_operation, data);
|
||||||
|
(passed, fut)
|
||||||
};
|
};
|
||||||
|
|
||||||
// if rate limit passed, execute api call future
|
// if rate limit passed, execute api call future
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{
|
use crate::websocket::{
|
||||||
chat_server::{ChatServer, SessionInfo},
|
chat_server::{ChatServer, SessionInfo},
|
||||||
messages::{
|
messages::{
|
||||||
CaptchaItem,
|
CaptchaItem,
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::UserOperation;
|
use crate::{comment::CommentResponse, post::PostResponse, websocket::UserOperation};
|
||||||
use actix::{prelude::*, Recipient};
|
use actix::{prelude::*, Recipient};
|
||||||
use lemmy_api_common::{comment::CommentResponse, post::PostResponse};
|
|
||||||
use lemmy_db_schema::newtypes::{CommunityId, LocalUserId, PostId};
|
use lemmy_db_schema::newtypes::{CommunityId, LocalUserId, PostId};
|
||||||
use lemmy_utils::{ConnectionId, IpAddr};
|
use lemmy_utils::{ConnectionId, IpAddr};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
|
@ -1,15 +1,4 @@
|
||||||
#[macro_use]
|
use lemmy_utils::error::LemmyError;
|
||||||
extern crate strum_macros;
|
|
||||||
|
|
||||||
use crate::chat_server::ChatServer;
|
|
||||||
use actix::Addr;
|
|
||||||
use lemmy_db_schema::{source::secret::Secret, utils::DbPool};
|
|
||||||
use lemmy_utils::{
|
|
||||||
error::LemmyError,
|
|
||||||
rate_limit::RateLimitCell,
|
|
||||||
settings::{structs::Settings, SETTINGS},
|
|
||||||
};
|
|
||||||
use reqwest_middleware::ClientWithMiddleware;
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
pub mod chat_server;
|
pub mod chat_server;
|
||||||
|
@ -17,66 +6,7 @@ pub mod handlers;
|
||||||
pub mod messages;
|
pub mod messages;
|
||||||
pub mod routes;
|
pub mod routes;
|
||||||
pub mod send;
|
pub mod send;
|
||||||
|
pub mod structs;
|
||||||
pub struct LemmyContext {
|
|
||||||
pool: DbPool,
|
|
||||||
chat_server: Addr<ChatServer>,
|
|
||||||
client: ClientWithMiddleware,
|
|
||||||
settings: Settings,
|
|
||||||
secret: Secret,
|
|
||||||
rate_limit_cell: RateLimitCell,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LemmyContext {
|
|
||||||
pub fn create(
|
|
||||||
pool: DbPool,
|
|
||||||
chat_server: Addr<ChatServer>,
|
|
||||||
client: ClientWithMiddleware,
|
|
||||||
settings: Settings,
|
|
||||||
secret: Secret,
|
|
||||||
settings_updated_channel: RateLimitCell,
|
|
||||||
) -> LemmyContext {
|
|
||||||
LemmyContext {
|
|
||||||
pool,
|
|
||||||
chat_server,
|
|
||||||
client,
|
|
||||||
settings,
|
|
||||||
secret,
|
|
||||||
rate_limit_cell: settings_updated_channel,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn pool(&self) -> &DbPool {
|
|
||||||
&self.pool
|
|
||||||
}
|
|
||||||
pub fn chat_server(&self) -> &Addr<ChatServer> {
|
|
||||||
&self.chat_server
|
|
||||||
}
|
|
||||||
pub fn client(&self) -> &ClientWithMiddleware {
|
|
||||||
&self.client
|
|
||||||
}
|
|
||||||
pub fn settings(&self) -> &'static Settings {
|
|
||||||
&SETTINGS
|
|
||||||
}
|
|
||||||
pub fn secret(&self) -> &Secret {
|
|
||||||
&self.secret
|
|
||||||
}
|
|
||||||
pub fn settings_updated_channel(&self) -> &RateLimitCell {
|
|
||||||
&self.rate_limit_cell
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Clone for LemmyContext {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
LemmyContext {
|
|
||||||
pool: self.pool.clone(),
|
|
||||||
chat_server: self.chat_server.clone(),
|
|
||||||
client: self.client.clone(),
|
|
||||||
settings: self.settings.clone(),
|
|
||||||
secret: self.secret.clone(),
|
|
||||||
rate_limit_cell: self.rate_limit_cell.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
struct WebsocketResponse<T> {
|
struct WebsocketResponse<T> {
|
||||||
|
@ -133,8 +63,6 @@ pub enum UserOperation {
|
||||||
ApproveRegistrationApplication,
|
ApproveRegistrationApplication,
|
||||||
BanPerson,
|
BanPerson,
|
||||||
GetBannedPersons,
|
GetBannedPersons,
|
||||||
Search,
|
|
||||||
ResolveObject,
|
|
||||||
MarkAllAsRead,
|
MarkAllAsRead,
|
||||||
SaveUserSettings,
|
SaveUserSettings,
|
||||||
TransferCommunity,
|
TransferCommunity,
|
||||||
|
@ -168,27 +96,23 @@ pub enum UserOperationCrud {
|
||||||
// Community
|
// Community
|
||||||
CreateCommunity,
|
CreateCommunity,
|
||||||
ListCommunities,
|
ListCommunities,
|
||||||
GetCommunity,
|
|
||||||
EditCommunity,
|
EditCommunity,
|
||||||
DeleteCommunity,
|
DeleteCommunity,
|
||||||
RemoveCommunity,
|
RemoveCommunity,
|
||||||
// Post
|
// Post
|
||||||
CreatePost,
|
CreatePost,
|
||||||
GetPost,
|
GetPost,
|
||||||
GetPosts,
|
|
||||||
EditPost,
|
EditPost,
|
||||||
DeletePost,
|
DeletePost,
|
||||||
RemovePost,
|
RemovePost,
|
||||||
// Comment
|
// Comment
|
||||||
CreateComment,
|
CreateComment,
|
||||||
GetComment,
|
GetComment,
|
||||||
GetComments,
|
|
||||||
EditComment,
|
EditComment,
|
||||||
DeleteComment,
|
DeleteComment,
|
||||||
RemoveComment,
|
RemoveComment,
|
||||||
// User
|
// User
|
||||||
Register,
|
Register,
|
||||||
GetPersonDetails,
|
|
||||||
DeleteAccount,
|
DeleteAccount,
|
||||||
// Private Message
|
// Private Message
|
||||||
CreatePrivateMessage,
|
CreatePrivateMessage,
|
||||||
|
@ -197,8 +121,20 @@ pub enum UserOperationCrud {
|
||||||
DeletePrivateMessage,
|
DeletePrivateMessage,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(EnumString, Display, Debug, Clone)]
|
||||||
|
pub enum UserOperationApub {
|
||||||
|
GetPosts,
|
||||||
|
GetCommunity,
|
||||||
|
GetComments,
|
||||||
|
GetPersonDetails,
|
||||||
|
Search,
|
||||||
|
ResolveObject,
|
||||||
|
}
|
||||||
|
|
||||||
pub trait OperationType {}
|
pub trait OperationType {}
|
||||||
|
|
||||||
impl OperationType for UserOperationCrud {}
|
impl OperationType for UserOperationCrud {}
|
||||||
|
|
||||||
impl OperationType for UserOperation {}
|
impl OperationType for UserOperation {}
|
||||||
|
|
||||||
|
impl OperationType for UserOperationApub {}
|
|
@ -1,7 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
chat_server::ChatServer,
|
context::LemmyContext,
|
||||||
messages::{Connect, Disconnect, StandardMessage, WsMessage},
|
websocket::{
|
||||||
LemmyContext,
|
chat_server::ChatServer,
|
||||||
|
messages::{Connect, Disconnect, StandardMessage, WsMessage},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use actix_web::{web, Error, HttpRequest, HttpResponse};
|
use actix_web::{web, Error, HttpRequest, HttpResponse};
|
|
@ -1,14 +1,14 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
messages::{SendComment, SendCommunityRoomMessage, SendPost, SendUserRoomMessage},
|
|
||||||
LemmyContext,
|
|
||||||
OperationType,
|
|
||||||
};
|
|
||||||
use lemmy_api_common::{
|
|
||||||
comment::CommentResponse,
|
comment::CommentResponse,
|
||||||
community::CommunityResponse,
|
community::CommunityResponse,
|
||||||
|
context::LemmyContext,
|
||||||
post::PostResponse,
|
post::PostResponse,
|
||||||
private_message::PrivateMessageResponse,
|
private_message::PrivateMessageResponse,
|
||||||
utils::{check_person_block, get_interface_language, send_email_to_user},
|
utils::{check_person_block, get_interface_language, send_email_to_user},
|
||||||
|
websocket::{
|
||||||
|
messages::{SendComment, SendCommunityRoomMessage, SendPost, SendUserRoomMessage},
|
||||||
|
OperationType,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId, PrivateMessageId},
|
newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId, PrivateMessageId},
|
|
@ -9,13 +9,11 @@ documentation.workspace = true
|
||||||
repository.workspace = true
|
repository.workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lemmy_apub = { workspace = true }
|
|
||||||
lemmy_utils = { workspace = true }
|
lemmy_utils = { workspace = true }
|
||||||
lemmy_db_schema = { workspace = true, features = ["full"] }
|
lemmy_db_schema = { workspace = true, features = ["full"] }
|
||||||
lemmy_db_views = { workspace = true, features = ["full"] }
|
lemmy_db_views = { workspace = true, features = ["full"] }
|
||||||
lemmy_db_views_actor = { workspace = true, features = ["full"] }
|
lemmy_db_views_actor = { workspace = true, features = ["full"] }
|
||||||
lemmy_api_common = { workspace = true, features = ["full"] }
|
lemmy_api_common = { workspace = true, features = ["full"] }
|
||||||
lemmy_websocket = { workspace = true }
|
|
||||||
activitypub_federation = { workspace = true }
|
activitypub_federation = { workspace = true }
|
||||||
bcrypt = { workspace = true }
|
bcrypt = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
|
|
@ -2,20 +2,21 @@ use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, CreateComment},
|
comment::{CommentResponse, CreateComment},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
check_community_deleted_or_removed,
|
check_community_deleted_or_removed,
|
||||||
check_post_deleted_or_removed,
|
check_post_deleted_or_removed,
|
||||||
|
generate_local_apub_endpoint,
|
||||||
get_local_user_view_from_jwt,
|
get_local_user_view_from_jwt,
|
||||||
get_post,
|
get_post,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
|
EndpointType,
|
||||||
|
},
|
||||||
|
websocket::{
|
||||||
|
send::{send_comment_ws_message, send_local_notifs},
|
||||||
|
UserOperationCrud,
|
||||||
},
|
},
|
||||||
};
|
|
||||||
use lemmy_apub::{
|
|
||||||
generate_local_apub_endpoint,
|
|
||||||
objects::comment::ApubComment,
|
|
||||||
protocol::activities::{create_or_update::note::CreateOrUpdateNote, CreateOrUpdateType},
|
|
||||||
EndpointType,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -32,11 +33,6 @@ use lemmy_utils::{
|
||||||
utils::{remove_slurs, scrape_text_for_mentions},
|
utils::{remove_slurs, scrape_text_for_mentions},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::{
|
|
||||||
send::{send_comment_ws_message, send_local_notifs},
|
|
||||||
LemmyContext,
|
|
||||||
UserOperationCrud,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for CreateComment {
|
impl PerformCrud for CreateComment {
|
||||||
|
@ -157,16 +153,6 @@ impl PerformCrud for CreateComment {
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
|
||||||
|
|
||||||
let apub_comment: ApubComment = updated_comment.into();
|
|
||||||
CreateOrUpdateNote::send(
|
|
||||||
apub_comment.clone(),
|
|
||||||
&local_user_view.person.clone().into(),
|
|
||||||
CreateOrUpdateType::Create,
|
|
||||||
context,
|
|
||||||
&mut 0,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
// If its a reply, mark the parent as read
|
// If its a reply, mark the parent as read
|
||||||
if let Some(parent) = parent_opt {
|
if let Some(parent) = parent_opt {
|
||||||
let parent_id = parent.id;
|
let parent_id = parent.id;
|
||||||
|
|
|
@ -2,24 +2,22 @@ use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, DeleteComment},
|
comment::{CommentResponse, DeleteComment},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{check_community_ban, get_local_user_view_from_jwt},
|
utils::{check_community_ban, get_local_user_view_from_jwt},
|
||||||
|
websocket::{
|
||||||
|
send::{send_comment_ws_message, send_local_notifs},
|
||||||
|
UserOperationCrud,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentUpdateForm},
|
comment::{Comment, CommentUpdateForm},
|
||||||
community::Community,
|
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::CommentView;
|
use lemmy_db_views::structs::CommentView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{
|
|
||||||
send::{send_comment_ws_message, send_local_notifs},
|
|
||||||
LemmyContext,
|
|
||||||
UserOperationCrud,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for DeleteComment {
|
impl PerformCrud for DeleteComment {
|
||||||
|
@ -88,19 +86,6 @@ impl PerformCrud for DeleteComment {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Send the apub message
|
|
||||||
let community = Community::read(context.pool(), orig_comment.post.community_id).await?;
|
|
||||||
let deletable = DeletableObjects::Comment(Box::new(updated_comment.clone().into()));
|
|
||||||
send_apub_delete_in_community(
|
|
||||||
local_user_view.person,
|
|
||||||
community,
|
|
||||||
deletable,
|
|
||||||
None,
|
|
||||||
deleted,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
mod create;
|
mod create;
|
||||||
mod delete;
|
mod delete;
|
||||||
mod list;
|
|
||||||
mod read;
|
mod read;
|
||||||
mod remove;
|
mod remove;
|
||||||
mod update;
|
mod update;
|
||||||
|
|
|
@ -2,12 +2,12 @@ use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, GetComment},
|
comment::{CommentResponse, GetComment},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{check_private_instance, get_local_user_view_from_jwt_opt},
|
utils::{check_private_instance, get_local_user_view_from_jwt_opt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::local_site::LocalSite;
|
use lemmy_db_schema::source::local_site::LocalSite;
|
||||||
use lemmy_db_views::structs::CommentView;
|
use lemmy_db_views::structs::CommentView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for GetComment {
|
impl PerformCrud for GetComment {
|
||||||
|
|
|
@ -2,13 +2,16 @@ use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, RemoveComment},
|
comment::{CommentResponse, RemoveComment},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin},
|
utils::{check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin},
|
||||||
|
websocket::{
|
||||||
|
send::{send_comment_ws_message, send_local_notifs},
|
||||||
|
UserOperationCrud,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
comment::{Comment, CommentUpdateForm},
|
comment::{Comment, CommentUpdateForm},
|
||||||
community::Community,
|
|
||||||
moderator::{ModRemoveComment, ModRemoveCommentForm},
|
moderator::{ModRemoveComment, ModRemoveCommentForm},
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
|
@ -16,11 +19,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::CommentView;
|
use lemmy_db_views::structs::CommentView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{
|
|
||||||
send::{send_comment_ws_message, send_local_notifs},
|
|
||||||
LemmyContext,
|
|
||||||
UserOperationCrud,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for RemoveComment {
|
impl PerformCrud for RemoveComment {
|
||||||
|
@ -96,19 +94,6 @@ impl PerformCrud for RemoveComment {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Send the apub message
|
|
||||||
let community = Community::read(context.pool(), orig_comment.post.community_id).await?;
|
|
||||||
let deletable = DeletableObjects::Comment(Box::new(updated_comment.clone().into()));
|
|
||||||
send_apub_delete_in_community(
|
|
||||||
local_user_view.person,
|
|
||||||
community,
|
|
||||||
deletable,
|
|
||||||
data.reason.clone().or_else(|| Some(String::new())),
|
|
||||||
removed,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
comment::{CommentResponse, EditComment},
|
comment::{CommentResponse, EditComment},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
check_community_deleted_or_removed,
|
check_community_deleted_or_removed,
|
||||||
|
@ -10,10 +11,10 @@ use lemmy_api_common::{
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
},
|
},
|
||||||
};
|
websocket::{
|
||||||
use lemmy_apub::protocol::activities::{
|
send::{send_comment_ws_message, send_local_notifs},
|
||||||
create_or_update::note::CreateOrUpdateNote,
|
UserOperationCrud,
|
||||||
CreateOrUpdateType,
|
},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -29,11 +30,6 @@ use lemmy_utils::{
|
||||||
utils::{remove_slurs, scrape_text_for_mentions},
|
utils::{remove_slurs, scrape_text_for_mentions},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::{
|
|
||||||
send::{send_comment_ws_message, send_local_notifs},
|
|
||||||
LemmyContext,
|
|
||||||
UserOperationCrud,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for EditComment {
|
impl PerformCrud for EditComment {
|
||||||
|
@ -114,16 +110,6 @@ impl PerformCrud for EditComment {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Send the apub update
|
|
||||||
CreateOrUpdateNote::send(
|
|
||||||
updated_comment.into(),
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
CreateOrUpdateType::Update,
|
|
||||||
context,
|
|
||||||
&mut 0,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
send_comment_ws_message(
|
send_comment_ws_message(
|
||||||
data.comment_id,
|
data.comment_id,
|
||||||
UserOperationCrud::EditComment,
|
UserOperationCrud::EditComment,
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use activitypub_federation::core::{object_id::ObjectId, signatures::generate_actor_keypair};
|
use activitypub_federation::core::signatures::generate_actor_keypair;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, CreateCommunity},
|
community::{CommunityResponse, CreateCommunity},
|
||||||
utils::{get_local_user_view_from_jwt, is_admin, local_site_to_slur_regex},
|
context::LemmyContext,
|
||||||
};
|
utils::{
|
||||||
use lemmy_apub::{
|
generate_followers_url,
|
||||||
generate_followers_url,
|
generate_inbox_url,
|
||||||
generate_inbox_url,
|
generate_local_apub_endpoint,
|
||||||
generate_local_apub_endpoint,
|
generate_shared_inbox_url,
|
||||||
generate_shared_inbox_url,
|
get_local_user_view_from_jwt,
|
||||||
objects::community::ApubCommunity,
|
is_admin,
|
||||||
EndpointType,
|
local_site_to_slur_regex,
|
||||||
|
EndpointType,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{
|
source::community::{
|
||||||
|
@ -22,7 +24,7 @@ use lemmy_db_schema::{
|
||||||
CommunityModerator,
|
CommunityModerator,
|
||||||
CommunityModeratorForm,
|
CommunityModeratorForm,
|
||||||
},
|
},
|
||||||
traits::{Crud, Followable, Joinable},
|
traits::{ApubActor, Crud, Followable, Joinable},
|
||||||
utils::diesel_option_overwrite_to_url_create,
|
utils::diesel_option_overwrite_to_url_create,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::SiteView;
|
use lemmy_db_views::structs::SiteView;
|
||||||
|
@ -32,7 +34,6 @@ use lemmy_utils::{
|
||||||
utils::{check_slurs, check_slurs_opt, is_valid_actor_name},
|
utils::{check_slurs, check_slurs_opt, is_valid_actor_name},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for CreateCommunity {
|
impl PerformCrud for CreateCommunity {
|
||||||
|
@ -75,9 +76,8 @@ impl PerformCrud for CreateCommunity {
|
||||||
&data.name,
|
&data.name,
|
||||||
&context.settings().get_protocol_and_hostname(),
|
&context.settings().get_protocol_and_hostname(),
|
||||||
)?;
|
)?;
|
||||||
let community_actor_id_wrapped = ObjectId::<ApubCommunity>::new(community_actor_id.clone());
|
let community_dupe = Community::read_from_apub_id(context.pool(), &community_actor_id).await?;
|
||||||
let community_dupe = community_actor_id_wrapped.dereference_local(context).await;
|
if community_dupe.is_some() {
|
||||||
if community_dupe.is_ok() {
|
|
||||||
return Err(LemmyError::from_message("community_already_exists"));
|
return Err(LemmyError::from_message("community_already_exists"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,16 +2,16 @@ use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, DeleteCommunity},
|
community::{CommunityResponse, DeleteCommunity},
|
||||||
|
context::LemmyContext,
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
|
websocket::{send::send_community_ws_message, UserOperationCrud},
|
||||||
};
|
};
|
||||||
use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{Community, CommunityUpdateForm},
|
source::community::{Community, CommunityUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for DeleteCommunity {
|
impl PerformCrud for DeleteCommunity {
|
||||||
|
@ -40,7 +40,7 @@ impl PerformCrud for DeleteCommunity {
|
||||||
// Do the delete
|
// Do the delete
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let deleted = data.deleted;
|
let deleted = data.deleted;
|
||||||
let updated_community = Community::update(
|
Community::update(
|
||||||
context.pool(),
|
context.pool(),
|
||||||
community_id,
|
community_id,
|
||||||
&CommunityUpdateForm::builder()
|
&CommunityUpdateForm::builder()
|
||||||
|
@ -59,18 +59,6 @@ impl PerformCrud for DeleteCommunity {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Send apub messages
|
|
||||||
let deletable = DeletableObjects::Community(Box::new(updated_community.clone().into()));
|
|
||||||
send_apub_delete_in_community(
|
|
||||||
local_user_view.person,
|
|
||||||
updated_community,
|
|
||||||
deletable,
|
|
||||||
None,
|
|
||||||
deleted,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,12 @@ use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{ListCommunities, ListCommunitiesResponse},
|
community::{ListCommunities, ListCommunitiesResponse},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{check_private_instance, get_local_user_view_from_jwt_opt},
|
utils::{check_private_instance, get_local_user_view_from_jwt_opt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::local_site::LocalSite, traits::DeleteableOrRemoveable};
|
use lemmy_db_schema::{source::local_site::LocalSite, traits::DeleteableOrRemoveable};
|
||||||
use lemmy_db_views_actor::community_view::CommunityQuery;
|
use lemmy_db_views_actor::community_view::CommunityQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for ListCommunities {
|
impl PerformCrud for ListCommunities {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
mod create;
|
mod create;
|
||||||
mod delete;
|
mod delete;
|
||||||
mod list;
|
mod list;
|
||||||
mod read;
|
|
||||||
mod remove;
|
mod remove;
|
||||||
mod update;
|
mod update;
|
||||||
|
|
|
@ -2,9 +2,10 @@ use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, RemoveCommunity},
|
community::{CommunityResponse, RemoveCommunity},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{get_local_user_view_from_jwt, is_admin},
|
utils::{get_local_user_view_from_jwt, is_admin},
|
||||||
|
websocket::{send::send_community_ws_message, UserOperationCrud},
|
||||||
};
|
};
|
||||||
use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
community::{Community, CommunityUpdateForm},
|
community::{Community, CommunityUpdateForm},
|
||||||
|
@ -13,7 +14,6 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, utils::naive_from_unix, ConnectionId};
|
use lemmy_utils::{error::LemmyError, utils::naive_from_unix, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for RemoveCommunity {
|
impl PerformCrud for RemoveCommunity {
|
||||||
|
@ -35,7 +35,7 @@ impl PerformCrud for RemoveCommunity {
|
||||||
// Do the remove
|
// Do the remove
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let removed = data.removed;
|
let removed = data.removed;
|
||||||
let updated_community = Community::update(
|
Community::update(
|
||||||
context.pool(),
|
context.pool(),
|
||||||
community_id,
|
community_id,
|
||||||
&CommunityUpdateForm::builder()
|
&CommunityUpdateForm::builder()
|
||||||
|
@ -65,17 +65,6 @@ impl PerformCrud for RemoveCommunity {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Apub messages
|
|
||||||
let deletable = DeletableObjects::Community(Box::new(updated_community.clone().into()));
|
|
||||||
send_apub_delete_in_community(
|
|
||||||
local_user_view.person,
|
|
||||||
updated_community,
|
|
||||||
deletable,
|
|
||||||
data.reason.clone().or_else(|| Some(String::new())),
|
|
||||||
removed,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,10 @@ use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{CommunityResponse, EditCommunity},
|
community::{CommunityResponse, EditCommunity},
|
||||||
|
context::LemmyContext,
|
||||||
utils::{get_local_user_view_from_jwt, local_site_to_slur_regex},
|
utils::{get_local_user_view_from_jwt, local_site_to_slur_regex},
|
||||||
|
websocket::{send::send_community_ws_message, UserOperationCrud},
|
||||||
};
|
};
|
||||||
use lemmy_apub::protocol::activities::community::update::UpdateCommunity;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
source::{
|
source::{
|
||||||
|
@ -17,7 +18,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
||||||
use lemmy_utils::{error::LemmyError, utils::check_slurs_opt, ConnectionId};
|
use lemmy_utils::{error::LemmyError, utils::check_slurs_opt, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for EditCommunity {
|
impl PerformCrud for EditCommunity {
|
||||||
|
@ -73,17 +73,10 @@ impl PerformCrud for EditCommunity {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let updated_community = Community::update(context.pool(), community_id, &community_form)
|
Community::update(context.pool(), community_id, &community_form)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
|
||||||
|
|
||||||
UpdateCommunity::send(
|
|
||||||
updated_community.into(),
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let op = UserOperationCrud::EditCommunity;
|
let op = UserOperationCrud::EditCommunity;
|
||||||
send_community_ws_message(data.community_id, op, websocket_id, None, context).await
|
send_community_ws_message(data.community_id, op, websocket_id, None, context).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,6 @@
|
||||||
use actix_web::{web, web::Data};
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::context::LemmyContext;
|
||||||
comment::{CreateComment, DeleteComment, EditComment, GetComment, GetComments, RemoveComment},
|
|
||||||
community::{
|
|
||||||
CreateCommunity,
|
|
||||||
DeleteCommunity,
|
|
||||||
EditCommunity,
|
|
||||||
GetCommunity,
|
|
||||||
ListCommunities,
|
|
||||||
RemoveCommunity,
|
|
||||||
},
|
|
||||||
person::{DeleteAccount, GetPersonDetails, Register},
|
|
||||||
post::{CreatePost, DeletePost, EditPost, GetPost, GetPosts, RemovePost},
|
|
||||||
private_message::{
|
|
||||||
CreatePrivateMessage,
|
|
||||||
DeletePrivateMessage,
|
|
||||||
EditPrivateMessage,
|
|
||||||
GetPrivateMessages,
|
|
||||||
},
|
|
||||||
site::{CreateSite, EditSite, GetSite},
|
|
||||||
};
|
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperationCrud};
|
|
||||||
use serde::Deserialize;
|
|
||||||
|
|
||||||
mod comment;
|
mod comment;
|
||||||
mod community;
|
mod community;
|
||||||
|
@ -40,115 +19,3 @@ pub trait PerformCrud {
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError>;
|
) -> Result<Self::Response, LemmyError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn match_websocket_operation_crud(
|
|
||||||
context: LemmyContext,
|
|
||||||
id: ConnectionId,
|
|
||||||
op: UserOperationCrud,
|
|
||||||
data: &str,
|
|
||||||
) -> Result<String, LemmyError> {
|
|
||||||
//TODO: handle commented out actions in crud crate
|
|
||||||
|
|
||||||
match op {
|
|
||||||
// User ops
|
|
||||||
UserOperationCrud::Register => do_websocket_operation::<Register>(context, id, op, data).await,
|
|
||||||
UserOperationCrud::GetPersonDetails => {
|
|
||||||
do_websocket_operation::<GetPersonDetails>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::DeleteAccount => {
|
|
||||||
do_websocket_operation::<DeleteAccount>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
|
|
||||||
// Private Message ops
|
|
||||||
UserOperationCrud::CreatePrivateMessage => {
|
|
||||||
do_websocket_operation::<CreatePrivateMessage>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::EditPrivateMessage => {
|
|
||||||
do_websocket_operation::<EditPrivateMessage>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::DeletePrivateMessage => {
|
|
||||||
do_websocket_operation::<DeletePrivateMessage>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::GetPrivateMessages => {
|
|
||||||
do_websocket_operation::<GetPrivateMessages>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
|
|
||||||
// Site ops
|
|
||||||
UserOperationCrud::CreateSite => {
|
|
||||||
do_websocket_operation::<CreateSite>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::EditSite => do_websocket_operation::<EditSite>(context, id, op, data).await,
|
|
||||||
UserOperationCrud::GetSite => do_websocket_operation::<GetSite>(context, id, op, data).await,
|
|
||||||
|
|
||||||
// Community ops
|
|
||||||
UserOperationCrud::GetCommunity => {
|
|
||||||
do_websocket_operation::<GetCommunity>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::ListCommunities => {
|
|
||||||
do_websocket_operation::<ListCommunities>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::CreateCommunity => {
|
|
||||||
do_websocket_operation::<CreateCommunity>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::EditCommunity => {
|
|
||||||
do_websocket_operation::<EditCommunity>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::DeleteCommunity => {
|
|
||||||
do_websocket_operation::<DeleteCommunity>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::RemoveCommunity => {
|
|
||||||
do_websocket_operation::<RemoveCommunity>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
|
|
||||||
// Post ops
|
|
||||||
UserOperationCrud::CreatePost => {
|
|
||||||
do_websocket_operation::<CreatePost>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::GetPost => do_websocket_operation::<GetPost>(context, id, op, data).await,
|
|
||||||
UserOperationCrud::GetPosts => do_websocket_operation::<GetPosts>(context, id, op, data).await,
|
|
||||||
UserOperationCrud::EditPost => do_websocket_operation::<EditPost>(context, id, op, data).await,
|
|
||||||
UserOperationCrud::DeletePost => {
|
|
||||||
do_websocket_operation::<DeletePost>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::RemovePost => {
|
|
||||||
do_websocket_operation::<RemovePost>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comment ops
|
|
||||||
UserOperationCrud::CreateComment => {
|
|
||||||
do_websocket_operation::<CreateComment>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::EditComment => {
|
|
||||||
do_websocket_operation::<EditComment>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::DeleteComment => {
|
|
||||||
do_websocket_operation::<DeleteComment>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::RemoveComment => {
|
|
||||||
do_websocket_operation::<RemoveComment>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::GetComment => {
|
|
||||||
do_websocket_operation::<GetComment>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
UserOperationCrud::GetComments => {
|
|
||||||
do_websocket_operation::<GetComments>(context, id, op, data).await
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn do_websocket_operation<'a, 'b, Data>(
|
|
||||||
context: LemmyContext,
|
|
||||||
id: ConnectionId,
|
|
||||||
op: UserOperationCrud,
|
|
||||||
data: &str,
|
|
||||||
) -> Result<String, LemmyError>
|
|
||||||
where
|
|
||||||
for<'de> Data: Deserialize<'de> + 'a,
|
|
||||||
Data: PerformCrud,
|
|
||||||
{
|
|
||||||
let parsed_data: Data = serde_json::from_str(data)?;
|
|
||||||
let res = parsed_data
|
|
||||||
.perform(&web::Data::new(context), Some(id))
|
|
||||||
.await?;
|
|
||||||
serialize_websocket_message(&op, &res)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,22 +1,20 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{CreatePost, PostResponse},
|
post::{CreatePost, PostResponse},
|
||||||
request::fetch_site_data,
|
request::fetch_site_data,
|
||||||
utils::{
|
utils::{
|
||||||
check_community_ban,
|
check_community_ban,
|
||||||
check_community_deleted_or_removed,
|
check_community_deleted_or_removed,
|
||||||
|
generate_local_apub_endpoint,
|
||||||
get_local_user_view_from_jwt,
|
get_local_user_view_from_jwt,
|
||||||
honeypot_check,
|
honeypot_check,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
mark_post_as_read,
|
mark_post_as_read,
|
||||||
|
EndpointType,
|
||||||
},
|
},
|
||||||
};
|
websocket::{send::send_post_ws_message, UserOperationCrud},
|
||||||
use lemmy_apub::{
|
|
||||||
generate_local_apub_endpoint,
|
|
||||||
objects::post::ApubPost,
|
|
||||||
protocol::activities::{create_or_update::page::CreateOrUpdatePage, CreateOrUpdateType},
|
|
||||||
EndpointType,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
impls::actor_language::default_post_language,
|
impls::actor_language::default_post_language,
|
||||||
|
@ -34,7 +32,6 @@ use lemmy_utils::{
|
||||||
utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title},
|
utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
|
|
||||||
use tracing::{warn, Instrument};
|
use tracing::{warn, Instrument};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use webmention::{Webmention, WebmentionError};
|
use webmention::{Webmention, WebmentionError};
|
||||||
|
@ -173,15 +170,6 @@ impl PerformCrud for CreatePost {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let apub_post: ApubPost = updated_post.into();
|
|
||||||
CreateOrUpdatePage::send(
|
|
||||||
apub_post.clone(),
|
|
||||||
&local_user_view.person.clone().into(),
|
|
||||||
CreateOrUpdateType::Create,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
send_post_ws_message(
|
send_post_ws_message(
|
||||||
inserted_post.id,
|
inserted_post.id,
|
||||||
UserOperationCrud::CreatePost,
|
UserOperationCrud::CreatePost,
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{DeletePost, PostResponse},
|
post::{DeletePost, PostResponse},
|
||||||
utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt},
|
utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt},
|
||||||
|
websocket::{send::send_post_ws_message, UserOperationCrud},
|
||||||
};
|
};
|
||||||
use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::post::{Post, PostUpdateForm},
|
||||||
community::Community,
|
|
||||||
post::{Post, PostUpdateForm},
|
|
||||||
},
|
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for DeletePost {
|
impl PerformCrud for DeletePost {
|
||||||
|
@ -53,7 +50,7 @@ impl PerformCrud for DeletePost {
|
||||||
// Update the post
|
// Update the post
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let deleted = data.deleted;
|
let deleted = data.deleted;
|
||||||
let updated_post = Post::update(
|
Post::update(
|
||||||
context.pool(),
|
context.pool(),
|
||||||
post_id,
|
post_id,
|
||||||
&PostUpdateForm::builder().deleted(Some(deleted)).build(),
|
&PostUpdateForm::builder().deleted(Some(deleted)).build(),
|
||||||
|
@ -69,18 +66,6 @@ impl PerformCrud for DeletePost {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// apub updates
|
|
||||||
let community = Community::read(context.pool(), orig_post.community_id).await?;
|
|
||||||
let deletable = DeletableObjects::Post(Box::new(updated_post.into()));
|
|
||||||
send_apub_delete_in_community(
|
|
||||||
local_user_view.person,
|
|
||||||
community,
|
|
||||||
deletable,
|
|
||||||
None,
|
|
||||||
deleted,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
mod create;
|
mod create;
|
||||||
mod delete;
|
mod delete;
|
||||||
mod list;
|
|
||||||
mod read;
|
mod read;
|
||||||
mod remove;
|
mod remove;
|
||||||
mod update;
|
mod update;
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{GetPost, GetPostResponse},
|
post::{GetPost, GetPostResponse},
|
||||||
utils::{check_private_instance, get_local_user_view_from_jwt_opt, mark_post_as_read},
|
utils::{check_private_instance, get_local_user_view_from_jwt_opt, mark_post_as_read},
|
||||||
|
websocket::messages::GetPostUsersOnline,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm},
|
aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm},
|
||||||
|
@ -12,7 +14,6 @@ use lemmy_db_schema::{
|
||||||
use lemmy_db_views::structs::PostView;
|
use lemmy_db_views::structs::PostView;
|
||||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{messages::GetPostUsersOnline, LemmyContext};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for GetPost {
|
impl PerformCrud for GetPost {
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{PostResponse, RemovePost},
|
post::{PostResponse, RemovePost},
|
||||||
utils::{check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin},
|
utils::{check_community_ban, get_local_user_view_from_jwt, is_mod_or_admin},
|
||||||
|
websocket::{send::send_post_ws_message, UserOperationCrud},
|
||||||
};
|
};
|
||||||
use lemmy_apub::activities::deletion::{send_apub_delete_in_community, DeletableObjects};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
community::Community,
|
|
||||||
moderator::{ModRemovePost, ModRemovePostForm},
|
moderator::{ModRemovePost, ModRemovePostForm},
|
||||||
post::{Post, PostUpdateForm},
|
post::{Post, PostUpdateForm},
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for RemovePost {
|
impl PerformCrud for RemovePost {
|
||||||
|
@ -51,7 +50,7 @@ impl PerformCrud for RemovePost {
|
||||||
// Update the post
|
// Update the post
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let removed = data.removed;
|
let removed = data.removed;
|
||||||
let updated_post = Post::update(
|
Post::update(
|
||||||
context.pool(),
|
context.pool(),
|
||||||
post_id,
|
post_id,
|
||||||
&PostUpdateForm::builder().removed(Some(removed)).build(),
|
&PostUpdateForm::builder().removed(Some(removed)).build(),
|
||||||
|
@ -76,18 +75,6 @@ impl PerformCrud for RemovePost {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// apub updates
|
|
||||||
let community = Community::read(context.pool(), orig_post.community_id).await?;
|
|
||||||
let deletable = DeletableObjects::Post(Box::new(updated_post.into()));
|
|
||||||
send_apub_delete_in_community(
|
|
||||||
local_user_view.person,
|
|
||||||
community,
|
|
||||||
deletable,
|
|
||||||
data.reason.clone().or_else(|| Some(String::new())),
|
|
||||||
removed,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
post::{EditPost, PostResponse},
|
post::{EditPost, PostResponse},
|
||||||
request::fetch_site_data,
|
request::fetch_site_data,
|
||||||
utils::{
|
utils::{
|
||||||
|
@ -9,10 +10,7 @@ use lemmy_api_common::{
|
||||||
get_local_user_view_from_jwt,
|
get_local_user_view_from_jwt,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
},
|
},
|
||||||
};
|
websocket::{send::send_post_ws_message, UserOperationCrud},
|
||||||
use lemmy_apub::protocol::activities::{
|
|
||||||
create_or_update::page::CreateOrUpdatePage,
|
|
||||||
CreateOrUpdateType,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -28,7 +26,6 @@ use lemmy_utils::{
|
||||||
utils::{check_slurs_opt, clean_url_params, is_valid_post_title},
|
utils::{check_slurs_opt, clean_url_params, is_valid_post_title},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for EditPost {
|
impl PerformCrud for EditPost {
|
||||||
|
@ -108,27 +105,15 @@ impl PerformCrud for EditPost {
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let res = Post::update(context.pool(), post_id, &post_form).await;
|
let res = Post::update(context.pool(), post_id, &post_form).await;
|
||||||
let updated_post: Post = match res {
|
if let Err(e) = res {
|
||||||
Ok(post) => post,
|
let err_type = if e.to_string() == "value too long for type character varying(200)" {
|
||||||
Err(e) => {
|
"post_title_too_long"
|
||||||
let err_type = if e.to_string() == "value too long for type character varying(200)" {
|
} else {
|
||||||
"post_title_too_long"
|
"couldnt_update_post"
|
||||||
} else {
|
};
|
||||||
"couldnt_update_post"
|
|
||||||
};
|
|
||||||
|
|
||||||
return Err(LemmyError::from_error_message(e, err_type));
|
return Err(LemmyError::from_error_message(e, err_type));
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// Send apub update
|
|
||||||
CreateOrUpdatePage::send(
|
|
||||||
updated_post.into(),
|
|
||||||
&local_user_view.person.clone().into(),
|
|
||||||
CreateOrUpdateType::Update,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
send_post_ws_message(
|
send_post_ws_message(
|
||||||
data.post_id,
|
data.post_id,
|
||||||
|
|
|
@ -1,22 +1,18 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
private_message::{CreatePrivateMessage, PrivateMessageResponse},
|
private_message::{CreatePrivateMessage, PrivateMessageResponse},
|
||||||
utils::{
|
utils::{
|
||||||
check_person_block,
|
check_person_block,
|
||||||
|
generate_local_apub_endpoint,
|
||||||
get_interface_language,
|
get_interface_language,
|
||||||
get_local_user_view_from_jwt,
|
get_local_user_view_from_jwt,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
send_email_to_user,
|
send_email_to_user,
|
||||||
|
EndpointType,
|
||||||
},
|
},
|
||||||
};
|
websocket::{send::send_pm_ws_message, UserOperationCrud},
|
||||||
use lemmy_apub::{
|
|
||||||
generate_local_apub_endpoint,
|
|
||||||
protocol::activities::{
|
|
||||||
create_or_update::chat_message::CreateOrUpdateChatMessage,
|
|
||||||
CreateOrUpdateType,
|
|
||||||
},
|
|
||||||
EndpointType,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -27,7 +23,6 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::{error::LemmyError, utils::remove_slurs, ConnectionId};
|
use lemmy_utils::{error::LemmyError, utils::remove_slurs, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for CreatePrivateMessage {
|
impl PerformCrud for CreatePrivateMessage {
|
||||||
|
@ -75,7 +70,7 @@ impl PerformCrud for CreatePrivateMessage {
|
||||||
&inserted_private_message_id.to_string(),
|
&inserted_private_message_id.to_string(),
|
||||||
&protocol_and_hostname,
|
&protocol_and_hostname,
|
||||||
)?;
|
)?;
|
||||||
let updated_private_message = PrivateMessage::update(
|
PrivateMessage::update(
|
||||||
context.pool(),
|
context.pool(),
|
||||||
inserted_private_message.id,
|
inserted_private_message.id,
|
||||||
&PrivateMessageUpdateForm::builder()
|
&PrivateMessageUpdateForm::builder()
|
||||||
|
@ -85,14 +80,6 @@ impl PerformCrud for CreatePrivateMessage {
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_private_message"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_private_message"))?;
|
||||||
|
|
||||||
CreateOrUpdateChatMessage::send(
|
|
||||||
updated_private_message.into(),
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
CreateOrUpdateType::Create,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let res = send_pm_ws_message(
|
let res = send_pm_ws_message(
|
||||||
inserted_private_message.id,
|
inserted_private_message.id,
|
||||||
UserOperationCrud::CreatePrivateMessage,
|
UserOperationCrud::CreatePrivateMessage,
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
private_message::{DeletePrivateMessage, PrivateMessageResponse},
|
private_message::{DeletePrivateMessage, PrivateMessageResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
|
websocket::{send::send_pm_ws_message, UserOperationCrud},
|
||||||
};
|
};
|
||||||
use lemmy_apub::activities::deletion::send_apub_delete_private_message;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
|
source::private_message::{PrivateMessage, PrivateMessageUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for DeletePrivateMessage {
|
impl PerformCrud for DeletePrivateMessage {
|
||||||
|
@ -36,7 +36,7 @@ impl PerformCrud for DeletePrivateMessage {
|
||||||
// Doing the update
|
// Doing the update
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = data.private_message_id;
|
||||||
let deleted = data.deleted;
|
let deleted = data.deleted;
|
||||||
let updated_private_message = PrivateMessage::update(
|
PrivateMessage::update(
|
||||||
context.pool(),
|
context.pool(),
|
||||||
private_message_id,
|
private_message_id,
|
||||||
&PrivateMessageUpdateForm::builder()
|
&PrivateMessageUpdateForm::builder()
|
||||||
|
@ -46,15 +46,6 @@ impl PerformCrud for DeletePrivateMessage {
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
||||||
|
|
||||||
// Send the apub update
|
|
||||||
send_apub_delete_private_message(
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
updated_private_message,
|
|
||||||
data.deleted,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let op = UserOperationCrud::DeletePrivateMessage;
|
let op = UserOperationCrud::DeletePrivateMessage;
|
||||||
send_pm_ws_message(data.private_message_id, op, websocket_id, context).await
|
send_pm_ws_message(data.private_message_id, op, websocket_id, context).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
private_message::{GetPrivateMessages, PrivateMessagesResponse},
|
private_message::{GetPrivateMessages, PrivateMessagesResponse},
|
||||||
utils::get_local_user_view_from_jwt,
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::traits::DeleteableOrRemoveable;
|
use lemmy_db_schema::traits::DeleteableOrRemoveable;
|
||||||
use lemmy_db_views::private_message_view::PrivateMessageQuery;
|
use lemmy_db_views::private_message_view::PrivateMessageQuery;
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for GetPrivateMessages {
|
impl PerformCrud for GetPrivateMessages {
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
private_message::{EditPrivateMessage, PrivateMessageResponse},
|
private_message::{EditPrivateMessage, PrivateMessageResponse},
|
||||||
utils::{get_local_user_view_from_jwt, local_site_to_slur_regex},
|
utils::{get_local_user_view_from_jwt, local_site_to_slur_regex},
|
||||||
};
|
websocket::{send::send_pm_ws_message, UserOperationCrud},
|
||||||
use lemmy_apub::protocol::activities::{
|
|
||||||
create_or_update::chat_message::CreateOrUpdateChatMessage,
|
|
||||||
CreateOrUpdateType,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -17,7 +15,6 @@ use lemmy_db_schema::{
|
||||||
utils::naive_now,
|
utils::naive_now,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, utils::remove_slurs, ConnectionId};
|
use lemmy_utils::{error::LemmyError, utils::remove_slurs, ConnectionId};
|
||||||
use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for EditPrivateMessage {
|
impl PerformCrud for EditPrivateMessage {
|
||||||
|
@ -44,7 +41,7 @@ impl PerformCrud for EditPrivateMessage {
|
||||||
// Doing the update
|
// Doing the update
|
||||||
let content_slurs_removed = remove_slurs(&data.content, &local_site_to_slur_regex(&local_site));
|
let content_slurs_removed = remove_slurs(&data.content, &local_site_to_slur_regex(&local_site));
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = data.private_message_id;
|
||||||
let updated_private_message = PrivateMessage::update(
|
PrivateMessage::update(
|
||||||
context.pool(),
|
context.pool(),
|
||||||
private_message_id,
|
private_message_id,
|
||||||
&PrivateMessageUpdateForm::builder()
|
&PrivateMessageUpdateForm::builder()
|
||||||
|
@ -55,15 +52,6 @@ impl PerformCrud for EditPrivateMessage {
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
||||||
|
|
||||||
// Send the apub update
|
|
||||||
CreateOrUpdateChatMessage::send(
|
|
||||||
updated_private_message.into(),
|
|
||||||
&local_user_view.person.into(),
|
|
||||||
CreateOrUpdateType::Update,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let op = UserOperationCrud::EditPrivateMessage;
|
let op = UserOperationCrud::EditPrivateMessage;
|
||||||
send_pm_ws_message(data.private_message_id, op, websocket_id, context).await
|
send_pm_ws_message(data.private_message_id, op, websocket_id, context).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@ use crate::PerformCrud;
|
||||||
use activitypub_federation::core::signatures::generate_actor_keypair;
|
use activitypub_federation::core::signatures::generate_actor_keypair;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
site::{CreateSite, SiteResponse},
|
site::{CreateSite, SiteResponse},
|
||||||
utils::{
|
utils::{
|
||||||
|
generate_site_inbox_url,
|
||||||
get_local_user_view_from_jwt,
|
get_local_user_view_from_jwt,
|
||||||
is_admin,
|
is_admin,
|
||||||
local_site_rate_limit_to_rate_limit_config,
|
local_site_rate_limit_to_rate_limit_config,
|
||||||
|
@ -11,7 +13,6 @@ use lemmy_api_common::{
|
||||||
site_description_length_check,
|
site_description_length_check,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use lemmy_apub::generate_site_inbox_url;
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::DbUrl,
|
newtypes::DbUrl,
|
||||||
source::{
|
source::{
|
||||||
|
@ -28,7 +29,6 @@ use lemmy_utils::{
|
||||||
utils::{check_application_question, check_slurs, check_slurs_opt},
|
utils::{check_application_question, check_slurs, check_slurs_opt},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
site::{GetSite, GetSiteResponse, MyUserInfo},
|
site::{GetSite, GetSiteResponse, MyUserInfo},
|
||||||
utils::{build_federated_instances, get_local_user_settings_view_from_jwt_opt},
|
utils::{build_federated_instances, get_local_user_settings_view_from_jwt_opt},
|
||||||
|
websocket::messages::GetUsersOnline,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::source::{actor_language::SiteLanguage, language::Language, tagline::Tagline};
|
use lemmy_db_schema::source::{actor_language::SiteLanguage, language::Language, tagline::Tagline};
|
||||||
use lemmy_db_views::structs::{LocalUserDiscussionLanguageView, SiteView};
|
use lemmy_db_views::structs::{LocalUserDiscussionLanguageView, SiteView};
|
||||||
|
@ -14,7 +16,6 @@ use lemmy_db_views_actor::structs::{
|
||||||
PersonViewSafe,
|
PersonViewSafe,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, version, ConnectionId};
|
use lemmy_utils::{error::LemmyError, version, ConnectionId};
|
||||||
use lemmy_websocket::{messages::GetUsersOnline, LemmyContext};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for GetSite {
|
impl PerformCrud for GetSite {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::PerformCrud;
|
use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
site::{EditSite, SiteResponse},
|
site::{EditSite, SiteResponse},
|
||||||
utils::{
|
utils::{
|
||||||
get_local_user_view_from_jwt,
|
get_local_user_view_from_jwt,
|
||||||
|
@ -9,6 +10,7 @@ use lemmy_api_common::{
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
site_description_length_check,
|
site_description_length_check,
|
||||||
},
|
},
|
||||||
|
websocket::{messages::SendAllMessage, UserOperationCrud},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{
|
source::{
|
||||||
|
@ -31,7 +33,6 @@ use lemmy_utils::{
|
||||||
utils::{check_application_question, check_slurs_opt},
|
utils::{check_application_question, check_slurs_opt},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::{messages::SendAllMessage, LemmyContext, UserOperationCrud};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
|
|
|
@ -2,20 +2,20 @@ use crate::PerformCrud;
|
||||||
use activitypub_federation::core::signatures::generate_actor_keypair;
|
use activitypub_federation::core::signatures::generate_actor_keypair;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{LoginResponse, Register},
|
person::{LoginResponse, Register},
|
||||||
utils::{
|
utils::{
|
||||||
|
generate_inbox_url,
|
||||||
|
generate_local_apub_endpoint,
|
||||||
|
generate_shared_inbox_url,
|
||||||
honeypot_check,
|
honeypot_check,
|
||||||
local_site_to_slur_regex,
|
local_site_to_slur_regex,
|
||||||
password_length_check,
|
password_length_check,
|
||||||
send_new_applicant_email_to_admins,
|
send_new_applicant_email_to_admins,
|
||||||
send_verification_email,
|
send_verification_email,
|
||||||
|
EndpointType,
|
||||||
},
|
},
|
||||||
};
|
websocket::messages::CheckCaptcha,
|
||||||
use lemmy_apub::{
|
|
||||||
generate_inbox_url,
|
|
||||||
generate_local_apub_endpoint,
|
|
||||||
generate_shared_inbox_url,
|
|
||||||
EndpointType,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::PersonAggregates,
|
aggregates::structs::PersonAggregates,
|
||||||
|
@ -33,7 +33,6 @@ use lemmy_utils::{
|
||||||
utils::{check_slurs, check_slurs_opt, is_valid_actor_name},
|
utils::{check_slurs, check_slurs_opt, is_valid_actor_name},
|
||||||
ConnectionId,
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use lemmy_websocket::{messages::CheckCaptcha, LemmyContext};
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for Register {
|
impl PerformCrud for Register {
|
||||||
|
|
|
@ -2,12 +2,11 @@ use crate::PerformCrud;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use bcrypt::verify;
|
use bcrypt::verify;
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
|
context::LemmyContext,
|
||||||
person::{DeleteAccount, DeleteAccountResponse},
|
person::{DeleteAccount, DeleteAccountResponse},
|
||||||
utils::{delete_user_account, get_local_user_view_from_jwt},
|
utils::get_local_user_view_from_jwt,
|
||||||
};
|
};
|
||||||
use lemmy_apub::protocol::activities::deletion::delete_user::DeleteUser;
|
|
||||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||||
use lemmy_websocket::LemmyContext;
|
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
impl PerformCrud for DeleteAccount {
|
impl PerformCrud for DeleteAccount {
|
||||||
|
@ -33,15 +32,6 @@ impl PerformCrud for DeleteAccount {
|
||||||
return Err(LemmyError::from_message("password_incorrect"));
|
return Err(LemmyError::from_message("password_incorrect"));
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_user_account(
|
|
||||||
local_user_view.person.id,
|
|
||||||
context.pool(),
|
|
||||||
context.settings(),
|
|
||||||
context.client(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
DeleteUser::send(&local_user_view.person.into(), context).await?;
|
|
||||||
|
|
||||||
Ok(DeleteAccountResponse {})
|
Ok(DeleteAccountResponse {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue