From 98c086abb9d5777381cf2426a36b92321440dc43 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 16 Sep 2020 12:25:22 +0200 Subject: [PATCH] Move websocket structs into lemmy_structs (ref #1115) --- Cargo.lock | 31 +++++---- Cargo.toml | 5 +- docker/dev/Dockerfile | 6 +- docker/prod/Dockerfile | 2 +- .../Cargo.toml | 8 ++- .../src/comment.rs | 0 .../src/community.rs | 0 .../src/lib.rs | 5 ++ .../src/post.rs | 0 .../src/site.rs | 0 .../src/user.rs | 0 .../src/websocket.rs | 67 ++++++++++++++++++- src/api/comment.rs | 8 ++- src/api/community.rs | 15 +++-- src/api/mod.rs | 2 +- src/api/post.rs | 10 +-- src/api/site.rs | 11 +-- src/api/user.rs | 17 +++-- src/apub/comment.rs | 2 +- src/apub/community.rs | 2 +- src/apub/fetcher.rs | 2 +- src/apub/inbox/activities/create.rs | 7 +- src/apub/inbox/activities/delete.rs | 7 +- src/apub/inbox/activities/dislike.rs | 11 +-- src/apub/inbox/activities/like.rs | 11 +-- src/apub/inbox/activities/remove.rs | 7 +- src/apub/inbox/activities/undo.rs | 7 +- src/apub/inbox/activities/update.rs | 7 +- src/apub/inbox/community_inbox.rs | 2 +- src/apub/inbox/user_inbox.rs | 7 +- src/apub/mod.rs | 2 +- src/apub/post.rs | 2 +- src/apub/private_message.rs | 2 +- src/apub/user.rs | 2 +- src/lib.rs | 2 - src/main.rs | 2 +- src/routes/api.rs | 2 +- src/routes/feeds.rs | 2 +- src/routes/nodeinfo.rs | 2 +- src/routes/webfinger.rs | 2 +- src/routes/websocket.rs | 9 +-- src/websocket/chat_server.rs | 8 +-- src/websocket/handlers.rs | 7 +- src/websocket/mod.rs | 65 ------------------ 44 files changed, 185 insertions(+), 183 deletions(-) rename {lemmy_api_structs => lemmy_structs}/Cargo.toml (69%) rename {lemmy_api_structs => lemmy_structs}/src/comment.rs (100%) rename {lemmy_api_structs => lemmy_structs}/src/community.rs (100%) rename {lemmy_api_structs => lemmy_structs}/src/lib.rs (97%) rename {lemmy_api_structs => lemmy_structs}/src/post.rs (100%) rename {lemmy_api_structs => lemmy_structs}/src/site.rs (100%) rename {lemmy_api_structs => lemmy_structs}/src/user.rs (100%) rename src/websocket/messages.rs => lemmy_structs/src/websocket.rs (70%) diff --git a/Cargo.lock b/Cargo.lock index 644c83ac8..8fef254fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1820,18 +1820,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lemmy_api_structs" -version = "0.1.0" -dependencies = [ - "actix-web", - "diesel", - "lemmy_db", - "lemmy_utils", - "log", - "serde 1.0.115", -] - [[package]] name = "lemmy_db" version = "0.1.0" @@ -1893,9 +1881,9 @@ dependencies = [ "itertools", "jsonwebtoken", "lazy_static", - "lemmy_api_structs", "lemmy_db", "lemmy_rate_limit", + "lemmy_structs", "lemmy_utils", "log", "openssl", @@ -1907,13 +1895,28 @@ dependencies = [ "serde_json", "sha2", "strum", - "strum_macros", "thiserror", "tokio", "url", "uuid 0.8.1", ] +[[package]] +name = "lemmy_structs" +version = "0.1.0" +dependencies = [ + "actix", + "actix-web", + "chrono", + "diesel", + "lemmy_db", + "lemmy_utils", + "log", + "serde 1.0.115", + "strum", + "strum_macros", +] + [[package]] name = "lemmy_utils" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index f1f490b0d..dc411a639 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,14 +10,14 @@ lto = true members = [ "lemmy_utils", "lemmy_db", - "lemmy_api_structs", + "lemmy_structs", "lemmy_rate_limit", ] [dependencies] lemmy_utils = { path = "./lemmy_utils" } lemmy_db = { path = "./lemmy_db" } -lemmy_api_structs = { path = "./lemmy_api_structs" } +lemmy_structs = { path = "./lemmy_structs" } lemmy_rate_limit = { path = "./lemmy_rate_limit" } diesel = "1.4.4" diesel_migrations = "1.4.0" @@ -38,7 +38,6 @@ log = "0.4.0" env_logger = "0.7.1" rand = "0.7.3" strum = "0.19.2" -strum_macros = "0.19.2" jsonwebtoken = "7.0.1" lazy_static = "1.3.0" rss = "1.9.0" diff --git a/docker/dev/Dockerfile b/docker/dev/Dockerfile index d9a95c85c..17e58fda4 100644 --- a/docker/dev/Dockerfile +++ b/docker/dev/Dockerfile @@ -10,7 +10,7 @@ RUN cargo install --git https://github.com/romac/cargo-build-deps.git WORKDIR /app/server RUN mkdir -p lemmy_db/src/ \ lemmy_utils/src/ \ - lemmy_api_structs/src/ \ + lemmy_structs/src/ \ lemmy_rate_limit/src/ \ lemmy @@ -18,7 +18,7 @@ RUN mkdir -p lemmy_db/src/ \ COPY Cargo.toml Cargo.lock ./ COPY lemmy_db/Cargo.toml ./lemmy_db/ COPY lemmy_utils/Cargo.toml ./lemmy_utils/ -COPY lemmy_api_structs/Cargo.toml ./lemmy_api_structs/ +COPY lemmy_structs/Cargo.toml ./lemmy_structs/ COPY lemmy_rate_limit/Cargo.toml ./lemmy_rate_limit/ # Cache the deps @@ -28,7 +28,7 @@ RUN cargo build-deps COPY src ./src/ COPY lemmy_db/src ./lemmy_db/src/ COPY lemmy_utils/src/ ./lemmy_utils/src/ -COPY lemmy_api_structs/src/ ./lemmy_api_structs/src/ +COPY lemmy_structs/src/ ./lemmy_structs/src/ COPY lemmy_rate_limit/src/ ./lemmy_rate_limit/src/ COPY migrations ./migrations/ diff --git a/docker/prod/Dockerfile b/docker/prod/Dockerfile index 2ba5bca70..20e910a42 100644 --- a/docker/prod/Dockerfile +++ b/docker/prod/Dockerfile @@ -13,7 +13,7 @@ WORKDIR /app/server COPY Cargo.toml Cargo.lock ./ COPY lemmy_db ./lemmy_db COPY lemmy_utils ./lemmy_utils -COPY lemmy_api_structs ./lemmy_api_structs +COPY lemmy_structs ./lemmy_structs COPY lemmy_rate_limit ./lemmy_rate_limit RUN mkdir -p ./src/bin \ && echo 'fn main() { println!("Dummy") }' > ./src/bin/main.rs diff --git a/lemmy_api_structs/Cargo.toml b/lemmy_structs/Cargo.toml similarity index 69% rename from lemmy_api_structs/Cargo.toml rename to lemmy_structs/Cargo.toml index b442f697d..25e38109a 100644 --- a/lemmy_api_structs/Cargo.toml +++ b/lemmy_structs/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "lemmy_api_structs" +name = "lemmy_structs" version = "0.1.0" authors = ["Felix Ableitner "] edition = "2018" [lib] -name = "lemmy_api_structs" +name = "lemmy_structs" path = "src/lib.rs" [dependencies] @@ -15,3 +15,7 @@ serde = { version = "1.0.105", features = ["derive"] } log = "0.4.0" diesel = "1.4.4" actix-web = { version = "3.0.0-beta.3", features = ["rustls"] } +actix = "0.10.0" +strum = "0.19.2" +strum_macros = "0.19.2" +chrono = { version = "0.4.7", features = ["serde"] } \ No newline at end of file diff --git a/lemmy_api_structs/src/comment.rs b/lemmy_structs/src/comment.rs similarity index 100% rename from lemmy_api_structs/src/comment.rs rename to lemmy_structs/src/comment.rs diff --git a/lemmy_api_structs/src/community.rs b/lemmy_structs/src/community.rs similarity index 100% rename from lemmy_api_structs/src/community.rs rename to lemmy_structs/src/community.rs diff --git a/lemmy_api_structs/src/lib.rs b/lemmy_structs/src/lib.rs similarity index 97% rename from lemmy_api_structs/src/lib.rs rename to lemmy_structs/src/lib.rs index dd2a78cda..f7140205a 100644 --- a/lemmy_api_structs/src/lib.rs +++ b/lemmy_structs/src/lib.rs @@ -1,13 +1,18 @@ +extern crate actix; extern crate actix_web; extern crate diesel; extern crate log; extern crate serde; +#[macro_use] +extern crate strum_macros; +extern crate chrono; pub mod comment; pub mod community; pub mod post; pub mod site; pub mod user; +pub mod websocket; use diesel::PgConnection; use lemmy_db::{ diff --git a/lemmy_api_structs/src/post.rs b/lemmy_structs/src/post.rs similarity index 100% rename from lemmy_api_structs/src/post.rs rename to lemmy_structs/src/post.rs diff --git a/lemmy_api_structs/src/site.rs b/lemmy_structs/src/site.rs similarity index 100% rename from lemmy_api_structs/src/site.rs rename to lemmy_structs/src/site.rs diff --git a/lemmy_api_structs/src/user.rs b/lemmy_structs/src/user.rs similarity index 100% rename from lemmy_api_structs/src/user.rs rename to lemmy_structs/src/user.rs diff --git a/src/websocket/messages.rs b/lemmy_structs/src/websocket.rs similarity index 70% rename from src/websocket/messages.rs rename to lemmy_structs/src/websocket.rs index 2a0e5fde1..c5c6c5d60 100644 --- a/src/websocket/messages.rs +++ b/lemmy_structs/src/websocket.rs @@ -1,9 +1,72 @@ -use crate::websocket::UserOperation; +use crate::{comment::CommentResponse, post::PostResponse}; use actix::{prelude::*, Recipient}; -use lemmy_api_structs::{comment::CommentResponse, post::PostResponse}; use lemmy_utils::{CommunityId, ConnectionId, IPAddr, PostId, UserId}; use serde::{Deserialize, Serialize}; +#[derive(EnumString, ToString, Debug, Clone)] +pub enum UserOperation { + Login, + Register, + GetCaptcha, + CreateCommunity, + CreatePost, + ListCommunities, + ListCategories, + GetPost, + GetCommunity, + CreateComment, + EditComment, + DeleteComment, + RemoveComment, + MarkCommentAsRead, + SaveComment, + CreateCommentLike, + GetPosts, + CreatePostLike, + EditPost, + DeletePost, + RemovePost, + LockPost, + StickyPost, + SavePost, + EditCommunity, + DeleteCommunity, + RemoveCommunity, + FollowCommunity, + GetFollowedCommunities, + GetUserDetails, + GetReplies, + GetUserMentions, + MarkUserMentionAsRead, + GetModlog, + BanFromCommunity, + AddModToCommunity, + CreateSite, + EditSite, + GetSite, + AddAdmin, + BanUser, + Search, + MarkAllAsRead, + SaveUserSettings, + TransferCommunity, + TransferSite, + DeleteAccount, + PasswordReset, + PasswordChange, + CreatePrivateMessage, + EditPrivateMessage, + DeletePrivateMessage, + MarkPrivateMessageAsRead, + GetPrivateMessages, + UserJoin, + GetComments, + GetSiteConfig, + SaveSiteConfig, + PostJoin, + CommunityJoin, +} + /// Chat server sends this messages to session #[derive(Message)] #[rtype(result = "()")] diff --git a/src/api/comment.rs b/src/api/comment.rs index 68481a40a..2f6a23b68 100644 --- a/src/api/comment.rs +++ b/src/api/comment.rs @@ -8,11 +8,15 @@ use crate::{ Perform, }, apub::{ApubLikeableType, ApubObjectType}, - websocket::{messages::SendComment, UserOperation}, LemmyContext, }; use actix_web::web::Data; -use lemmy_api_structs::{blocking, comment::*, send_local_notifs}; +use lemmy_structs::{ + blocking, + comment::*, + send_local_notifs, + websocket::{SendComment, UserOperation}, +}; use lemmy_db::{ comment::*, comment_view::*, diff --git a/src/api/community.rs b/src/api/community.rs index 7c8c93f14..e16e7f717 100644 --- a/src/api/community.rs +++ b/src/api/community.rs @@ -1,15 +1,20 @@ use crate::{ api::{get_user_from_jwt, get_user_from_jwt_opt, is_admin, is_mod_or_admin, Perform}, apub::ActorType, - websocket::{ - messages::{GetCommunityUsersOnline, JoinCommunityRoom, SendCommunityRoomMessage}, - UserOperation, - }, LemmyContext, }; use actix_web::web::Data; use anyhow::Context; -use lemmy_api_structs::{blocking, community::*}; +use lemmy_structs::{ + blocking, + community::*, + websocket::{ + GetCommunityUsersOnline, + JoinCommunityRoom, + SendCommunityRoomMessage, + UserOperation, + }, +}; use lemmy_db::{ comment::Comment, comment_view::CommentQueryBuilder, diff --git a/src/api/mod.rs b/src/api/mod.rs index 1aff5d106..0c66e7d71 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,6 +1,6 @@ use crate::{api::claims::Claims, DbPool, LemmyContext}; use actix_web::web::Data; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::{ community::Community, community_view::CommunityUserBanView, diff --git a/src/api/post.rs b/src/api/post.rs index d38c10c9d..4cfb3babd 100644 --- a/src/api/post.rs +++ b/src/api/post.rs @@ -2,14 +2,14 @@ use crate::{ api::{check_community_ban, get_user_from_jwt, get_user_from_jwt_opt, is_mod_or_admin, Perform}, apub::{ApubLikeableType, ApubObjectType}, fetch_iframely_and_pictrs_data, - websocket::{ - messages::{GetPostUsersOnline, JoinPostRoom, SendPost}, - UserOperation, - }, LemmyContext, }; use actix_web::web::Data; -use lemmy_api_structs::{blocking, post::*}; +use lemmy_structs::{ + blocking, + post::*, + websocket::{GetPostUsersOnline, JoinPostRoom, SendPost, UserOperation}, +}; use lemmy_db::{ comment_view::*, community_view::*, diff --git a/src/api/site.rs b/src/api/site.rs index 727078e27..e0e2b6ff8 100644 --- a/src/api/site.rs +++ b/src/api/site.rs @@ -2,15 +2,16 @@ use crate::{ api::{get_user_from_jwt, get_user_from_jwt_opt, is_admin, Perform}, apub::fetcher::search_by_apub_id, version, - websocket::{ - messages::{GetUsersOnline, SendAllMessage}, - UserOperation, - }, LemmyContext, }; use actix_web::web::Data; use anyhow::Context; -use lemmy_api_structs::{blocking, site::*, user::Register}; +use lemmy_structs::{ + blocking, + site::*, + user::Register, + websocket::{GetUsersOnline, SendAllMessage, UserOperation}, +}; use lemmy_db::{ category::*, comment_view::*, diff --git a/src/api/user.rs b/src/api/user.rs index 195e93dc4..3301be9dc 100644 --- a/src/api/user.rs +++ b/src/api/user.rs @@ -2,10 +2,6 @@ use crate::{ api::{claims::Claims, get_user_from_jwt, get_user_from_jwt_opt, is_admin, Perform}, apub::ApubObjectType, captcha_espeak_wav_base64, - websocket::{ - messages::{CaptchaItem, CheckCaptcha, JoinUserRoom, SendAllMessage, SendUserRoomMessage}, - UserOperation, - }, LemmyContext, }; use actix_web::web::Data; @@ -13,7 +9,18 @@ use anyhow::Context; use bcrypt::verify; use captcha::{gen, Difficulty}; use chrono::Duration; -use lemmy_api_structs::{blocking, user::*}; +use lemmy_structs::{ + blocking, + user::*, + websocket::{ + CaptchaItem, + CheckCaptcha, + JoinUserRoom, + SendAllMessage, + SendUserRoomMessage, + UserOperation, + }, +}; use lemmy_db::{ comment::*, comment_view::*, diff --git a/src/apub/comment.rs b/src/apub/comment.rs index 78fe6f8ab..e71eeacde 100644 --- a/src/apub/comment.rs +++ b/src/apub/comment.rs @@ -40,7 +40,7 @@ use activitystreams::{ use actix_web::{body::Body, web, web::Path, HttpResponse}; use anyhow::Context; use itertools::Itertools; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::{ comment::{Comment, CommentForm}, community::Community, diff --git a/src/apub/community.rs b/src/apub/community.rs index 8f64c671d..8a11f5702 100644 --- a/src/apub/community.rs +++ b/src/apub/community.rs @@ -38,7 +38,7 @@ use activitystreams_ext::Ext2; use actix_web::{body::Body, web, HttpResponse}; use anyhow::Context; use itertools::Itertools; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::{ community::{Community, CommunityForm}, community_view::{CommunityFollowerView, CommunityModeratorView}, diff --git a/src/apub/fetcher.rs b/src/apub/fetcher.rs index 4891a9705..c1caa039b 100644 --- a/src/apub/fetcher.rs +++ b/src/apub/fetcher.rs @@ -15,7 +15,7 @@ use activitystreams::{base::BaseExt, collection::OrderedCollection, object::Note use anyhow::{anyhow, Context}; use chrono::NaiveDateTime; use diesel::result::Error::NotFound; -use lemmy_api_structs::{blocking, site::SearchResponse}; +use lemmy_structs::{blocking, site::SearchResponse}; use lemmy_db::{ comment::{Comment, CommentForm}, comment_view::CommentView, diff --git a/src/apub/inbox/activities/create.rs b/src/apub/inbox/activities/create.rs index 66286ce17..d54834e17 100644 --- a/src/apub/inbox/activities/create.rs +++ b/src/apub/inbox/activities/create.rs @@ -9,20 +9,17 @@ use crate::{ FromApub, PageExt, }, - websocket::{ - messages::{SendComment, SendPost}, - UserOperation, - }, LemmyContext, }; use activitystreams::{activity::Create, base::AnyBase, object::Note, prelude::*}; use actix_web::HttpResponse; use anyhow::Context; -use lemmy_api_structs::{ +use lemmy_structs::{ blocking, comment::CommentResponse, post::PostResponse, send_local_notifs, + websocket::{SendComment, SendPost, UserOperation}, }; use lemmy_db::{ comment::{Comment, CommentForm}, diff --git a/src/apub/inbox/activities/delete.rs b/src/apub/inbox/activities/delete.rs index 4adc7c33c..41615132a 100644 --- a/src/apub/inbox/activities/delete.rs +++ b/src/apub/inbox/activities/delete.rs @@ -11,20 +11,17 @@ use crate::{ GroupExt, PageExt, }, - websocket::{ - messages::{SendComment, SendCommunityRoomMessage, SendPost}, - UserOperation, - }, LemmyContext, }; use activitystreams::{activity::Delete, base::AnyBase, object::Note, prelude::*}; use actix_web::HttpResponse; use anyhow::Context; -use lemmy_api_structs::{ +use lemmy_structs::{ blocking, comment::CommentResponse, community::CommunityResponse, post::PostResponse, + websocket::{SendComment, SendCommunityRoomMessage, SendPost, UserOperation}, }; use lemmy_db::{ comment::{Comment, CommentForm}, diff --git a/src/apub/inbox/activities/dislike.rs b/src/apub/inbox/activities/dislike.rs index 9b63e82d8..07bf08150 100644 --- a/src/apub/inbox/activities/dislike.rs +++ b/src/apub/inbox/activities/dislike.rs @@ -9,16 +9,17 @@ use crate::{ FromApub, PageExt, }, - websocket::{ - messages::{SendComment, SendPost}, - UserOperation, - }, LemmyContext, }; use activitystreams::{activity::Dislike, base::AnyBase, object::Note, prelude::*}; use actix_web::HttpResponse; use anyhow::Context; -use lemmy_api_structs::{blocking, comment::CommentResponse, post::PostResponse}; +use lemmy_structs::{ + blocking, + comment::CommentResponse, + post::PostResponse, + websocket::{SendComment, SendPost, UserOperation}, +}; use lemmy_db::{ comment::{CommentForm, CommentLike, CommentLikeForm}, comment_view::CommentView, diff --git a/src/apub/inbox/activities/like.rs b/src/apub/inbox/activities/like.rs index e6f865b93..dbb6363da 100644 --- a/src/apub/inbox/activities/like.rs +++ b/src/apub/inbox/activities/like.rs @@ -9,16 +9,17 @@ use crate::{ FromApub, PageExt, }, - websocket::{ - messages::{SendComment, SendPost}, - UserOperation, - }, LemmyContext, }; use activitystreams::{activity::Like, base::AnyBase, object::Note, prelude::*}; use actix_web::HttpResponse; use anyhow::Context; -use lemmy_api_structs::{blocking, comment::CommentResponse, post::PostResponse}; +use lemmy_structs::{ + blocking, + comment::CommentResponse, + post::PostResponse, + websocket::{SendComment, SendPost, UserOperation}, +}; use lemmy_db::{ comment::{CommentForm, CommentLike, CommentLikeForm}, comment_view::CommentView, diff --git a/src/apub/inbox/activities/remove.rs b/src/apub/inbox/activities/remove.rs index 011f57b95..3299d5cfa 100644 --- a/src/apub/inbox/activities/remove.rs +++ b/src/apub/inbox/activities/remove.rs @@ -12,20 +12,17 @@ use crate::{ GroupExt, PageExt, }, - websocket::{ - messages::{SendComment, SendCommunityRoomMessage, SendPost}, - UserOperation, - }, LemmyContext, }; use activitystreams::{activity::Remove, base::AnyBase, object::Note, prelude::*}; use actix_web::HttpResponse; use anyhow::{anyhow, Context}; -use lemmy_api_structs::{ +use lemmy_structs::{ blocking, comment::CommentResponse, community::CommunityResponse, post::PostResponse, + websocket::{SendComment, SendCommunityRoomMessage, SendPost, UserOperation}, }; use lemmy_db::{ comment::{Comment, CommentForm}, diff --git a/src/apub/inbox/activities/undo.rs b/src/apub/inbox/activities/undo.rs index bf2073860..c3dad4208 100644 --- a/src/apub/inbox/activities/undo.rs +++ b/src/apub/inbox/activities/undo.rs @@ -11,10 +11,6 @@ use crate::{ GroupExt, PageExt, }, - websocket::{ - messages::{SendComment, SendCommunityRoomMessage, SendPost}, - UserOperation, - }, LemmyContext, }; use activitystreams::{ @@ -25,11 +21,12 @@ use activitystreams::{ }; use actix_web::HttpResponse; use anyhow::{anyhow, Context}; -use lemmy_api_structs::{ +use lemmy_structs::{ blocking, comment::CommentResponse, community::CommunityResponse, post::PostResponse, + websocket::{SendComment, SendCommunityRoomMessage, SendPost, UserOperation}, }; use lemmy_db::{ comment::{Comment, CommentForm, CommentLike}, diff --git a/src/apub/inbox/activities/update.rs b/src/apub/inbox/activities/update.rs index f078e67aa..137dc0615 100644 --- a/src/apub/inbox/activities/update.rs +++ b/src/apub/inbox/activities/update.rs @@ -10,20 +10,17 @@ use crate::{ FromApub, PageExt, }, - websocket::{ - messages::{SendComment, SendPost}, - UserOperation, - }, LemmyContext, }; use activitystreams::{activity::Update, base::AnyBase, object::Note, prelude::*}; use actix_web::HttpResponse; use anyhow::Context; -use lemmy_api_structs::{ +use lemmy_structs::{ blocking, comment::CommentResponse, post::PostResponse, send_local_notifs, + websocket::{SendComment, SendPost, UserOperation}, }; use lemmy_db::{ comment::{Comment, CommentForm}, diff --git a/src/apub/inbox/community_inbox.rs b/src/apub/inbox/community_inbox.rs index b27e6b6a9..e60c3fe7a 100644 --- a/src/apub/inbox/community_inbox.rs +++ b/src/apub/inbox/community_inbox.rs @@ -15,7 +15,7 @@ use activitystreams::{ }; use actix_web::{web, HttpRequest, HttpResponse}; use anyhow::{anyhow, Context}; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::{ community::{Community, CommunityFollower, CommunityFollowerForm}, user::User_, diff --git a/src/apub/inbox/user_inbox.rs b/src/apub/inbox/user_inbox.rs index ccc4d105a..cf47a597c 100644 --- a/src/apub/inbox/user_inbox.rs +++ b/src/apub/inbox/user_inbox.rs @@ -6,7 +6,6 @@ use crate::{ insert_activity, FromApub, }, - websocket::{messages::SendUserRoomMessage, UserOperation}, LemmyContext, }; use activitystreams::{ @@ -17,7 +16,11 @@ use activitystreams::{ }; use actix_web::{web, HttpRequest, HttpResponse}; use anyhow::Context; -use lemmy_api_structs::{blocking, user::PrivateMessageResponse}; +use lemmy_structs::{ + blocking, + user::PrivateMessageResponse, + websocket::{SendUserRoomMessage, UserOperation}, +}; use lemmy_db::{ community::{CommunityFollower, CommunityFollowerForm}, naive_now, diff --git a/src/apub/mod.rs b/src/apub/mod.rs index e9184c33a..db489622f 100644 --- a/src/apub/mod.rs +++ b/src/apub/mod.rs @@ -32,7 +32,7 @@ use activitystreams_ext::{Ext1, Ext2}; use actix_web::{body::Body, HttpResponse}; use anyhow::{anyhow, Context}; use chrono::NaiveDateTime; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::{activity::do_insert_activity, user::User_}; use lemmy_utils::{ apub::get_apub_protocol_string, diff --git a/src/apub/post.rs b/src/apub/post.rs index be9e2304b..d2fa7dc59 100644 --- a/src/apub/post.rs +++ b/src/apub/post.rs @@ -35,7 +35,7 @@ use activitystreams::{ use activitystreams_ext::Ext1; use actix_web::{body::Body, web, HttpResponse}; use anyhow::Context; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::{ community::Community, post::{Post, PostForm}, diff --git a/src/apub/private_message.rs b/src/apub/private_message.rs index 6ae30a3f4..00196bfd7 100644 --- a/src/apub/private_message.rs +++ b/src/apub/private_message.rs @@ -27,7 +27,7 @@ use activitystreams::{ prelude::*, }; use anyhow::Context; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::{ private_message::{PrivateMessage, PrivateMessageForm}, user::User_, diff --git a/src/apub/user.rs b/src/apub/user.rs index 54daadb96..5bd6d2579 100644 --- a/src/apub/user.rs +++ b/src/apub/user.rs @@ -27,7 +27,7 @@ use activitystreams::{ use activitystreams_ext::Ext1; use actix_web::{body::Body, web, HttpResponse}; use anyhow::Context; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::{ naive_now, user::{UserForm, User_}, diff --git a/src/lib.rs b/src/lib.rs index 11b8df7cb..2bab3552a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,5 @@ #![recursion_limit = "512"] #[macro_use] -extern crate strum_macros; -#[macro_use] extern crate lazy_static; extern crate actix; extern crate actix_web; diff --git a/src/main.rs b/src/main.rs index 6ec2b81ee..39ab014de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use diesel::{ PgConnection, }; use lazy_static::lazy_static; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::get_database_url_from_env; use lemmy_rate_limit::{rate_limiter::RateLimiter, RateLimit}; use lemmy_server::{ diff --git a/src/routes/api.rs b/src/routes/api.rs index 3435b5438..fffb7cdf0 100644 --- a/src/routes/api.rs +++ b/src/routes/api.rs @@ -1,6 +1,6 @@ use crate::{api::Perform, LemmyContext}; use actix_web::{error::ErrorBadRequest, *}; -use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*}; +use lemmy_structs::{comment::*, community::*, post::*, site::*, user::*}; use lemmy_rate_limit::RateLimit; use serde::Deserialize; diff --git a/src/routes/feeds.rs b/src/routes/feeds.rs index 1d8641490..c73b8e051 100644 --- a/src/routes/feeds.rs +++ b/src/routes/feeds.rs @@ -3,7 +3,7 @@ use actix_web::{error::ErrorBadRequest, *}; use anyhow::anyhow; use chrono::{DateTime, NaiveDateTime, Utc}; use diesel::PgConnection; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::{ comment_view::{ReplyQueryBuilder, ReplyView}, community::Community, diff --git a/src/routes/nodeinfo.rs b/src/routes/nodeinfo.rs index 2273fae54..20e55cca7 100644 --- a/src/routes/nodeinfo.rs +++ b/src/routes/nodeinfo.rs @@ -1,7 +1,7 @@ use crate::{version, LemmyContext}; use actix_web::{body::Body, error::ErrorBadRequest, *}; use anyhow::anyhow; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::site_view::SiteView; use lemmy_utils::{apub::get_apub_protocol_string, settings::Settings, LemmyError}; use serde::{Deserialize, Serialize}; diff --git a/src/routes/webfinger.rs b/src/routes/webfinger.rs index 458fa0f37..1ea38867f 100644 --- a/src/routes/webfinger.rs +++ b/src/routes/webfinger.rs @@ -1,7 +1,7 @@ use crate::LemmyContext; use actix_web::{error::ErrorBadRequest, web::Query, *}; use anyhow::anyhow; -use lemmy_api_structs::blocking; +use lemmy_structs::blocking; use lemmy_db::{community::Community, user::User_}; use lemmy_utils::{ settings::Settings, diff --git a/src/routes/websocket.rs b/src/routes/websocket.rs index 540af34fa..aaa7ef37a 100644 --- a/src/routes/websocket.rs +++ b/src/routes/websocket.rs @@ -1,13 +1,8 @@ -use crate::{ - websocket::{ - chat_server::ChatServer, - messages::{Connect, Disconnect, StandardMessage, WSMessage}, - }, - LemmyContext, -}; +use crate::{websocket::chat_server::ChatServer, LemmyContext}; use actix::prelude::*; use actix_web::*; use actix_web_actors::ws; +use lemmy_structs::websocket::{Connect, Disconnect, StandardMessage, WSMessage}; use lemmy_utils::utils::get_ip; use log::{debug, error, info}; use std::time::{Duration, Instant}; diff --git a/src/websocket/chat_server.rs b/src/websocket/chat_server.rs index 2da107217..13106d9d2 100644 --- a/src/websocket/chat_server.rs +++ b/src/websocket/chat_server.rs @@ -1,9 +1,5 @@ use crate::{ - websocket::{ - handlers::{do_user_operation, to_json_string, Args}, - messages::*, - UserOperation, - }, + websocket::handlers::{do_user_operation, to_json_string, Args}, LemmyContext, }; use actix::prelude::*; @@ -13,7 +9,7 @@ use diesel::{ r2d2::{ConnectionManager, Pool}, PgConnection, }; -use lemmy_api_structs::{comment::*, community::*, post::*, site::*, user::*}; +use lemmy_structs::{comment::*, community::*, post::*, site::*, user::*, websocket::*}; use lemmy_rate_limit::RateLimit; use lemmy_utils::{ location_info, diff --git a/src/websocket/handlers.rs b/src/websocket/handlers.rs index a65e88bb5..b3c8d5410 100644 --- a/src/websocket/handlers.rs +++ b/src/websocket/handlers.rs @@ -1,14 +1,11 @@ use crate::{ api::Perform, - websocket::{ - chat_server::{ChatServer, SessionInfo}, - messages::*, - UserOperation, - }, + websocket::chat_server::{ChatServer, SessionInfo}, LemmyContext, }; use actix::{Actor, Context, Handler, ResponseFuture}; use actix_web::web; +use lemmy_structs::websocket::*; use lemmy_db::naive_now; use lemmy_rate_limit::RateLimit; use lemmy_utils::{ConnectionId, IPAddr, LemmyError}; diff --git a/src/websocket/mod.rs b/src/websocket/mod.rs index 42793a786..e892f78f8 100644 --- a/src/websocket/mod.rs +++ b/src/websocket/mod.rs @@ -1,67 +1,2 @@ pub mod chat_server; pub mod handlers; -pub mod messages; - -#[derive(EnumString, ToString, Debug, Clone)] -pub enum UserOperation { - Login, - Register, - GetCaptcha, - CreateCommunity, - CreatePost, - ListCommunities, - ListCategories, - GetPost, - GetCommunity, - CreateComment, - EditComment, - DeleteComment, - RemoveComment, - MarkCommentAsRead, - SaveComment, - CreateCommentLike, - GetPosts, - CreatePostLike, - EditPost, - DeletePost, - RemovePost, - LockPost, - StickyPost, - SavePost, - EditCommunity, - DeleteCommunity, - RemoveCommunity, - FollowCommunity, - GetFollowedCommunities, - GetUserDetails, - GetReplies, - GetUserMentions, - MarkUserMentionAsRead, - GetModlog, - BanFromCommunity, - AddModToCommunity, - CreateSite, - EditSite, - GetSite, - AddAdmin, - BanUser, - Search, - MarkAllAsRead, - SaveUserSettings, - TransferCommunity, - TransferSite, - DeleteAccount, - PasswordReset, - PasswordChange, - CreatePrivateMessage, - EditPrivateMessage, - DeletePrivateMessage, - MarkPrivateMessageAsRead, - GetPrivateMessages, - UserJoin, - GetComments, - GetSiteConfig, - SaveSiteConfig, - PostJoin, - CommunityJoin, -}