]> Untitled Git - lemmy.git/commitdiff
A few API v2 changes based on nutomic's suggestions.
authorDessalines <tyhou13@gmx.com>
Mon, 18 Jan 2021 21:57:31 +0000 (16:57 -0500)
committerDessalines <tyhou13@gmx.com>
Mon, 18 Jan 2021 21:57:31 +0000 (16:57 -0500)
- Changed `edit_id` s to their type (comment_id)
- Moved websocket actions to their own file in structs and api.
- Got rid of UserViewDangerous, added UserSafeSettings.
  - GetSite now returns UserSafeSettings for `my_user`.
- Got rid of `admin` field in `Register`.

22 files changed:
api_tests/package.json
api_tests/src/shared.ts
api_tests/yarn.lock
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_api/src/websocket.rs [new file with mode: 0644]
lemmy_db_queries/src/lib.rs
lemmy_db_queries/src/source/user.rs
lemmy_db_schema/src/source/user.rs
lemmy_db_views_actor/src/user_view.rs
lemmy_structs/src/comment.rs
lemmy_structs/src/community.rs
lemmy_structs/src/lib.rs
lemmy_structs/src/post.rs
lemmy_structs/src/site.rs
lemmy_structs/src/user.rs
lemmy_structs/src/websocket.rs [new file with mode: 0644]
src/routes/api.rs

