Split lemmy_db into lemmy_db_queries, lemmy_db_aggregates and lemmy_db_views
authorFelix Ableitner <me@nutomic.com>
Mon, 21 Dec 2020 16:30:34 +0000 (17:30 +0100)
committerFelix Ableitner <me@nutomic.com>
Mon, 21 Dec 2020 16:39:11 +0000 (17:39 +0100)
82 files changed:
Cargo.lock
Cargo.toml
lemmy_api/Cargo.toml
lemmy_api/src/comment.rs
lemmy_api/src/community.rs
lemmy_api/src/lib.rs
lemmy_api/src/post.rs
lemmy_api/src/site.rs
lemmy_api/src/user.rs
lemmy_apub/Cargo.toml
lemmy_apub/src/activities/receive/comment.rs
lemmy_apub/src/activities/receive/comment_undo.rs
lemmy_apub/src/activities/receive/community.rs
lemmy_apub/src/activities/receive/post.rs
lemmy_apub/src/activities/receive/post_undo.rs
lemmy_apub/src/activities/receive/private_message.rs
lemmy_apub/src/activities/send/community.rs
lemmy_apub/src/fetcher.rs
lemmy_apub/src/http/community.rs
lemmy_apub/src/inbox/community_inbox.rs
lemmy_apub/src/objects/community.rs
lemmy_db_aggregates/Cargo.toml [new file with mode: 0644]
lemmy_db_aggregates/src/comment_aggregates.rs [moved from lemmy_db/src/aggregates/comment_aggregates.rs with 94% similarity]
lemmy_db_aggregates/src/community_aggregates.rs [moved from lemmy_db/src/aggregates/community_aggregates.rs with 97% similarity]
lemmy_db_aggregates/src/lib.rs [moved from lemmy_db/src/aggregates/mod.rs with 100% similarity]
lemmy_db_aggregates/src/post_aggregates.rs [moved from lemmy_db/src/aggregates/post_aggregates.rs with 97% similarity]
lemmy_db_aggregates/src/site_aggregates.rs [moved from lemmy_db/src/aggregates/site_aggregates.rs with 96% similarity]
lemmy_db_aggregates/src/user_aggregates.rs [moved from lemmy_db/src/aggregates/user_aggregates.rs with 97% similarity]
lemmy_db_queries/Cargo.toml [moved from lemmy_db/Cargo.toml with 96% similarity]
lemmy_db_queries/src/lib.rs [moved from lemmy_db/src/lib.rs with 88% similarity]
lemmy_db_queries/src/source/activity.rs [moved from lemmy_db/src/source/activity.rs with 97% similarity]
lemmy_db_queries/src/source/category.rs [moved from lemmy_db/src/source/category.rs with 94% similarity]
lemmy_db_queries/src/source/comment.rs [moved from lemmy_db/src/source/comment.rs with 98% similarity]
lemmy_db_queries/src/source/comment_report.rs [moved from lemmy_db/src/source/comment_report.rs with 100% similarity]
lemmy_db_queries/src/source/community.rs [moved from lemmy_db/src/source/community.rs with 92% similarity]
lemmy_db_queries/src/source/mod.rs [moved from lemmy_db/src/source/mod.rs with 100% similarity]
lemmy_db_queries/src/source/moderator.rs [moved from lemmy_db/src/source/moderator.rs with 99% similarity]
lemmy_db_queries/src/source/password_reset_request.rs [moved from lemmy_db/src/source/password_reset_request.rs with 96% similarity]
lemmy_db_queries/src/source/post.rs [moved from lemmy_db/src/source/post.rs with 99% similarity]
lemmy_db_queries/src/source/post_report.rs [moved from lemmy_db/src/source/post_report.rs with 100% similarity]
lemmy_db_queries/src/source/private_message.rs [moved from lemmy_db/src/source/private_message.rs with 98% similarity]
lemmy_db_queries/src/source/site.rs [moved from lemmy_db/src/source/site.rs with 100% similarity]
lemmy_db_queries/src/source/user.rs [moved from lemmy_db/src/source/user.rs with 99% similarity]
lemmy_db_queries/src/source/user_mention.rs [moved from lemmy_db/src/source/user_mention.rs with 98% similarity]
lemmy_db_schema/src/lib.rs
lemmy_db_schema/src/source/comment_report.rs
lemmy_db_schema/src/source/post_report.rs
lemmy_db_views/Cargo.toml [new file with mode: 0644]
lemmy_db_views/src/comment_report_view.rs [moved from lemmy_db/src/views/comment_report_view.rs with 98% similarity]
lemmy_db_views/src/comment_view.rs [moved from lemmy_db/src/views/comment_view.rs with 98% similarity]
lemmy_db_views/src/community/community_follower_view.rs [moved from lemmy_db/src/views/community/community_follower_view.rs with 97% similarity]
lemmy_db_views/src/community/community_moderator_view.rs [moved from lemmy_db/src/views/community/community_moderator_view.rs with 97% similarity]
lemmy_db_views/src/community/community_user_ban_view.rs [moved from lemmy_db/src/views/community/community_user_ban_view.rs with 97% similarity]
lemmy_db_views/src/community/community_view.rs [moved from lemmy_db/src/views/community/community_view.rs with 85% similarity]
lemmy_db_views/src/community/mod.rs [moved from lemmy_db/src/views/community/mod.rs with 100% similarity]
lemmy_db_views/src/lib.rs [moved from lemmy_db/src/views/mod.rs with 100% similarity]
lemmy_db_views/src/moderator/mod.rs [moved from lemmy_db/src/views/moderator/mod.rs with 100% similarity]
lemmy_db_views/src/moderator/mod_add_community_view.rs [moved from lemmy_db/src/views/moderator/mod_add_community_view.rs with 97% similarity]
lemmy_db_views/src/moderator/mod_add_view.rs [moved from lemmy_db/src/views/moderator/mod_add_view.rs with 96% similarity]
lemmy_db_views/src/moderator/mod_ban_from_community_view.rs [moved from lemmy_db/src/views/moderator/mod_ban_from_community_view.rs with 97% similarity]
lemmy_db_views/src/moderator/mod_ban_view.rs [moved from lemmy_db/src/views/moderator/mod_ban_view.rs with 96% similarity]
lemmy_db_views/src/moderator/mod_lock_post_view.rs [moved from lemmy_db/src/views/moderator/mod_lock_post_view.rs with 96% similarity]
lemmy_db_views/src/moderator/mod_remove_comment_view.rs [moved from lemmy_db/src/views/moderator/mod_remove_comment_view.rs with 97% similarity]
lemmy_db_views/src/moderator/mod_remove_community_view.rs [moved from lemmy_db/src/views/moderator/mod_remove_community_view.rs with 96% similarity]
lemmy_db_views/src/moderator/mod_remove_post_view.rs [moved from lemmy_db/src/views/moderator/mod_remove_post_view.rs with 96% similarity]
lemmy_db_views/src/moderator/mod_sticky_post_view.rs [moved from lemmy_db/src/views/moderator/mod_sticky_post_view.rs with 96% similarity]
lemmy_db_views/src/post_report_view.rs [moved from lemmy_db/src/views/post_report_view.rs with 98% similarity]
lemmy_db_views/src/post_view.rs [moved from lemmy_db/src/views/post_view.rs with 98% similarity]
lemmy_db_views/src/private_message_view.rs [moved from lemmy_db/src/views/private_message_view.rs with 97% similarity]
lemmy_db_views/src/site_view.rs [moved from lemmy_db/src/views/site_view.rs with 90% similarity]
lemmy_db_views/src/user_mention_view.rs [moved from lemmy_db/src/views/user_mention_view.rs with 98% similarity]
lemmy_db_views/src/user_view.rs [moved from lemmy_db/src/views/user_view.rs with 96% similarity]
lemmy_structs/Cargo.toml
lemmy_structs/src/comment.rs
lemmy_structs/src/community.rs
lemmy_structs/src/post.rs
lemmy_structs/src/site.rs
lemmy_structs/src/user.rs
lemmy_utils/src/settings.rs
lemmy_websocket/Cargo.toml
src/routes/feeds.rs
src/routes/nodeinfo.rs

