]> Untitled Git - lemmy.git/blobdiff - crates/websocket/src/lib.rs
Fix API and clippy warnings
[lemmy.git] / crates / websocket / src / lib.rs
index 56b18a179d803b4d705978626244cc43d831d891..0b2a9fb4fbd69f6ad7b441f7d4d79ddb0528730b 100644 (file)
@@ -66,12 +66,13 @@ struct WebsocketResponse<T> {
   data: T,
 }
 
-pub fn serialize_websocket_message<Response>(
-  op: &UserOperation,
+pub fn serialize_websocket_message<OP, Response>(
+  op: &OP,
   data: &Response,
 ) -> Result<String, LemmyError>
 where
   Response: Serialize,
+  OP: ToString,
 {
   let response = WebsocketResponse {
     op: op.to_string(),
@@ -83,28 +84,14 @@ where
 #[derive(EnumString, ToString, Debug, Clone)]
 pub enum UserOperation {
   Login,
-  Register,
   GetCaptcha,
-  CreateCommunity,
-  CreatePost,
-  ListCommunities,
-  GetPost,
-  GetCommunity,
-  CreateComment,
-  EditComment,
-  DeleteComment,
-  RemoveComment,
   MarkCommentAsRead,
   SaveComment,
   CreateCommentLike,
   CreateCommentReport,
   ResolveCommentReport,
   ListCommentReports,
-  GetPosts,
   CreatePostLike,
-  EditPost,
-  DeletePost,
-  RemovePost,
   LockPost,
   StickyPost,
   SavePost,
@@ -112,21 +99,14 @@ pub enum UserOperation {
   ResolvePostReport,
   ListPostReports,
   GetReportCount,
-  EditCommunity,
-  DeleteCommunity,
-  RemoveCommunity,
   FollowCommunity,
   GetFollowedCommunities,
-  GetPersonDetails,
   GetReplies,
   GetPersonMentions,
   MarkPersonMentionAsRead,
   GetModlog,
   BanFromCommunity,
   AddModToCommunity,
-  CreateSite,
-  EditSite,
-  GetSite,
   AddAdmin,
   BanPerson,
   Search,
@@ -134,19 +114,56 @@ pub enum UserOperation {
   SaveUserSettings,
   TransferCommunity,
   TransferSite,
-  DeleteAccount,
   PasswordReset,
   PasswordChange,
-  CreatePrivateMessage,
-  EditPrivateMessage,
-  DeletePrivateMessage,
   MarkPrivateMessageAsRead,
-  GetPrivateMessages,
   UserJoin,
-  GetComments,
   GetSiteConfig,
   SaveSiteConfig,
   PostJoin,
   CommunityJoin,
   ModJoin,
 }
+
+#[derive(EnumString, ToString, Debug, Clone)]
+pub enum UserOperationCrud {
+  // Site
+  CreateSite,
+  GetSite,
+  EditSite,
+  // Community
+  CreateCommunity,
+  ListCommunities,
+  GetCommunity,
+  EditCommunity,
+  DeleteCommunity,
+  RemoveCommunity,
+  // Post
+  CreatePost,
+  GetPost,
+  GetPosts,
+  EditPost,
+  DeletePost,
+  RemovePost,
+  // Comment
+  CreateComment,
+  GetComments,
+  EditComment,
+  DeleteComment,
+  RemoveComment,
+  // User
+  Register,
+  GetPersonDetails,
+  DeleteAccount,
+  // Private Message
+  CreatePrivateMessage,
+  GetPrivateMessages,
+  EditPrivateMessage,
+  DeletePrivateMessage,
+}
+
+pub trait OperationType {}
+
+impl OperationType for UserOperationCrud {}
+
+impl OperationType for UserOperation {}