index 6a9a4d6d9772ee508815419254c609edfacb5618..4ec227d58289580cc05d96cd4c8d06e64257903d 100644 (file)
@@ -14,7 +14,7 @@
   "devDependencies": {
     "@types/jest": "^26.0.19",
     "jest": "^26.6.3",
-    "lemmy-js-client": "1.0.17-beta6",
+    "lemmy-js-client": "0.9.0-rc.12",
     "node-fetch": "^2.6.1",
     "ts-jest": "^26.4.4",
     "prettier": "^2.1.2",
index 207870388950601f3247bb378aae4b6d6bb18601..0c12d29c0f8cfae82b761dbbe006585317dda353 100644 (file)
@@ -144,7 +144,7 @@ export async function editPost(api: API, post: Post): Promise<PostResponse> {
   let name = 'A jest test federated post, updated';
   let form: EditPost = {
     name,
-    edit_id: post.id,
+    post_id: post.id,
     auth: api.auth,
     nsfw: false,
   };
@@ -157,7 +157,7 @@ export async function deletePost(
   post: Post
 ): Promise<PostResponse> {
   let form: DeletePost = {
-    edit_id: post.id,
+    post_id: post.id,
     deleted: deleted,
     auth: api.auth,
   };
@@ -170,7 +170,7 @@ export async function removePost(
   post: Post
 ): Promise<PostResponse> {
   let form: RemovePost = {
-    edit_id: post.id,
+    post_id: post.id,
     removed,
     auth: api.auth,
   };
@@ -183,7 +183,7 @@ export async function stickyPost(
   post: Post
 ): Promise<PostResponse> {
   let form: StickyPost = {
-    edit_id: post.id,
+    post_id: post.id,
     stickied,
     auth: api.auth,
   };
@@ -196,7 +196,7 @@ export async function lockPost(
   post: Post
 ): Promise<PostResponse> {
   let form: LockPost = {
-    edit_id: post.id,
+    post_id: post.id,
     locked,
     auth: api.auth,
   };
@@ -376,12 +376,12 @@ export async function createComment(
 
 export async function editComment(
   api: API,
-  edit_id: number,
+  comment_id: number,
   content = 'A jest test federated comment update'
 ): Promise<CommentResponse> {
   let form: EditComment = {
     content,
-    edit_id,
+    comment_id,
     auth: api.auth,
   };
   return api.client.editComment(form);
@@ -390,10 +390,10 @@ export async function editComment(
 export async function deleteComment(
   api: API,
   deleted: boolean,
-  edit_id: number
+  comment_id: number
 ): Promise<CommentResponse> {
   let form: DeleteComment = {
-    edit_id,
+    comment_id,
     deleted,
     auth: api.auth,
   };
@@ -403,10 +403,10 @@ export async function deleteComment(
 export async function removeComment(
   api: API,
   removed: boolean,
-  edit_id: number
+  comment_id: number
 ): Promise<CommentResponse> {
   let form: RemoveComment = {
-    edit_id,
+    comment_id,
     removed,
     auth: api.auth,
   };
@@ -468,10 +468,10 @@ export async function getCommunity(
 export async function deleteCommunity(
   api: API,
   deleted: boolean,
-  edit_id: number
+  community_id: number
 ): Promise<CommunityResponse> {
   let form: DeleteCommunity = {
-    edit_id,
+    community_id,
     deleted,
     auth: api.auth,
   };
@@ -481,10 +481,10 @@ export async function deleteCommunity(
 export async function removeCommunity(
   api: API,
   removed: boolean,
-  edit_id: number
+  community_id: number
 ): Promise<CommunityResponse> {
   let form: RemoveCommunity = {
-    edit_id,
+    community_id,
     removed,
     auth: api.auth,
   };
@@ -506,12 +506,12 @@ export async function createPrivateMessage(
 
 export async function editPrivateMessage(
   api: API,
-  edit_id: number
+  private_message_id: number
 ): Promise<PrivateMessageResponse> {
   let updatedContent = 'A jest test federated private message edited';
   let form: EditPrivateMessage = {
     content: updatedContent,
-    edit_id,
+    private_message_id,
     auth: api.auth,
   };
   return api.client.editPrivateMessage(form);
@@ -520,11 +520,11 @@ export async function editPrivateMessage(
 export async function deletePrivateMessage(
   api: API,
   deleted: boolean,
-  edit_id: number
+  private_message_id: number
 ): Promise<PrivateMessageResponse> {
   let form: DeletePrivateMessage = {
     deleted,
-    edit_id,
+    private_message_id,
     auth: api.auth,
   };
   return api.client.deletePrivateMessage(form);
@@ -538,7 +538,6 @@ export async function registerUser(
     username,
     password: 'test',
     password_verify: 'test',
-    admin: false,
     show_nsfw: true,
   };
   return api.client.register(form);
index 5ee034481c9229d1ff08321eb81022fe4ddd55d3..8daa3213267db22b0c76b89825c765154e17a737 100644 (file)
@@ -3225,10 +3225,10 @@ language-tags@^1.0.5:
   dependencies:
     language-subtag-registry "~0.3.2"
 
-lemmy-js-client@1.0.17-beta6:
-  version "1.0.17-beta6"
-  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.17-beta6.tgz#afe1e1da13172a161c4d976b1ee58fe81eb22829"
-  integrity sha512-+oX7J7wht8nH4a5NQngK1GNner3TDv6ZOhQQVI5KcK7vynVVIcgveC5KBJArHBAl5acXpLs3Khmx0ZEb+sErJA==
+lemmy-js-client@0.9.0-rc.12:
+  version "0.9.0-rc.12"
+  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.9.0-rc.12.tgz#991d31c4ef89b9bd4088a17c60b6cbaac997df41"
+  integrity sha512-SeCw9wjU89Zm4YWhr+neHC2XvqoqzJg2e42sFEgcDmnQxpPt2sND9Udu+tjGXatbz0tCu6ybGmpR5M0QT4xx9Q==
 
 leven@^3.1.0:
   version "3.1.0"
index 631addb82f79cea9dba82e8d4a41a75342427c08..50fddf2b1114a064ffd138a9c9ee211e12e29ed9 100644 (file)
@@ -182,9 +182,9 @@ impl Perform for EditComment {
     let data: &EditComment = &self;
     let user = get_user_from_jwt(&data.auth, context.pool()).await?;
 
-    let edit_id = data.edit_id;
+    let comment_id = data.comment_id;
     let orig_comment = blocking(context.pool(), move |conn| {
-      CommentView::read(&conn, edit_id, None)
+      CommentView::read(&conn, comment_id, None)
     })
     .await??;
 
@@ -197,9 +197,9 @@ impl Perform for EditComment {
 
     // Do the update
     let content_slurs_removed = remove_slurs(&data.content.to_owned());
-    let edit_id = data.edit_id;
+    let comment_id = data.comment_id;
     let updated_comment = match blocking(context.pool(), move |conn| {
-      Comment::update_content(conn, edit_id, &content_slurs_removed)
+      Comment::update_content(conn, comment_id, &content_slurs_removed)
     })
     .await?
     {
@@ -223,10 +223,10 @@ impl Perform for EditComment {
     )
     .await?;
 
-    let edit_id = data.edit_id;
+    let comment_id = data.comment_id;
     let user_id = user.id;
     let comment_view = blocking(context.pool(), move |conn| {
-      CommentView::read(conn, edit_id, Some(user_id))
+      CommentView::read(conn, comment_id, Some(user_id))
     })
     .await??;
 
@@ -258,9 +258,9 @@ impl Perform for DeleteComment {
     let data: &DeleteComment = &self;
     let user = get_user_from_jwt(&data.auth, context.pool()).await?;
 
-    let edit_id = data.edit_id;
+    let comment_id = data.comment_id;
     let orig_comment = blocking(context.pool(), move |conn| {
-      CommentView::read(&conn, edit_id, None)
+      CommentView::read(&conn, comment_id, None)
     })
     .await??;
 
@@ -274,7 +274,7 @@ impl Perform for DeleteComment {
     // Do the delete
     let deleted = data.deleted;
     let updated_comment = match blocking(context.pool(), move |conn| {
-      Comment::update_deleted(conn, edit_id, deleted)
+      Comment::update_deleted(conn, comment_id, deleted)
     })
     .await?
     {
@@ -290,10 +290,10 @@ impl Perform for DeleteComment {
     }
 
     // Refetch it
-    let edit_id = data.edit_id;
+    let comment_id = data.comment_id;
     let user_id = user.id;
     let comment_view = blocking(context.pool(), move |conn| {
-      CommentView::read(conn, edit_id, Some(user_id))
+      CommentView::read(conn, comment_id, Some(user_id))
     })
     .await??;
 
@@ -338,9 +338,9 @@ impl Perform for RemoveComment {
     let data: &RemoveComment = &self;
     let user = get_user_from_jwt(&data.auth, context.pool()).await?;
 
-    let edit_id = data.edit_id;
+    let comment_id = data.comment_id;
     let orig_comment = blocking(context.pool(), move |conn| {
-      CommentView::read(&conn, edit_id, None)
+      CommentView::read(&conn, comment_id, None)
     })
     .await??;
 
@@ -352,7 +352,7 @@ impl Perform for RemoveComment {
     // Do the remove
     let removed = data.removed;
     let updated_comment = match blocking(context.pool(), move |conn| {
-      Comment::update_removed(conn, edit_id, removed)
+      Comment::update_removed(conn, comment_id, removed)
     })
     .await?
     {
@@ -363,7 +363,7 @@ impl Perform for RemoveComment {
     // Mod tables
     let form = ModRemoveCommentForm {
       mod_user_id: user.id,
-      comment_id: data.edit_id,
+      comment_id: data.comment_id,
       removed: Some(removed),
       reason: data.reason.to_owned(),
     };
@@ -380,10 +380,10 @@ impl Perform for RemoveComment {
     }
 
     // Refetch it
-    let edit_id = data.edit_id;
+    let comment_id = data.comment_id;
     let user_id = user.id;
     let comment_view = blocking(context.pool(), move |conn| {
-      CommentView::read(conn, edit_id, Some(user_id))
+      CommentView::read(conn, comment_id, Some(user_id))
     })
     .await??;
 
@@ -454,10 +454,10 @@ impl Perform for MarkCommentAsRead {
     };
 
     // Refetch it
-    let edit_id = data.comment_id;
+    let comment_id = data.comment_id;
     let user_id = user.id;
     let comment_view = blocking(context.pool(), move |conn| {
-      CommentView::read(conn, edit_id, Some(user_id))
+      CommentView::read(conn, comment_id, Some(user_id))
     })
     .await??;
 
index 7cb7be7d8b192f766c628834117f33ed6e222728..efdea06ad80769e6266b2145ac9688a3cf7119de 100644 (file)
@@ -44,7 +44,7 @@ use lemmy_utils::{
   LemmyError,
 };
 use lemmy_websocket::{
-  messages::{GetCommunityUsersOnline, JoinCommunityRoom, JoinModRoom, SendCommunityRoomMessage},
+  messages::{GetCommunityUsersOnline, SendCommunityRoomMessage},
   LemmyContext,
   UserOperation,
 };
@@ -233,9 +233,9 @@ impl Perform for EditCommunity {
     check_slurs_opt(&data.description)?;
 
     // Verify its a mod (only mods can edit it)
-    let edit_id = data.edit_id;
+    let community_id = data.community_id;
     let mods: Vec<i32> = blocking(context.pool(), move |conn| {
-      CommunityModeratorView::for_community(conn, edit_id)
+      CommunityModeratorView::for_community(conn, community_id)
         .map(|v| v.into_iter().map(|m| m.moderator.id).collect())
     })
     .await??;
@@ -243,9 +243,11 @@ impl Perform for EditCommunity {
       return Err(APIError::err("not_a_moderator").into());
     }
 
-    let edit_id = data.edit_id;
-    let read_community =
-      blocking(context.pool(), move |conn| Community::read(conn, edit_id)).await??;
+    let community_id = data.community_id;
+    let read_community = blocking(context.pool(), move |conn| {
+      Community::read(conn, community_id)
+    })
+    .await??;
 
     let icon = diesel_option_overwrite(&data.icon);
     let banner = diesel_option_overwrite(&data.banner);
@@ -273,9 +275,9 @@ impl Perform for EditCommunity {
       published: None,
     };
 
-    let edit_id = data.edit_id;
+    let community_id = data.community_id;
     match blocking(context.pool(), move |conn| {
-      Community::update(conn, edit_id, &community_form)
+      Community::update(conn, community_id, &community_form)
     })
     .await?
     {
@@ -286,10 +288,10 @@ impl Perform for EditCommunity {
     // TODO there needs to be some kind of an apub update
     // process for communities and users
 
-    let edit_id = data.edit_id;
+    let community_id = data.community_id;
     let user_id = user.id;
     let community_view = blocking(context.pool(), move |conn| {
-      CommunityView::read(conn, edit_id, Some(user_id))
+      CommunityView::read(conn, community_id, Some(user_id))
     })
     .await??;
 
@@ -314,18 +316,20 @@ impl Perform for DeleteCommunity {
     let user = get_user_from_jwt(&data.auth, context.pool()).await?;
 
     // Verify its the creator (only a creator can delete the community)
-    let edit_id = data.edit_id;
-    let read_community =
-      blocking(context.pool(), move |conn| Community::read(conn, edit_id)).await??;
+    let community_id = data.community_id;
+    let read_community = blocking(context.pool(), move |conn| {
+      Community::read(conn, community_id)
+    })
+    .await??;
     if read_community.creator_id != user.id {
       return Err(APIError::err("no_community_edit_allowed").into());
     }
 
     // Do the delete
-    let edit_id = data.edit_id;
+    let community_id = data.community_id;
     let deleted = data.deleted;
     let updated_community = match blocking(context.pool(), move |conn| {
-      Community::update_deleted(conn, edit_id, deleted)
+      Community::update_deleted(conn, community_id, deleted)
     })
     .await?
     {
@@ -340,10 +344,10 @@ impl Perform for DeleteCommunity {
       updated_community.send_undo_delete(context).await?;
     }
 
-    let edit_id = data.edit_id;
+    let community_id = data.community_id;
     let user_id = user.id;
     let community_view = blocking(context.pool(), move |conn| {
-      CommunityView::read(conn, edit_id, Some(user_id))
+      CommunityView::read(conn, community_id, Some(user_id))
     })
     .await??;
 
@@ -371,10 +375,10 @@ impl Perform for RemoveCommunity {
     is_admin(context.pool(), user.id).await?;
 
     // Do the remove
-    let edit_id = data.edit_id;
+    let community_id = data.community_id;
     let removed = data.removed;
     let updated_community = match blocking(context.pool(), move |conn| {
-      Community::update_removed(conn, edit_id, removed)
+      Community::update_removed(conn, community_id, removed)
     })
     .await?
     {
@@ -389,7 +393,7 @@ impl Perform for RemoveCommunity {
     };
     let form = ModRemoveCommunityForm {
       mod_user_id: user.id,
-      community_id: data.edit_id,
+      community_id: data.community_id,
       removed: Some(removed),
       reason: data.reason.to_owned(),
       expires,
@@ -406,10 +410,10 @@ impl Perform for RemoveCommunity {
       updated_community.send_undo_remove(context).await?;
     }
 
-    let edit_id = data.edit_id;
+    let community_id = data.community_id;
     let user_id = user.id;
     let community_view = blocking(context.pool(), move |conn| {
-      CommunityView::read(conn, edit_id, Some(user_id))
+      CommunityView::read(conn, community_id, Some(user_id))
     })
     .await??;
 
@@ -864,47 +868,3 @@ fn send_community_websocket(
     websocket_id,
   });
 }
-
-#[async_trait::async_trait(?Send)]
-impl Perform for CommunityJoin {
-  type Response = CommunityJoinResponse;
-
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<CommunityJoinResponse, LemmyError> {
-    let data: &CommunityJoin = &self;
-
-    if let Some(ws_id) = websocket_id {
-      context.chat_server().do_send(JoinCommunityRoom {
-        community_id: data.community_id,
-        id: ws_id,
-      });
-    }
-
-    Ok(CommunityJoinResponse { joined: true })
-  }
-}
-
-#[async_trait::async_trait(?Send)]
-impl Perform for ModJoin {
-  type Response = ModJoinResponse;
-
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<ModJoinResponse, LemmyError> {
-    let data: &ModJoin = &self;
-
-    if let Some(ws_id) = websocket_id {
-      context.chat_server().do_send(JoinModRoom {
-        community_id: data.community_id,
-        id: ws_id,
-      });
-    }
-
-    Ok(ModJoinResponse { joined: true })
-  }
-}
index c1dee7aa362ca09a425d95f8c6125bc0b6dd937a..2ed3862aed48ebfd5f15dc0948b5c2eabe105789 100644 (file)
@@ -4,6 +4,7 @@ use lemmy_db_queries::{
   source::{
     community::{CommunityModerator_, Community_},
     site::Site_,
+    user::UserSafeSettings_,
   },
   Crud,
   DbPool,
@@ -12,13 +13,13 @@ use lemmy_db_schema::source::{
   community::{Community, CommunityModerator},
   post::Post,
   site::Site,
-  user::User_,
+  user::{UserSafeSettings, User_},
 };
 use lemmy_db_views_actor::{
   community_user_ban_view::CommunityUserBanView,
   community_view::CommunityView,
 };
-use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*};
+use lemmy_structs::{blocking, comment::*, community::*, post::*, site::*, user::*, websocket::*};
 use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError};
 use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
 use serde::Deserialize;
@@ -32,6 +33,7 @@ pub mod post;
 pub mod site;
 pub mod user;
 pub mod version;
+pub mod websocket;
 
 #[async_trait::async_trait(?Send)]
 pub trait Perform {
@@ -97,6 +99,33 @@ pub(crate) async fn get_user_from_jwt_opt(
   }
 }
 
+pub(crate) async fn get_user_safe_settings_from_jwt(
+  jwt: &str,
+  pool: &DbPool,
+) -> Result<UserSafeSettings, LemmyError> {
+  let claims = match Claims::decode(&jwt) {
+    Ok(claims) => claims.claims,
+    Err(_e) => return Err(APIError::err("not_logged_in").into()),
+  };
+  let user_id = claims.id;
+  let user = blocking(pool, move |conn| UserSafeSettings::read(conn, user_id)).await??;
+  // Check for a site ban
+  if user.banned {
+    return Err(APIError::err("site_ban").into());
+  }
+  Ok(user)
+}
+
+pub(crate) async fn get_user_safe_settings_from_jwt_opt(
+  jwt: &Option<String>,
+  pool: &DbPool,
+) -> Result<Option<UserSafeSettings>, LemmyError> {
+  match jwt {
+    Some(jwt) => Ok(Some(get_user_safe_settings_from_jwt(jwt, pool).await?)),
+    None => Ok(None),
+  }
+}
+
 pub(crate) async fn check_community_ban(
   user_id: i32,
   community_id: i32,
index 4630918be245824905d3d3a1b5c3333baea809ba..4a2f14cea9b5d02318fd7e54fc7fd8717e20bda9 100644 (file)
@@ -46,7 +46,7 @@ use lemmy_utils::{
   LemmyError,
 };
 use lemmy_websocket::{
-  messages::{GetPostUsersOnline, JoinPostRoom, SendModRoomMessage, SendPost, SendUserRoomMessage},
+  messages::{GetPostUsersOnline, SendModRoomMessage, SendPost, SendUserRoomMessage},
   LemmyContext,
   UserOperation,
 };
@@ -376,8 +376,8 @@ impl Perform for EditPost {
       return Err(APIError::err("invalid_post_title").into());
     }
 
-    let edit_id = data.edit_id;
-    let orig_post = blocking(context.pool(), move |conn| Post::read(conn, edit_id)).await??;
+    let post_id = data.post_id;
+    let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
 
     check_community_ban(user.id, orig_post.community_id, context.pool()).await?;
 
@@ -411,9 +411,9 @@ impl Perform for EditPost {
       published: None,
     };
 
-    let edit_id = data.edit_id;
+    let post_id = data.post_id;
     let res = blocking(context.pool(), move |conn| {
-      Post::update(conn, edit_id, &post_form)
+      Post::update(conn, post_id, &post_form)
     })
     .await?;
     let updated_post: Post = match res {
@@ -432,9 +432,9 @@ impl Perform for EditPost {
     // Send apub update
     updated_post.send_update(&user, context).await?;
 
-    let edit_id = data.edit_id;
+    let post_id = data.post_id;
     let post_view = blocking(context.pool(), move |conn| {
-      PostView::read(conn, edit_id, Some(user.id))
+      PostView::read(conn, post_id, Some(user.id))
     })
     .await??;
 
@@ -462,8 +462,8 @@ impl Perform for DeletePost {
     let data: &DeletePost = &self;
     let user = get_user_from_jwt(&data.auth, context.pool()).await?;
 
-    let edit_id = data.edit_id;
-    let orig_post = blocking(context.pool(), move |conn| Post::read(conn, edit_id)).await??;
+    let post_id = data.post_id;
+    let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
 
     check_community_ban(user.id, orig_post.community_id, context.pool()).await?;
 
@@ -473,10 +473,10 @@ impl Perform for DeletePost {
     }
 
     // Update the post
-    let edit_id = data.edit_id;
+    let post_id = data.post_id;
     let deleted = data.deleted;
     let updated_post = blocking(context.pool(), move |conn| {
-      Post::update_deleted(conn, edit_id, deleted)
+      Post::update_deleted(conn, post_id, deleted)
     })
     .await??;
 
@@ -488,9 +488,9 @@ impl Perform for DeletePost {
     }
 
     // Refetch the post
-    let edit_id = data.edit_id;
+    let post_id = data.post_id;
     let post_view = blocking(context.pool(), move |conn| {
-      PostView::read(conn, edit_id, Some(user.id))
+      PostView::read(conn, post_id, Some(user.id))
     })
     .await??;
 
@@ -518,8 +518,8 @@ impl Perform for RemovePost {
     let data: &RemovePost = &self;
     let user = get_user_from_jwt(&data.auth, context.pool()).await?;
 
-    let edit_id = data.edit_id;
-    let orig_post = blocking(context.pool(), move |conn| Post::read(conn, edit_id)).await??;
+    let post_id = data.post_id;
+    let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
 
     check_community_ban(user.id, orig_post.community_id, context.pool()).await?;
 
@@ -527,17 +527,17 @@ impl Perform for RemovePost {
     is_mod_or_admin(context.pool(), user.id, orig_post.community_id).await?;
 
     // Update the post
-    let edit_id = data.edit_id;
+    let post_id = data.post_id;
     let removed = data.removed;
     let updated_post = blocking(context.pool(), move |conn| {
-      Post::update_removed(conn, edit_id, removed)
+      Post::update_removed(conn, post_id, removed)
     })
     .await??;
 
     // Mod tables
     let form = ModRemovePostForm {
       mod_user_id: user.id,
-      post_id: data.edit_id,
+      post_id: data.post_id,
       removed: Some(removed),
       reason: data.reason.to_owned(),
     };
@@ -554,10 +554,10 @@ impl Perform for RemovePost {
     }
 
     // Refetch the post
-    let edit_id = data.edit_id;
+    let post_id = data.post_id;
     let user_id = user.id;
     let post_view = blocking(context.pool(), move |conn| {
-      PostView::read(conn, edit_id, Some(user_id))
+      PostView::read(conn, post_id, Some(user_id))
     })
     .await??;
 
@@ -585,8 +585,8 @@ impl Perform for LockPost {
     let data: &LockPost = &self;
     let user = get_user_from_jwt(&data.auth, context.pool()).await?;
 
-    let edit_id = data.edit_id;
-    let orig_post = blocking(context.pool(), move |conn| Post::read(conn, edit_id)).await??;
+    let post_id = data.post_id;
+    let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
 
     check_community_ban(user.id, orig_post.community_id, context.pool()).await?;
 
@@ -594,17 +594,17 @@ impl Perform for LockPost {
     is_mod_or_admin(context.pool(), user.id, orig_post.community_id).await?;
 
     // Update the post
-    let edit_id = data.edit_id;
+    let post_id = data.post_id;
     let locked = data.locked;
     let updated_post = blocking(context.pool(), move |conn| {
-      Post::update_locked(conn, edit_id, locked)
+      Post::update_locked(conn, post_id, locked)
     })
     .await??;
 
     // Mod tables
     let form = ModLockPostForm {
       mod_user_id: user.id,
-      post_id: data.edit_id,
+      post_id: data.post_id,
       locked: Some(locked),
     };
     blocking(context.pool(), move |conn| ModLockPost::create(conn, &form)).await??;
@@ -613,9 +613,9 @@ impl Perform for LockPost {
     updated_post.send_update(&user, context).await?;
 
     // Refetch the post
-    let edit_id = data.edit_id;
+    let post_id = data.post_id;
     let post_view = blocking(context.pool(), move |conn| {
-      PostView::read(conn, edit_id, Some(user.id))
+      PostView::read(conn, post_id, Some(user.id))
     })
     .await??;
 
@@ -643,8 +643,8 @@ impl Perform for StickyPost {
     let data: &StickyPost = &self;
     let user = get_user_from_jwt(&data.auth, context.pool()).await?;
 
-    let edit_id = data.edit_id;
-    let orig_post = blocking(context.pool(), move |conn| Post::read(conn, edit_id)).await??;
+    let post_id = data.post_id;
+    let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
 
     check_community_ban(user.id, orig_post.community_id, context.pool()).await?;
 
@@ -652,17 +652,17 @@ impl Perform for StickyPost {
     is_mod_or_admin(context.pool(), user.id, orig_post.community_id).await?;
 
     // Update the post
-    let edit_id = data.edit_id;
+    let post_id = data.post_id;
     let stickied = data.stickied;
     let updated_post = blocking(context.pool(), move |conn| {
-      Post::update_stickied(conn, edit_id, stickied)
+      Post::update_stickied(conn, post_id, stickied)
     })
     .await??;
 
     // Mod tables
     let form = ModStickyPostForm {
       mod_user_id: user.id,
-      post_id: data.edit_id,
+      post_id: data.post_id,
       stickied: Some(stickied),
     };
     blocking(context.pool(), move |conn| {
@@ -675,9 +675,9 @@ impl Perform for StickyPost {
     updated_post.send_update(&user, context).await?;
 
     // Refetch the post
-    let edit_id = data.edit_id;
+    let post_id = data.post_id;
     let post_view = blocking(context.pool(), move |conn| {
-      PostView::read(conn, edit_id, Some(user.id))
+      PostView::read(conn, post_id, Some(user.id))
     })
     .await??;
 
@@ -733,28 +733,6 @@ impl Perform for SavePost {
   }
 }
 
-#[async_trait::async_trait(?Send)]
-impl Perform for PostJoin {
-  type Response = PostJoinResponse;
-
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<PostJoinResponse, LemmyError> {
-    let data: &PostJoin = &self;
-
-    if let Some(ws_id) = websocket_id {
-      context.chat_server().do_send(JoinPostRoom {
-        post_id: data.post_id,
-        id: ws_id,
-      });
-    }
-
-    Ok(PostJoinResponse { joined: true })
-  }
-}
-
 /// Creates a post report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for CreatePostReport {
index ff032562fce84469e4373b90c3f1983cbf8bb9dd..0475954cd6d21256891e917e021cdf6c0b85bc6d 100644 (file)
@@ -1,6 +1,8 @@
 use crate::{
   get_user_from_jwt,
   get_user_from_jwt_opt,
+  get_user_safe_settings_from_jwt,
+  get_user_safe_settings_from_jwt_opt,
   is_admin,
   linked_instances,
   version,
@@ -274,7 +276,6 @@ impl Perform for GetSite {
             email: setup.admin_email.to_owned(),
             password: setup.admin_password.to_owned(),
             password_verify: setup.admin_password.to_owned(),
-            admin: true,
             show_nsfw: true,
             captcha_uuid: None,
             captcha_answer: None,
@@ -322,14 +323,7 @@ impl Perform for GetSite {
       .await
       .unwrap_or(1);
 
-    let my_user = get_user_from_jwt_opt(&data.auth, context.pool())
-      .await?
-      .map(|mut u| {
-        u.password_encrypted = "".to_string();
-        u.private_key = None;
-        u.public_key = None;
-        u
-      });
+    let my_user = get_user_safe_settings_from_jwt_opt(&data.auth, context.pool()).await?;
 
     Ok(GetSiteResponse {
       site_view,
@@ -519,15 +513,10 @@ impl Perform for TransferSite {
     _websocket_id: Option<ConnectionId>,
   ) -> Result<GetSiteResponse, LemmyError> {
     let data: &TransferSite = &self;
-    let mut user = get_user_from_jwt(&data.auth, context.pool()).await?;
+    let user = get_user_safe_settings_from_jwt(&data.auth, context.pool()).await?;
 
     is_admin(context.pool(), user.id).await?;
 
-    // TODO add a User_::read_safe() for this.
-    user.password_encrypted = "".to_string();
-    user.private_key = None;
-    user.public_key = None;
-
     let read_site = blocking(context.pool(), move |conn| Site::read_simple(conn)).await??;
 
     // Make sure user is the creator
index ceafad8a3e26738c1b127f0acffee327cc633455..16d390c59b07be265247dbc08574aed4bacc148d 100644 (file)
@@ -57,7 +57,7 @@ use lemmy_db_views_actor::{
   community_follower_view::CommunityFollowerView,
   community_moderator_view::CommunityModeratorView,
   user_mention_view::{UserMentionQueryBuilder, UserMentionView},
-  user_view::{UserViewDangerous, UserViewSafe},
+  user_view::UserViewSafe,
 };
 use lemmy_structs::{blocking, send_email_to_user, user::*};
 use lemmy_utils::{
@@ -78,7 +78,7 @@ use lemmy_utils::{
   LemmyError,
 };
 use lemmy_websocket::{
-  messages::{CaptchaItem, CheckCaptcha, JoinUserRoom, SendAllMessage, SendUserRoomMessage},
+  messages::{CaptchaItem, CheckCaptcha, SendAllMessage, SendUserRoomMessage},
   LemmyContext,
   UserOperation,
 };
@@ -147,8 +147,14 @@ impl Perform for Register {
       return Err(APIError::err("passwords_dont_match").into());
     }
 
+    // Check if there are admins. False if admins exist
+    let no_admins = blocking(context.pool(), move |conn| {
+      UserViewSafe::admins(conn).map(|a| a.is_empty())
+    })
+    .await??;
+
     // If its not the admin, check the captcha
-    if !data.admin && Settings::get().captcha.enabled {
+    if !no_admins && Settings::get().captcha.enabled {
       let check = context
         .chat_server()
         .send(CheckCaptcha {
@@ -169,15 +175,6 @@ impl Perform for Register {
 
     check_slurs(&data.username)?;
 
-    // Make sure there are no admins
-    let any_admins = blocking(context.pool(), move |conn| {
-      UserViewSafe::admins(conn).map(|a| a.is_empty())
-    })
-    .await??;
-    if data.admin && !any_admins {
-      return Err(APIError::err("admin_already_created").into());
-    }
-
     let user_keypair = generate_actor_keypair()?;
     if !is_valid_username(&data.username) {
       return Err(APIError::err("invalid_username").into());
@@ -194,7 +191,7 @@ impl Perform for Register {
       preferred_username: None,
       published: None,
       updated: None,
-      admin: data.admin,
+      admin: no_admins,
       banned: Some(false),
       show_nsfw: data.show_nsfw,
       theme: "browser".into(),
@@ -280,7 +277,7 @@ impl Perform for Register {
     };
 
     // If its an admin, add them as a mod and follower to main
-    if data.admin {
+    if no_admins {
       let community_moderator_form = CommunityModeratorForm {
         community_id: main_community.id,
         user_id: inserted_user.id,
@@ -509,39 +506,12 @@ impl Perform for GetUserDetails {
 
     let user_id = user.map(|u| u.id);
 
-    let (user_view, user_view_dangerous) = if let Some(auth_user_id) = user_id {
-      if user_details_id == auth_user_id {
-        (
-          None,
-          Some(
-            blocking(context.pool(), move |conn| {
-              UserViewDangerous::read(conn, auth_user_id)
-            })
-            .await??,
-          ),
-        )
-      } else {
-        (
-          Some(
-            blocking(context.pool(), move |conn| {
-              UserViewSafe::read(conn, user_details_id)
-            })
-            .await??,
-          ),
-          None,
-        )
-      }
-    } else {
-      (
-        Some(
-          blocking(context.pool(), move |conn| {
-            UserViewSafe::read(conn, user_details_id)
-          })
-          .await??,
-        ),
-        None,
-      )
-    };
+    // You don't need to return settings for the user, since this comes back with GetSite
+    // `my_user`
+    let user_view = blocking(context.pool(), move |conn| {
+      UserViewSafe::read(conn, user_details_id)
+    })
+    .await??;
 
     let page = data.page;
     let limit = data.limit;
@@ -591,7 +561,6 @@ impl Perform for GetUserDetails {
     // Return the jwt
     Ok(GetUserDetailsResponse {
       user_view,
-      user_view_dangerous,
       follows,
       moderates,
       comments,
@@ -1129,9 +1098,9 @@ impl Perform for EditPrivateMessage {
     let user = get_user_from_jwt(&data.auth, context.pool()).await?;
 
     // Checking permissions
-    let edit_id = data.edit_id;
+    let private_message_id = data.private_message_id;
     let orig_private_message = blocking(context.pool(), move |conn| {
-      PrivateMessage::read(conn, edit_id)
+      PrivateMessage::read(conn, private_message_id)
     })
     .await??;
     if user.id != orig_private_message.creator_id {
@@ -1140,9 +1109,9 @@ impl Perform for EditPrivateMessage {
 
     // Doing the update
     let content_slurs_removed = remove_slurs(&data.content);
-    let edit_id = data.edit_id;
+    let private_message_id = data.private_message_id;
     let updated_private_message = match blocking(context.pool(), move |conn| {
-      PrivateMessage::update_content(conn, edit_id, &content_slurs_removed)
+      PrivateMessage::update_content(conn, private_message_id, &content_slurs_removed)
     })
     .await?
     {
@@ -1153,9 +1122,9 @@ impl Perform for EditPrivateMessage {
     // Send the apub update
     updated_private_message.send_update(&user, context).await?;
 
-    let edit_id = data.edit_id;
+    let private_message_id = data.private_message_id;
     let message = blocking(context.pool(), move |conn| {
-      PrivateMessageView::read(conn, edit_id)
+      PrivateMessageView::read(conn, private_message_id)
     })
     .await??;
     let recipient_id = message.recipient.id;
@@ -1188,9 +1157,9 @@ impl Perform for DeletePrivateMessage {
     let user = get_user_from_jwt(&data.auth, context.pool()).await?;
 
     // Checking permissions
-    let edit_id = data.edit_id;
+    let private_message_id = data.private_message_id;
     let orig_private_message = blocking(context.pool(), move |conn| {
-      PrivateMessage::read(conn, edit_id)
+      PrivateMessage::read(conn, private_message_id)
     })
     .await??;
     if user.id != orig_private_message.creator_id {
@@ -1198,10 +1167,10 @@ impl Perform for DeletePrivateMessage {
     }
 
     // Doing the update
-    let edit_id = data.edit_id;
+    let private_message_id = data.private_message_id;
     let deleted = data.deleted;
     let updated_private_message = match blocking(context.pool(), move |conn| {
-      PrivateMessage::update_deleted(conn, edit_id, deleted)
+      PrivateMessage::update_deleted(conn, private_message_id, deleted)
     })
     .await?
     {
@@ -1218,9 +1187,9 @@ impl Perform for DeletePrivateMessage {
         .await?;
     }
 
-    let edit_id = data.edit_id;
+    let private_message_id = data.private_message_id;
     let message = blocking(context.pool(), move |conn| {
-      PrivateMessageView::read(conn, edit_id)
+      PrivateMessageView::read(conn, private_message_id)
     })
     .await??;
     let recipient_id = message.recipient.id;
@@ -1253,9 +1222,9 @@ impl Perform for MarkPrivateMessageAsRead {
     let user = get_user_from_jwt(&data.auth, context.pool()).await?;
 
     // Checking permissions
-    let edit_id = data.edit_id;
+    let private_message_id = data.private_message_id;
     let orig_private_message = blocking(context.pool(), move |conn| {
-      PrivateMessage::read(conn, edit_id)
+      PrivateMessage::read(conn, private_message_id)
     })
     .await??;
     if user.id != orig_private_message.recipient_id {
@@ -1263,10 +1232,10 @@ impl Perform for MarkPrivateMessageAsRead {
     }
 
     // Doing the update
-    let edit_id = data.edit_id;
+    let private_message_id = data.private_message_id;
     let read = data.read;
     match blocking(context.pool(), move |conn| {
-      PrivateMessage::update_read(conn, edit_id, read)
+      PrivateMessage::update_read(conn, private_message_id, read)
     })
     .await?
     {
@@ -1276,9 +1245,9 @@ impl Perform for MarkPrivateMessageAsRead {
 
     // No need to send an apub update
 
-    let edit_id = data.edit_id;
+    let private_message_id = data.private_message_id;
     let message = blocking(context.pool(), move |conn| {
-      PrivateMessageView::read(conn, edit_id)
+      PrivateMessageView::read(conn, private_message_id)
     })
     .await??;
     let recipient_id = message.recipient.id;
@@ -1329,29 +1298,6 @@ impl Perform for GetPrivateMessages {
   }
 }
 
-#[async_trait::async_trait(?Send)]
-impl Perform for UserJoin {
-  type Response = UserJoinResponse;
-
-  async fn perform(
-    &self,
-    context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
-  ) -> Result<UserJoinResponse, LemmyError> {
-    let data: &UserJoin = &self;
-    let user = get_user_from_jwt(&data.auth, context.pool()).await?;
-
-    if let Some(ws_id) = websocket_id {
-      context.chat_server().do_send(JoinUserRoom {
-        user_id: user.id,
-        id: ws_id,
-      });
-    }
-
-    Ok(UserJoinResponse { joined: true })
-  }
-}
-
 #[async_trait::async_trait(?Send)]
 impl Perform for GetReportCount {
   type Response = GetReportCountResponse;
diff --git a/lemmy_api/src/websocket.rs b/lemmy_api/src/websocket.rs
new file mode 100644 (file)
index 0000000..4342f15
--- /dev/null
@@ -0,0 +1,97 @@
+use crate::{get_user_from_jwt, Perform};
+use actix_web::web::Data;
+use lemmy_structs::websocket::*;
+use lemmy_utils::{ConnectionId, LemmyError};
+use lemmy_websocket::{
+  messages::{JoinCommunityRoom, JoinModRoom, JoinPostRoom, JoinUserRoom},
+  LemmyContext,
+};
+
+#[async_trait::async_trait(?Send)]
+impl Perform for UserJoin {
+  type Response = UserJoinResponse;
+
+  async fn perform(
+    &self,
+    context: &Data<LemmyContext>,
+    websocket_id: Option<ConnectionId>,
+  ) -> Result<UserJoinResponse, LemmyError> {
+    let data: &UserJoin = &self;
+    let user = get_user_from_jwt(&data.auth, context.pool()).await?;
+
+    if let Some(ws_id) = websocket_id {
+      context.chat_server().do_send(JoinUserRoom {
+        user_id: user.id,
+        id: ws_id,
+      });
+    }
+
+    Ok(UserJoinResponse { joined: true })
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl Perform for CommunityJoin {
+  type Response = CommunityJoinResponse;
+
+  async fn perform(
+    &self,
+    context: &Data<LemmyContext>,
+    websocket_id: Option<ConnectionId>,
+  ) -> Result<CommunityJoinResponse, LemmyError> {
+    let data: &CommunityJoin = &self;
+
+    if let Some(ws_id) = websocket_id {
+      context.chat_server().do_send(JoinCommunityRoom {
+        community_id: data.community_id,
+        id: ws_id,
+      });
+    }
+
+    Ok(CommunityJoinResponse { joined: true })
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl Perform for ModJoin {
+  type Response = ModJoinResponse;
+
+  async fn perform(
+    &self,
+    context: &Data<LemmyContext>,
+    websocket_id: Option<ConnectionId>,
+  ) -> Result<ModJoinResponse, LemmyError> {
+    let data: &ModJoin = &self;
+
+    if let Some(ws_id) = websocket_id {
+      context.chat_server().do_send(JoinModRoom {
+        community_id: data.community_id,
+        id: ws_id,
+      });
+    }
+
+    Ok(ModJoinResponse { joined: true })
+  }
+}
+
+#[async_trait::async_trait(?Send)]
+impl Perform for PostJoin {
+  type Response = PostJoinResponse;
+
+  async fn perform(
+    &self,
+    context: &Data<LemmyContext>,
+    websocket_id: Option<ConnectionId>,
+  ) -> Result<PostJoinResponse, LemmyError> {
+    let data: &PostJoin = &self;
+
+    if let Some(ws_id) = websocket_id {
+      context.chat_server().do_send(JoinPostRoom {
+        post_id: data.post_id,
+        id: ws_id,
+      });
+    }
+
+    Ok(PostJoinResponse { joined: true })
+  }
+}
index 44ea66c733a623057054b2274be8e32724533c8e..997f4f9644ef426041eb259c2b5c9369b0760025 100644 (file)
@@ -137,6 +137,11 @@ pub trait ToSafe {
   fn safe_columns_tuple() -> Self::SafeColumns;
 }
 
+pub trait ToSafeSettings {
+  type SafeSettingsColumns;
+  fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns;
+}
+
 pub trait ViewToVec {
   type DbTuple;
   fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
index 7789ff2beb4e11f0b56e6e58065519292db71e97..6e285f99bf9bacaea918d0a82dec41e5f6dec304 100644 (file)
@@ -1,10 +1,10 @@
-use crate::{is_email_regex, ApubObject, Crud};
+use crate::{is_email_regex, ApubObject, Crud, ToSafeSettings};
 use bcrypt::{hash, DEFAULT_COST};
 use diesel::{dsl::*, result::Error, *};
 use lemmy_db_schema::{
   naive_now,
   schema::user_::dsl::*,
-  source::user::{UserForm, User_},
+  source::user::{UserForm, UserSafeSettings, User_},
 };
 use lemmy_utils::settings::Settings;
 
@@ -140,6 +140,82 @@ mod safe_type_alias_2 {
   }
 }
 
+mod safe_settings_type {
+  use crate::ToSafeSettings;
+  use lemmy_db_schema::{schema::user_::columns::*, source::user::User_};
+
+  type Columns = (
+    id,
+    name,
+    preferred_username,
+    email,
+    avatar,
+    admin,
+    banned,
+    published,
+    updated,
+    show_nsfw,
+    theme,
+    default_sort_type,
+    default_listing_type,
+    lang,
+    show_avatars,
+    send_notifications_to_email,
+    matrix_user_id,
+    actor_id,
+    bio,
+    local,
+    last_refreshed_at,
+    banner,
+    deleted,
+  );
+
+  impl ToSafeSettings for User_ {
+    type SafeSettingsColumns = Columns;
+    fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns {
+      (
+        id,
+        name,
+        preferred_username,
+        email,
+        avatar,
+        admin,
+        banned,
+        published,
+        updated,
+        show_nsfw,
+        theme,
+        default_sort_type,
+        default_listing_type,
+        lang,
+        show_avatars,
+        send_notifications_to_email,
+        matrix_user_id,
+        actor_id,
+        bio,
+        local,
+        last_refreshed_at,
+        banner,
+        deleted,
+      )
+    }
+  }
+}
+
+pub trait UserSafeSettings_ {
+  fn read(conn: &PgConnection, user_id: i32) -> Result<UserSafeSettings, Error>;
+}
+
+impl UserSafeSettings_ for UserSafeSettings {
+  fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
+    user_
+      .select(User_::safe_settings_columns_tuple())
+      .filter(deleted.eq(false))
+      .find(user_id)
+      .first::<Self>(conn)
+  }
+}
+
 impl Crud<UserForm> for User_ {
   fn read(conn: &PgConnection, user_id: i32) -> Result<Self, Error> {
     user_
index 3d9d9e500bab091fc3263d54df3fb4391f9626f5..f9dc0a59ad3be37479003b2e45b9ff5b661f7321 100644 (file)
@@ -52,6 +52,35 @@ pub struct UserSafe {
   pub deleted: bool,
 }
 
+/// A safe user view with only settings
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "user_"]
+pub struct UserSafeSettings {
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub email: Option<String>,
+  pub avatar: Option<String>,
+  pub admin: bool,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub show_nsfw: bool,
+  pub theme: String,
+  pub default_sort_type: i16,
+  pub default_listing_type: i16,
+  pub lang: String,
+  pub show_avatars: bool,
+  pub send_notifications_to_email: bool,
+  pub matrix_user_id: Option<String>,
+  pub actor_id: String,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub last_refreshed_at: chrono::NaiveDateTime,
+  pub banner: Option<String>,
+  pub deleted: bool,
+}
+
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "user_alias_1"]
 pub struct UserAlias1 {
index afd968ed97c6e316ba0a565506d6bed5eabf6c01..acb8c4c8d4fbd26ba40d2335e3f05a686c996acd 100644 (file)
@@ -22,24 +22,6 @@ pub struct UserViewSafe {
 
 type UserViewSafeTuple = (UserSafe, UserAggregates);
 
-#[derive(Debug, Serialize, Clone)]
-pub struct UserViewDangerous {
-  pub user: User_,
-  pub counts: UserAggregates,
-}
-
-type UserViewDangerousTuple = (User_, UserAggregates);
-
-impl UserViewDangerous {
-  pub fn read(conn: &PgConnection, id: i32) -> Result<Self, Error> {
-    let (user, counts) = user_::table
-      .find(id)
-      .inner_join(user_aggregates::table)
-      .first::<UserViewDangerousTuple>(conn)?;
-    Ok(Self { user, counts })
-  }
-}
-
 impl UserViewSafe {
   pub fn read(conn: &PgConnection, id: i32) -> Result<Self, Error> {
     let (user, counts) = user_::table
index 1e113b366231257d3f0980ad39074e5e6707c3eb..71c26e11d57f1f2d70a166565ea810eae9586194 100644 (file)
@@ -13,21 +13,21 @@ pub struct CreateComment {
 #[derive(Deserialize)]
 pub struct EditComment {
   pub content: String,
-  pub edit_id: i32,
+  pub comment_id: i32,
   pub form_id: Option<String>,
   pub auth: String,
 }
 
 #[derive(Deserialize)]
 pub struct DeleteComment {
-  pub edit_id: i32,
+  pub comment_id: i32,
   pub deleted: bool,
   pub auth: String,
 }
 
 #[derive(Deserialize)]
 pub struct RemoveComment {
-  pub edit_id: i32,
+  pub comment_id: i32,
   pub removed: bool,
   pub reason: Option<String>,
   pub auth: String,
index 8c45cc9f3ddb5d6f21aafac85b9c3a203baf6aea..5cf3d36d95ee8752ec290d9a04b97b1fc0107d98 100644 (file)
@@ -82,7 +82,7 @@ pub struct AddModToCommunityResponse {
 
 #[derive(Deserialize)]
 pub struct EditCommunity {
-  pub edit_id: i32,
+  pub community_id: i32,
   pub title: String,
   pub description: Option<String>,
   pub icon: Option<String>,
@@ -94,14 +94,14 @@ pub struct EditCommunity {
 
 #[derive(Deserialize)]
 pub struct DeleteCommunity {
-  pub edit_id: i32,
+  pub community_id: i32,
   pub deleted: bool,
   pub auth: String,
 }
 
 #[derive(Deserialize)]
 pub struct RemoveCommunity {
-  pub edit_id: i32,
+  pub community_id: i32,
   pub removed: bool,
   pub reason: Option<String>,
   pub expires: Option<i64>,
@@ -131,23 +131,3 @@ pub struct TransferCommunity {
   pub user_id: i32,
   pub auth: String,
 }
-
-#[derive(Deserialize, Debug)]
-pub struct CommunityJoin {
-  pub community_id: i32,
-}
-
-#[derive(Serialize, Clone)]
-pub struct CommunityJoinResponse {
-  pub joined: bool,
-}
-
-#[derive(Deserialize, Debug)]
-pub struct ModJoin {
-  pub community_id: i32,
-}
-
-#[derive(Serialize, Clone)]
-pub struct ModJoinResponse {
-  pub joined: bool,
-}
index 546eb4ee13305ad303116bdca4a96ed3d77f9ca4..f91b5fcb0b1f943b996a9e8c9594c6fe3a6c6d76 100644 (file)
@@ -3,6 +3,7 @@ pub mod community;
 pub mod post;
 pub mod site;
 pub mod user;
+pub mod websocket;
 
 use diesel::PgConnection;
 use lemmy_db_queries::{source::user::User, Crud, DbPool};
index 02dcf28afd77b2f22c40ec8542049c93094d130e..4e2011e91dbaaf63b4662c889959e9aa1e20c8d9 100644 (file)
@@ -64,7 +64,7 @@ pub struct CreatePostLike {
 
 #[derive(Deserialize)]
 pub struct EditPost {
-  pub edit_id: i32,
+  pub post_id: i32,
   pub name: String,
   pub url: Option<String>,
   pub body: Option<String>,
@@ -74,14 +74,14 @@ pub struct EditPost {
 
 #[derive(Deserialize)]
 pub struct DeletePost {
-  pub edit_id: i32,
+  pub post_id: i32,
   pub deleted: bool,
   pub auth: String,
 }
 
 #[derive(Deserialize)]
 pub struct RemovePost {
-  pub edit_id: i32,
+  pub post_id: i32,
   pub removed: bool,
   pub reason: Option<String>,
   pub auth: String,
@@ -89,14 +89,14 @@ pub struct RemovePost {
 
 #[derive(Deserialize)]
 pub struct LockPost {
-  pub edit_id: i32,
+  pub post_id: i32,
   pub locked: bool,
   pub auth: String,
 }
 
 #[derive(Deserialize)]
 pub struct StickyPost {
-  pub edit_id: i32,
+  pub post_id: i32,
   pub stickied: bool,
   pub auth: String,
 }
@@ -108,16 +108,6 @@ pub struct SavePost {
   pub auth: String,
 }
 
-#[derive(Deserialize, Debug)]
-pub struct PostJoin {
-  pub post_id: i32,
-}
-
-#[derive(Serialize, Clone)]
-pub struct PostJoinResponse {
-  pub joined: bool,
-}
-
 #[derive(Serialize, Deserialize)]
 pub struct CreatePostReport {
   pub post_id: i32,
index e30523464190a73cec15f4ca33a5714a3b1e48f1..ffe311b0aaaf53d7b30e2236e27df8b6b31532e6 100644 (file)
@@ -1,4 +1,4 @@
-use lemmy_db_schema::source::{category::*, user::User_};
+use lemmy_db_schema::source::{category::*, user::UserSafeSettings};
 use lemmy_db_views::{comment_view::CommentView, post_view::PostView, site_view::SiteView};
 use lemmy_db_views_actor::{community_view::CommunityView, user_view::UserViewSafe};
 use lemmy_db_views_moderator::{
@@ -105,7 +105,7 @@ pub struct GetSiteResponse {
   pub banned: Vec<UserViewSafe>,
   pub online: usize,
   pub version: String,
-  pub my_user: Option<User_>,
+  pub my_user: Option<UserSafeSettings>,
   pub federated_instances: Vec<String>,
 }
 
index 5964bf6000f532db2ae72c0a8118c3389295165b..dcc35f06c161bc16890c465a499b6c873904bded 100644 (file)
@@ -7,7 +7,7 @@ use lemmy_db_views_actor::{
   community_follower_view::CommunityFollowerView,
   community_moderator_view::CommunityModeratorView,
   user_mention_view::UserMentionView,
-  user_view::{UserViewDangerous, UserViewSafe},
+  user_view::UserViewSafe,
 };
 use serde::{Deserialize, Serialize};
 
@@ -23,7 +23,6 @@ pub struct Register {
   pub email: Option<String>,
   pub password: String,
   pub password_verify: String,
-  pub admin: bool,
   pub show_nsfw: bool,
   pub captcha_uuid: Option<String>,
   pub captcha_answer: Option<String>,
@@ -34,7 +33,7 @@ pub struct GetCaptcha {}
 
 #[derive(Serialize)]
 pub struct GetCaptchaResponse {
-  pub ok: Option<CaptchaResponse>,
+  pub ok: Option<CaptchaResponse>, // Will be None if captchas are disabled
 }
 
 #[derive(Serialize)]
@@ -84,8 +83,7 @@ pub struct GetUserDetails {
 
 #[derive(Serialize)]
 pub struct GetUserDetailsResponse {
-  pub user_view: Option<UserViewSafe>,
-  pub user_view_dangerous: Option<UserViewDangerous>,
+  pub user_view: UserViewSafe,
   pub follows: Vec<CommunityFollowerView>,
   pub moderates: Vec<CommunityModeratorView>,
   pub comments: Vec<CommentView>,
@@ -195,21 +193,21 @@ pub struct CreatePrivateMessage {
 
 #[derive(Deserialize)]
 pub struct EditPrivateMessage {
-  pub edit_id: i32,
+  pub private_message_id: i32,
   pub content: String,
   pub auth: String,
 }
 
 #[derive(Deserialize)]
 pub struct DeletePrivateMessage {
-  pub edit_id: i32,
+  pub private_message_id: i32,
   pub deleted: bool,
   pub auth: String,
 }
 
 #[derive(Deserialize)]
 pub struct MarkPrivateMessageAsRead {
-  pub edit_id: i32,
+  pub private_message_id: i32,
   pub read: bool,
   pub auth: String,
 }
@@ -232,16 +230,6 @@ pub struct PrivateMessageResponse {
   pub private_message_view: PrivateMessageView,
 }
 
-#[derive(Deserialize, Debug)]
-pub struct UserJoin {
-  pub auth: String,
-}
-
-#[derive(Serialize, Clone)]
-pub struct UserJoinResponse {
-  pub joined: bool,
-}
-
 #[derive(Serialize, Deserialize, Debug)]
 pub struct GetReportCount {
   pub community: Option<i32>,
diff --git a/lemmy_structs/src/websocket.rs b/lemmy_structs/src/websocket.rs
new file mode 100644 (file)
index 0000000..c3ae146
--- /dev/null
@@ -0,0 +1,41 @@
+use serde::{Deserialize, Serialize};
+
+#[derive(Deserialize, Debug)]
+pub struct UserJoin {
+  pub auth: String,
+}
+
+#[derive(Serialize, Clone)]
+pub struct UserJoinResponse {
+  pub joined: bool,
+}
+
+#[derive(Deserialize, Debug)]
+pub struct CommunityJoin {
+  pub community_id: i32,
+}
+
+#[derive(Serialize, Clone)]
+pub struct CommunityJoinResponse {
+  pub joined: bool,
+}
+
+#[derive(Deserialize, Debug)]
+pub struct ModJoin {
+  pub community_id: i32,
+}
+
+#[derive(Serialize, Clone)]
+pub struct ModJoinResponse {
+  pub joined: bool,
+}
+
+#[derive(Deserialize, Debug)]
+pub struct PostJoin {
+  pub post_id: i32,
+}
+
+#[derive(Serialize, Clone)]
+pub struct PostJoinResponse {
+  pub joined: bool,
+}
index 2a91b2c5f43ebaf0fffd7cf814560106a617ec84..1f5a54544e838a0c14112ea8c58e73d5801b68aa 100644 (file)
@@ -1,6 +1,6 @@
 use actix_web::{error::ErrorBadRequest, *};
 use lemmy_api::Perform;
-use lemmy_structs::{comment::*, community::*, post::*, site::*, user::*};
+use lemmy_structs::{comment::*, community::*, post::*, site::*, user::*, websocket::*};
 use lemmy_utils::rate_limit::RateLimit;
 use lemmy_websocket::LemmyContext;
 use serde::Deserialize;