index a639b800ed4d4be262b947d64f2b218fa5cf8229..dd16aa97ff1b99c5e245b82f5b425384e18019a2 100644 (file)
@@ -1717,8 +1717,9 @@ dependencies = [
  "jsonwebtoken",
  "lazy_static",
  "lemmy_apub",
- "lemmy_db",
+ "lemmy_db_queries",
  "lemmy_db_schema",
+ "lemmy_db_views",
  "lemmy_rate_limit",
  "lemmy_structs",
  "lemmy_utils",
@@ -1762,8 +1763,9 @@ dependencies = [
  "http-signature-normalization-reqwest",
  "itertools",
  "lazy_static",
- "lemmy_db",
+ "lemmy_db_queries",
  "lemmy_db_schema",
+ "lemmy_db_views",
  "lemmy_structs",
  "lemmy_utils",
  "lemmy_websocket",
@@ -1784,7 +1786,18 @@ dependencies = [
 ]
 
 [[package]]
-name = "lemmy_db"
+name = "lemmy_db_aggregates"
+version = "0.1.0"
+dependencies = [
+ "chrono",
+ "diesel",
+ "lemmy_db_queries",
+ "lemmy_db_schema",
+ "serde 1.0.118",
+]
+
+[[package]]
+name = "lemmy_db_queries"
 version = "0.1.0"
 dependencies = [
  "bcrypt",
@@ -1816,6 +1829,17 @@ dependencies = [
  "url",
 ]
 
+[[package]]
+name = "lemmy_db_views"
+version = "0.1.0"
+dependencies = [
+ "diesel",
+ "lemmy_db_aggregates",
+ "lemmy_db_queries",
+ "lemmy_db_schema",
+ "serde 1.0.118",
+]
+
 [[package]]
 name = "lemmy_rate_limit"
 version = "0.1.0"
@@ -1850,8 +1874,10 @@ dependencies = [
  "lazy_static",
  "lemmy_api",
  "lemmy_apub",
- "lemmy_db",
+ "lemmy_db_aggregates",
+ "lemmy_db_queries",
  "lemmy_db_schema",
+ "lemmy_db_views",
  "lemmy_rate_limit",
  "lemmy_structs",
  "lemmy_utils",
@@ -1875,8 +1901,9 @@ dependencies = [
  "actix-web",
  "chrono",
  "diesel",
- "lemmy_db",
+ "lemmy_db_queries",
  "lemmy_db_schema",
+ "lemmy_db_views",
  "lemmy_utils",
  "log",
  "serde 1.0.118",
@@ -1917,7 +1944,7 @@ dependencies = [
  "background-jobs",
  "chrono",
  "diesel",
- "lemmy_db",
+ "lemmy_db_queries",
  "lemmy_db_schema",
  "lemmy_rate_limit",
  "lemmy_structs",
index e77140659025e00e8be887815a35ae59d24d518e..f6234416b34f9bd1d9583f9f43062589b366f689 100644 (file)
@@ -11,7 +11,7 @@ members = [
     "lemmy_api",
     "lemmy_apub",
     "lemmy_utils",
-    "lemmy_db",
+    "lemmy_db_queries",
     "lemmy_db_schema",
     "lemmy_structs",
     "lemmy_rate_limit",
@@ -23,7 +23,9 @@ lemmy_api = { path = "./lemmy_api" }
 lemmy_apub = { path = "./lemmy_apub" }
 lemmy_utils = { path = "./lemmy_utils" }
 lemmy_db_schema = { path = "./lemmy_db_schema" }
-lemmy_db = { path = "./lemmy_db" }
+lemmy_db_queries = { path = "lemmy_db_queries" }
+lemmy_db_views = { path = "./lemmy_db_views" }
+lemmy_db_aggregates = { path = "./lemmy_db_aggregates" }
 lemmy_structs = { path = "./lemmy_structs" }
 lemmy_rate_limit = { path = "./lemmy_rate_limit" }
 lemmy_websocket = { path = "./lemmy_websocket" }
index fc845c118833a7482b21c1404e9ec78bf03ade26..b9bda5990bf488bfd899b732cb5ab32414d76dd6 100644 (file)
@@ -11,8 +11,9 @@ path = "src/lib.rs"
 [dependencies]
 lemmy_apub = { path = "../lemmy_apub" }
 lemmy_utils = { path = "../lemmy_utils" }
-lemmy_db = { path = "../lemmy_db" }
+lemmy_db_queries = { path = "../lemmy_db_queries" }
 lemmy_db_schema = { path = "../lemmy_db_schema" }
+lemmy_db_views = { path = "../lemmy_db_views" }
 lemmy_structs = { path = "../lemmy_structs" }
 lemmy_rate_limit = { path = "../lemmy_rate_limit" }
 lemmy_websocket = { path = "../lemmy_websocket" }
index bafde6bfbeb67d3d0736e97e5e88b7039e90cfd6..eb8d68b7c566be4bc87468e99c260e2f1f6e5b17 100644 (file)
@@ -12,10 +12,6 @@ use actix_web::web::Data;
 use lemmy_apub::{ApubLikeableType, ApubObjectType};
 use lemmy_db::{
   source::comment::Comment_,
-  views::{
-    comment_report_view::{CommentReportQueryBuilder, CommentReportView},
-    comment_view::{CommentQueryBuilder, CommentView},
-  },
   Crud,
   Likeable,
   ListingType,
@@ -24,6 +20,10 @@ use lemmy_db::{
   SortType,
 };
 use lemmy_db_schema::source::{comment::*, comment_report::*, moderator::*};
+use lemmy_db_views::{
+  comment_report_view::{CommentReportQueryBuilder, CommentReportView},
+  comment_view::{CommentQueryBuilder, CommentView},
+};
 use lemmy_structs::{blocking, comment::*, send_local_notifs};
 use lemmy_utils::{
   apub::{make_apub_endpoint, EndpointType},
index 405491bd2a2f8da76a28d75fe835677fc5f43e4c..8c2d9ad5a9456a5c522414cf017525156486cc21 100644 (file)
@@ -16,15 +16,6 @@ use lemmy_db::{
     community::{CommunityModerator_, Community_},
     post::Post_,
   },
-  views::{
-    comment_view::CommentQueryBuilder,
-    community::{
-      community_follower_view::CommunityFollowerView,
-      community_moderator_view::CommunityModeratorView,
-      community_view::{CommunityQueryBuilder, CommunityView},
-    },
-    user_view::UserViewSafe,
-  },
   ApubObject,
   Bannable,
   Crud,
@@ -36,6 +27,15 @@ use lemmy_db_schema::{
   naive_now,
   source::{comment::Comment, community::*, moderator::*, post::Post, site::*},
 };
+use lemmy_db_views::{
+  comment_view::CommentQueryBuilder,
+  community::{
+    community_follower_view::CommunityFollowerView,
+    community_moderator_view::CommunityModeratorView,
+    community_view::{CommunityQueryBuilder, CommunityView},
+  },
+  user_view::UserViewSafe,
+};
 use lemmy_structs::{blocking, community::*};
 use lemmy_utils::{
   apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
index 4b61539b4d9853b0af3048e31e70124e66a8f45f..72c2316de2bd6dade2b13bff7e11ae5d9d41659a 100644 (file)
@@ -5,7 +5,6 @@ use lemmy_db::{
     community::{CommunityModerator_, Community_},
     site::Site_,
   },
-  views::community::community_user_ban_view::CommunityUserBanView,
   Crud,
   DbPool,
 };
@@ -15,6 +14,10 @@ use lemmy_db_schema::source::{
   site::Site,
   user::User_,
 };
+use lemmy_db_views::community::{
+  community_user_ban_view::CommunityUserBanView,
+  community_view::CommunityView,
+};
 use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*};
 use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError};
 use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
@@ -47,7 +50,7 @@ pub(crate) async fn is_mod_or_admin(
   community_id: i32,
 ) -> Result<(), LemmyError> {
   let is_mod_or_admin = blocking(pool, move |conn| {
-    Community::is_mod_or_admin(conn, user_id, community_id)
+    CommunityView::is_mod_or_admin(conn, user_id, community_id)
   })
   .await?;
   if !is_mod_or_admin {
index 20b5b8d556e1e6f77fef4a1f137675adc0858526..6f51497026be9d0ad1fcd6b8f8e556d221881c41 100644 (file)
@@ -10,21 +10,7 @@ use crate::{
 };
 use actix_web::web::Data;
 use lemmy_apub::{ApubLikeableType, ApubObjectType};
-use lemmy_db::{
-  source::post::Post_,
-  views::{
-    comment_view::CommentQueryBuilder,
-    community::community_moderator_view::CommunityModeratorView,
-    post_report_view::{PostReportQueryBuilder, PostReportView},
-    post_view::{PostQueryBuilder, PostView},
-  },
-  Crud,
-  Likeable,
-  ListingType,
-  Reportable,
-  Saveable,
-  SortType,
-};
+use lemmy_db::{source::post::Post_, Crud, Likeable, ListingType, Reportable, Saveable, SortType};
 use lemmy_db_schema::{
   naive_now,
   source::{
@@ -33,6 +19,12 @@ use lemmy_db_schema::{
     post_report::{PostReport, PostReportForm},
   },
 };
+use lemmy_db_views::{
+  comment_view::CommentQueryBuilder,
+  community::community_moderator_view::CommunityModeratorView,
+  post_report_view::{PostReportQueryBuilder, PostReportView},
+  post_view::{PostQueryBuilder, PostView},
+};
 use lemmy_structs::{blocking, post::*};
 use lemmy_utils::{
   apub::{make_apub_endpoint, EndpointType},
index e30e62303213683d5496352b47dd753686b42163..dcf35c007e22a4f8d4b2bf0312b8eaaccd630b99 100644 (file)
@@ -12,24 +12,6 @@ use lemmy_apub::fetcher::search_by_apub_id;
 use lemmy_db::{
   diesel_option_overwrite,
   source::{category::Category_, site::Site_},
-  views::{
-    comment_view::CommentQueryBuilder,
-    community::community_view::CommunityQueryBuilder,
-    moderator::{
-      mod_add_community_view::ModAddCommunityView,
-      mod_add_view::ModAddView,
-      mod_ban_from_community_view::ModBanFromCommunityView,
-      mod_ban_view::ModBanView,
-      mod_lock_post_view::ModLockPostView,
-      mod_remove_comment_view::ModRemoveCommentView,
-      mod_remove_community_view::ModRemoveCommunityView,
-      mod_remove_post_view::ModRemovePostView,
-      mod_sticky_post_view::ModStickyPostView,
-    },
-    post_view::PostQueryBuilder,
-    site_view::SiteView,
-    user_view::{UserQueryBuilder, UserViewSafe},
-  },
   Crud,
   SearchType,
   SortType,
@@ -42,6 +24,24 @@ use lemmy_db_schema::{
     site::{Site, *},
   },
 };
+use lemmy_db_views::{
+  comment_view::CommentQueryBuilder,
+  community::community_view::CommunityQueryBuilder,
+  moderator::{
+    mod_add_community_view::ModAddCommunityView,
+    mod_add_view::ModAddView,
+    mod_ban_from_community_view::ModBanFromCommunityView,
+    mod_ban_view::ModBanView,
+    mod_lock_post_view::ModLockPostView,
+    mod_remove_comment_view::ModRemoveCommentView,
+    mod_remove_community_view::ModRemoveCommunityView,
+    mod_remove_post_view::ModRemovePostView,
+    mod_sticky_post_view::ModStickyPostView,
+  },
+  post_view::PostQueryBuilder,
+  site_view::SiteView,
+  user_view::{UserQueryBuilder, UserViewSafe},
+};
 use lemmy_structs::{blocking, site::*, user::Register};
 use lemmy_utils::{
   location_info,
index 34ef5022e17f470ed1ceada4a1dc81de2ea52e18..90891154635674eeec7fae43932d010848617d24 100644 (file)
@@ -26,19 +26,6 @@ use lemmy_db::{
     user::User,
     user_mention::UserMention_,
   },
-  views::{
-    comment_report_view::CommentReportView,
-    comment_view::CommentQueryBuilder,
-    community::{
-      community_follower_view::CommunityFollowerView,
-      community_moderator_view::CommunityModeratorView,
-    },
-    post_report_view::PostReportView,
-    post_view::PostQueryBuilder,
-    private_message_view::{PrivateMessageQueryBuilder, PrivateMessageView},
-    user_mention_view::{UserMentionQueryBuilder, UserMentionView},
-    user_view::{UserViewDangerous, UserViewSafe},
-  },
   Crud,
   Followable,
   Joinable,
@@ -59,6 +46,19 @@ use lemmy_db_schema::{
     user_mention::*,
   },
 };
+use lemmy_db_views::{
+  comment_report_view::CommentReportView,
+  comment_view::CommentQueryBuilder,
+  community::{
+    community_follower_view::CommunityFollowerView,
+    community_moderator_view::CommunityModeratorView,
+  },
+  post_report_view::PostReportView,
+  post_view::PostQueryBuilder,
+  private_message_view::{PrivateMessageQueryBuilder, PrivateMessageView},
+  user_mention_view::{UserMentionQueryBuilder, UserMentionView},
+  user_view::{UserViewDangerous, UserViewSafe},
+};
 use lemmy_structs::{blocking, send_email_to_user, user::*};
 use lemmy_utils::{
   apub::{generate_actor_keypair, make_apub_endpoint, EndpointType},
index 09dd9be83d47cd9853edee1aa1356f82bd4c4e82..a912f4487ec6a8e27b002ddeff358f8df047c5c1 100644 (file)
@@ -10,8 +10,9 @@ path = "src/lib.rs"
 
 [dependencies]
 lemmy_utils = { path = "../lemmy_utils" }
-lemmy_db = { path = "../lemmy_db" }
+lemmy_db_queries = { path = "../lemmy_db_queries" }
 lemmy_db_schema = { path = "../lemmy_db_schema" }
+lemmy_db_views = { path = "../lemmy_db_views" }
 lemmy_structs = { path = "../lemmy_structs" }
 lemmy_websocket = { path = "../lemmy_websocket" }
 diesel = "1.4.5"
index 0149e9313307adc7d3062be4b467bc73f0608e60..483ef54fe3a2e7bb2d965ba088e5c3a9557dda5b 100644 (file)
@@ -4,11 +4,12 @@ use activitystreams::{
   base::ExtendsExt,
 };
 use anyhow::Context;
-use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Crud, Likeable};
+use lemmy_db::{source::comment::Comment_, Crud, Likeable};
 use lemmy_db_schema::source::{
   comment::{Comment, CommentLike, CommentLikeForm},
   post::Post,
 };
+use lemmy_db_views::comment_view::CommentView;
 use lemmy_structs::{blocking, comment::CommentResponse, send_local_notifs};
 use lemmy_utils::{location_info, utils::scrape_text_for_mentions, LemmyError};
 use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
index 7e67204578c03e66b751cfc4425f43a0bf3e8989..4f845523d2d120943fa9f6f6dc98f7fd1ba84b4e 100644 (file)
@@ -1,7 +1,8 @@
 use crate::activities::receive::get_actor_as_user;
 use activitystreams::activity::{Dislike, Like};
-use lemmy_db::{source::comment::Comment_, views::comment_view::CommentView, Likeable};
+use lemmy_db::{source::comment::Comment_, Likeable};
 use lemmy_db_schema::source::comment::{Comment, CommentLike};
+use lemmy_db_views::comment_view::CommentView;
 use lemmy_structs::{blocking, comment::CommentResponse};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation};
index 932917b1e570fb2d213cc5c693abcc72319eb1a2..f493a56322c95f037c82de00fdf8c8da8970c2e0 100644 (file)
@@ -4,12 +4,9 @@ use activitystreams::{
   base::{AnyBase, ExtendsExt},
 };
 use anyhow::Context;
-use lemmy_db::{
-  source::community::Community_,
-  views::community::community_view::CommunityView,
-  ApubObject,
-};
+use lemmy_db::{source::community::Community_, ApubObject};
 use lemmy_db_schema::source::community::Community;
+use lemmy_db_views::community::community_view::CommunityView;
 use lemmy_structs::{blocking, community::CommunityResponse};
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
index 8e20da75fb905084360b2db385df77e6d66e382a..2b46cf54acbf902dd5c0f8a10e80cf883b50bb4e 100644 (file)
@@ -4,8 +4,9 @@ use activitystreams::{
   prelude::*,
 };
 use anyhow::Context;
-use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable};
+use lemmy_db::{source::post::Post_, Likeable};
 use lemmy_db_schema::source::post::{Post, PostLike, PostLikeForm};
+use lemmy_db_views::post_view::PostView;
 use lemmy_structs::{blocking, post::PostResponse};
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
index facaf65f193730be0dead566430bd2c19bbfbdf3..bf188a9f694b2087cd2f3d6858baff44bc9a2dba 100644 (file)
@@ -1,7 +1,8 @@
 use crate::activities::receive::get_actor_as_user;
 use activitystreams::activity::{Dislike, Like};
-use lemmy_db::{source::post::Post_, views::post_view::PostView, Likeable};
+use lemmy_db::{source::post::Post_, Likeable};
 use lemmy_db_schema::source::post::{Post, PostLike};
+use lemmy_db_views::post_view::PostView;
 use lemmy_structs::{blocking, post::PostResponse};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation};
index 09c234cac2e9a2e93e46c2340886561a9e23cc79..d2755094a08655171de23c502fc7920b6380fe19 100644 (file)
@@ -13,11 +13,9 @@ use activitystreams::{
   public,
 };
 use anyhow::{anyhow, Context};
-use lemmy_db::{
-  source::private_message::PrivateMessage_,
-  views::private_message_view::PrivateMessageView,
-};
+use lemmy_db::source::private_message::PrivateMessage_;
 use lemmy_db_schema::source::private_message::PrivateMessage;
+use lemmy_db_views::private_message_view::PrivateMessageView;
 use lemmy_structs::{blocking, user::PrivateMessageResponse};
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::{messages::SendUserRoomMessage, LemmyContext, UserOperation};
index 035a8dfed8e0bde1c6aec6cf370316d8a08105d1..1a4a4a5720934fbf0dc43f4c60fac74df171839a 100644 (file)
@@ -23,8 +23,9 @@ use activitystreams::{
 };
 use anyhow::Context;
 use itertools::Itertools;
-use lemmy_db::{views::community::community_follower_view::CommunityFollowerView, DbPool};
+use lemmy_db::DbPool;
 use lemmy_db_schema::source::community::Community;
+use lemmy_db_views::community::community_follower_view::CommunityFollowerView;
 use lemmy_structs::blocking;
 use lemmy_utils::{location_info, settings::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;
index 608302fabd4d444cce4e412a2eae06fe6502144a..e67fbc9694c2f659b41256d80e3a20bfb8431c12 100644 (file)
@@ -12,19 +12,7 @@ use activitystreams::{base::BaseExt, collection::OrderedCollection, prelude::*};
 use anyhow::{anyhow, Context};
 use chrono::NaiveDateTime;
 use diesel::result::Error::NotFound;
-use lemmy_db::{
-  source::user::User,
-  views::{
-    comment_view::CommentView,
-    community::community_view::CommunityView,
-    post_view::PostView,
-    user_view::UserViewSafe,
-  },
-  ApubObject,
-  Crud,
-  Joinable,
-  SearchType,
-};
+use lemmy_db::{source::user::User, ApubObject, Crud, Joinable, SearchType};
 use lemmy_db_schema::{
   naive_now,
   source::{
@@ -34,6 +22,12 @@ use lemmy_db_schema::{
     user::User_,
   },
 };
+use lemmy_db_views::{
+  comment_view::CommentView,
+  community::community_view::CommunityView,
+  post_view::PostView,
+  user_view::UserViewSafe,
+};
 use lemmy_structs::{blocking, site::SearchResponse};
 use lemmy_utils::{
   location_info,
index 45c576d24c09f8794dcf98bcdff223db0759fa59..011f2d88986045a099a0af78dd04acf7258c4432 100644 (file)
@@ -9,11 +9,9 @@ use activitystreams::{
   collection::{CollectionExt, OrderedCollection, UnorderedCollection},
 };
 use actix_web::{body::Body, web, HttpResponse};
-use lemmy_db::{
-  source::{community::Community_, post::Post_},
-  views::community::community_follower_view::CommunityFollowerView,
-};
+use lemmy_db::source::{community::Community_, post::Post_};
 use lemmy_db_schema::source::{community::Community, post::Post};
+use lemmy_db_views::community::community_follower_view::CommunityFollowerView;
 use lemmy_structs::blocking;
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index f82da236bd176aaa3b6d74bb9e58847c78f7aa9f..e6d7b29c717ffc3d91c794799b555a05041e1132 100644 (file)
@@ -26,17 +26,12 @@ use activitystreams::{
 };
 use actix_web::{web, HttpRequest, HttpResponse};
 use anyhow::{anyhow, Context};
-use lemmy_db::{
-  source::community::Community_,
-  views::community::community_user_ban_view::CommunityUserBanView,
-  ApubObject,
-  DbPool,
-  Followable,
-};
+use lemmy_db::{source::community::Community_, ApubObject, DbPool, Followable};
 use lemmy_db_schema::source::{
   community::{Community, CommunityFollower, CommunityFollowerForm},
   user::User_,
 };
+use lemmy_db_views::community::community_user_ban_view::CommunityUserBanView;
 use lemmy_structs::blocking;
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::LemmyContext;
index b408f7737ba3c6a3d848449903cce151b578bbff..f4910716a053adb9c0c2e3018f15f684e9bd7af2 100644 (file)
@@ -22,11 +22,12 @@ use activitystreams::{
 };
 use activitystreams_ext::Ext2;
 use anyhow::Context;
-use lemmy_db::{views::community::community_moderator_view::CommunityModeratorView, DbPool};
+use lemmy_db::DbPool;
 use lemmy_db_schema::{
   naive_now,
   source::community::{Community, CommunityForm},
 };
+use lemmy_db_views::community::community_moderator_view::CommunityModeratorView;
 use lemmy_structs::blocking;
 use lemmy_utils::{
   location_info,
diff --git a/lemmy_db_aggregates/Cargo.toml b/lemmy_db_aggregates/Cargo.toml
new file mode 100644 (file)
index 0000000..6fdd77f
--- /dev/null
@@ -0,0 +1,11 @@
+[package]
+name = "lemmy_db_aggregates"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+lemmy_db_schema = { path = "../lemmy_db_schema" }
+lemmy_db_queries = { path = "../lemmy_db_queries" }
+diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
+serde = { version = "1.0.118", features = ["derive"] }
+chrono = { version = "0.4.19", features = ["serde"] }
similarity index 94%
rename from lemmy_db/src/aggregates/comment_aggregates.rs
rename to lemmy_db_aggregates/src/comment_aggregates.rs
index c6b726755a99383b96e6a0b2075140dc0e8592a0..611ec287c3698d5004a5c01a479db35157f56ce2 100644 (file)
@@ -22,19 +22,13 @@ impl CommentAggregates {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    aggregates::comment_aggregates::CommentAggregates,
-    source::{
-      comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
-      community::{Community, CommunityForm},
-      post::{Post, PostForm},
-      user::{UserForm, User_},
-    },
-    tests::establish_unpooled_connection,
-    Crud,
-    Likeable,
-    ListingType,
-    SortType,
+  use crate::comment_aggregates::CommentAggregates;
+  use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType};
+  use lemmy_db_schema::source::{
+    comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
+    community::{Community, CommunityForm},
+    post::{Post, PostForm},
+    user::{UserForm, User_},
   };
 
   #[test]
similarity index 97%
rename from lemmy_db/src/aggregates/community_aggregates.rs
rename to lemmy_db_aggregates/src/community_aggregates.rs
index 229652f00037d54925c813fc15e1c06e32bcdb1a..d6491546ce8fc5eb4212098af0e9c8d9be126a1a 100644 (file)
@@ -22,14 +22,8 @@ impl CommunityAggregates {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    aggregates::community_aggregates::CommunityAggregates,
-    tests::establish_unpooled_connection,
-    Crud,
-    Followable,
-    ListingType,
-    SortType,
-  };
+  use crate::community_aggregates::CommunityAggregates;
+  use lemmy_db::{establish_unpooled_connection, Crud, Followable, ListingType, SortType};
   use lemmy_db_schema::source::{
     comment::{Comment, CommentForm},
     community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
similarity index 97%
rename from lemmy_db/src/aggregates/post_aggregates.rs
rename to lemmy_db_aggregates/src/post_aggregates.rs
index 01082ca06b226e0af6de60d8b1a7d3df7641cbc5..e2d9140856f128f0ff64a4593e88821c098dc985 100644 (file)
@@ -24,14 +24,8 @@ impl PostAggregates {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    aggregates::post_aggregates::PostAggregates,
-    tests::establish_unpooled_connection,
-    Crud,
-    Likeable,
-    ListingType,
-    SortType,
-  };
+  use crate::post_aggregates::PostAggregates;
+  use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType};
   use lemmy_db_schema::source::{
     comment::{Comment, CommentForm},
     community::{Community, CommunityForm},
similarity index 96%
rename from lemmy_db/src/aggregates/site_aggregates.rs
rename to lemmy_db_aggregates/src/site_aggregates.rs
index 70997a66a77dd7427216a49901afe49ad6e40e95..559c5b53da53331b99ed1ee14ba2572350189316 100644 (file)
@@ -21,17 +21,13 @@ impl SiteAggregates {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    aggregates::site_aggregates::SiteAggregates,
-    tests::establish_unpooled_connection,
-    Crud,
-    ListingType,
-    SortType,
-  };
+  use crate::site_aggregates::SiteAggregates;
+  use lemmy_db::{establish_unpooled_connection, Crud, ListingType, SortType};
   use lemmy_db_schema::source::{
     comment::{Comment, CommentForm},
     community::{Community, CommunityForm},
     post::{Post, PostForm},
+    site::{Site, SiteForm},
     user::{UserForm, User_},
   };
 
similarity index 97%
rename from lemmy_db/src/aggregates/user_aggregates.rs
rename to lemmy_db_aggregates/src/user_aggregates.rs
index e8981fd62f93a15026f3a2fd037e5f8ed6467c50..cf5dfe69e73438e9bc9067a25dab5bf291f203ea 100644 (file)
@@ -23,14 +23,8 @@ impl UserAggregates {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    aggregates::user_aggregates::UserAggregates,
-    tests::establish_unpooled_connection,
-    Crud,
-    Likeable,
-    ListingType,
-    SortType,
-  };
+  use crate::user_aggregates::UserAggregates;
+  use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType};
   use lemmy_db_schema::source::{
     comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
     community::{Community, CommunityForm},
similarity index 96%
rename from lemmy_db/Cargo.toml
rename to lemmy_db_queries/Cargo.toml
index 15dd749acaff940c7f98c68fea09fdf348be038f..eb633c7d1b1ca950cc7183b684b36abb278d5489 100644 (file)
@@ -1,5 +1,5 @@
 [package]
-name = "lemmy_db"
+name = "lemmy_db_queries"
 version = "0.1.0"
 edition = "2018"
 
similarity index 88%
rename from lemmy_db/src/lib.rs
rename to lemmy_db_queries/src/lib.rs
index 8e3521478dcdf9eacb42149c5c286b9f451d6073..6f4c62c7fcad0e462401feefba59116452f3cca8 100644 (file)
@@ -14,9 +14,7 @@ use regex::Regex;
 use serde::{Deserialize, Serialize};
 use std::{env, env::VarError};
 
-pub mod aggregates;
 pub mod source;
-pub mod views;
 
 pub type DbPool = diesel::r2d2::Pool<diesel::r2d2::ConnectionManager<diesel::PgConnection>>;
 
@@ -133,7 +131,7 @@ impl<T> MaybeOptional<T> for Option<T> {
   }
 }
 
-pub(crate) trait ToSafe {
+pub trait ToSafe {
   type SafeColumns;
   fn safe_columns_tuple() -> Self::SafeColumns;
 }
@@ -202,12 +200,28 @@ pub fn diesel_option_overwrite(opt: &Option<String>) -> Option<Option<String>> {
   }
 }
 
+embed_migrations!();
+
+pub fn establish_unpooled_connection() -> PgConnection {
+  let db_url = match get_database_url_from_env() {
+    Ok(url) => url,
+    Err(e) => panic!(
+      "Failed to read database URL from env var LEMMY_DATABASE_URL: {}",
+      e
+    ),
+  };
+  let conn =
+    PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
+  embedded_migrations::run(&conn).unwrap();
+  conn
+}
+
 lazy_static! {
   static ref EMAIL_REGEX: Regex =
     Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$").unwrap();
 }
 
-pub(crate) mod functions {
+pub mod functions {
   use diesel::sql_types::*;
 
   sql_function! {
@@ -218,24 +232,7 @@ pub(crate) mod functions {
 #[cfg(test)]
 mod tests {
   use super::fuzzy_search;
-  use crate::{get_database_url_from_env, is_email_regex};
-  use diesel::{Connection, PgConnection};
-
-  embed_migrations!();
-
-  pub fn establish_unpooled_connection() -> PgConnection {
-    let db_url = match get_database_url_from_env() {
-      Ok(url) => url,
-      Err(e) => panic!(
-        "Failed to read database URL from env var LEMMY_DATABASE_URL: {}",
-        e
-      ),
-    };
-    let conn =
-      PgConnection::establish(&db_url).unwrap_or_else(|_| panic!("Error connecting to {}", db_url));
-    embedded_migrations::run(&conn).unwrap();
-    conn
-  }
+  use crate::is_email_regex;
 
   #[test]
   fn test_fuzzy_search() {
similarity index 97%
rename from lemmy_db/src/source/activity.rs
rename to lemmy_db_queries/src/source/activity.rs
index d63b3b6bf861900efb1d91ca71aa738ccdd5e00e..662db3aedc38645febfe9eded1ead44ce45ca0d1 100644 (file)
@@ -87,7 +87,13 @@ impl Activity_ for Activity {
 
 #[cfg(test)]
 mod tests {
-  use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+  use crate::{
+    establish_unpooled_connection,
+    source::activity::Activity_,
+    Crud,
+    ListingType,
+    SortType,
+  };
   use lemmy_db_schema::source::{
     activity::{Activity, ActivityForm},
     user::{UserForm, User_},
similarity index 94%
rename from lemmy_db/src/source/category.rs
rename to lemmy_db_queries/src/source/category.rs
index c190ddf8ffa925e0e8723d9b50085beb3e0e9756..2d9eeb37b4ed5a374719e6a7aa4f04e5ef4eeb8a 100644 (file)
@@ -36,7 +36,7 @@ impl Category_ for Category {
 
 #[cfg(test)]
 mod tests {
-  use crate::tests::establish_unpooled_connection;
+  use crate::{establish_unpooled_connection, source::category::Category_};
   use lemmy_db_schema::source::category::Category;
 
   #[test]
similarity index 98%
rename from lemmy_db/src/source/comment.rs
rename to lemmy_db_queries/src/source/comment.rs
index d70d7b6998763454eac1644be22878cf8ac2a8fd..6e99bf36e2fad795b2c0b51c284e49acb8c79261 100644 (file)
@@ -204,14 +204,7 @@ impl Saveable<CommentSavedForm> for CommentSaved {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    tests::establish_unpooled_connection,
-    Crud,
-    Likeable,
-    ListingType,
-    Saveable,
-    SortType,
-  };
+  use crate::{establish_unpooled_connection, Crud, Likeable, ListingType, Saveable, SortType};
   use lemmy_db_schema::source::{
     comment::*,
     community::{Community, CommunityForm},
similarity index 92%
rename from lemmy_db/src/source/community.rs
rename to lemmy_db_queries/src/source/community.rs
index 9a30ca4cde390c22c78c1c9e774a88ed023520ba..28245d8dc358f2db41a8181101c2f52d221a1902 100644 (file)
@@ -1,11 +1,4 @@
-use crate::{
-  views::{community::community_moderator_view::CommunityModeratorView, user_view::UserViewSafe},
-  ApubObject,
-  Bannable,
-  Crud,
-  Followable,
-  Joinable,
-};
+use crate::{ApubObject, Bannable, Crud, Followable, Joinable};
 use diesel::{dsl::*, result::Error, *};
 use lemmy_db_schema::{
   naive_now,
@@ -138,9 +131,7 @@ pub trait Community_ {
     community_id: i32,
     new_creator_id: i32,
   ) -> Result<Community, Error>;
-  fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error>;
   fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error>;
-  fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool;
 }
 
 impl Community_ for Community {
@@ -196,27 +187,10 @@ impl Community_ for Community {
       .get_result::<Self>(conn)
   }
 
-  fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error> {
-    let mut mods_and_admins: Vec<i32> = Vec::new();
-    mods_and_admins.append(
-      &mut CommunityModeratorView::for_community(conn, community_id)
-        .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?,
-    );
-    mods_and_admins
-      .append(&mut UserViewSafe::admins(conn).map(|v| v.into_iter().map(|a| a.user.id).collect())?);
-    Ok(mods_and_admins)
-  }
-
   fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
     use lemmy_db_schema::schema::community::dsl::*;
     community.select(actor_id).distinct().load::<String>(conn)
   }
-
-  fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool {
-    Self::community_mods_and_admins(conn, community_id)
-      .unwrap_or_default()
-      .contains(&user_id)
-  }
 }
 
 impl Joinable<CommunityModeratorForm> for CommunityModerator {
@@ -347,7 +321,7 @@ impl Followable<CommunityFollowerForm> for CommunityFollower {
 #[cfg(test)]
 mod tests {
   use crate::{
-    tests::establish_unpooled_connection,
+    establish_unpooled_connection,
     Bannable,
     Crud,
     Followable,
similarity index 99%
rename from lemmy_db/src/source/moderator.rs
rename to lemmy_db_queries/src/source/moderator.rs
index b0a17d6d5f89edcf65431ca46b458deb0c038e66..93c424164ab928217867bfd1a08e9340be38a7c3 100644 (file)
@@ -197,7 +197,7 @@ impl Crud<ModAddForm> for ModAdd {
 
 #[cfg(test)]
 mod tests {
-  use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+  use crate::{establish_unpooled_connection, Crud, ListingType, SortType};
   use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, user::*};
 
   // use Crud;
similarity index 96%
rename from lemmy_db/src/source/password_reset_request.rs
rename to lemmy_db_queries/src/source/password_reset_request.rs
index 9ca8dab6821f62b18075d5cc91472101fd5089bd..d4ba2f12d4a571bab43b32b54326fb808040c0d1 100644 (file)
@@ -72,7 +72,13 @@ fn bytes_to_hex(bytes: Vec<u8>) -> String {
 
 #[cfg(test)]
 mod tests {
-  use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+  use crate::{
+    establish_unpooled_connection,
+    source::password_reset_request::PasswordResetRequest_,
+    Crud,
+    ListingType,
+    SortType,
+  };
   use lemmy_db_schema::source::{password_reset_request::PasswordResetRequest, user::*};
 
   #[test]
similarity index 99%
rename from lemmy_db/src/source/post.rs
rename to lemmy_db_queries/src/source/post.rs
index c681adbe47bf1282b7c5e188c63d0852121bc258..bca848cad2af96369aa0d0841053d6e75703fc96 100644 (file)
@@ -225,7 +225,7 @@ impl Readable<PostReadForm> for PostRead {
 
 #[cfg(test)]
 mod tests {
-  use crate::{source::post::*, tests::establish_unpooled_connection, ListingType, SortType};
+  use crate::{establish_unpooled_connection, source::post::*, ListingType, SortType};
   use lemmy_db_schema::source::{
     community::{Community, CommunityForm},
     user::*,
similarity index 98%
rename from lemmy_db/src/source/private_message.rs
rename to lemmy_db_queries/src/source/private_message.rs
index b49ed8f4f30c04f2dbc3cb036e98c46e9230b4d0..d63f698d90709b9fa0ac06cb001e49f75a3f393c 100644 (file)
@@ -139,7 +139,13 @@ impl PrivateMessage_ for PrivateMessage {
 
 #[cfg(test)]
 mod tests {
-  use crate::{tests::establish_unpooled_connection, ListingType, SortType};
+  use crate::{
+    establish_unpooled_connection,
+    source::private_message::PrivateMessage_,
+    Crud,
+    ListingType,
+    SortType,
+  };
   use lemmy_db_schema::source::{private_message::*, user::*};
 
   #[test]
similarity index 99%
rename from lemmy_db/src/source/user.rs
rename to lemmy_db_queries/src/source/user.rs
index 7461f4b45675d1b979d965e71c1876bc40e87b94..7789ff2beb4e11f0b56e6e58065519292db71e97 100644 (file)
@@ -297,7 +297,7 @@ impl User for User_ {
 
 #[cfg(test)]
 mod tests {
-  use crate::{source::user::*, tests::establish_unpooled_connection, ListingType, SortType};
+  use crate::{establish_unpooled_connection, source::user::*, ListingType, SortType};
 
   #[test]
   fn test_crud() {
similarity index 98%
rename from lemmy_db/src/source/user_mention.rs
rename to lemmy_db_queries/src/source/user_mention.rs
index 64406f989f8c0db5116b4674e67298abad0a07df..d9e0cce30da84213514f6b718e7b858f28ddd8f3 100644 (file)
@@ -73,7 +73,7 @@ impl UserMention_ for UserMention {
 
 #[cfg(test)]
 mod tests {
-  use crate::{tests::establish_unpooled_connection, Crud, ListingType, SortType};
+  use crate::{establish_unpooled_connection, Crud, ListingType, SortType};
   use lemmy_db_schema::source::{
     comment::*,
     community::{Community, CommunityForm},
index 3868a3b753969265f9f2f4b36a76228a5b9282be..981ecba27f0e0e217f59c2e35f7f8e280cf28246 100644 (file)
@@ -6,7 +6,7 @@ use chrono::NaiveDateTime;
 pub mod schema;
 pub mod source;
 
-// TODO: can probably move this back to lemmy_db
+// TODO: can probably move this back to lemmy_db_queries
 pub fn naive_now() -> NaiveDateTime {
   chrono::prelude::Utc::now().naive_utc()
 }
index ec53408d125a13e677a8df257d7e9af856418695..d94fed578cc38bbc35b35471e16a82d2bc0fa41e 100644 (file)
@@ -1,9 +1,7 @@
 use crate::{schema::comment_report, source::comment::Comment};
 use serde::{Deserialize, Serialize};
 
-#[derive(
-  Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone,
-)]
+#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
 #[belongs_to(Comment)]
 #[table_name = "comment_report"]
 pub struct CommentReport {
index b75fb954a078cc1a6bc77b01d8a2836523d68298..608104dbc90dcf14bf8796f54d1de1919a6ea98a 100644 (file)
@@ -1,9 +1,7 @@
 use crate::{schema::post_report, source::post::Post};
 use serde::{Deserialize, Serialize};
 
-#[derive(
-  Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone,
-)]
+#[derive(Identifiable, Queryable, Associations, PartialEq, Serialize, Deserialize, Debug, Clone)]
 #[belongs_to(Post)]
 #[table_name = "post_report"]
 pub struct PostReport {
diff --git a/lemmy_db_views/Cargo.toml b/lemmy_db_views/Cargo.toml
new file mode 100644 (file)
index 0000000..86c7ada
--- /dev/null
@@ -0,0 +1,11 @@
+[package]
+name = "lemmy_db_views"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+lemmy_db_queries = { path = "../lemmy_db_queries" }
+lemmy_db_schema = { path = "../lemmy_db_schema" }
+lemmy_db_aggregates = { path = "../lemmy_db_aggregates" }
+diesel = { version = "1.4.5", features = ["postgres","chrono","r2d2","serde_json"] }
+serde = { version = "1.0.118", features = ["derive"] }
\ No newline at end of file
similarity index 98%
rename from lemmy_db/src/views/comment_report_view.rs
rename to lemmy_db_views/src/comment_report_view.rs
index 7a260cd59bf3c5d14476c2df5897d2ec3c5f7e2f..fa795a0bfa086b035fb4aadeeb0c5d7961821560 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe};
 use lemmy_db_schema::{
   schema::{comment, comment_report, community, post, user_, user_alias_1, user_alias_2},
   source::{
similarity index 98%
rename from lemmy_db/src/views/comment_view.rs
rename to lemmy_db_views/src/comment_view.rs
index 1b114e19057473e8deea406a01c3dee75895cba4..3101fcea81cff9803bd802c6969485fa186e4c42 100644 (file)
@@ -1,15 +1,15 @@
-use crate::{
-  aggregates::comment_aggregates::CommentAggregates,
+use crate::ViewToVec;
+use diesel::{result::Error, *};
+use lemmy_db::{
   functions::hot_rank,
   fuzzy_search,
   limit_and_offset,
-  views::ViewToVec,
   ListingType,
   MaybeOptional,
   SortType,
   ToSafe,
 };
-use diesel::{result::Error, *};
+use lemmy_db_aggregates::comment_aggregates::CommentAggregates;
 use lemmy_db_schema::{
   schema::{
     comment,
@@ -418,7 +418,9 @@ impl ViewToVec for CommentView {
 
 #[cfg(test)]
 mod tests {
-  use crate::{tests::establish_unpooled_connection, views::comment_view::*, Crud, Likeable, *};
+  use crate::comment_view::*;
+  use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType};
+  use lemmy_db_aggregates::comment_aggregates::CommentAggregates;
   use lemmy_db_schema::source::{comment::*, community::*, post::*, user::*};
 
   #[test]
similarity index 97%
rename from lemmy_db/src/views/community/community_follower_view.rs
rename to lemmy_db_views/src/community/community_follower_view.rs
index e7ba0e4a6005c13ad6e9a5de0e8faf32f231b9d3..9837624cbd0b2ec022e5a7a5d1d2afada213e3a7 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{views::ViewToVec, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::ToSafe;
 use lemmy_db_schema::{
   schema::{community, community_follower, user_},
   source::{
similarity index 97%
rename from lemmy_db/src/views/community/community_moderator_view.rs
rename to lemmy_db_views/src/community/community_moderator_view.rs
index 6800853ea2a368bc13802543a0c2cb93b804763a..490105d8bbad7bbf8d2a6ddc9dfd20606bddd0ae 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{views::ViewToVec, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::ToSafe;
 use lemmy_db_schema::{
   schema::{community, community_moderator, user_},
   source::{
similarity index 97%
rename from lemmy_db/src/views/community/community_user_ban_view.rs
rename to lemmy_db_views/src/community/community_user_ban_view.rs
index 1c26ebcf1bbce375d0a70503e1dd95a91fb0d22d..ddc902766737b50006cbc43399c9582a1952dcb3 100644 (file)
@@ -1,5 +1,5 @@
-use crate::ToSafe;
 use diesel::{result::Error, *};
+use lemmy_db::ToSafe;
 use lemmy_db_schema::{
   schema::{community, community_user_ban, user_},
   source::{
similarity index 85%
rename from lemmy_db/src/views/community/community_view.rs
rename to lemmy_db_views/src/community/community_view.rs
index 11962d79a92098df5297abd786d569fcfa520d17..fe87e2c786888d2204d7fbb75bbcad5b353ef78d 100644 (file)
@@ -1,14 +1,18 @@
 use crate::{
-  aggregates::community_aggregates::CommunityAggregates,
+  community::community_moderator_view::CommunityModeratorView,
+  user_view::UserViewSafe,
+  ViewToVec,
+};
+use diesel::{result::Error, *};
+use lemmy_db::{
   functions::hot_rank,
   fuzzy_search,
   limit_and_offset,
-  views::ViewToVec,
   MaybeOptional,
   SortType,
   ToSafe,
 };
-use diesel::{result::Error, *};
+use lemmy_db_aggregates::community_aggregates::CommunityAggregates;
 use lemmy_db_schema::{
   schema::{category, community, community_aggregates, community_follower, user_},
   source::{
@@ -74,6 +78,24 @@ impl CommunityView {
       counts,
     })
   }
+
+  // TODO: this function is only used by is_mod_or_admin() below, can probably be merged
+  fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error> {
+    let mut mods_and_admins: Vec<i32> = Vec::new();
+    mods_and_admins.append(
+      &mut CommunityModeratorView::for_community(conn, community_id)
+        .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?,
+    );
+    mods_and_admins
+      .append(&mut UserViewSafe::admins(conn).map(|v| v.into_iter().map(|a| a.user.id).collect())?);
+    Ok(mods_and_admins)
+  }
+
+  pub fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool {
+    Self::community_mods_and_admins(conn, community_id)
+      .unwrap_or_default()
+      .contains(&user_id)
+  }
 }
 
 pub struct CommunityQueryBuilder<'a> {
similarity index 97%
rename from lemmy_db/src/views/moderator/mod_add_community_view.rs
rename to lemmy_db_views/src/moderator/mod_add_community_view.rs
index 302d37a0b347d8e2a615c56cae4c9a1c2c7cce6a..606ee51e8badc465dbf2a62a102fbab1e5a397a1 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
 use lemmy_db_schema::{
   schema::{community, mod_add_community, user_, user_alias_1},
   source::{
similarity index 96%
rename from lemmy_db/src/views/moderator/mod_add_view.rs
rename to lemmy_db_views/src/moderator/mod_add_view.rs
index 8f586a6ff8b35c20042bfdd5406144d1f6794ee9..efe33fd3c79b2c23963d3b3075ff02233e496280 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
 use lemmy_db_schema::{
   schema::{mod_add, user_, user_alias_1},
   source::{
similarity index 97%
rename from lemmy_db/src/views/moderator/mod_ban_from_community_view.rs
rename to lemmy_db_views/src/moderator/mod_ban_from_community_view.rs
index 0ed52dd25f83dfa96424690894ae9ee85d4354ca..430259a41795d936c1493bdbc8072b1e2f3cd6d1 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
 use lemmy_db_schema::{
   schema::{community, mod_ban_from_community, user_, user_alias_1},
   source::{
similarity index 96%
rename from lemmy_db/src/views/moderator/mod_ban_view.rs
rename to lemmy_db_views/src/moderator/mod_ban_view.rs
index 98cf1969f3dfa5d5f1b46278b0b5f4b8be22c6c7..f61a04219dee381ed4c576ced966fe6f37ed2285 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
 use lemmy_db_schema::{
   schema::{mod_ban, user_, user_alias_1},
   source::{
similarity index 96%
rename from lemmy_db/src/views/moderator/mod_lock_post_view.rs
rename to lemmy_db_views/src/moderator/mod_lock_post_view.rs
index dbe81c5c385e5991dfcbc8d3fb5943247bcc17fa..11521329e425333f9343ad609a3a7bd2c3f8da8d 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
 use lemmy_db_schema::{
   schema::{community, mod_lock_post, post, user_},
   source::{
similarity index 97%
rename from lemmy_db/src/views/moderator/mod_remove_comment_view.rs
rename to lemmy_db_views/src/moderator/mod_remove_comment_view.rs
index 04aab30af35e4f5f1b1463897380bb5fc9c2283f..0c52be2f9581d071bbb9cdaffd139b24d4af2e8c 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
 use lemmy_db_schema::{
   schema::{comment, community, mod_remove_comment, post, user_, user_alias_1},
   source::{
similarity index 96%
rename from lemmy_db/src/views/moderator/mod_remove_community_view.rs
rename to lemmy_db_views/src/moderator/mod_remove_community_view.rs
index 37ffe540262fbb7e651b1186fc21ef11e17cd05b..86fcf1954f9adb2e09efe32ad37db1371cb9ce3b 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
 use lemmy_db_schema::{
   schema::{community, mod_remove_community, user_},
   source::{
similarity index 96%
rename from lemmy_db/src/views/moderator/mod_remove_post_view.rs
rename to lemmy_db_views/src/moderator/mod_remove_post_view.rs
index 21bf1b867a3b128778695321336a2846fc4f4a58..d4332918ff3cedc91d065ec020a84e40bb0bddce 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
 use lemmy_db_schema::{
   schema::{community, mod_remove_post, post, user_},
   source::{
similarity index 96%
rename from lemmy_db/src/views/moderator/mod_sticky_post_view.rs
rename to lemmy_db_views/src/moderator/mod_sticky_post_view.rs
index 8512e07935808fe345f6e96cbe699a567cba2cee..ec785ce1b2c4b6f3b0dcd67a767883a4843f41b0 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, ToSafe};
 use lemmy_db_schema::{
   schema::{community, mod_sticky_post, post, user_},
   source::{
similarity index 98%
rename from lemmy_db/src/views/post_report_view.rs
rename to lemmy_db_views/src/post_report_view.rs
index 37d6275cd0abb067711d9366681eff52cc83644c..3e0ef3d68915e9f848647f48e7fd498e829d6a17 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe};
 use lemmy_db_schema::{
   schema::{community, post, post_report, user_, user_alias_1, user_alias_2},
   source::{
similarity index 98%
rename from lemmy_db/src/views/post_view.rs
rename to lemmy_db_views/src/post_view.rs
index 3cfee1b371300c14ec24e7e19c28a912209b73ac..fe11592742516ad4bf590b79b3bad3266062d9e0 100644 (file)
@@ -1,15 +1,15 @@
-use crate::{
-  aggregates::post_aggregates::PostAggregates,
+use crate::ViewToVec;
+use diesel::{result::Error, *};
+use lemmy_db::{
   functions::hot_rank,
   fuzzy_search,
   limit_and_offset,
-  views::ViewToVec,
   ListingType,
   MaybeOptional,
   SortType,
   ToSafe,
 };
-use diesel::{result::Error, *};
+use lemmy_db_aggregates::post_aggregates::PostAggregates;
 use lemmy_db_schema::{
   schema::{
     community,
@@ -406,14 +406,9 @@ impl ViewToVec for PostView {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    aggregates::post_aggregates::PostAggregates,
-    tests::establish_unpooled_connection,
-    views::post_view::{PostQueryBuilder, PostView},
-    Crud,
-    Likeable,
-    *,
-  };
+  use crate::post_view::{PostQueryBuilder, PostView};
+  use lemmy_db::{establish_unpooled_connection, Crud, Likeable, ListingType, SortType};
+  use lemmy_db_aggregates::post_aggregates::PostAggregates;
   use lemmy_db_schema::source::{community::*, post::*, user::*};
 
   #[test]
similarity index 97%
rename from lemmy_db/src/views/private_message_view.rs
rename to lemmy_db_views/src/private_message_view.rs
index f439a75d54128f0235038e54cbc3ddbd36d995e9..62cb78987eab121d522f582ecb3fbb6afd4c12ad 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{limit_and_offset, views::ViewToVec, MaybeOptional, ToSafe};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{limit_and_offset, MaybeOptional, ToSafe};
 use lemmy_db_schema::{
   schema::{private_message, user_, user_alias_1},
   source::{
similarity index 90%
rename from lemmy_db/src/views/site_view.rs
rename to lemmy_db_views/src/site_view.rs
index 7772ccdcef6b37da0ad2e81e25bc6a2c691a614a..a4c533e05ece1aba0a5d60857b968b0501d21f04 100644 (file)
@@ -1,5 +1,6 @@
-use crate::{aggregates::site_aggregates::SiteAggregates, ToSafe};
 use diesel::{result::Error, *};
+use lemmy_db::ToSafe;
+use lemmy_db_aggregates::site_aggregates::SiteAggregates;
 use lemmy_db_schema::{
   schema::{site, site_aggregates, user_},
   source::{
similarity index 98%
rename from lemmy_db/src/views/user_mention_view.rs
rename to lemmy_db_views/src/user_mention_view.rs
index 2cd1cd3c87dca2426e6d4985f79c5ed38cb0aaa2..f6afd298a15bec143aad939c0ce7236283e28829 100644 (file)
@@ -1,13 +1,7 @@
-use crate::{
-  aggregates::comment_aggregates::CommentAggregates,
-  functions::hot_rank,
-  limit_and_offset,
-  views::ViewToVec,
-  MaybeOptional,
-  SortType,
-  ToSafe,
-};
+use crate::ViewToVec;
 use diesel::{result::Error, *};
+use lemmy_db::{functions::hot_rank, limit_and_offset, MaybeOptional, SortType, ToSafe};
+use lemmy_db_aggregates::comment_aggregates::CommentAggregates;
 use lemmy_db_schema::{
   schema::{
     comment,
similarity index 96%
rename from lemmy_db/src/views/user_view.rs
rename to lemmy_db_views/src/user_view.rs
index f3109011e91a13d50c3f863da89b967c2ab65d92..5e5e7f2c1713985ee1ae4d863e96bd5da02d68ba 100644 (file)
@@ -1,13 +1,7 @@
-use crate::{
-  aggregates::user_aggregates::UserAggregates,
-  fuzzy_search,
-  limit_and_offset,
-  views::ViewToVec,
-  MaybeOptional,
-  SortType,
-  ToSafe,
-};
+use crate::ViewToVec;
 use diesel::{dsl::*, result::Error, *};
+use lemmy_db::{fuzzy_search, limit_and_offset, MaybeOptional, SortType, ToSafe};
+use lemmy_db_aggregates::user_aggregates::UserAggregates;
 use lemmy_db_schema::{
   schema::{user_, user_aggregates},
   source::user::{UserSafe, User_},
index 329ef4139a125e9d5454498c299dce4091b11439..d4f013b92f2e2f40c5190c3862f28533a2d01d00 100644 (file)
@@ -9,7 +9,8 @@ name = "lemmy_structs"
 path = "src/lib.rs"
 
 [dependencies]
-lemmy_db = { path = "../lemmy_db" }
+lemmy_db_queries = { path = "../lemmy_db_queries" }
+lemmy_db_views = { path = "../lemmy_db_views" }
 lemmy_db_schema = { path = "../lemmy_db_schema" }
 lemmy_utils = { path = "../lemmy_utils" }
 serde = { version = "1.0.118", features = ["derive"] }
index fe65738d873d801d2f71b020f29994856e05ed7f..1e113b366231257d3f0980ad39074e5e6707c3eb 100644 (file)
@@ -1,4 +1,4 @@
-use lemmy_db::views::{comment_report_view::CommentReportView, comment_view::CommentView};
+use lemmy_db_views::{comment_report_view::CommentReportView, comment_view::CommentView};
 use serde::{Deserialize, Serialize};
 
 #[derive(Deserialize)]
index 65ea0aaaff0a97b6ccf785541702488c6fb7bb9c..74f7a4e4279c141760db5c01d48d81b7e9379b1c 100644 (file)
@@ -1,4 +1,4 @@
-use lemmy_db::views::{
+use lemmy_db_views::{
   community::{
     community_follower_view::CommunityFollowerView,
     community_moderator_view::CommunityModeratorView,
index ac29d8f7807d373ad0f24ad697bc141fbedffa93..5a35fa37ed92aa6e29a429ec13b90ff9cc419ac4 100644 (file)
@@ -1,4 +1,4 @@
-use lemmy_db::views::{
+use lemmy_db_views::{
   comment_view::CommentView,
   community::community_moderator_view::CommunityModeratorView,
   post_report_view::PostReportView,
index f24d9f49ee42db21292b2d09f40a253653b4beea..fbb295d51cfda76b6b04f3e0f285586ee518f6fc 100644 (file)
@@ -1,4 +1,5 @@
-use lemmy_db::views::{
+use lemmy_db_schema::source::{category::*, user::User_};
+use lemmy_db_views::{
   comment_view::CommentView,
   community::community_view::CommunityView,
   moderator::{
@@ -16,7 +17,6 @@ use lemmy_db::views::{
   site_view::SiteView,
   user_view::UserViewSafe,
 };
-use lemmy_db_schema::source::{category::*, user::User_};
 use serde::{Deserialize, Serialize};
 
 #[derive(Deserialize)]
index 52871696cf71cabd7ce4b080fe94280604536283..4b4d6a886d09b8e09ec4255630402ec6649d592e 100644 (file)
@@ -1,4 +1,4 @@
-use lemmy_db::views::{
+use lemmy_db_views::{
   comment_view::CommentView,
   community::{
     community_follower_view::CommunityFollowerView,
index 4edcbd13be9c3135c372c2609ea6af1fb7be92d5..4ca87f2829c7791f832eff4123ad4dfdada3a080 100644 (file)
@@ -89,7 +89,7 @@ impl Settings {
   /// added to the config.
   ///
   /// Note: The env var `LEMMY_DATABASE_URL` is parsed in
-  /// `lemmy_db/src/lib.rs::get_database_url_from_env()`
+  /// `lemmy_db_queries/src/lib.rs::get_database_url_from_env()`
   fn init() -> Result<Self, ConfigError> {
     let mut s = Config::new();
 
index 90cf0e175f9e4590b649619705956cc3e178e47b..4f036ae5293058d9bfed8c30a7ce8284b1f386aa 100644 (file)
@@ -11,7 +11,7 @@ path = "src/lib.rs"
 [dependencies]
 lemmy_utils = { path = "../lemmy_utils" }
 lemmy_structs = { path = "../lemmy_structs" }
-lemmy_db = { path = "../lemmy_db" }
+lemmy_db_queries = { path = "../lemmy_db_queries" }
 lemmy_db_schema = { path = "../lemmy_db_schema" }
 lemmy_rate_limit = { path = "../lemmy_rate_limit" }
 reqwest = { version = "0.10.10", features = ["json"] }
index fc397fff0e0be059a0b13b64af0f1ca9bb1212c4..d7862dcd5114003f7c6d441dcfe6abb4ecbcd334 100644 (file)
@@ -5,16 +5,16 @@ use diesel::PgConnection;
 use lemmy_api::claims::Claims;
 use lemmy_db::{
   source::{community::Community_, user::User},
-  views::{
-    comment_view::{CommentQueryBuilder, CommentView},
-    post_view::{PostQueryBuilder, PostView},
-    site_view::SiteView,
-    user_mention_view::{UserMentionQueryBuilder, UserMentionView},
-  },
   ListingType,
   SortType,
 };
 use lemmy_db_schema::source::{community::Community, user::User_};
+use lemmy_db_views::{
+  comment_view::{CommentQueryBuilder, CommentView},
+  post_view::{PostQueryBuilder, PostView},
+  site_view::SiteView,
+  user_mention_view::{UserMentionQueryBuilder, UserMentionView},
+};
 use lemmy_structs::blocking;
 use lemmy_utils::{settings::Settings, utils::markdown_to_html, LemmyError};
 use lemmy_websocket::LemmyContext;
index 9f63a523b1632dc9bc950d1b6dc7c4e51c4be040..e6c5e6c423a3aacf9714dd87605ab0d49256adf4 100644 (file)
@@ -1,7 +1,7 @@
 use actix_web::{body::Body, error::ErrorBadRequest, *};
 use anyhow::anyhow;
 use lemmy_api::version;
-use lemmy_db::views::site_view::SiteView;
+use lemmy_db_views::site_view::SiteView;
 use lemmy_structs::blocking;
 use lemmy_utils::{settings::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;