]> Untitled Git - lemmy.git/blobdiff - crates/websocket/src/lib.rs
Removing the site creator, adding leave_admin. Fixes #1808 (#2052)
[lemmy.git] / crates / websocket / src / lib.rs
index f5f5f08045e5dfb69bd3cbcbb49d79dfb0e18019..324562180b0854d9ff897a5ce5ece6f8de0e1219 100644 (file)
@@ -4,35 +4,42 @@ extern crate strum_macros;
 use crate::chat_server::ChatServer;
 use actix::Addr;
 use background_jobs::QueueHandle;
-use lemmy_db_queries::DbPool;
-use lemmy_utils::LemmyError;
-use reqwest::Client;
+use lemmy_db_schema::{source::secret::Secret, DbPool};
+use lemmy_utils::{settings::structs::Settings, LemmyError};
+use reqwest_middleware::ClientWithMiddleware;
 use serde::Serialize;
 
 pub mod chat_server;
 pub mod handlers;
 pub mod messages;
 pub mod routes;
+pub mod send;
 
 pub struct LemmyContext {
-  pub pool: DbPool,
-  pub chat_server: Addr<ChatServer>,
-  pub client: Client,
-  pub activity_queue: QueueHandle,
+  pool: DbPool,
+  chat_server: Addr<ChatServer>,
+  client: ClientWithMiddleware,
+  activity_queue: QueueHandle,
+  settings: Settings,
+  secret: Secret,
 }
 
 impl LemmyContext {
   pub fn create(
     pool: DbPool,
     chat_server: Addr<ChatServer>,
-    client: Client,
+    client: ClientWithMiddleware,
     activity_queue: QueueHandle,
+    settings: Settings,
+    secret: Secret,
   ) -> LemmyContext {
     LemmyContext {
       pool,
       chat_server,
       client,
       activity_queue,
+      settings,
+      secret,
     }
   }
   pub fn pool(&self) -> &DbPool {
@@ -41,12 +48,19 @@ impl LemmyContext {
   pub fn chat_server(&self) -> &Addr<ChatServer> {
     &self.chat_server
   }
-  pub fn client(&self) -> &Client {
+  pub fn client(&self) -> &ClientWithMiddleware {
     &self.client
   }
   pub fn activity_queue(&self) -> &QueueHandle {
     &self.activity_queue
   }
+  pub fn settings(&self) -> Settings {
+    // TODO hacky solution to be able to hotload the settings.
+    Settings::get()
+  }
+  pub fn secret(&self) -> &Secret {
+    &self.secret
+  }
 }
 
 impl Clone for LemmyContext {
@@ -56,6 +70,8 @@ impl Clone for LemmyContext {
       chat_server: self.chat_server.clone(),
       client: self.client.clone(),
       activity_queue: self.activity_queue.clone(),
+      settings: self.settings.clone(),
+      secret: self.secret.clone(),
     }
   }
 }
@@ -81,7 +97,7 @@ where
   Ok(serde_json::to_string(&response)?)
 }
 
-#[derive(EnumString, ToString, Debug, Clone)]
+#[derive(EnumString, Display, Debug, Clone)]
 pub enum UserOperation {
   Login,
   GetCaptcha,
@@ -94,13 +110,15 @@ pub enum UserOperation {
   CreatePostLike,
   LockPost,
   StickyPost,
+  MarkPostAsRead,
   SavePost,
   CreatePostReport,
   ResolvePostReport,
   ListPostReports,
   GetReportCount,
+  GetUnreadCount,
+  VerifyEmail,
   FollowCommunity,
-  GetFollowedCommunities,
   GetReplies,
   GetPersonMentions,
   MarkPersonMentionAsRead,
@@ -108,12 +126,17 @@ pub enum UserOperation {
   BanFromCommunity,
   AddModToCommunity,
   AddAdmin,
+  GetUnreadRegistrationApplicationCount,
+  ListRegistrationApplications,
+  ApproveRegistrationApplication,
   BanPerson,
+  GetBannedPersons,
   Search,
+  ResolveObject,
   MarkAllAsRead,
   SaveUserSettings,
   TransferCommunity,
-  TransferSite,
+  LeaveAdmin,
   PasswordReset,
   PasswordChange,
   MarkPrivateMessageAsRead,
@@ -124,9 +147,12 @@ pub enum UserOperation {
   CommunityJoin,
   ModJoin,
   ChangePassword,
+  GetSiteMetadata,
+  BlockCommunity,
+  BlockPerson,
 }
 
-#[derive(EnumString, ToString, Debug, Clone)]
+#[derive(EnumString, Display, Debug, Clone)]
 pub enum UserOperationCrud {
   // Site
   CreateSite,
@@ -148,6 +174,7 @@ pub enum UserOperationCrud {
   RemovePost,
   // Comment
   CreateComment,
+  GetComment,
   GetComments,
   EditComment,
   DeleteComment,