]> Untitled Git - lemmy.git/commitdiff
A first pass.
authorDessalines <tyhou13@gmx.com>
Thu, 11 Mar 2021 04:43:11 +0000 (23:43 -0500)
committerDessalines <tyhou13@gmx.com>
Thu, 11 Mar 2021 04:43:11 +0000 (23:43 -0500)
73 files changed:
crates/api/src/comment.rs
crates/api/src/community.rs
crates/api/src/lib.rs
crates/api/src/local_user.rs [moved from crates/api/src/user.rs with 74% similarity]
crates/api/src/post.rs
crates/api/src/routes.rs
crates/api/src/site.rs
crates/api_structs/src/lib.rs
crates/api_structs/src/person.rs
crates/api_structs/src/site.rs
crates/apub/src/activities/receive/comment.rs
crates/apub/src/activities/send/comment.rs
crates/apub/src/activities/send/mod.rs
crates/apub/src/activities/send/post.rs
crates/apub/src/activities/send/private_message.rs
crates/apub/src/fetcher/mod.rs
crates/apub/src/fetcher/person.rs
crates/apub/src/fetcher/search.rs
crates/apub/src/http/mod.rs
crates/apub/src/inbox/community_inbox.rs
crates/apub/src/inbox/mod.rs
crates/apub/src/inbox/person_inbox.rs
crates/apub/src/lib.rs
crates/apub/src/objects/comment.rs
crates/apub/src/objects/mod.rs
crates/apub/src/objects/person.rs
crates/apub/src/objects/post.rs
crates/apub/src/objects/private_message.rs
crates/apub/src/routes.rs
crates/db_queries/src/aggregates/comment_aggregates.rs
crates/db_queries/src/aggregates/community_aggregates.rs
crates/db_queries/src/aggregates/mod.rs
crates/db_queries/src/aggregates/person_aggregates.rs
crates/db_queries/src/aggregates/post_aggregates.rs
crates/db_queries/src/aggregates/site_aggregates.rs
crates/db_queries/src/source/activity.rs
crates/db_queries/src/source/comment.rs
crates/db_queries/src/source/community.rs
crates/db_queries/src/source/local_user.rs
crates/db_queries/src/source/mod.rs
crates/db_queries/src/source/moderator.rs
crates/db_queries/src/source/person.rs
crates/db_queries/src/source/person_mention.rs
crates/db_queries/src/source/private_message.rs
crates/db_queries/src/source/user.rs [deleted file]
crates/db_schema/src/source/local_user.rs
crates/db_schema/src/source/mod.rs
crates/db_schema/src/source/person.rs
crates/db_schema/src/source/user.rs [deleted file]
crates/db_views/src/comment_report_view.rs
crates/db_views/src/comment_view.rs
crates/db_views/src/lib.rs
crates/db_views/src/local_user_view.rs
crates/db_views/src/post_report_view.rs
crates/db_views/src/post_view.rs
crates/db_views/src/private_message_view.rs
crates/db_views/src/site_view.rs
crates/db_views_actor/src/community_follower_view.rs
crates/db_views_actor/src/community_moderator_view.rs
crates/db_views_actor/src/community_person_ban_view.rs
crates/db_views_actor/src/community_view.rs
crates/db_views_actor/src/person_mention_view.rs
crates/db_views_actor/src/person_view.rs
crates/db_views_moderator/src/mod_add_community_view.rs
crates/db_views_moderator/src/mod_add_view.rs
crates/db_views_moderator/src/mod_ban_from_community_view.rs
crates/db_views_moderator/src/mod_ban_view.rs
crates/db_views_moderator/src/mod_lock_post_view.rs
crates/db_views_moderator/src/mod_remove_comment_view.rs
crates/db_views_moderator/src/mod_remove_community_view.rs
crates/db_views_moderator/src/mod_remove_post_view.rs
crates/db_views_moderator/src/mod_sticky_post_view.rs
src/code_migrations.rs

index 711e8e725f4f5bbc38200665b2725b465ed1f084..aff39e0249ffbb1af50b3b2da3448d14a86fbd85 100644 (file)
@@ -2,9 +2,9 @@ use crate::{
   check_community_ban,
   check_downvotes_enabled,
   collect_moderated_communities,
-  get_post,
   get_local_user_view_from_jwt,
   get_local_user_view_from_jwt_opt,
+  get_post,
   is_mod_or_admin,
   Perform,
 };
@@ -115,7 +115,9 @@ impl Perform for CreateComment {
         Err(_e) => return Err(ApiError::err("couldnt_create_comment").into()),
       };
 
-    updated_comment.send_create(&local_user_view.person, context).await?;
+    updated_comment
+      .send_create(&local_user_view.person, context)
+      .await?;
 
     // Scan the comment for user mentions, add those rows
     let post_id = post.id;
@@ -143,7 +145,9 @@ impl Perform for CreateComment {
       return Err(ApiError::err("couldnt_like_comment").into());
     }
 
-    updated_comment.send_like(&local_user_view.person, context).await?;
+    updated_comment
+      .send_like(&local_user_view.person, context)
+      .await?;
 
     let person_id = local_user_view.person.id;
     let mut comment_view = blocking(context.pool(), move |conn| {
@@ -201,7 +205,12 @@ impl Perform for EditComment {
     })
     .await??;
 
-    check_community_ban(local_user_view.person.id, orig_comment.community.id, context.pool()).await?;
+    check_community_ban(
+      local_user_view.person.id,
+      orig_comment.community.id,
+      context.pool(),
+    )
+    .await?;
 
     // Verify that only the creator can edit
     if local_user_view.person.id != orig_comment.creator.id {
@@ -221,7 +230,9 @@ impl Perform for EditComment {
     };
 
     // Send the apub update
-    updated_comment.send_update(&local_user_view.person, context).await?;
+    updated_comment
+      .send_update(&local_user_view.person, context)
+      .await?;
 
     // Do the mentions / recipients
     let updated_comment_content = updated_comment.content.to_owned();
@@ -277,7 +288,12 @@ impl Perform for DeleteComment {
     })
     .await??;
 
-    check_community_ban(local_user_view.person.id, orig_comment.community.id, context.pool()).await?;
+    check_community_ban(
+      local_user_view.person.id,
+      orig_comment.community.id,
+      context.pool(),
+    )
+    .await?;
 
     // Verify that only the creator can delete
     if local_user_view.person.id != orig_comment.creator.id {
@@ -297,9 +313,13 @@ impl Perform for DeleteComment {
 
     // Send the apub message
     if deleted {
-      updated_comment.send_delete(&local_user_view.person, context).await?;
+      updated_comment
+        .send_delete(&local_user_view.person, context)
+        .await?;
     } else {
-      updated_comment.send_undo_delete(&local_user_view.person, context).await?;
+      updated_comment
+        .send_undo_delete(&local_user_view.person, context)
+        .await?;
     }
 
     // Refetch it
@@ -357,10 +377,20 @@ impl Perform for RemoveComment {
     })
     .await??;
 
-    check_community_ban(local_user_view.person.id, orig_comment.community.id, context.pool()).await?;
+    check_community_ban(
+      local_user_view.person.id,
+      orig_comment.community.id,
+      context.pool(),
+    )
+    .await?;
 
     // Verify that only a mod or admin can remove
-    is_mod_or_admin(context.pool(), local_user_view.person.id, orig_comment.community.id).await?;
+    is_mod_or_admin(
+      context.pool(),
+      local_user_view.person.id,
+      orig_comment.community.id,
+    )
+    .await?;
 
     // Do the remove
     let removed = data.removed;
@@ -387,9 +417,13 @@ impl Perform for RemoveComment {
 
     // Send the apub message
     if removed {
-      updated_comment.send_remove(&local_user_view.person, context).await?;
+      updated_comment
+        .send_remove(&local_user_view.person, context)
+        .await?;
     } else {
-      updated_comment.send_undo_remove(&local_user_view.person, context).await?;
+      updated_comment
+        .send_undo_remove(&local_user_view.person, context)
+        .await?;
     }
 
     // Refetch it
@@ -448,7 +482,12 @@ impl Perform for MarkCommentAsRead {
     })
     .await??;
 
-    check_community_ban(local_user_view.person.id, orig_comment.community.id, context.pool()).await?;
+    check_community_ban(
+      local_user_view.person.id,
+      orig_comment.community.id,
+      context.pool(),
+    )
+    .await?;
 
     // Verify that only the recipient can mark as read
     if local_user_view.person.id != orig_comment.get_recipient_id() {
@@ -551,7 +590,12 @@ impl Perform for CreateCommentLike {
     })
     .await??;
 
-    check_community_ban(local_user_view.person.id, orig_comment.community.id, context.pool()).await?;
+    check_community_ban(
+      local_user_view.person.id,
+      orig_comment.community.id,
+      context.pool(),
+    )
+    .await?;
 
     // Add parent user to recipients
     recipient_ids.push(orig_comment.get_recipient_id());
@@ -583,10 +627,14 @@ impl Perform for CreateCommentLike {
       if like_form.score == 1 {
         comment.send_like(&local_user_view.person, context).await?;
       } else if like_form.score == -1 {
-        comment.send_dislike(&local_user_view.person, context).await?;
+        comment
+          .send_dislike(&local_user_view.person, context)
+          .await?;
       }
     } else {
-      comment.send_undo_like(&local_user_view.person, context).await?;
+      comment
+        .send_undo_like(&local_user_view.person, context)
+        .await?;
     }
 
     // Have to refetch the comment to get the current state
index 6949a4a9994418c7eb01126b8234a4b0f7f8fe19..53b99c2264d3f818ae69fc7fef46fe56df87f4f4 100644 (file)
@@ -517,9 +517,15 @@ impl Perform for FollowCommunity {
     } else if data.follow {
       // Dont actually add to the community followers here, because you need
       // to wait for the accept
-      local_user_view.person.send_follow(&community.actor_id(), context).await?;
+      local_user_view
+        .person
+        .send_follow(&community.actor_id(), context)
+        .await?;
     } else {
-      local_user_view.person.send_unfollow(&community.actor_id(), context).await?;
+      local_user_view
+        .person
+        .send_unfollow(&community.actor_id(), context)
+        .await?;
       let unfollow = move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
       if blocking(context.pool(), unfollow).await?.is_err() {
         return Err(ApiError::err("community_follower_already_exists").into());
@@ -788,7 +794,10 @@ impl Perform for TransferCommunity {
 
     // Make sure user is the creator, or an admin
     if local_user_view.person.id != read_community.creator_id
-      && !admins.iter().map(|a| a.person.id).any(|x| x == local_user_view.person.id)
+      && !admins
+        .iter()
+        .map(|a| a.person.id)
+        .any(|x| x == local_user_view.person.id)
     {
       return Err(ApiError::err("not_an_admin").into());
     }
index 3fe3bc7ab1b07084c4955e3195b4eb79253dfe33..d71f4b6eed088e66a8e86d0d07de8251e84f2dfd 100644 (file)
@@ -3,17 +3,15 @@ use lemmy_api_structs::{
   blocking,
   comment::*,
   community::*,
+  person::*,
   post::*,
   site::*,
-  person::*,
   websocket::*,
 };
 use lemmy_db_queries::{
   source::{
     community::{CommunityModerator_, Community_},
     site::Site_,
-    local_user::LocalUserSettings_,
-    local_user::LocalUser_,
   },
   Crud,
   DbPool,
@@ -22,15 +20,12 @@ use lemmy_db_schema::source::{
   community::{Community, CommunityModerator},
   post::Post,
   site::Site,
-  person::{Person, PersonSafe},
-  local_user::LocalUserSettings,
-  local_user::LocalUser,
 };
+use lemmy_db_views::local_user_view::{LocalUserSettingsView, LocalUserView};
 use lemmy_db_views_actor::{
   community_person_ban_view::CommunityPersonBanView,
   community_view::CommunityView,
 };
-use lemmy_db_views::local_user_view::{LocalUserView, LocalUserSettingsView};
 use lemmy_utils::{
   claims::Claims,
   settings::structs::Settings,
@@ -45,10 +40,10 @@ use url::Url;
 
 pub mod comment;
 pub mod community;
+pub mod local_user;
 pub mod post;
 pub mod routes;
 pub mod site;
-pub mod user;
 pub mod websocket;
 
 #[async_trait::async_trait(?Send)]
@@ -100,13 +95,19 @@ pub(crate) async fn get_post(post_id: i32, pool: &DbPool) -> Result<Post, LemmyE
   }
 }
 
-pub(crate) async fn get_local_user_view_from_jwt(jwt: &str, pool: &DbPool) -> Result<LocalUserView, LemmyError> {
+pub(crate) async fn get_local_user_view_from_jwt(
+  jwt: &str,
+  pool: &DbPool,
+) -> Result<LocalUserView, LemmyError> {
   let claims = match Claims::decode(&jwt) {
     Ok(claims) => claims.claims,
     Err(_e) => return Err(ApiError::err("not_logged_in").into()),
   };
   let person_id = claims.id;
-  let local_user_view = blocking(pool, move |conn| LocalUserView::read(conn, person_id)).await??;
+  let local_user_view = blocking(pool, move |conn| {
+    LocalUserView::read_person(conn, person_id)
+  })
+  .await??;
   // Check for a site ban
   if local_user_view.person.banned {
     return Err(ApiError::err("site_ban").into());
@@ -124,13 +125,19 @@ pub(crate) async fn get_local_user_view_from_jwt_opt(
   }
 }
 
-pub(crate) async fn get_local_user_settings_view_from_jwt(jwt: &str, pool: &DbPool) -> Result<LocalUserSettingsView, LemmyError> {
+pub(crate) async fn get_local_user_settings_view_from_jwt(
+  jwt: &str,
+  pool: &DbPool,
+) -> Result<LocalUserSettingsView, LemmyError> {
   let claims = match Claims::decode(&jwt) {
     Ok(claims) => claims.claims,
     Err(_e) => return Err(ApiError::err("not_logged_in").into()),
   };
   let person_id = claims.id;
-  let local_user_view = blocking(pool, move |conn| LocalUserSettingsView::read(conn, person_id)).await??;
+  let local_user_view = blocking(pool, move |conn| {
+    LocalUserSettingsView::read(conn, person_id)
+  })
+  .await??;
   // Check for a site ban
   if local_user_view.person.banned {
     return Err(ApiError::err("site_ban").into());
@@ -143,7 +150,9 @@ pub(crate) async fn get_local_user_settings_view_from_jwt_opt(
   pool: &DbPool,
 ) -> Result<Option<LocalUserSettingsView>, LemmyError> {
   match jwt {
-    Some(jwt) => Ok(Some(get_local_user_settings_view_from_jwt(jwt, pool).await?)),
+    Some(jwt) => Ok(Some(
+      get_local_user_settings_view_from_jwt(jwt, pool).await?,
+    )),
     None => Ok(None),
   }
 }
@@ -153,7 +162,8 @@ pub(crate) async fn check_community_ban(
   community_id: i32,
   pool: &DbPool,
 ) -> Result<(), LemmyError> {
-  let is_banned = move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
+  let is_banned =
+    move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
   if blocking(pool, is_banned).await? {
     Err(ApiError::err("community_ban").into())
   } else {
similarity index 74%
rename from crates/api/src/user.rs
rename to crates/api/src/local_user.rs
index 112814904824a8bcea3e25573c0e51748e34b9f6..781ef8f9ad17b800f3a019172222b8d028a9ce59 100644 (file)
@@ -12,7 +12,7 @@ use anyhow::Context;
 use bcrypt::verify;
 use captcha::{gen, Difficulty};
 use chrono::Duration;
-use lemmy_api_structs::{blocking, send_email_to_user, person::*};
+use lemmy_api_structs::{blocking, person::*, send_email_to_user};
 use lemmy_apub::{
   generate_apub_endpoint,
   generate_followers_url,
@@ -27,12 +27,13 @@ use lemmy_db_queries::{
   source::{
     comment::Comment_,
     community::Community_,
+    local_user::LocalUser_,
     password_reset_request::PasswordResetRequest_,
+    person::Person_,
+    person_mention::PersonMention_,
     post::Post_,
     private_message::PrivateMessage_,
     site::Site_,
-    person::Person_,
-    person_mention::PersonMention_,
   },
   Crud,
   Followable,
@@ -40,14 +41,28 @@ use lemmy_db_queries::{
   ListingType,
   SortType,
 };
-use lemmy_db_schema::{naive_now, source::{comment::Comment, community::*, local_user::LocalUserForm, moderator::*, password_reset_request::*, person::*, person_mention::*, post::Post, private_message::*, site::*}};
+use lemmy_db_schema::{
+  naive_now,
+  source::{
+    comment::Comment,
+    community::*,
+    local_user::{LocalUser, LocalUserForm},
+    moderator::*,
+    password_reset_request::*,
+    person::*,
+    person_mention::*,
+    post::Post,
+    private_message::*,
+    site::*,
+  },
+};
 use lemmy_db_views::{
   comment_report_view::CommentReportView,
   comment_view::CommentQueryBuilder,
+  local_user_view::LocalUserView,
   post_report_view::PostReportView,
   post_view::PostQueryBuilder,
   private_message_view::{PrivateMessageQueryBuilder, PrivateMessageView},
-  local_user_view::LocalUserView,
 };
 use lemmy_db_views_actor::{
   community_follower_view::CommunityFollowerView,
@@ -103,7 +118,11 @@ impl Perform for Login {
     };
 
     // Verify the password
-    let valid: bool = verify(&data.password, &local_user_view.local_user.password_encrypted).unwrap_or(false);
+    let valid: bool = verify(
+      &data.password,
+      &local_user_view.local_user.password_encrypted,
+    )
+    .unwrap_or(false);
     if !valid {
       return Err(ApiError::err("password_incorrect").into());
     }
@@ -175,7 +194,7 @@ impl Perform for Register {
     let actor_id = generate_apub_endpoint(EndpointType::Person, &data.username)?;
 
     // We have to create both a person, and local_user
-    
+
     // Register the new person
     let person_form = PersonForm {
       name: data.username.to_owned(),
@@ -186,18 +205,11 @@ impl Perform for Register {
       updated: None,
       banned: None,
       deleted: None,
-      show_nsfw: data.show_nsfw,
-      theme: "browser".into(),
-      default_sort_type: SortType::Active as i16,
-      default_listing_type: ListingType::Subscribed as i16,
-      lang: "browser".into(),
-      show_avatars: true,
-      send_notifications_to_email: false,
       actor_id: Some(actor_id.clone()),
       bio: None,
-      local: true,
-      private_key: Some(actor_keypair.private_key),
-      public_key: Some(actor_keypair.public_key),
+      local: Some(true),
+      private_key: Some(Some(actor_keypair.private_key)),
+      public_key: Some(Some(actor_keypair.public_key)),
       last_refreshed_at: None,
       inbox_url: Some(generate_inbox_url(&actor_id)?),
       shared_inbox_url: Some(Some(generate_shared_inbox_url(&actor_id)?)),
@@ -209,8 +221,8 @@ impl Perform for Register {
     })
     .await?
     {
-      Ok(user) => user,
-      Err(e) => {
+      Ok(u) => u,
+      Err(_) => {
         return Err(ApiError::err("user_already_exists").into());
       }
     };
@@ -221,11 +233,17 @@ impl Perform for Register {
       email: Some(data.email.to_owned()),
       matrix_user_id: None,
       password_encrypted: data.password.to_owned(),
-      admin: no_admins,
-
+      admin: Some(no_admins),
+      show_nsfw: Some(data.show_nsfw),
+      theme: Some("browser".into()),
+      default_sort_type: Some(SortType::Active as i16),
+      default_listing_type: Some(ListingType::Subscribed as i16),
+      lang: Some("browser".into()),
+      show_avatars: Some(true),
+      send_notifications_to_email: Some(false),
     };
 
-    let inserted_local_user = match blocking(context.pool(), move |conn| {
+    match blocking(context.pool(), move |conn| {
       LocalUser::register(conn, &local_user_form)
     })
     .await?
@@ -241,12 +259,14 @@ impl Perform for Register {
         };
 
         // If the local user creation errored, then delete that person
-        blocking(context.pool(), move |conn| Person::delete(&conn, inserted_person.id)).await??;
+        blocking(context.pool(), move |conn| {
+          Person::delete(&conn, inserted_person.id)
+        })
+        .await??;
 
         return Err(ApiError::err(err_type).into());
       }
     };
-    
 
     let main_community_keypair = generate_actor_keypair()?;
 
@@ -374,7 +394,7 @@ impl Perform for SaveUserSettings {
     _websocket_id: Option<ConnectionId>,
   ) -> Result<LoginResponse, LemmyError> {
     let data: &SaveUserSettings = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
     let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
     let banner = diesel_option_overwrite_to_url(&data.banner)?;
@@ -395,7 +415,8 @@ impl Perform for SaveUserSettings {
       }
     }
 
-    let user_id = user.id;
+    let local_user_id = local_user_view.local_user.id;
+    let person_id = local_user_view.person.id;
     let password_encrypted = match &data.new_password {
       Some(new_password) => {
         match &data.new_password_verify {
@@ -410,13 +431,15 @@ impl Perform for SaveUserSettings {
             // Check the old password
             match &data.old_password {
               Some(old_password) => {
-                let valid: bool = verify(old_password, &user.password_encrypted).unwrap_or(false);
+                let valid: bool =
+                  verify(old_password, &local_user_view.local_user.password_encrypted)
+                    .unwrap_or(false);
                 if !valid {
                   return Err(ApiError::err("password_incorrect").into());
                 }
                 let new_password = new_password.to_owned();
                 let user = blocking(context.pool(), move |conn| {
-                  User_::update_password(conn, user_id, &new_password)
+                  LocalUser::update_password(conn, local_user_id, &new_password)
                 })
                 .await??;
                 user.password_encrypted
@@ -427,25 +450,48 @@ impl Perform for SaveUserSettings {
           None => return Err(ApiError::err("passwords_dont_match").into()),
         }
       }
-      None => user.password_encrypted,
+      None => local_user_view.local_user.password_encrypted,
     };
 
     let default_listing_type = data.default_listing_type;
     let default_sort_type = data.default_sort_type;
 
-    let user_form = UserForm {
-      name: user.name,
-      email,
-      matrix_user_id,
+    let person_form = PersonForm {
+      name: local_user_view.person.name,
       avatar,
       banner,
       inbox_url: None,
-      password_encrypted,
       preferred_username,
-      published: Some(user.published),
+      published: None,
       updated: Some(naive_now()),
-      admin: user.admin,
-      banned: Some(user.banned),
+      banned: None,
+      deleted: None,
+      actor_id: None,
+      bio,
+      local: None,
+      private_key: None,
+      public_key: None,
+      last_refreshed_at: None,
+      shared_inbox_url: None,
+    };
+
+    let person_res = blocking(context.pool(), move |conn| {
+      Person::update(conn, person_id, &person_form)
+    })
+    .await?;
+    let updated_person: Person = match person_res {
+      Ok(p) => p,
+      Err(_) => {
+        return Err(ApiError::err("user_already_exists").into());
+      }
+    };
+
+    let local_user_form = LocalUserForm {
+      person_id,
+      email,
+      matrix_user_id,
+      password_encrypted,
+      admin: None,
       show_nsfw: data.show_nsfw,
       theme: data.theme.to_owned(),
       default_sort_type,
@@ -453,24 +499,17 @@ impl Perform for SaveUserSettings {
       lang: data.lang.to_owned(),
       show_avatars: data.show_avatars,
       send_notifications_to_email: data.send_notifications_to_email,
-      actor_id: Some(user.actor_id),
-      bio,
-      local: user.local,
-      private_key: user.private_key,
-      public_key: user.public_key,
-      last_refreshed_at: None,
-      shared_inbox_url: None,
     };
 
-    let res = blocking(context.pool(), move |conn| {
-      User_::update(conn, user_id, &user_form)
+    let local_user_res = blocking(context.pool(), move |conn| {
+      LocalUser::update(conn, local_user_id, &local_user_form)
     })
     .await?;
-    let updated_user: User_ = match res {
+    match local_user_res {
       Ok(user) => user,
       Err(e) => {
         let err_type = if e.to_string()
-          == "duplicate key value violates unique constraint \"user__email_key\""
+          == "duplicate key value violates unique constraint \"local_user_email_key\""
         {
           "email_already_exists"
         } else {
@@ -483,25 +522,25 @@ impl Perform for SaveUserSettings {
 
     // Return the jwt
     Ok(LoginResponse {
-      jwt: Claims::jwt(updated_user.id, Settings::get().hostname())?,
+      jwt: Claims::jwt(updated_person.id, Settings::get().hostname())?,
     })
   }
 }
 
 #[async_trait::async_trait(?Send)]
-impl Perform for GetUserDetails {
-  type Response = GetUserDetailsResponse;
+impl Perform for GetPersonDetails {
+  type Response = GetPersonDetailsResponse;
 
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
     _websocket_id: Option<ConnectionId>,
-  ) -> Result<GetUserDetailsResponse, LemmyError> {
-    let data: &GetUserDetails = &self;
-    let user = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
+  ) -> Result<GetPersonDetailsResponse, LemmyError> {
+    let data: &GetPersonDetails = &self;
+    let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
 
-    let show_nsfw = match &user {
-      Some(user) => user.show_nsfw,
+    let show_nsfw = match &local_user_view {
+      Some(uv) => uv.local_user.show_nsfw,
       None => false,
     };
 
@@ -511,26 +550,26 @@ impl Perform for GetUserDetails {
       .username
       .to_owned()
       .unwrap_or_else(|| "admin".to_string());
-    let user_details_id = match data.user_id {
+    let person_details_id = match data.person_id {
       Some(id) => id,
       None => {
-        let user = blocking(context.pool(), move |conn| {
-          User_::read_from_name(conn, &username)
+        let person = blocking(context.pool(), move |conn| {
+          Person::find_by_name(conn, &username)
         })
         .await?;
-        match user {
-          Ok(user) => user.id,
+        match person {
+          Ok(p) => p.id,
           Err(_e) => return Err(ApiError::err("couldnt_find_that_username_or_email").into()),
         }
       }
     };
 
-    let user_id = user.map(|u| u.id);
+    let person_id = local_user_view.map(|uv| uv.person.id);
 
     // 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)
+    let person_view = blocking(context.pool(), move |conn| {
+      PersonViewSafe::read(conn, person_details_id)
     })
     .await??;
 
@@ -545,12 +584,12 @@ impl Perform for GetUserDetails {
         .show_nsfw(show_nsfw)
         .saved_only(saved_only)
         .community_id(community_id)
-        .my_user_id(user_id)
+        .my_person_id(person_id)
         .page(page)
         .limit(limit);
 
       let mut comments_query = CommentQueryBuilder::create(conn)
-        .my_person_id(user_id)
+        .my_person_id(person_id)
         .sort(&sort)
         .saved_only(saved_only)
         .page(page)
@@ -559,8 +598,8 @@ impl Perform for GetUserDetails {
       // If its saved only, you don't care what creator it was
       // Or, if its not saved, then you only want it for that specific creator
       if !saved_only {
-        posts_query = posts_query.creator_id(user_details_id);
-        comments_query = comments_query.creator_id(user_details_id);
+        posts_query = posts_query.creator_id(person_details_id);
+        comments_query = comments_query.creator_id(person_details_id);
       }
 
       let posts = posts_query.list()?;
@@ -571,22 +610,22 @@ impl Perform for GetUserDetails {
     .await??;
 
     let mut follows = vec![];
-    if let Some(uid) = user_id {
-      if uid == user_details_id {
+    if let Some(pid) = person_id {
+      if pid == person_details_id {
         follows = blocking(context.pool(), move |conn| {
-          CommunityFollowerView::for_user(conn, user_details_id)
+          CommunityFollowerView::for_person(conn, person_details_id)
         })
         .await??;
       }
     };
     let moderates = blocking(context.pool(), move |conn| {
-      CommunityModeratorView::for_person(conn, user_details_id)
+      CommunityModeratorView::for_person(conn, person_details_id)
     })
     .await??;
 
     // Return the jwt
-    Ok(GetUserDetailsResponse {
-      user_view,
+    Ok(GetPersonDetailsResponse {
+      person_view,
       follows,
       moderates,
       comments,
@@ -605,22 +644,28 @@ impl Perform for AddAdmin {
     websocket_id: Option<ConnectionId>,
   ) -> Result<AddAdminResponse, LemmyError> {
     let data: &AddAdmin = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
     // Make sure user is an admin
-    is_admin(context.pool(), user.id).await?;
+    is_admin(&local_user_view)?;
 
     let added = data.added;
-    let added_user_id = data.user_id;
-    let add_admin = move |conn: &'_ _| User_::add_admin(conn, added_user_id, added);
-    if blocking(context.pool(), add_admin).await?.is_err() {
-      return Err(ApiError::err("couldnt_update_user").into());
-    }
+    let added_local_user_id = data.local_user_id;
+    let added_admin = match blocking(context.pool(), move |conn| {
+      LocalUser::add_admin(conn, added_local_user_id, added)
+    })
+    .await?
+    {
+      Ok(a) => a,
+      Err(_) => {
+        return Err(ApiError::err("couldnt_update_user").into());
+      }
+    };
 
     // Mod tables
     let form = ModAddForm {
-      mod_person_id: user.id,
-      other_person_id: data.user_id,
+      mod_person_id: local_user_view.person.id,
+      other_person_id: added_admin.person_id,
       removed: Some(!data.added),
     };
 
@@ -631,13 +676,13 @@ impl Perform for AddAdmin {
     })
     .await??;
 
-    let mut admins = blocking(context.pool(), move |conn| UserViewSafe::admins(conn)).await??;
+    let mut admins = blocking(context.pool(), move |conn| PersonViewSafe::admins(conn)).await??;
     let creator_index = admins
       .iter()
-      .position(|r| r.user.id == site_creator_id)
+      .position(|r| r.person.id == site_creator_id)
       .context(location_info!())?;
-    let creator_user = admins.remove(creator_index);
-    admins.insert(0, creator_user);
+    let creator_person = admins.remove(creator_index);
+    admins.insert(0, creator_person);
 
     let res = AddAdminResponse { admins };
 
@@ -652,24 +697,24 @@ impl Perform for AddAdmin {
 }
 
 #[async_trait::async_trait(?Send)]
-impl Perform for BanUser {
-  type Response = BanUserResponse;
+impl Perform for BanPerson {
+  type Response = BanPersonResponse;
 
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
     websocket_id: Option<ConnectionId>,
-  ) -> Result<BanUserResponse, LemmyError> {
-    let data: &BanUser = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+  ) -> Result<BanPersonResponse, LemmyError> {
+    let data: &BanPerson = &self;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
     // Make sure user is an admin
-    is_admin(context.pool(), user.id).await?;
+    is_admin(&local_user_view)?;
 
     let ban = data.ban;
-    let banned_user_id = data.user_id;
-    let ban_user = move |conn: &'_ _| User_::ban_user(conn, banned_user_id, ban);
-    if blocking(context.pool(), ban_user).await?.is_err() {
+    let banned_person_id = data.person_id;
+    let ban_person = move |conn: &'_ _| Person::ban_person(conn, banned_person_id, ban);
+    if blocking(context.pool(), ban_person).await?.is_err() {
       return Err(ApiError::err("couldnt_update_user").into());
     }
 
@@ -677,19 +722,19 @@ impl Perform for BanUser {
     if data.remove_data {
       // Posts
       blocking(context.pool(), move |conn: &'_ _| {
-        Post::update_removed_for_creator(conn, banned_user_id, None, true)
+        Post::update_removed_for_creator(conn, banned_person_id, None, true)
       })
       .await??;
 
       // Communities
       blocking(context.pool(), move |conn: &'_ _| {
-        Community::update_removed_for_creator(conn, banned_user_id, true)
+        Community::update_removed_for_creator(conn, banned_person_id, true)
       })
       .await??;
 
       // Comments
       blocking(context.pool(), move |conn: &'_ _| {
-        Comment::update_removed_for_creator(conn, banned_user_id, true)
+        Comment::update_removed_for_creator(conn, banned_person_id, true)
       })
       .await??;
     }
@@ -701,8 +746,8 @@ impl Perform for BanUser {
     };
 
     let form = ModBanForm {
-      mod_person_id: user.id,
-      other_person_id: data.user_id,
+      mod_person_id: local_user_view.person.id,
+      other_person_id: data.person_id,
       reason: data.reason.to_owned(),
       banned: Some(data.ban),
       expires,
@@ -710,14 +755,14 @@ impl Perform for BanUser {
 
     blocking(context.pool(), move |conn| ModBan::create(conn, &form)).await??;
 
-    let user_id = data.user_id;
-    let user_view = blocking(context.pool(), move |conn| {
-      UserViewSafe::read(conn, user_id)
+    let person_id = data.person_id;
+    let person_view = blocking(context.pool(), move |conn| {
+      PersonViewSafe::read(conn, person_id)
     })
     .await??;
 
-    let res = BanUserResponse {
-      user_view,
+    let res = BanPersonResponse {
+      person_view,
       banned: data.ban,
     };
 
@@ -741,20 +786,20 @@ impl Perform for GetReplies {
     _websocket_id: Option<ConnectionId>,
   ) -> Result<GetRepliesResponse, LemmyError> {
     let data: &GetReplies = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
     let sort = SortType::from_str(&data.sort)?;
 
     let page = data.page;
     let limit = data.limit;
     let unread_only = data.unread_only;
-    let user_id = user.id;
+    let person_id = local_user_view.person.id;
     let replies = blocking(context.pool(), move |conn| {
       CommentQueryBuilder::create(conn)
         .sort(&sort)
         .unread_only(unread_only)
-        .recipient_id(user_id)
-        .my_person_id(user_id)
+        .recipient_id(person_id)
+        .my_person_id(person_id)
         .page(page)
         .limit(limit)
         .list()
@@ -766,27 +811,27 @@ impl Perform for GetReplies {
 }
 
 #[async_trait::async_trait(?Send)]
-impl Perform for GetUserMentions {
-  type Response = GetUserMentionsResponse;
+impl Perform for GetPersonMentions {
+  type Response = GetPersonMentionsResponse;
 
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
     _websocket_id: Option<ConnectionId>,
-  ) -> Result<GetUserMentionsResponse, LemmyError> {
-    let data: &GetUserMentions = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+  ) -> Result<GetPersonMentionsResponse, LemmyError> {
+    let data: &GetPersonMentions = &self;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
     let sort = SortType::from_str(&data.sort)?;
 
     let page = data.page;
     let limit = data.limit;
     let unread_only = data.unread_only;
-    let user_id = user.id;
+    let person_id = local_user_view.person.id;
     let mentions = blocking(context.pool(), move |conn| {
-      UserMentionQueryBuilder::create(conn)
-        .recipient_id(user_id)
-        .my_user_id(user_id)
+      PersonMentionQueryBuilder::create(conn)
+        .recipient_id(person_id)
+        .my_person_id(person_id)
         .sort(&sort)
         .unread_only(unread_only)
         .page(page)
@@ -795,47 +840,50 @@ impl Perform for GetUserMentions {
     })
     .await??;
 
-    Ok(GetUserMentionsResponse { mentions })
+    Ok(GetPersonMentionsResponse { mentions })
   }
 }
 
 #[async_trait::async_trait(?Send)]
-impl Perform for MarkUserMentionAsRead {
-  type Response = UserMentionResponse;
+impl Perform for MarkPersonMentionAsRead {
+  type Response = PersonMentionResponse;
 
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
     _websocket_id: Option<ConnectionId>,
-  ) -> Result<UserMentionResponse, LemmyError> {
-    let data: &MarkUserMentionAsRead = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+  ) -> Result<PersonMentionResponse, LemmyError> {
+    let data: &MarkPersonMentionAsRead = &self;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
-    let user_mention_id = data.user_mention_id;
-    let read_user_mention = blocking(context.pool(), move |conn| {
-      UserMention::read(conn, user_mention_id)
+    let person_mention_id = data.person_mention_id;
+    let read_person_mention = blocking(context.pool(), move |conn| {
+      PersonMention::read(conn, person_mention_id)
     })
     .await??;
 
-    if user.id != read_user_mention.recipient_id {
+    if local_user_view.person.id != read_person_mention.recipient_id {
       return Err(ApiError::err("couldnt_update_comment").into());
     }
 
-    let user_mention_id = read_user_mention.id;
+    let person_mention_id = read_person_mention.id;
     let read = data.read;
-    let update_mention = move |conn: &'_ _| UserMention::update_read(conn, user_mention_id, read);
+    let update_mention =
+      move |conn: &'_ _| PersonMention::update_read(conn, person_mention_id, read);
     if blocking(context.pool(), update_mention).await?.is_err() {
       return Err(ApiError::err("couldnt_update_comment").into());
     };
 
-    let user_mention_id = read_user_mention.id;
-    let user_id = user.id;
-    let user_mention_view = blocking(context.pool(), move |conn| {
-      UserMentionView::read(conn, user_mention_id, Some(user_id))
+    let person_mention_id = read_person_mention.id;
+    let person_id = local_user_view.person.id;
+    let person_mention_view = blocking(context.pool(), move |conn| {
+      PersonMentionView::read(conn, person_mention_id, Some(person_id))
     })
     .await??;
 
-    Ok(UserMentionResponse { user_mention_view })
+    Ok(PersonMentionResponse {
+      person_mention_view,
+    })
   }
 }
 
@@ -849,13 +897,13 @@ impl Perform for MarkAllAsRead {
     _websocket_id: Option<ConnectionId>,
   ) -> Result<GetRepliesResponse, LemmyError> {
     let data: &MarkAllAsRead = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
-    let user_id = user.id;
+    let person_id = local_user_view.person.id;
     let replies = blocking(context.pool(), move |conn| {
       CommentQueryBuilder::create(conn)
-        .my_person_id(user_id)
-        .recipient_id(user_id)
+        .my_person_id(person_id)
+        .recipient_id(person_id)
         .unread_only(true)
         .page(1)
         .limit(999)
@@ -875,8 +923,9 @@ impl Perform for MarkAllAsRead {
     }
 
     // Mark all user mentions as read
-    let update_user_mentions = move |conn: &'_ _| UserMention::mark_all_as_read(conn, user_id);
-    if blocking(context.pool(), update_user_mentions)
+    let update_person_mentions =
+      move |conn: &'_ _| PersonMention::mark_all_as_read(conn, person_id);
+    if blocking(context.pool(), update_person_mentions)
       .await?
       .is_err()
     {
@@ -884,7 +933,7 @@ impl Perform for MarkAllAsRead {
     }
 
     // Mark all private_messages as read
-    let update_pm = move |conn: &'_ _| PrivateMessage::mark_all_as_read(conn, user_id);
+    let update_pm = move |conn: &'_ _| PrivateMessage::mark_all_as_read(conn, person_id);
     if blocking(context.pool(), update_pm).await?.is_err() {
       return Err(ApiError::err("couldnt_update_private_message").into());
     }
@@ -903,29 +952,33 @@ impl Perform for DeleteAccount {
     _websocket_id: Option<ConnectionId>,
   ) -> Result<LoginResponse, LemmyError> {
     let data: &DeleteAccount = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
     // Verify the password
-    let valid: bool = verify(&data.password, &user.password_encrypted).unwrap_or(false);
+    let valid: bool = verify(
+      &data.password,
+      &local_user_view.local_user.password_encrypted,
+    )
+    .unwrap_or(false);
     if !valid {
       return Err(ApiError::err("password_incorrect").into());
     }
 
     // Comments
-    let user_id = user.id;
-    let permadelete = move |conn: &'_ _| Comment::permadelete_for_creator(conn, user_id);
+    let person_id = local_user_view.person.id;
+    let permadelete = move |conn: &'_ _| Comment::permadelete_for_creator(conn, person_id);
     if blocking(context.pool(), permadelete).await?.is_err() {
       return Err(ApiError::err("couldnt_update_comment").into());
     }
 
     // Posts
-    let permadelete = move |conn: &'_ _| Post::permadelete_for_creator(conn, user_id);
+    let permadelete = move |conn: &'_ _| Post::permadelete_for_creator(conn, person_id);
     if blocking(context.pool(), permadelete).await?.is_err() {
       return Err(ApiError::err("couldnt_update_post").into());
     }
 
     blocking(context.pool(), move |conn| {
-      User_::delete_account(conn, user_id)
+      Person::delete_account(conn, person_id)
     })
     .await??;
 
@@ -948,12 +1001,12 @@ impl Perform for PasswordReset {
 
     // Fetch that email
     let email = data.email.clone();
-    let user = match blocking(context.pool(), move |conn| {
-      User_::find_by_email(conn, &email)
+    let local_user_view = match blocking(context.pool(), move |conn| {
+      LocalUserView::find_by_email(conn, &email)
     })
     .await?
     {
-      Ok(user) => user,
+      Ok(lu) => lu,
       Err(_e) => return Err(ApiError::err("couldnt_find_that_username_or_email").into()),
     };
 
@@ -962,19 +1015,19 @@ impl Perform for PasswordReset {
 
     // Insert the row
     let token2 = token.clone();
-    let user_id = user.id;
+    let local_user_id = local_user_view.local_user.id;
     blocking(context.pool(), move |conn| {
-      PasswordResetRequest::create_token(conn, user_id, &token2)
+      PasswordResetRequest::create_token(conn, local_user_id, &token2)
     })
     .await??;
 
     // Email the pure token to the user.
     // TODO no i18n support here.
-    let user_email = &user.email.expect("email");
-    let subject = &format!("Password reset for {}", user.name);
+    let email = &local_user_view.local_user.email.expect("email");
+    let subject = &format!("Password reset for {}", local_user_view.person.name);
     let hostname = &Settings::get().get_protocol_and_hostname();
-    let html = &format!("<h1>Password Reset Request for {}</h1><br><a href={}/password_change/{}>Click here to reset your password</a>", user.name, hostname, &token);
-    match send_email(subject, user_email, &user.name, html) {
+    let html = &format!("<h1>Password Reset Request for {}</h1><br><a href={}/password_change/{}>Click here to reset your password</a>", local_user_view.person.name, hostname, &token);
+    match send_email(subject, email, &local_user_view.person.name, html) {
       Ok(_o) => _o,
       Err(_e) => return Err(ApiError::err(&_e).into()),
     };
@@ -996,7 +1049,7 @@ impl Perform for PasswordChange {
 
     // Fetch the user_id from the token
     let token = data.token.clone();
-    let user_id = blocking(context.pool(), move |conn| {
+    let local_user_id = blocking(context.pool(), move |conn| {
       PasswordResetRequest::read_from_token(conn, &token).map(|p| p.local_user_id)
     })
     .await??;
@@ -1010,18 +1063,18 @@ impl Perform for PasswordChange {
 
     // Update the user with the new password
     let password = data.password.clone();
-    let updated_user = match blocking(context.pool(), move |conn| {
-      User_::update_password(conn, user_id, &password)
+    let updated_local_user = match blocking(context.pool(), move |conn| {
+      LocalUser::update_password(conn, local_user_id, &password)
     })
     .await?
     {
-      Ok(user) => user,
+      Ok(u) => u,
       Err(_e) => return Err(ApiError::err("couldnt_update_user").into()),
     };
 
     // Return the jwt
     Ok(LoginResponse {
-      jwt: Claims::jwt(updated_user.id, Settings::get().hostname())?,
+      jwt: Claims::jwt(updated_local_user.id, Settings::get().hostname())?,
     })
   }
 }
@@ -1036,13 +1089,13 @@ impl Perform for CreatePrivateMessage {
     websocket_id: Option<ConnectionId>,
   ) -> Result<PrivateMessageResponse, LemmyError> {
     let data: &CreatePrivateMessage = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
     let content_slurs_removed = remove_slurs(&data.content.to_owned());
 
     let private_message_form = PrivateMessageForm {
       content: content_slurs_removed.to_owned(),
-      creator_id: user.id,
+      creator_id: local_user_view.person.id,
       recipient_id: data.recipient_id,
       deleted: None,
       read: None,
@@ -1084,28 +1137,32 @@ impl Perform for CreatePrivateMessage {
       Err(_e) => return Err(ApiError::err("couldnt_create_private_message").into()),
     };
 
-    updated_private_message.send_create(&user, context).await?;
+    updated_private_message
+      .send_create(&local_user_view.person, context)
+      .await?;
 
     // Send notifications to the recipient
     let recipient_id = data.recipient_id;
-    let recipient_user =
-      blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
-    if recipient_user.send_notifications_to_email {
+    let recipient = blocking(context.pool(), move |conn| {
+      LocalUserView::read_person(conn, recipient_id)
+    })
+    .await??;
+    if recipient.local_user.send_notifications_to_email {
       send_email_to_user(
-        recipient_user,
+        recipient,
         "Private Message from",
         "Private Message",
         &content_slurs_removed,
       );
     }
 
-    let message = blocking(context.pool(), move |conn| {
+    let private_message_view = blocking(context.pool(), move |conn| {
       PrivateMessageView::read(conn, inserted_private_message.id)
     })
     .await??;
 
     let res = PrivateMessageResponse {
-      private_message_view: message,
+      private_message_view,
     };
 
     context.chat_server().do_send(SendUserRoomMessage {
@@ -1129,7 +1186,7 @@ impl Perform for EditPrivateMessage {
     websocket_id: Option<ConnectionId>,
   ) -> Result<PrivateMessageResponse, LemmyError> {
     let data: &EditPrivateMessage = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
     // Checking permissions
     let private_message_id = data.private_message_id;
@@ -1137,7 +1194,7 @@ impl Perform for EditPrivateMessage {
       PrivateMessage::read(conn, private_message_id)
     })
     .await??;
-    if user.id != orig_private_message.creator_id {
+    if local_user_view.person.id != orig_private_message.creator_id {
       return Err(ApiError::err("no_private_message_edit_allowed").into());
     }
 
@@ -1154,17 +1211,19 @@ impl Perform for EditPrivateMessage {
     };
 
     // Send the apub update
-    updated_private_message.send_update(&user, context).await?;
+    updated_private_message
+      .send_update(&local_user_view.person, context)
+      .await?;
 
     let private_message_id = data.private_message_id;
-    let message = blocking(context.pool(), move |conn| {
+    let private_message_view = blocking(context.pool(), move |conn| {
       PrivateMessageView::read(conn, private_message_id)
     })
     .await??;
-    let recipient_id = message.recipient.id;
+    let recipient_id = private_message_view.recipient.id;
 
     let res = PrivateMessageResponse {
-      private_message_view: message,
+      private_message_view,
     };
 
     context.chat_server().do_send(SendUserRoomMessage {
@@ -1188,7 +1247,7 @@ impl Perform for DeletePrivateMessage {
     websocket_id: Option<ConnectionId>,
   ) -> Result<PrivateMessageResponse, LemmyError> {
     let data: &DeletePrivateMessage = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
     // Checking permissions
     let private_message_id = data.private_message_id;
@@ -1196,7 +1255,7 @@ impl Perform for DeletePrivateMessage {
       PrivateMessage::read(conn, private_message_id)
     })
     .await??;
-    if user.id != orig_private_message.creator_id {
+    if local_user_view.person.id != orig_private_message.creator_id {
       return Err(ApiError::err("no_private_message_edit_allowed").into());
     }
 
@@ -1214,22 +1273,24 @@ impl Perform for DeletePrivateMessage {
 
     // Send the apub update
     if data.deleted {
-      updated_private_message.send_delete(&user, context).await?;
+      updated_private_message
+        .send_delete(&local_user_view.person, context)
+        .await?;
     } else {
       updated_private_message
-        .send_undo_delete(&user, context)
+        .send_undo_delete(&local_user_view.person, context)
         .await?;
     }
 
     let private_message_id = data.private_message_id;
-    let message = blocking(context.pool(), move |conn| {
+    let private_message_view = blocking(context.pool(), move |conn| {
       PrivateMessageView::read(conn, private_message_id)
     })
     .await??;
-    let recipient_id = message.recipient.id;
+    let recipient_id = private_message_view.recipient.id;
 
     let res = PrivateMessageResponse {
-      private_message_view: message,
+      private_message_view,
     };
 
     context.chat_server().do_send(SendUserRoomMessage {
@@ -1253,7 +1314,7 @@ impl Perform for MarkPrivateMessageAsRead {
     websocket_id: Option<ConnectionId>,
   ) -> Result<PrivateMessageResponse, LemmyError> {
     let data: &MarkPrivateMessageAsRead = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
     // Checking permissions
     let private_message_id = data.private_message_id;
@@ -1261,7 +1322,7 @@ impl Perform for MarkPrivateMessageAsRead {
       PrivateMessage::read(conn, private_message_id)
     })
     .await??;
-    if user.id != orig_private_message.recipient_id {
+    if local_user_view.person.id != orig_private_message.recipient_id {
       return Err(ApiError::err("couldnt_update_private_message").into());
     }
 
@@ -1280,14 +1341,14 @@ impl Perform for MarkPrivateMessageAsRead {
     // No need to send an apub update
 
     let private_message_id = data.private_message_id;
-    let message = blocking(context.pool(), move |conn| {
+    let private_message_view = blocking(context.pool(), move |conn| {
       PrivateMessageView::read(conn, private_message_id)
     })
     .await??;
-    let recipient_id = message.recipient.id;
+    let recipient_id = private_message_view.recipient.id;
 
     let res = PrivateMessageResponse {
-      private_message_view: message,
+      private_message_view,
     };
 
     context.chat_server().do_send(SendUserRoomMessage {
@@ -1311,14 +1372,14 @@ impl Perform for GetPrivateMessages {
     _websocket_id: Option<ConnectionId>,
   ) -> Result<PrivateMessagesResponse, LemmyError> {
     let data: &GetPrivateMessages = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
-    let user_id = user.id;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+    let person_id = local_user_view.person.id;
 
     let page = data.page;
     let limit = data.limit;
     let unread_only = data.unread_only;
     let messages = blocking(context.pool(), move |conn| {
-      PrivateMessageQueryBuilder::create(&conn, user_id)
+      PrivateMessageQueryBuilder::create(&conn, person_id)
         .page(page)
         .limit(limit)
         .unread_only(unread_only)
@@ -1342,12 +1403,12 @@ impl Perform for GetReportCount {
     websocket_id: Option<ConnectionId>,
   ) -> Result<GetReportCountResponse, LemmyError> {
     let data: &GetReportCount = &self;
-    let user = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
+    let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
-    let user_id = user.id;
+    let person_id = local_user_view.person.id;
     let community_id = data.community;
     let community_ids =
-      collect_moderated_communities(user_id, community_id, context.pool()).await?;
+      collect_moderated_communities(person_id, community_id, context.pool()).await?;
 
     let res = {
       if community_ids.is_empty() {
@@ -1380,7 +1441,7 @@ impl Perform for GetReportCount {
     context.chat_server().do_send(SendUserRoomMessage {
       op: UserOperation::GetReportCount,
       response: res.clone(),
-      recipient_id: user.id,
+      recipient_id: local_user_view.person.id,
       websocket_id,
     });
 
index 92226171583fe77d31f3b94f4715339e3fc82566..5515575e67b088776403d7ce177cebc53651e65c 100644 (file)
@@ -122,7 +122,9 @@ impl Perform for CreatePost {
       Err(_e) => return Err(ApiError::err("couldnt_create_post").into()),
     };
 
-    updated_post.send_create(&local_user_view.person, context).await?;
+    updated_post
+      .send_create(&local_user_view.person, context)
+      .await?;
 
     // They like their own post by default
     let like_form = PostLikeForm {
@@ -136,7 +138,9 @@ impl Perform for CreatePost {
       return Err(ApiError::err("couldnt_like_post").into());
     }
 
-    updated_post.send_like(&local_user_view.person, context).await?;
+    updated_post
+      .send_like(&local_user_view.person, context)
+      .await?;
 
     // Refetch the view
     let inserted_post_id = inserted_post.id;
@@ -327,7 +331,9 @@ impl Perform for CreatePostLike {
         post.send_dislike(&local_user_view.person, context).await?;
       }
     } else {
-      post.send_undo_like(&local_user_view.person, context).await?;
+      post
+        .send_undo_like(&local_user_view.person, context)
+        .await?;
     }
 
     let post_id = data.post_id;
@@ -375,7 +381,12 @@ impl Perform for EditPost {
     let post_id = data.post_id;
     let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
 
-    check_community_ban(local_user_view.person.id, orig_post.community_id, context.pool()).await?;
+    check_community_ban(
+      local_user_view.person.id,
+      orig_post.community_id,
+      context.pool(),
+    )
+    .await?;
 
     // Verify that only the creator can edit
     if !Post::is_post_creator(local_user_view.person.id, orig_post.creator_id) {
@@ -427,7 +438,9 @@ impl Perform for EditPost {
     };
 
     // Send apub update
-    updated_post.send_update(&local_user_view.person, context).await?;
+    updated_post
+      .send_update(&local_user_view.person, context)
+      .await?;
 
     let post_id = data.post_id;
     let post_view = blocking(context.pool(), move |conn| {
@@ -462,7 +475,12 @@ impl Perform for DeletePost {
     let post_id = data.post_id;
     let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
 
-    check_community_ban(local_user_view.person.id, orig_post.community_id, context.pool()).await?;
+    check_community_ban(
+      local_user_view.person.id,
+      orig_post.community_id,
+      context.pool(),
+    )
+    .await?;
 
     // Verify that only the creator can delete
     if !Post::is_post_creator(local_user_view.person.id, orig_post.creator_id) {
@@ -479,9 +497,13 @@ impl Perform for DeletePost {
 
     // apub updates
     if deleted {
-      updated_post.send_delete(&local_user_view.person, context).await?;
+      updated_post
+        .send_delete(&local_user_view.person, context)
+        .await?;
     } else {
-      updated_post.send_undo_delete(&local_user_view.person, context).await?;
+      updated_post
+        .send_undo_delete(&local_user_view.person, context)
+        .await?;
     }
 
     // Refetch the post
@@ -518,10 +540,20 @@ impl Perform for RemovePost {
     let post_id = data.post_id;
     let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
 
-    check_community_ban(local_user_view.person.id, orig_post.community_id, context.pool()).await?;
+    check_community_ban(
+      local_user_view.person.id,
+      orig_post.community_id,
+      context.pool(),
+    )
+    .await?;
 
     // Verify that only the mods can remove
-    is_mod_or_admin(context.pool(), local_user_view.person.id, orig_post.community_id).await?;
+    is_mod_or_admin(
+      context.pool(),
+      local_user_view.person.id,
+      orig_post.community_id,
+    )
+    .await?;
 
     // Update the post
     let post_id = data.post_id;
@@ -545,9 +577,13 @@ impl Perform for RemovePost {
 
     // apub updates
     if removed {
-      updated_post.send_remove(&local_user_view.person, context).await?;
+      updated_post
+        .send_remove(&local_user_view.person, context)
+        .await?;
     } else {
-      updated_post.send_undo_remove(&local_user_view.person, context).await?;
+      updated_post
+        .send_undo_remove(&local_user_view.person, context)
+        .await?;
     }
 
     // Refetch the post
@@ -585,10 +621,20 @@ impl Perform for LockPost {
     let post_id = data.post_id;
     let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
 
-    check_community_ban(local_user_view.person.id, orig_post.community_id, context.pool()).await?;
+    check_community_ban(
+      local_user_view.person.id,
+      orig_post.community_id,
+      context.pool(),
+    )
+    .await?;
 
     // Verify that only the mods can lock
-    is_mod_or_admin(context.pool(), local_user_view.person.id, orig_post.community_id).await?;
+    is_mod_or_admin(
+      context.pool(),
+      local_user_view.person.id,
+      orig_post.community_id,
+    )
+    .await?;
 
     // Update the post
     let post_id = data.post_id;
@@ -607,7 +653,9 @@ impl Perform for LockPost {
     blocking(context.pool(), move |conn| ModLockPost::create(conn, &form)).await??;
 
     // apub updates
-    updated_post.send_update(&local_user_view.person, context).await?;
+    updated_post
+      .send_update(&local_user_view.person, context)
+      .await?;
 
     // Refetch the post
     let post_id = data.post_id;
@@ -643,10 +691,20 @@ impl Perform for StickyPost {
     let post_id = data.post_id;
     let orig_post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
 
-    check_community_ban(local_user_view.person.id, orig_post.community_id, context.pool()).await?;
+    check_community_ban(
+      local_user_view.person.id,
+      orig_post.community_id,
+      context.pool(),
+    )
+    .await?;
 
     // Verify that only the mods can sticky
-    is_mod_or_admin(context.pool(), local_user_view.person.id, orig_post.community_id).await?;
+    is_mod_or_admin(
+      context.pool(),
+      local_user_view.person.id,
+      orig_post.community_id,
+    )
+    .await?;
 
     // Update the post
     let post_id = data.post_id;
@@ -669,7 +727,9 @@ impl Perform for StickyPost {
 
     // Apub updates
     // TODO stickied should pry work like locked for ease of use
-    updated_post.send_update(&local_user_view.person, context).await?;
+    updated_post
+      .send_update(&local_user_view.person, context)
+      .await?;
 
     // Refetch the post
     let post_id = data.post_id;
index 0c70dc0d3b47f621a97b97863c30b5709d4788ed..6fc46ca4caaabbea704b013b0e557cc5949fee97 100644 (file)
@@ -1,6 +1,6 @@
 use crate::Perform;
 use actix_web::{error::ErrorBadRequest, *};
-use lemmy_api_structs::{comment::*, community::*, post::*, site::*, person::*, websocket::*};
+use lemmy_api_structs::{comment::*, community::*, person::*, post::*, site::*, websocket::*};
 use lemmy_utils::rate_limit::RateLimit;
 use lemmy_websocket::{routes::chat_route, LemmyContext};
 use serde::Deserialize;
index 5acd099c467a4713b7db7bc2f8d1be3fa08caa27..4d561ab212419960b2c838f12fd389808ce85a25 100644 (file)
@@ -1,14 +1,15 @@
 use crate::{
   build_federated_instances,
+  get_local_user_settings_view_from_jwt,
+  get_local_user_settings_view_from_jwt_opt,
   get_local_user_view_from_jwt,
   get_local_user_view_from_jwt_opt,
-  get_local_user_settings_view_from_jwt_opt,
   is_admin,
   Perform,
 };
 use actix_web::web::Data;
 use anyhow::Context;
-use lemmy_api_structs::{blocking, site::*, person::Register};
+use lemmy_api_structs::{blocking, person::Register, site::*};
 use lemmy_apub::fetcher::search::search_by_apub_id;
 use lemmy_db_queries::{
   diesel_option_overwrite_to_url,
@@ -536,13 +537,15 @@ impl Perform for TransferSite {
     let banned = blocking(context.pool(), move |conn| PersonViewSafe::banned(conn)).await??;
     let federated_instances = build_federated_instances(context.pool()).await?;
 
+    let my_user = Some(get_local_user_settings_view_from_jwt(&data.auth, context.pool()).await?);
+
     Ok(GetSiteResponse {
       site_view: Some(site_view),
       admins,
       banned,
       online: 0,
       version: version::VERSION.to_string(),
-      my_user: Some(local_user_view),
+      my_user,
       federated_instances,
     })
   }
@@ -582,7 +585,6 @@ impl Perform for SaveSiteConfig {
     let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
 
     // Only let admins read this
-    let person_id = local_user_view.person.id;
     is_admin(&local_user_view)?;
 
     // Make sure docker doesn't have :ro at the end of the volume, so its not a read-only filesystem
index b28cb37f9067c9ece9b5fbaf95f0f1dec6c0a7b9..c861136a193e8ee46fb85241ef8b4bf34fbc82d7 100644 (file)
@@ -1,17 +1,17 @@
 pub mod comment;
 pub mod community;
+pub mod person;
 pub mod post;
 pub mod site;
-pub mod person;
 pub mod websocket;
 
 use diesel::PgConnection;
 use lemmy_db_queries::{Crud, DbPool};
 use lemmy_db_schema::source::{
   comment::Comment,
-  post::Post,
   person::Person,
   person_mention::{PersonMention, PersonMentionForm},
+  post::Post,
 };
 use lemmy_db_views::local_user_view::LocalUserView;
 use lemmy_utils::{email::send_email, settings::structs::Settings, utils::MentionData, LemmyError};
@@ -119,11 +119,17 @@ fn do_send_local_notifs(
     Some(parent_id) => {
       if let Ok(parent_comment) = Comment::read(&conn, parent_id) {
         if parent_comment.creator_id != person.id {
-          if let Ok(parent_user_view) = LocalUserView::read(&conn, parent_comment.creator_id) {
+          if let Ok(parent_user_view) = LocalUserView::read_person(&conn, parent_comment.creator_id)
+          {
             recipient_ids.push(parent_user_view.person.id);
 
             if do_send_email && parent_user_view.local_user.send_notifications_to_email {
-              send_email_to_user(parent_user_view, "Reply from", "Comment Reply", &comment.content)
+              send_email_to_user(
+                parent_user_view,
+                "Reply from",
+                "Comment Reply",
+                &comment.content,
+              )
             }
           }
         }
@@ -132,11 +138,16 @@ fn do_send_local_notifs(
     // Its a post
     None => {
       if post.creator_id != person.id {
-        if let Ok(parent_user_view) = LocalUserView::read(&conn, post.creator_id) {
+        if let Ok(parent_user_view) = LocalUserView::read_person(&conn, post.creator_id) {
           recipient_ids.push(parent_user_view.person.id);
 
           if do_send_email && parent_user_view.local_user.send_notifications_to_email {
-            send_email_to_user(parent_user_view, "Reply from", "Post Reply", &comment.content)
+            send_email_to_user(
+              parent_user_view,
+              "Reply from",
+              "Post Reply",
+              &comment.content,
+            )
           }
         }
       }
@@ -145,7 +156,12 @@ fn do_send_local_notifs(
   recipient_ids
 }
 
-pub fn send_email_to_user(local_user_view: LocalUserView, subject_text: &str, body_text: &str, comment_content: &str) {
+pub fn send_email_to_user(
+  local_user_view: LocalUserView,
+  subject_text: &str,
+  body_text: &str,
+  comment_content: &str,
+) {
   if local_user_view.person.banned {
     return;
   }
index ac1cca8587d38b8ac232df75427f8d0b46e6f248..53e6d9f8d82588b4ae0892e559b3aaaef2b25da7 100644 (file)
@@ -45,11 +45,11 @@ pub struct CaptchaResponse {
 
 #[derive(Deserialize)]
 pub struct SaveUserSettings {
-  pub show_nsfw: bool,
-  pub theme: String,
-  pub default_sort_type: i16,
-  pub default_listing_type: i16,
-  pub lang: String,
+  pub show_nsfw: Option<bool>,
+  pub theme: Option<String>,
+  pub default_sort_type: Option<i16>,
+  pub default_listing_type: Option<i16>,
+  pub lang: Option<String>,
   pub avatar: Option<String>,
   pub banner: Option<String>,
   pub preferred_username: Option<String>,
@@ -59,8 +59,8 @@ pub struct SaveUserSettings {
   pub new_password: Option<String>,
   pub new_password_verify: Option<String>,
   pub old_password: Option<String>,
-  pub show_avatars: bool,
-  pub send_notifications_to_email: bool,
+  pub show_avatars: Option<bool>,
+  pub send_notifications_to_email: Option<bool>,
   pub auth: String,
 }
 
@@ -107,7 +107,7 @@ pub struct MarkAllAsRead {
 
 #[derive(Deserialize)]
 pub struct AddAdmin {
-  pub person_id: i32,
+  pub local_user_id: i32,
   pub added: bool,
   pub auth: String,
 }
index d574a1604b366730ff1b7564ea39197880e6a8fc..f2781668dd4f05828c2671014960af75e4cb4733 100644 (file)
@@ -1,4 +1,9 @@
-use lemmy_db_views::{comment_view::CommentView, post_view::PostView, site_view::SiteView, local_user_view::LocalUserSettingsView};
+use lemmy_db_views::{
+  comment_view::CommentView,
+  local_user_view::LocalUserSettingsView,
+  post_view::PostView,
+  site_view::SiteView,
+};
 use lemmy_db_views_actor::{community_view::CommunityView, person_view::PersonViewSafe};
 use lemmy_db_views_moderator::{
   mod_add_community_view::ModAddCommunityView,
index 5e01533d92fd01a15641343c859c9116a07e7151..9ab14dabfdb9c9af511acb54a8d3ddd20e47793b 100644 (file)
@@ -33,8 +33,15 @@ pub(crate) async fn receive_create_comment(
   // Its much easier to scrape them from the comment body, since the API has to do that
   // anyway.
   let mentions = scrape_text_for_mentions(&comment.content);
-  let recipient_ids =
-    send_local_notifs(mentions, comment.clone(), person, post, context.pool(), true).await?;
+  let recipient_ids = send_local_notifs(
+    mentions,
+    comment.clone(),
+    person,
+    post,
+    context.pool(),
+    true,
+  )
+  .await?;
 
   // Refetch the view
   let comment_view = blocking(context.pool(), move |conn| {
index c11e86b73988ebdd961dcda23ba103524108e8a9..867e45e9fec3825ae362aadab19810a5687a7a2b 100644 (file)
@@ -28,7 +28,7 @@ use anyhow::anyhow;
 use itertools::Itertools;
 use lemmy_api_structs::{blocking, WebFingerResponse};
 use lemmy_db_queries::{Crud, DbPool};
-use lemmy_db_schema::source::{comment::Comment, community::Community, post::Post, person::Person};
+use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
 use lemmy_utils::{
   request::{retry, RecvError},
   settings::structs::Settings,
@@ -197,7 +197,11 @@ impl ApubObjectType for Comment {
     Ok(())
   }
 
-  async fn send_undo_remove(&self, mod_: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
+  async fn send_undo_remove(
+    &self,
+    mod_: &Person,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
     let post_id = self.post_id;
     let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
 
@@ -389,7 +393,10 @@ async fn collect_non_local_mentions(
 
 /// Returns the apub ID of the person this comment is responding to. Meaning, in case this is a
 /// top-level comment, the creator of the post, otherwise the creator of the parent comment.
-async fn get_comment_parent_creator(pool: &DbPool, comment: &Comment) -> Result<Person, LemmyError> {
+async fn get_comment_parent_creator(
+  pool: &DbPool,
+  comment: &Comment,
+) -> Result<Person, LemmyError> {
   let parent_creator_id = if let Some(parent_comment_id) = comment.parent_id {
     let parent_comment =
       blocking(pool, move |conn| Comment::read(conn, parent_comment_id)).await??;
index 7f19d0426e7b6bc959bf8a4c57625a0edca6575f..10dd8a26398b73fbf4ec48c9efc4b1e67d6f42c7 100644 (file)
@@ -4,9 +4,9 @@ use uuid::Uuid;
 
 pub(crate) mod comment;
 pub(crate) mod community;
+pub(crate) mod person;
 pub(crate) mod post;
 pub(crate) mod private_message;
-pub(crate) mod person;
 
 /// Generate a unique ID for an activity, in the format:
 /// `http(s)://example.com/receive/create/202daf0a-1489-45df-8d2e-c8a3173fed36`
index 0fe3f6344c60cf8cb7b5522c8796ff00efbf8067..4d3bb9d1bc50b770835bd5b0f849f7d16ed07c32 100644 (file)
@@ -23,7 +23,7 @@ use activitystreams::{
 };
 use lemmy_api_structs::blocking;
 use lemmy_db_queries::Crud;
-use lemmy_db_schema::source::{community::Community, post::Post, person::Person};
+use lemmy_db_schema::source::{community::Community, person::Person, post::Post};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
 
@@ -155,7 +155,11 @@ impl ApubObjectType for Post {
     Ok(())
   }
 
-  async fn send_undo_remove(&self, mod_: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
+  async fn send_undo_remove(
+    &self,
+    mod_: &Person,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError> {
     let community_id = self.community_id;
     let community = blocking(context.pool(), move |conn| {
       Community::read(conn, community_id)
index cf0046fa4e8881966bec42dcc661bd4b702ea297..92d818ab9c78e82ceb480ecda1e99a38484dec0f 100644 (file)
@@ -18,7 +18,7 @@ use activitystreams::{
 };
 use lemmy_api_structs::blocking;
 use lemmy_db_queries::Crud;
-use lemmy_db_schema::source::{private_message::PrivateMessage, person::Person};
+use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
 
@@ -29,7 +29,8 @@ impl ApubObjectType for PrivateMessage {
     let note = self.to_apub(context.pool()).await?;
 
     let recipient_id = self.recipient_id;
-    let recipient = blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
+    let recipient =
+      blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
 
     let mut create = Create::new(
       creator.actor_id.to_owned().into_inner(),
@@ -50,7 +51,8 @@ impl ApubObjectType for PrivateMessage {
     let note = self.to_apub(context.pool()).await?;
 
     let recipient_id = self.recipient_id;
-    let recipient = blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
+    let recipient =
+      blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
 
     let mut update = Update::new(
       creator.actor_id.to_owned().into_inner(),
@@ -67,7 +69,8 @@ impl ApubObjectType for PrivateMessage {
 
   async fn send_delete(&self, creator: &Person, context: &LemmyContext) -> Result<(), LemmyError> {
     let recipient_id = self.recipient_id;
-    let recipient = blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
+    let recipient =
+      blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
 
     let mut delete = Delete::new(
       creator.actor_id.to_owned().into_inner(),
@@ -88,7 +91,8 @@ impl ApubObjectType for PrivateMessage {
     context: &LemmyContext,
   ) -> Result<(), LemmyError> {
     let recipient_id = self.recipient_id;
-    let recipient = blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
+    let recipient =
+      blocking(context.pool(), move |conn| Person::read(conn, recipient_id)).await??;
 
     let mut delete = Delete::new(
       creator.actor_id.to_owned().into_inner(),
index 2c1b6b9afc59fe73daf0d1f36e05516e0c595f93..234a929b97cefda28c0029f6b7f512f3395f661a 100644 (file)
@@ -1,8 +1,8 @@
 pub(crate) mod community;
 mod fetch;
 pub(crate) mod objects;
-pub mod search;
 pub(crate) mod person;
+pub mod search;
 
 use crate::{
   fetcher::{
index 120ff8453787192dfd405cccf1e82677dd60fd1e..792e63707384fd45ed4a1c6ed630442ceaa81b75 100644 (file)
@@ -46,7 +46,8 @@ pub(crate) async fn get_or_fetch_and_upsert_person(
         return Ok(u);
       }
 
-      let person = Person::from_apub(&person?, context, apub_id.to_owned(), recursion_counter).await?;
+      let person =
+        Person::from_apub(&person?, context, apub_id.to_owned(), recursion_counter).await?;
 
       let person_id = person.id;
       blocking(context.pool(), move |conn| {
@@ -62,7 +63,8 @@ pub(crate) async fn get_or_fetch_and_upsert_person(
       let person =
         fetch_remote_object::<PersonExt>(context.client(), apub_id, recursion_counter).await?;
 
-      let person = Person::from_apub(&person, context, apub_id.to_owned(), recursion_counter).await?;
+      let person =
+        Person::from_apub(&person, context, apub_id.to_owned(), recursion_counter).await?;
 
       Ok(person)
     }
index 0b2921c7bdb3519126f022b26b59752e49d8174c..36482eed96812521c53a331885ae025b806e4103 100644 (file)
@@ -20,18 +20,18 @@ use lemmy_db_queries::{
   source::{
     comment::Comment_,
     community::Community_,
+    person::Person_,
     post::Post_,
     private_message::PrivateMessage_,
-    person::Person_,
   },
   SearchType,
 };
 use lemmy_db_schema::source::{
   comment::Comment,
   community::Community,
+  person::Person,
   post::Post,
   private_message::PrivateMessage,
-  person::Person,
 };
 use lemmy_db_views::{comment_view::CommentView, post_view::PostView};
 use lemmy_db_views_actor::{community_view::CommunityView, person_view::PersonViewSafe};
index 5a1add8d7b2bf8ccd5d52e0da180a4704efeea03..77cd5e797fa22c3ad7a25767446b14baaebc00bf 100644 (file)
@@ -11,8 +11,8 @@ use url::Url;
 
 pub mod comment;
 pub mod community;
-pub mod post;
 pub mod person;
+pub mod post;
 
 /// Convert the data to json and turn it into an HTTP Response with the correct ActivityPub
 /// headers.
index f82b1b55fc1354c57dcf3a56af767ef3fb3eed30..cb697184c6b69018076c9acc9c1f5f0d49b0d68c 100644 (file)
@@ -268,7 +268,8 @@ pub(crate) async fn check_community_or_site_ban(
     return Err(anyhow!("Person is banned from site").into());
   }
   let person_id = person.id;
-  let is_banned = move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
+  let is_banned =
+    move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
   if blocking(pool, is_banned).await? {
     return Err(anyhow!("Person is banned from community").into());
   }
index 71d1c133841b07e976500007fa6bd2059e13f707..5a3b9d3d5868404fab249668a3840b0f7cb76259 100644 (file)
@@ -26,9 +26,9 @@ use std::fmt::Debug;
 use url::Url;
 
 pub mod community_inbox;
+pub mod person_inbox;
 mod receive_for_community;
 pub mod shared_inbox;
-pub mod person_inbox;
 
 pub(crate) fn get_activity_id<T, Kind>(activity: &T, creator_uri: &Url) -> Result<Url, LemmyError>
 where
index c83c5037b0ccf94d2db81e019ae8883245328a03..14d76f0c890e17a0ac2d708a50d2ce89649a9ed3 100644 (file)
@@ -52,8 +52,8 @@ use lemmy_api_structs::blocking;
 use lemmy_db_queries::{source::person::Person_, ApubObject, Followable};
 use lemmy_db_schema::source::{
   community::{Community, CommunityFollower},
-  private_message::PrivateMessage,
   person::Person,
+  private_message::PrivateMessage,
 };
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::LemmyContext;
index 2def37d9110018b289b081f32f07a22caa431d83..38b039ca921e6f8a00a2b12a8c3fa8a3e83adc41 100644 (file)
@@ -31,9 +31,9 @@ use lemmy_db_schema::{
     activity::Activity,
     comment::Comment,
     community::Community,
+    person::Person as DbPerson,
     post::Post,
     private_message::PrivateMessage,
-    person::Person as DbPerson,
   },
   DbUrl,
 };
@@ -121,24 +121,38 @@ fn check_is_apub_id_valid(apub_id: &Url) -> Result<(), LemmyError> {
 /// and actors in Lemmy.
 #[async_trait::async_trait(?Send)]
 pub trait ApubObjectType {
-  async fn send_create(&self, creator: &DbPerson, context: &LemmyContext) -> Result<(), LemmyError>;
-  async fn send_update(&self, creator: &DbPerson, context: &LemmyContext) -> Result<(), LemmyError>;
-  async fn send_delete(&self, creator: &DbPerson, context: &LemmyContext) -> Result<(), LemmyError>;
+  async fn send_create(&self, creator: &DbPerson, context: &LemmyContext)
+    -> Result<(), LemmyError>;
+  async fn send_update(&self, creator: &DbPerson, context: &LemmyContext)
+    -> Result<(), LemmyError>;
+  async fn send_delete(&self, creator: &DbPerson, context: &LemmyContext)
+    -> Result<(), LemmyError>;
   async fn send_undo_delete(
     &self,
     creator: &DbPerson,
     context: &LemmyContext,
   ) -> Result<(), LemmyError>;
   async fn send_remove(&self, mod_: &DbPerson, context: &LemmyContext) -> Result<(), LemmyError>;
-  async fn send_undo_remove(&self, mod_: &DbPerson, context: &LemmyContext) -> Result<(), LemmyError>;
+  async fn send_undo_remove(
+    &self,
+    mod_: &DbPerson,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError>;
 }
 
 #[async_trait::async_trait(?Send)]
 pub trait ApubLikeableType {
   async fn send_like(&self, creator: &DbPerson, context: &LemmyContext) -> Result<(), LemmyError>;
-  async fn send_dislike(&self, creator: &DbPerson, context: &LemmyContext) -> Result<(), LemmyError>;
-  async fn send_undo_like(&self, creator: &DbPerson, context: &LemmyContext)
-    -> Result<(), LemmyError>;
+  async fn send_dislike(
+    &self,
+    creator: &DbPerson,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError>;
+  async fn send_undo_like(
+    &self,
+    creator: &DbPerson,
+    context: &LemmyContext,
+  ) -> Result<(), LemmyError>;
 }
 
 /// Common methods provided by ActivityPub actors (community and person). Not all methods are
@@ -316,11 +330,11 @@ pub(crate) async fn find_post_or_comment_by_id(
 }
 
 pub(crate) enum Object {
-  Comment(Comment),
-  Post(Post),
-  Community(Community),
-  Person(DbPerson),
-  PrivateMessage(PrivateMessage),
+  Comment(Box<Comment>),
+  Post(Box<Post>),
+  Community(Box<Community>),
+  Person(Box<DbPerson>),
+  PrivateMessage(Box<PrivateMessage>),
 }
 
 pub(crate) async fn find_object_by_id(
@@ -330,8 +344,8 @@ pub(crate) async fn find_object_by_id(
   let ap_id = apub_id.clone();
   if let Ok(pc) = find_post_or_comment_by_id(context, ap_id.to_owned()).await {
     return Ok(match pc {
-      PostOrComment::Post(p) => Object::Post(*p),
-      PostOrComment::Comment(c) => Object::Comment(*c),
+      PostOrComment::Post(p) => Object::Post(Box::new(*p)),
+      PostOrComment::Comment(c) => Object::Comment(Box::new(*c)),
     });
   }
 
@@ -341,7 +355,7 @@ pub(crate) async fn find_object_by_id(
   })
   .await?;
   if let Ok(u) = person {
-    return Ok(Object::Person(u));
+    return Ok(Object::Person(Box::new(u)));
   }
 
   let ap_id = apub_id.clone();
@@ -350,7 +364,7 @@ pub(crate) async fn find_object_by_id(
   })
   .await?;
   if let Ok(c) = community {
-    return Ok(Object::Community(c));
+    return Ok(Object::Community(Box::new(c)));
   }
 
   let private_message = blocking(context.pool(), move |conn| {
@@ -358,7 +372,7 @@ pub(crate) async fn find_object_by_id(
   })
   .await?;
   if let Ok(pm) = private_message {
-    return Ok(Object::PrivateMessage(pm));
+    return Ok(Object::PrivateMessage(Box::new(pm)));
   }
 
   Err(NotFound.into())
index ae5537e3f7e386cb07b75f0dcfd1cb330c359e95..0d9aab16ed608413dff4b64dc7c1262d18c88322 100644 (file)
@@ -25,8 +25,8 @@ use lemmy_api_structs::blocking;
 use lemmy_db_queries::{Crud, DbPool};
 use lemmy_db_schema::source::{
   comment::{Comment, CommentForm},
-  post::Post,
   person::Person,
+  post::Post,
 };
 use lemmy_utils::{
   location_info,
@@ -135,7 +135,8 @@ impl FromApubToForm<NoteExt> for CommentForm {
       .as_single_xsd_any_uri()
       .context(location_info!())?;
 
-    let creator = get_or_fetch_and_upsert_person(creator_actor_id, context, request_counter).await?;
+    let creator =
+      get_or_fetch_and_upsert_person(creator_actor_id, context, request_counter).await?;
 
     let mut in_reply_tos = note
       .in_reply_to()
index 235d5223c39cc58676c57ea4a8d2338dc15f49c7..b21a3a21d10609629408eb36ed603c95deb0e7bf 100644 (file)
@@ -26,9 +26,9 @@ use url::Url;
 
 pub(crate) mod comment;
 pub(crate) mod community;
+pub(crate) mod person;
 pub(crate) mod post;
 pub(crate) mod private_message;
-pub(crate) mod person;
 
 /// Trait for converting an object or actor into the respective ActivityPub type.
 #[async_trait::async_trait(?Send)]
index a632fcdb056d37dae339b7a33b8fc1567865076d..de45aedd3ffffa7eef9a69fcc9cebbe490a3c774 100644 (file)
@@ -22,7 +22,7 @@ use lemmy_api_structs::blocking;
 use lemmy_db_queries::{ApubObject, DbPool};
 use lemmy_db_schema::{
   naive_now,
-  source::person::{PersonForm, Person as DbPerson},
+  source::person::{Person as DbPerson, PersonForm},
 };
 use lemmy_utils::{
   location_info,
@@ -105,7 +105,10 @@ impl FromApub for DbPerson {
     } else {
       let person_form =
         PersonForm::from_apub(person, context, expected_domain, request_counter).await?;
-      let person = blocking(context.pool(), move |conn| DbPerson::upsert(conn, &person_form)).await??;
+      let person = blocking(context.pool(), move |conn| {
+        DbPerson::upsert(conn, &person_form)
+      })
+      .await??;
       Ok(person)
     }
   }
index a189c2deef026be98482c1a1a46baa3e1bf13bcb..776946cbdceec6afae927ad85c8a6990f17cd037 100644 (file)
@@ -28,8 +28,8 @@ use lemmy_db_schema::{
   self,
   source::{
     community::Community,
-    post::{Post, PostForm},
     person::Person,
+    post::{Post, PostForm},
   },
 };
 use lemmy_utils::{
@@ -142,7 +142,8 @@ impl FromApubToForm<PageExt> for PostForm {
       .as_single_xsd_any_uri()
       .context(location_info!())?;
 
-    let creator = get_or_fetch_and_upsert_person(creator_actor_id, context, request_counter).await?;
+    let creator =
+      get_or_fetch_and_upsert_person(creator_actor_id, context, request_counter).await?;
 
     let community = get_to_community(page, context, request_counter).await?;
 
index 09b49dd08c95557b0255aef3b64758d7568fafe5..d8c0077cf50ce48c8dafa8f83fdf4d18810f3339 100644 (file)
@@ -22,8 +22,8 @@ use anyhow::Context;
 use lemmy_api_structs::blocking;
 use lemmy_db_queries::{Crud, DbPool};
 use lemmy_db_schema::source::{
-  private_message::{PrivateMessage, PrivateMessageForm},
   person::Person,
+  private_message::{PrivateMessage, PrivateMessageForm},
 };
 use lemmy_utils::{location_info, utils::convert_datetime, LemmyError};
 use lemmy_websocket::LemmyContext;
@@ -97,7 +97,8 @@ impl FromApubToForm<NoteExt> for PrivateMessageForm {
       .single_xsd_any_uri()
       .context(location_info!())?;
 
-    let creator = get_or_fetch_and_upsert_person(&creator_actor_id, context, request_counter).await?;
+    let creator =
+      get_or_fetch_and_upsert_person(&creator_actor_id, context, request_counter).await?;
     let recipient_actor_id = note
       .to()
       .context(location_info!())?
index 6cc887785369205fc0193ba62a984b7ad50ea726..37fdd66f08d2cb827ecfcd44f1c7c0ed98af411d 100644 (file)
@@ -8,10 +8,14 @@ use crate::{
       get_apub_community_outbox,
     },
     get_activity,
-    post::get_apub_post,
     person::{get_apub_person_http, get_apub_person_inbox, get_apub_person_outbox},
+    post::get_apub_post,
+  },
+  inbox::{
+    community_inbox::community_inbox,
+    person_inbox::person_inbox,
+    shared_inbox::shared_inbox,
   },
-  inbox::{community_inbox::community_inbox, shared_inbox::shared_inbox, person_inbox::person_inbox},
   APUB_JSON_CONTENT_TYPE,
 };
 use actix_web::*;
@@ -54,7 +58,10 @@ pub fn config(cfg: &mut web::ServiceConfig) {
             web::get().to(get_apub_community_inbox),
           )
           .route("/u/{user_name}", web::get().to(get_apub_person_http))
-          .route("/u/{user_name}/outbox", web::get().to(get_apub_person_outbox))
+          .route(
+            "/u/{user_name}/outbox",
+            web::get().to(get_apub_person_outbox),
+          )
           .route("/u/{user_name}/inbox", web::get().to(get_apub_person_inbox))
           .route("/post/{post_id}", web::get().to(get_apub_post))
           .route("/comment/{comment_id}", web::get().to(get_apub_comment))
index 5d4fe5dc2fe4bf76f978e33fb4051a7de94501a1..72bdd024218477357abb11842ddde66318cdc52e 100644 (file)
@@ -32,8 +32,8 @@ mod tests {
   use lemmy_db_schema::source::{
     comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
     community::{Community, CommunityForm},
+    person::{Person, PersonForm},
     post::{Post, PostForm},
-    person::{PersonForm, Person},
   };
   use serial_test::serial;
 
index 23fbe8bd6211b1b26bca55e471d76046fe8fef17..4bf524596bbc6801db9da2115aafa42d1ae76e23 100644 (file)
@@ -36,8 +36,8 @@ mod tests {
   use lemmy_db_schema::source::{
     comment::{Comment, CommentForm},
     community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
+    person::{Person, PersonForm},
     post::{Post, PostForm},
-    person::{PersonForm, Person},
   };
   use serial_test::serial;
 
index 23854dfda21d6538f23c05acf2b8d051d0c7d8a3..ad20f8a668d07a94e8d8ad2e7b4405e60bcf1370 100644 (file)
@@ -1,5 +1,5 @@
 pub mod comment_aggregates;
 pub mod community_aggregates;
+pub mod person_aggregates;
 pub mod post_aggregates;
 pub mod site_aggregates;
-pub mod person_aggregates;
index cebf70b02ef07a9d1225730ba8202da402210248..473dac32c5527ca3d37ad97d164cd3dc4ec29cde 100644 (file)
@@ -32,8 +32,8 @@ mod tests {
   use lemmy_db_schema::source::{
     comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
     community::{Community, CommunityForm},
+    person::{Person, PersonForm},
     post::{Post, PostForm, PostLike, PostLikeForm},
-    person::{PersonForm, Person},
   };
   use serial_test::serial;
 
@@ -189,7 +189,8 @@ mod tests {
 
     let _inserted_child_comment_like = CommentLike::like(&conn, &child_comment_like).unwrap();
 
-    let person_aggregates_before_delete = PersonAggregates::read(&conn, inserted_person.id).unwrap();
+    let person_aggregates_before_delete =
+      PersonAggregates::read(&conn, inserted_person.id).unwrap();
 
     assert_eq!(1, person_aggregates_before_delete.post_count);
     assert_eq!(1, person_aggregates_before_delete.post_score);
index be4e8dc72366ca7648591075a14e680bdb671a54..a88918ae1ee2474dfa474034d591c63668a0f581 100644 (file)
@@ -36,8 +36,8 @@ mod tests {
   use lemmy_db_schema::source::{
     comment::{Comment, CommentForm},
     community::{Community, CommunityForm},
+    person::{Person, PersonForm},
     post::{Post, PostForm, PostLike, PostLikeForm},
-    person::{PersonForm, Person},
   };
   use serial_test::serial;
 
index fe25c969d9e65af8343c1ab1b44a9f19fb321da5..a685ad0dae81b167667434cae51151c1e0a744e0 100644 (file)
@@ -25,17 +25,13 @@ impl SiteAggregates {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    aggregates::site_aggregates::SiteAggregates,
-    establish_unpooled_connection,
-    Crud,
-  };
+  use crate::{aggregates::site_aggregates::SiteAggregates, establish_unpooled_connection, Crud};
   use lemmy_db_schema::source::{
     comment::{Comment, CommentForm},
     community::{Community, CommunityForm},
+    person::{Person, PersonForm},
     post::{Post, PostForm},
     site::{Site, SiteForm},
-    person::{PersonForm, Person},
   };
   use serial_test::serial;
 
index 06b9bd8754a76cf3914d3af6d7fccaa9bb0ba31f..bd1bf451f317c6c6b611075a46765a5bd68d11ef 100644 (file)
@@ -122,13 +122,10 @@ impl Activity_ for Activity {
 #[cfg(test)]
 mod tests {
   use super::*;
-  use crate::{
-    establish_unpooled_connection,
-    source::activity::Activity_,
-  };
+  use crate::{establish_unpooled_connection, source::activity::Activity_};
   use lemmy_db_schema::source::{
     activity::{Activity, ActivityForm},
-    person::{PersonForm, Person},
+    person::{Person, PersonForm},
   };
   use serde_json::Value;
   use serial_test::serial;
index e4feef80c2eb3b67cc4975d660311dcd1dc727bf..674888984ed41fc1fb548cadecbf649f663021e0 100644 (file)
@@ -209,8 +209,8 @@ mod tests {
   use lemmy_db_schema::source::{
     comment::*,
     community::{Community, CommunityForm},
+    person::{Person, PersonForm},
     post::*,
-    person::{PersonForm, Person},
   };
   use serial_test::serial;
 
index 9a6a0560febb5204669866bf64c9ebbf3e06003f..2981f23092035822cf9b2bb609f6544e1a4cc7b1 100644 (file)
@@ -295,7 +295,11 @@ impl Followable<CommunityFollowerForm> for CommunityFollower {
       .set(community_follower_form)
       .get_result::<Self>(conn)
   }
-  fn follow_accepted(conn: &PgConnection, community_id_: i32, person_id_: i32) -> Result<Self, Error>
+  fn follow_accepted(
+    conn: &PgConnection,
+    community_id_: i32,
+    person_id_: i32,
+  ) -> Result<Self, Error>
   where
     Self: Sized,
   {
@@ -333,13 +337,7 @@ impl Followable<CommunityFollowerForm> for CommunityFollower {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    establish_unpooled_connection,
-    Bannable,
-    Crud,
-    Followable,
-    Joinable,
-  };
+  use crate::{establish_unpooled_connection, Bannable, Crud, Followable, Joinable};
   use lemmy_db_schema::source::{community::*, person::*};
   use serial_test::serial;
 
@@ -438,7 +436,8 @@ mod tests {
       person_id: inserted_person.id,
     };
 
-    let inserted_community_moderator = CommunityModerator::join(&conn, &community_moderator_form).unwrap();
+    let inserted_community_moderator =
+      CommunityModerator::join(&conn, &community_moderator_form).unwrap();
 
     let expected_community_moderator = CommunityModerator {
       id: inserted_community_moderator.id,
index 644c3eacbab7f9eb95041fc0ac919ee3757ca079..58579f962849c2e307f96e773dacb3bc6d9266c9 100644 (file)
@@ -1,30 +1,21 @@
-use crate::{is_email_regex, Crud, ToSafeSettings};
-use diesel::{dsl::*, result::Error, *};
-use lemmy_db_schema::source::local_user::LocalUserSettings;
-use lemmy_db_schema::schema::local_user::dsl::*;
-use lemmy_db_schema::source::local_user::{LocalUser, LocalUserForm};
+use crate::{Crud, ToSafeSettings};
 use bcrypt::{hash, DEFAULT_COST};
+use diesel::{dsl::*, result::Error, *};
+use lemmy_db_schema::{
+  schema::local_user::dsl::*,
+  source::local_user::{LocalUser, LocalUserForm, LocalUserSettings},
+};
 
 mod safe_type {
   use crate::ToSafe;
   use lemmy_db_schema::{schema::local_user::columns::*, source::local_user::LocalUser};
 
-  type Columns = (
-  id,
-  person_id,
-  admin,
-  matrix_user_id,
-  );
+  type Columns = (id, person_id, admin, matrix_user_id);
 
   impl ToSafe for LocalUser {
     type SafeColumns = Columns;
     fn safe_columns_tuple() -> Self::SafeColumns {
-      (
-        id,
-        person_id,
-        admin,
-        matrix_user_id,
-      )
+      (id, person_id, admin, matrix_user_id)
     }
   }
 }
@@ -50,7 +41,7 @@ mod safe_settings_type {
 
   impl ToSafeSettings for LocalUser {
     type SafeSettingsColumns = Columns;
-    
+
     /// Includes everything but the hashed password
     fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns {
       (
@@ -73,10 +64,12 @@ mod safe_settings_type {
 
 pub trait LocalUser_ {
   fn register(conn: &PgConnection, form: &LocalUserForm) -> Result<LocalUser, Error>;
-  fn update_password(conn: &PgConnection, person_id: i32, new_password: &str)
-    -> Result<LocalUser, Error>;
+  fn update_password(
+    conn: &PgConnection,
+    local_user_id: i32,
+    new_password: &str,
+  ) -> Result<LocalUser, Error>;
   fn add_admin(conn: &PgConnection, local_user_id: i32, added: bool) -> Result<LocalUser, Error>;
-  fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<LocalUser, Error>;
   fn find_by_person(conn: &PgConnection, from_person_id: i32) -> Result<LocalUser, Error>;
 }
 
@@ -91,13 +84,15 @@ impl LocalUser_ for LocalUser {
   }
 
   // TODO do more individual updates like these
-  fn update_password(conn: &PgConnection, local_user_id: i32, new_password: &str) -> Result<Self, Error> {
+  fn update_password(
+    conn: &PgConnection,
+    local_user_id: i32,
+    new_password: &str,
+  ) -> Result<Self, Error> {
     let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password");
 
     diesel::update(local_user.find(local_user_id))
-      .set((
-        password_encrypted.eq(password_hash),
-      ))
+      .set((password_encrypted.eq(password_hash),))
       .get_result::<Self>(conn)
   }
 
@@ -108,33 +103,25 @@ impl LocalUser_ for LocalUser {
       .get_result::<Self>(conn)
   }
 
-  // TODO is this used?
-  fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<LocalUser, Error> {
-    local_user
-      .filter(email.eq(from_email))
-      .first::<LocalUser>(conn)
-  }
-
   // TODO is this used?
   fn find_by_person(conn: &PgConnection, for_person_id: i32) -> Result<LocalUser, Error> {
     local_user
       .filter(person_id.eq(for_person_id))
       .first::<LocalUser>(conn)
   }
-
 }
 
 impl Crud<LocalUserForm> for LocalUser {
   fn read(conn: &PgConnection, local_user_id: i32) -> Result<Self, Error> {
-    local_user
-      .find(local_user_id)
-      .first::<Self>(conn)
+    local_user.find(local_user_id).first::<Self>(conn)
   }
   fn delete(conn: &PgConnection, local_user_id: i32) -> Result<usize, Error> {
     diesel::delete(local_user.find(local_user_id)).execute(conn)
   }
   fn create(conn: &PgConnection, form: &LocalUserForm) -> Result<Self, Error> {
-    insert_into(local_user).values(form).get_result::<Self>(conn)
+    insert_into(local_user)
+      .values(form)
+      .get_result::<Self>(conn)
   }
   fn update(conn: &PgConnection, local_user_id: i32, form: &LocalUserForm) -> Result<Self, Error> {
     diesel::update(local_user.find(local_user_id))
index 4882ddf4bf473780e49bf0f5a59291d7a5649e0f..db928bd4f6ac908f3a9571399e027132acfc4ea4 100644 (file)
@@ -2,12 +2,12 @@ pub mod activity;
 pub mod comment;
 pub mod comment_report;
 pub mod community;
+pub mod local_user;
 pub mod moderator;
 pub mod password_reset_request;
+pub mod person;
+pub mod person_mention;
 pub mod post;
 pub mod post_report;
 pub mod private_message;
 pub mod site;
-pub mod person;
-pub mod person_mention;
-pub mod local_user;
index 4477b55e4ca15350049e8d582338465ae769c9e1..0a3fd7ef4b40dedeb71aa9c2305e9eff8b31c12a 100644 (file)
@@ -198,7 +198,7 @@ impl Crud<ModAddForm> for ModAdd {
 #[cfg(test)]
 mod tests {
   use crate::{establish_unpooled_connection, Crud};
-  use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, person::*};
+  use lemmy_db_schema::source::{comment::*, community::*, moderator::*, person::*, post::*};
   use serial_test::serial;
 
   // use Crud;
index 86b04925d538adb6256e327f092d5e02dc2fab79..1e6622aea0feb2b4c0424a0a01b3c11b43af352c 100644 (file)
@@ -1,32 +1,31 @@
-use crate::{is_email_regex, ApubObject, Crud};
+use crate::{ApubObject, Crud};
 use diesel::{dsl::*, result::Error, *};
 use lemmy_db_schema::{
   naive_now,
   schema::person::dsl::*,
-  source::person::{PersonForm, Person},
+  source::person::{Person, PersonForm},
   DbUrl,
 };
-use lemmy_utils::settings::structs::Settings;
 
 mod safe_type {
   use crate::ToSafe;
   use lemmy_db_schema::{schema::person::columns::*, source::person::Person};
 
   type Columns = (
-  id,
-  name,
-  preferred_username,
-  avatar,
-  banned,
-  published,
-  updated,
-  actor_id,
-  bio,
-  local,
-  banner,
-  deleted,
-  inbox_url,
-  shared_inbox_url,
+    id,
+    name,
+    preferred_username,
+    avatar,
+    banned,
+    published,
+    updated,
+    actor_id,
+    bio,
+    local,
+    banner,
+    deleted,
+    inbox_url,
+    shared_inbox_url,
   );
 
   impl ToSafe for Person {
@@ -57,20 +56,20 @@ mod safe_type_alias_1 {
   use lemmy_db_schema::{schema::person_alias_1::columns::*, source::person::PersonAlias1};
 
   type Columns = (
-        id,
-        name,
-        preferred_username,
-        avatar,
-        banned,
-        published,
-        updated,
-        actor_id,
-        bio,
-        local,
-        banner,
-        deleted,
-        inbox_url,
-        shared_inbox_url,
+    id,
+    name,
+    preferred_username,
+    avatar,
+    banned,
+    published,
+    updated,
+    actor_id,
+    bio,
+    local,
+    banner,
+    deleted,
+    inbox_url,
+    shared_inbox_url,
   );
 
   impl ToSafe for PersonAlias1 {
@@ -101,20 +100,20 @@ mod safe_type_alias_2 {
   use lemmy_db_schema::{schema::person_alias_2::columns::*, source::person::PersonAlias2};
 
   type Columns = (
-        id,
-        name,
-        preferred_username,
-        avatar,
-        banned,
-        published,
-        updated,
-        actor_id,
-        bio,
-        local,
-        banner,
-        deleted,
-        inbox_url,
-        shared_inbox_url,
+    id,
+    name,
+    preferred_username,
+    avatar,
+    banned,
+    published,
+    updated,
+    actor_id,
+    bio,
+    local,
+    banner,
+    deleted,
+    inbox_url,
+    shared_inbox_url,
   );
 
   impl ToSafe for PersonAlias2 {
@@ -181,36 +180,19 @@ impl ApubObject<PersonForm> for Person {
 
 pub trait Person_ {
   fn ban_person(conn: &PgConnection, person_id: i32, ban: bool) -> Result<Person, Error>;
-  // TODO
-  // fn find_by_email_or_name(
-  //   conn: &PgConnection,
-  //   name_or_email: &str,
-  // ) -> Result<Person, Error>;
   fn find_by_name(conn: &PgConnection, name: &str) -> Result<Person, Error>;
   fn mark_as_updated(conn: &PgConnection, person_id: i32) -> Result<Person, Error>;
   fn delete_account(conn: &PgConnection, person_id: i32) -> Result<Person, Error>;
 }
 
 impl Person_ for Person {
-
   fn ban_person(conn: &PgConnection, person_id: i32, ban: bool) -> Result<Self, Error> {
     diesel::update(person.find(person_id))
       .set(banned.eq(ban))
       .get_result::<Self>(conn)
   }
 
-  // TODO this needs to get moved to aggregates i think
-  // fn find_by_email_or_name(
-  //   conn: &PgConnection,
-  //   name_or_email: &str,
-  // ) -> Result<Self, Error> {
-  //   if is_email_regex(name_or_email) {
-  //     Self::find_by_email(conn, name_or_email)
-  //   } else {
-  //     Self::find_by_name(conn, name_or_email)
-  //   }
-  // }
-
+  // TODO is this used?
   fn find_by_name(conn: &PgConnection, from_name: &str) -> Result<Person, Error> {
     person
       .filter(deleted.eq(false))
index ba40c17fe645b4f6beee241fb2b6d7cba6e89966..7a568ba9b4ccfc59e411d5695ec7cd305551ec65 100644 (file)
@@ -77,9 +77,9 @@ mod tests {
   use lemmy_db_schema::source::{
     comment::*,
     community::{Community, CommunityForm},
-    post::*,
     person::*,
     person_mention::*,
+    post::*,
   };
   use serial_test::serial;
 
index c0f74367f85218e54a20dcf07fbab02d1ea01b4a..936471f133885ef37b5c53078ff1b0ef959623c2 100644 (file)
@@ -139,12 +139,8 @@ impl PrivateMessage_ for PrivateMessage {
 
 #[cfg(test)]
 mod tests {
-  use crate::{
-    establish_unpooled_connection,
-    source::private_message::PrivateMessage_,
-    Crud,
-  };
-  use lemmy_db_schema::source::{private_message::*, person::*};
+  use crate::{establish_unpooled_connection, source::private_message::PrivateMessage_, Crud};
+  use lemmy_db_schema::source::{person::*, private_message::*};
   use serial_test::serial;
 
   #[test]
diff --git a/crates/db_queries/src/source/user.rs b/crates/db_queries/src/source/user.rs
deleted file mode 100644 (file)
index 077b3e7..0000000
+++ /dev/null
@@ -1,459 +0,0 @@
-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, UserSafeSettings, User_},
-  DbUrl,
-};
-use lemmy_utils::settings::structs::Settings;
-
-mod safe_type {
-  use crate::ToSafe;
-  use lemmy_db_schema::{schema::user_::columns::*, source::user::User_};
-
-  type Columns = (
-    id,
-    name,
-    preferred_username,
-    avatar,
-    admin,
-    banned,
-    published,
-    updated,
-    matrix_user_id,
-    actor_id,
-    bio,
-    local,
-    banner,
-    deleted,
-    inbox_url,
-    shared_inbox_url,
-  );
-
-  impl ToSafe for User_ {
-    type SafeColumns = Columns;
-    fn safe_columns_tuple() -> Self::SafeColumns {
-      (
-        id,
-        name,
-        preferred_username,
-        avatar,
-        admin,
-        banned,
-        published,
-        updated,
-        matrix_user_id,
-        actor_id,
-        bio,
-        local,
-        banner,
-        deleted,
-        inbox_url,
-        shared_inbox_url,
-      )
-    }
-  }
-}
-
-mod safe_type_alias_1 {
-  use crate::ToSafe;
-  use lemmy_db_schema::{schema::user_alias_1::columns::*, source::user::UserAlias1};
-
-  type Columns = (
-    id,
-    name,
-    preferred_username,
-    avatar,
-    admin,
-    banned,
-    published,
-    updated,
-    matrix_user_id,
-    actor_id,
-    bio,
-    local,
-    banner,
-    deleted,
-  );
-
-  impl ToSafe for UserAlias1 {
-    type SafeColumns = Columns;
-    fn safe_columns_tuple() -> Self::SafeColumns {
-      (
-        id,
-        name,
-        preferred_username,
-        avatar,
-        admin,
-        banned,
-        published,
-        updated,
-        matrix_user_id,
-        actor_id,
-        bio,
-        local,
-        banner,
-        deleted,
-      )
-    }
-  }
-}
-
-mod safe_type_alias_2 {
-  use crate::ToSafe;
-  use lemmy_db_schema::{schema::user_alias_2::columns::*, source::user::UserAlias2};
-
-  type Columns = (
-    id,
-    name,
-    preferred_username,
-    avatar,
-    admin,
-    banned,
-    published,
-    updated,
-    matrix_user_id,
-    actor_id,
-    bio,
-    local,
-    banner,
-    deleted,
-  );
-
-  impl ToSafe for UserAlias2 {
-    type SafeColumns = Columns;
-    fn safe_columns_tuple() -> Self::SafeColumns {
-      (
-        id,
-        name,
-        preferred_username,
-        avatar,
-        admin,
-        banned,
-        published,
-        updated,
-        matrix_user_id,
-        actor_id,
-        bio,
-        local,
-        banner,
-        deleted,
-      )
-    }
-  }
-}
-
-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_
-      .filter(deleted.eq(false))
-      .find(user_id)
-      .first::<Self>(conn)
-  }
-  fn delete(conn: &PgConnection, user_id: i32) -> Result<usize, Error> {
-    diesel::delete(user_.find(user_id)).execute(conn)
-  }
-  fn create(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
-    insert_into(user_).values(form).get_result::<Self>(conn)
-  }
-  fn update(conn: &PgConnection, user_id: i32, form: &UserForm) -> Result<Self, Error> {
-    diesel::update(user_.find(user_id))
-      .set(form)
-      .get_result::<Self>(conn)
-  }
-}
-
-impl ApubObject<UserForm> for User_ {
-  fn read_from_apub_id(conn: &PgConnection, object_id: &DbUrl) -> Result<Self, Error> {
-    use lemmy_db_schema::schema::user_::dsl::*;
-    user_
-      .filter(deleted.eq(false))
-      .filter(actor_id.eq(object_id))
-      .first::<Self>(conn)
-  }
-
-  fn upsert(conn: &PgConnection, user_form: &UserForm) -> Result<User_, Error> {
-    insert_into(user_)
-      .values(user_form)
-      .on_conflict(actor_id)
-      .do_update()
-      .set(user_form)
-      .get_result::<Self>(conn)
-  }
-}
-
-pub trait User {
-  fn register(conn: &PgConnection, form: &UserForm) -> Result<User_, Error>;
-  fn update_password(conn: &PgConnection, user_id: i32, new_password: &str)
-    -> Result<User_, Error>;
-  fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<User_, Error>;
-  fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result<User_, Error>;
-  fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result<User_, Error>;
-  fn find_by_email_or_username(
-    conn: &PgConnection,
-    username_or_email: &str,
-  ) -> Result<User_, Error>;
-  fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error>;
-  fn get_profile_url(&self, hostname: &str) -> String;
-  fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result<User_, Error>;
-  fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error>;
-}
-
-impl User for User_ {
-  fn register(conn: &PgConnection, form: &UserForm) -> Result<Self, Error> {
-    let mut edited_user = form.clone();
-    let password_hash =
-      hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
-    edited_user.password_encrypted = password_hash;
-
-    Self::create(&conn, &edited_user)
-  }
-
-  // TODO do more individual updates like these
-  fn update_password(conn: &PgConnection, user_id: i32, new_password: &str) -> Result<Self, Error> {
-    let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password");
-
-    diesel::update(user_.find(user_id))
-      .set((
-        password_encrypted.eq(password_hash),
-        updated.eq(naive_now()),
-      ))
-      .get_result::<Self>(conn)
-  }
-
-  fn read_from_name(conn: &PgConnection, from_user_name: &str) -> Result<Self, Error> {
-    user_
-      .filter(local.eq(true))
-      .filter(deleted.eq(false))
-      .filter(name.eq(from_user_name))
-      .first::<Self>(conn)
-  }
-
-  fn add_admin(conn: &PgConnection, user_id: i32, added: bool) -> Result<Self, Error> {
-    diesel::update(user_.find(user_id))
-      .set(admin.eq(added))
-      .get_result::<Self>(conn)
-  }
-
-  fn ban_user(conn: &PgConnection, user_id: i32, ban: bool) -> Result<Self, Error> {
-    diesel::update(user_.find(user_id))
-      .set(banned.eq(ban))
-      .get_result::<Self>(conn)
-  }
-
-  fn find_by_email_or_username(
-    conn: &PgConnection,
-    username_or_email: &str,
-  ) -> Result<Self, Error> {
-    if is_email_regex(username_or_email) {
-      Self::find_by_email(conn, username_or_email)
-    } else {
-      Self::find_by_username(conn, username_or_email)
-    }
-  }
-
-  fn find_by_username(conn: &PgConnection, username: &str) -> Result<User_, Error> {
-    user_
-      .filter(deleted.eq(false))
-      .filter(local.eq(true))
-      .filter(name.ilike(username))
-      .first::<User_>(conn)
-  }
-
-  fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<User_, Error> {
-    user_
-      .filter(deleted.eq(false))
-      .filter(local.eq(true))
-      .filter(email.eq(from_email))
-      .first::<User_>(conn)
-  }
-
-  fn get_profile_url(&self, hostname: &str) -> String {
-    format!(
-      "{}://{}/u/{}",
-      Settings::get().get_protocol_string(),
-      hostname,
-      self.name
-    )
-  }
-
-  fn mark_as_updated(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
-    diesel::update(user_.find(user_id))
-      .set((last_refreshed_at.eq(naive_now()),))
-      .get_result::<Self>(conn)
-  }
-
-  fn delete_account(conn: &PgConnection, user_id: i32) -> Result<User_, Error> {
-    diesel::update(user_.find(user_id))
-      .set((
-        preferred_username.eq::<Option<String>>(None),
-        email.eq::<Option<String>>(None),
-        matrix_user_id.eq::<Option<String>>(None),
-        bio.eq::<Option<String>>(None),
-        deleted.eq(true),
-        updated.eq(naive_now()),
-      ))
-      .get_result::<Self>(conn)
-  }
-}
-
-#[cfg(test)]
-mod tests {
-  use crate::{establish_unpooled_connection, source::user::*, ListingType, SortType};
-  use serial_test::serial;
-
-  #[test]
-  #[serial]
-  fn test_crud() {
-    let conn = establish_unpooled_connection();
-
-    let new_user = UserForm {
-      name: "thommy".into(),
-      preferred_username: None,
-      password_encrypted: "nope".into(),
-      email: None,
-      matrix_user_id: None,
-      avatar: None,
-      banner: None,
-      admin: false,
-      banned: Some(false),
-      published: None,
-      updated: None,
-      show_nsfw: false,
-      theme: "browser".into(),
-      default_sort_type: SortType::Hot as i16,
-      default_listing_type: ListingType::Subscribed as i16,
-      lang: "browser".into(),
-      show_avatars: true,
-      send_notifications_to_email: false,
-      actor_id: None,
-      bio: None,
-      local: true,
-      private_key: None,
-      public_key: None,
-      last_refreshed_at: None,
-      inbox_url: None,
-      shared_inbox_url: None,
-    };
-
-    let inserted_user = User_::create(&conn, &new_user).unwrap();
-
-    let expected_user = User_ {
-      id: inserted_user.id,
-      name: "thommy".into(),
-      preferred_username: None,
-      password_encrypted: "nope".into(),
-      email: None,
-      matrix_user_id: None,
-      avatar: None,
-      banner: None,
-      admin: false,
-      banned: false,
-      published: inserted_user.published,
-      updated: None,
-      show_nsfw: false,
-      theme: "browser".into(),
-      default_sort_type: SortType::Hot as i16,
-      default_listing_type: ListingType::Subscribed as i16,
-      lang: "browser".into(),
-      show_avatars: true,
-      send_notifications_to_email: false,
-      actor_id: inserted_user.actor_id.to_owned(),
-      bio: None,
-      local: true,
-      private_key: None,
-      public_key: None,
-      last_refreshed_at: inserted_user.published,
-      deleted: false,
-      inbox_url: inserted_user.inbox_url.to_owned(),
-      shared_inbox_url: None,
-    };
-
-    let read_user = User_::read(&conn, inserted_user.id).unwrap();
-    let updated_user = User_::update(&conn, inserted_user.id, &new_user).unwrap();
-    let num_deleted = User_::delete(&conn, inserted_user.id).unwrap();
-
-    assert_eq!(expected_user, read_user);
-    assert_eq!(expected_user, inserted_user);
-    assert_eq!(expected_user, updated_user);
-    assert_eq!(1, num_deleted);
-  }
-}
index 68a8bdcfc72fa5e1c989177f84583f007817b906..692017974b2134e0da47f6882275acc670bf2ea7 100644 (file)
@@ -4,53 +4,53 @@ use serde::Serialize;
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "local_user"]
 pub struct LocalUser {
-  pub id: i32,                                  
-  pub person_id: i32,                          
-  pub password_encrypted: String,               
-  pub email: Option<String>,                    
-  pub admin: bool,                              
-  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 id: i32,
+  pub person_id: i32,
+  pub password_encrypted: String,
+  pub email: Option<String>,
+  pub admin: bool,
+  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>,
 }
 
 // TODO redo these, check table defaults
 #[derive(Insertable, AsChangeset, Clone)]
 #[table_name = "local_user"]
 pub struct LocalUserForm {
-  pub person_id: i32,                          
-  pub password_encrypted: String,               
+  pub person_id: i32,
+  pub password_encrypted: String,
   pub email: Option<Option<String>>,
-  pub admin: Option<bool>,                              
-  pub show_nsfw: Option<bool>,                          
-  pub theme: Option<String>,                            
-  pub default_sort_type: Option<i16>,                   
-  pub default_listing_type: Option<i16>,                
-  pub lang: Option<String>,                             
-  pub show_avatars: Option<bool>,                       
-  pub send_notifications_to_email: Option<bool>,        
+  pub admin: Option<bool>,
+  pub show_nsfw: Option<bool>,
+  pub theme: Option<String>,
+  pub default_sort_type: Option<i16>,
+  pub default_listing_type: Option<i16>,
+  pub lang: Option<String>,
+  pub show_avatars: Option<bool>,
+  pub send_notifications_to_email: Option<bool>,
   pub matrix_user_id: Option<Option<String>>,
 }
 
 /// A local user view that removes password encrypted
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "local_user"]
-pub struct LocalUserSettings{
-  pub id: i32,                                  
-  pub person_id: i32,                          
-  pub email: Option<String>,                    
-  pub admin: bool,                              
-  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 struct LocalUserSettings {
+  pub id: i32,
+  pub person_id: i32,
+  pub email: Option<String>,
+  pub admin: bool,
+  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>,
 }
index 4882ddf4bf473780e49bf0f5a59291d7a5649e0f..db928bd4f6ac908f3a9571399e027132acfc4ea4 100644 (file)
@@ -2,12 +2,12 @@ pub mod activity;
 pub mod comment;
 pub mod comment_report;
 pub mod community;
+pub mod local_user;
 pub mod moderator;
 pub mod password_reset_request;
+pub mod person;
+pub mod person_mention;
 pub mod post;
 pub mod post_report;
 pub mod private_message;
 pub mod site;
-pub mod person;
-pub mod person_mention;
-pub mod local_user;
index 5971d9303ba82993076b6834cad8dae78bec8d58..7fc3692f84591019a831885e86a152f3bb729954 100644 (file)
@@ -7,145 +7,144 @@ use serde::Serialize;
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "person"]
 pub struct Person {
-  pub id: i32,                                  
-  pub name: String,                             
-  pub preferred_username: Option<String>,       
-  pub avatar: Option<DbUrl>,                   
-  pub banned: bool,                             
-  pub published: chrono::NaiveDateTime,         
-  pub updated: Option<chrono::NaiveDateTime>,   
-  pub actor_id: DbUrl,                            
-  pub bio: Option<String>,                      
-  pub local: bool,                              
-  pub private_key: Option<String>,              
-  pub public_key: Option<String>,               
-  pub last_refreshed_at: chrono::NaiveDateTime, 
-  pub banner: Option<DbUrl>,                   
-  pub deleted: bool,                            
-  pub inbox_url: DbUrl,                           
-  pub shared_inbox_url: Option<DbUrl>,            
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub avatar: Option<DbUrl>,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub actor_id: DbUrl,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub private_key: Option<String>,
+  pub public_key: Option<String>,
+  pub last_refreshed_at: chrono::NaiveDateTime,
+  pub banner: Option<DbUrl>,
+  pub deleted: bool,
+  pub inbox_url: DbUrl,
+  pub shared_inbox_url: Option<DbUrl>,
 }
 
 /// A safe representation of user, without the sensitive info
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "person"]
 pub struct PersonSafe {
-  pub id: i32,                                  
-  pub name: String,                             
-  pub preferred_username: Option<String>,       
-  pub avatar: Option<DbUrl>,                   
-  pub banned: bool,                             
-  pub published: chrono::NaiveDateTime,         
-  pub updated: Option<chrono::NaiveDateTime>,   
-  pub actor_id: DbUrl,                            
-  pub bio: Option<String>,                      
-  pub local: bool,                              
-  pub banner: Option<DbUrl>,                   
-  pub deleted: bool,                            
-  pub inbox_url: DbUrl,                           
-  pub shared_inbox_url: Option<DbUrl>,            
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub avatar: Option<DbUrl>,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub actor_id: DbUrl,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub banner: Option<DbUrl>,
+  pub deleted: bool,
+  pub inbox_url: DbUrl,
+  pub shared_inbox_url: Option<DbUrl>,
 }
 
-
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "person_alias_1"]
 pub struct PersonAlias1 {
-  pub id: i32,                                  
-  pub name: String,                             
-  pub preferred_username: Option<String>,       
-  pub avatar: Option<DbUrl>,                   
-  pub banned: bool,                             
-  pub published: chrono::NaiveDateTime,         
-  pub updated: Option<chrono::NaiveDateTime>,   
-  pub actor_id: DbUrl,                            
-  pub bio: Option<String>,                      
-  pub local: bool,                              
-  pub private_key: Option<String>,              
-  pub public_key: Option<String>,               
-  pub last_refreshed_at: chrono::NaiveDateTime, 
-  pub banner: Option<DbUrl>,                   
-  pub deleted: bool,                            
-  pub inbox_url: DbUrl,                           
-  pub shared_inbox_url: Option<DbUrl>,            
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub avatar: Option<DbUrl>,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub actor_id: DbUrl,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub private_key: Option<String>,
+  pub public_key: Option<String>,
+  pub last_refreshed_at: chrono::NaiveDateTime,
+  pub banner: Option<DbUrl>,
+  pub deleted: bool,
+  pub inbox_url: DbUrl,
+  pub shared_inbox_url: Option<DbUrl>,
 }
 
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "person_alias_1"]
 pub struct PersonSafeAlias1 {
-  pub id: i32,                                  
-  pub name: String,                             
-  pub preferred_username: Option<String>,       
-  pub avatar: Option<DbUrl>,                   
-  pub banned: bool,                             
-  pub published: chrono::NaiveDateTime,         
-  pub updated: Option<chrono::NaiveDateTime>,   
-  pub actor_id: DbUrl,                            
-  pub bio: Option<String>,                      
-  pub local: bool,                              
-  pub banner: Option<DbUrl>,                   
-  pub deleted: bool,                            
-  pub inbox_url: DbUrl,                           
-  pub shared_inbox_url: Option<DbUrl>,            
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub avatar: Option<DbUrl>,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub actor_id: DbUrl,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub banner: Option<DbUrl>,
+  pub deleted: bool,
+  pub inbox_url: DbUrl,
+  pub shared_inbox_url: Option<DbUrl>,
 }
 
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "person_alias_2"]
 pub struct PersonAlias2 {
-  pub id: i32,                                  
-  pub name: String,                             
-  pub preferred_username: Option<String>,       
-  pub avatar: Option<DbUrl>,                   
-  pub banned: bool,                             
-  pub published: chrono::NaiveDateTime,         
-  pub updated: Option<chrono::NaiveDateTime>,   
-  pub actor_id: DbUrl,                            
-  pub bio: Option<String>,                      
-  pub local: bool,                              
-  pub private_key: Option<String>,              
-  pub public_key: Option<String>,               
-  pub last_refreshed_at: chrono::NaiveDateTime, 
-  pub banner: Option<DbUrl>,                   
-  pub deleted: bool,                            
-  pub inbox_url: DbUrl,                           
-  pub shared_inbox_url: Option<DbUrl>,            
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub avatar: Option<DbUrl>,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub actor_id: DbUrl,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub private_key: Option<String>,
+  pub public_key: Option<String>,
+  pub last_refreshed_at: chrono::NaiveDateTime,
+  pub banner: Option<DbUrl>,
+  pub deleted: bool,
+  pub inbox_url: DbUrl,
+  pub shared_inbox_url: Option<DbUrl>,
 }
 
 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
 #[table_name = "person_alias_1"]
 pub struct PersonSafeAlias2 {
-  pub id: i32,                                  
-  pub name: String,                             
-  pub preferred_username: Option<String>,       
-  pub avatar: Option<DbUrl>,                   
-  pub banned: bool,                             
-  pub published: chrono::NaiveDateTime,         
-  pub updated: Option<chrono::NaiveDateTime>,   
-  pub actor_id: DbUrl,                            
-  pub bio: Option<String>,                      
-  pub local: bool,                              
-  pub banner: Option<DbUrl>,                   
-  pub deleted: bool,                            
-  pub inbox_url: DbUrl,                           
-  pub shared_inbox_url: Option<DbUrl>,            
+  pub id: i32,
+  pub name: String,
+  pub preferred_username: Option<String>,
+  pub avatar: Option<DbUrl>,
+  pub banned: bool,
+  pub published: chrono::NaiveDateTime,
+  pub updated: Option<chrono::NaiveDateTime>,
+  pub actor_id: DbUrl,
+  pub bio: Option<String>,
+  pub local: bool,
+  pub banner: Option<DbUrl>,
+  pub deleted: bool,
+  pub inbox_url: DbUrl,
+  pub shared_inbox_url: Option<DbUrl>,
 }
 
 #[derive(Insertable, AsChangeset, Clone)]
 #[table_name = "person"]
 pub struct PersonForm {
-  pub name: String,                             
+  pub name: String,
   pub preferred_username: Option<Option<String>>,
   pub avatar: Option<Option<DbUrl>>,
-  pub banned: Option<bool>,                             
+  pub banned: Option<bool>,
   pub published: Option<chrono::NaiveDateTime>,
   pub updated: Option<chrono::NaiveDateTime>,
-  pub actor_id: Option<DbUrl>,                            
-  pub bio: Option<Option<String>>,                      
-  pub local: Option<bool>,                              
-  pub private_key: Option<Option<String>>,              
-  pub public_key: Option<Option<String>>,               
+  pub actor_id: Option<DbUrl>,
+  pub bio: Option<Option<String>>,
+  pub local: Option<bool>,
+  pub private_key: Option<Option<String>>,
+  pub public_key: Option<Option<String>>,
   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
   pub banner: Option<Option<DbUrl>>,
-  pub deleted: Option<bool>,                            
-  pub inbox_url: Option<DbUrl>,                           
+  pub deleted: Option<bool>,
+  pub inbox_url: Option<DbUrl>,
   pub shared_inbox_url: Option<Option<DbUrl>>,
 }
diff --git a/crates/db_schema/src/source/user.rs b/crates/db_schema/src/source/user.rs
deleted file mode 100644 (file)
index f04b9a6..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-use crate::{
-  schema::{user_, user_alias_1, user_alias_2},
-  DbUrl,
-};
-use serde::Serialize;
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_"]
-pub struct User_ {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub password_encrypted: String,
-  pub email: Option<String>,
-  pub avatar: Option<DbUrl>,
-  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: DbUrl,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub private_key: Option<String>,
-  pub public_key: Option<String>,
-  pub last_refreshed_at: chrono::NaiveDateTime,
-  pub banner: Option<DbUrl>,
-  pub deleted: bool,
-  pub inbox_url: DbUrl,
-  pub shared_inbox_url: Option<DbUrl>,
-}
-
-/// A safe representation of user, without the sensitive info
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_"]
-pub struct UserSafe {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub avatar: Option<DbUrl>,
-  pub admin: bool,
-  pub banned: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub matrix_user_id: Option<String>,
-  pub actor_id: DbUrl,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub banner: Option<DbUrl>,
-  pub deleted: bool,
-  pub inbox_url: DbUrl,
-  pub shared_inbox_url: Option<DbUrl>,
-}
-
-/// 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<DbUrl>,
-  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: DbUrl,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub last_refreshed_at: chrono::NaiveDateTime,
-  pub banner: Option<DbUrl>,
-  pub deleted: bool,
-}
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_1"]
-pub struct UserAlias1 {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub password_encrypted: String,
-  pub email: Option<String>,
-  pub avatar: Option<DbUrl>,
-  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: DbUrl,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub private_key: Option<String>,
-  pub public_key: Option<String>,
-  pub last_refreshed_at: chrono::NaiveDateTime,
-  pub banner: Option<DbUrl>,
-  pub deleted: bool,
-}
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_1"]
-pub struct UserSafeAlias1 {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub avatar: Option<DbUrl>,
-  pub admin: bool,
-  pub banned: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub matrix_user_id: Option<String>,
-  pub actor_id: DbUrl,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub banner: Option<DbUrl>,
-  pub deleted: bool,
-}
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_2"]
-pub struct UserAlias2 {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub password_encrypted: String,
-  pub email: Option<String>,
-  pub avatar: Option<DbUrl>,
-  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: DbUrl,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub private_key: Option<String>,
-  pub public_key: Option<String>,
-  pub last_refreshed_at: chrono::NaiveDateTime,
-  pub banner: Option<DbUrl>,
-  pub deleted: bool,
-}
-
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
-#[table_name = "user_alias_2"]
-pub struct UserSafeAlias2 {
-  pub id: i32,
-  pub name: String,
-  pub preferred_username: Option<String>,
-  pub avatar: Option<DbUrl>,
-  pub admin: bool,
-  pub banned: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub matrix_user_id: Option<String>,
-  pub actor_id: DbUrl,
-  pub bio: Option<String>,
-  pub local: bool,
-  pub banner: Option<DbUrl>,
-  pub deleted: bool,
-}
-
-#[derive(Insertable, AsChangeset, Clone)]
-#[table_name = "user_"]
-pub struct UserForm {
-  pub name: String,
-  pub preferred_username: Option<Option<String>>,
-  pub password_encrypted: String,
-  pub admin: bool,
-  pub banned: Option<bool>,
-  pub email: Option<Option<String>>,
-  pub avatar: Option<Option<DbUrl>>,
-  pub published: Option<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<Option<String>>,
-  pub actor_id: Option<DbUrl>,
-  pub bio: Option<Option<String>>,
-  pub local: bool,
-  pub private_key: Option<String>,
-  pub public_key: Option<String>,
-  pub last_refreshed_at: Option<chrono::NaiveDateTime>,
-  pub banner: Option<Option<DbUrl>>,
-  pub inbox_url: Option<DbUrl>,
-  pub shared_inbox_url: Option<Option<DbUrl>>,
-}
index eb10bffbedda23466dd94f25355034cec0cc7c66..d06d17fbbe17cf4ea488661339bf4267ca617bc0 100644 (file)
@@ -1,13 +1,13 @@
 use diesel::{result::Error, *};
 use lemmy_db_queries::{limit_and_offset, MaybeOptional, ToSafe, ViewToVec};
 use lemmy_db_schema::{
-  schema::{comment, comment_report, community, post, person, person_alias_1, person_alias_2},
+  schema::{comment, comment_report, community, person, person_alias_1, person_alias_2, post},
   source::{
     comment::Comment,
     comment_report::CommentReport,
     community::{Community, CommunitySafe},
+    person::{Person, PersonAlias1, PersonAlias2, PersonSafe, PersonSafeAlias1, PersonSafeAlias2},
     post::Post,
-    person::{PersonAlias1, PersonAlias2, PersonSafe, PersonSafeAlias1, PersonSafeAlias2, Person},
   },
 };
 use serde::Serialize;
index eb95a2ccdcc6a6fd3e8d3ed36cff0d26950f1c4e..49bad6c03efafdb5fa229e6d74784674c5943da3 100644 (file)
@@ -20,15 +20,15 @@ use lemmy_db_schema::{
     community,
     community_follower,
     community_person_ban,
-    post,
     person,
     person_alias_1,
+    post,
   },
   source::{
     comment::{Comment, CommentAlias1, CommentSaved},
-    community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
+    community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
+    person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
     post::Post,
-    person::{PersonAlias1, PersonSafe, PersonSafeAlias1, Person},
   },
 };
 use serde::Serialize;
@@ -440,7 +440,7 @@ mod tests {
     Crud,
     Likeable,
   };
-  use lemmy_db_schema::source::{comment::*, community::*, post::*, person::*};
+  use lemmy_db_schema::source::{comment::*, community::*, person::*, post::*};
   use serial_test::serial;
 
   #[test]
@@ -646,7 +646,10 @@ mod tests {
     Community::delete(&conn, inserted_community.id).unwrap();
     Person::delete(&conn, inserted_person.id).unwrap();
 
-    assert_eq!(expected_comment_view_no_person, read_comment_views_no_person[0]);
+    assert_eq!(
+      expected_comment_view_no_person,
+      read_comment_views_no_person[0]
+    );
     assert_eq!(
       expected_comment_view_with_person,
       read_comment_views_with_person[0]
index d37a1d3ed9ca1ecbd461764c69a1e85f88ba9711..54435c1e2f639b42edfd630c46b30adac6602e9a 100644 (file)
@@ -3,8 +3,8 @@ extern crate serial_test;
 
 pub mod comment_report_view;
 pub mod comment_view;
+pub mod local_user_view;
 pub mod post_report_view;
 pub mod post_view;
 pub mod private_message_view;
 pub mod site_view;
-pub mod local_user_view;
index 384bf900702555f0ff7f03fa7bebb7463be303fb..d377af6330dcceac72361ffe71326dc1629adf65 100644 (file)
@@ -1,13 +1,11 @@
 use diesel::{result::Error, *};
-use lemmy_db_queries::{
-  aggregates::person_aggregates::PersonAggregates,
-  ToSafe,
-  ToSafeSettings,
-};
+use lemmy_db_queries::{aggregates::person_aggregates::PersonAggregates, ToSafe, ToSafeSettings};
 use lemmy_db_schema::{
-  schema::{person, person_aggregates, local_user},
-  source::person::{PersonSafe, Person},
-  source::local_user::{LocalUser, LocalUserSettings},
+  schema::{local_user, person, person_aggregates},
+  source::{
+    local_user::{LocalUser, LocalUserSettings},
+    person::{Person, PersonSafe},
+  },
 };
 use serde::Serialize;
 
@@ -21,14 +19,22 @@ pub struct LocalUserView {
 type LocalUserViewTuple = (Person, PersonAggregates, LocalUser);
 
 impl LocalUserView {
-  pub fn read(conn: &PgConnection, person_id: i32) -> Result<Self, Error> {
+  pub fn read_person(conn: &PgConnection, person_id: i32) -> Result<Self, Error> {
     let (person, counts, local_user) = person::table
       .find(person_id)
       .inner_join(person_aggregates::table)
       .inner_join(local_user::table)
-      .select((person::all_columns, person_aggregates::all_columns, local_user::all_columns))
+      .select((
+        person::all_columns,
+        person_aggregates::all_columns,
+        local_user::all_columns,
+      ))
       .first::<LocalUserViewTuple>(conn)?;
-    Ok(Self { person, counts, local_user })
+    Ok(Self {
+      person,
+      counts,
+      local_user,
+    })
   }
 
   // TODO check where this is used
@@ -37,22 +43,57 @@ impl LocalUserView {
       .filter(person::name.eq(name))
       .inner_join(person_aggregates::table)
       .inner_join(local_user::table)
-      .select((person::all_columns, person_aggregates::all_columns, local_user::all_columns))
+      .select((
+        person::all_columns,
+        person_aggregates::all_columns,
+        local_user::all_columns,
+      ))
+      .first::<LocalUserViewTuple>(conn)?;
+    Ok(Self {
+      person,
+      counts,
+      local_user,
+    })
+  }
+
+  pub fn find_by_email_or_name(conn: &PgConnection, name_or_email: &str) -> Result<Self, Error> {
+    let (person, counts, local_user) = person::table
+      .inner_join(person_aggregates::table)
+      .inner_join(local_user::table)
+      .filter(
+        person::name
+          .ilike(name_or_email)
+          .or(local_user::email.ilike(name_or_email)),
+      )
+      .select((
+        person::all_columns,
+        person_aggregates::all_columns,
+        local_user::all_columns,
+      ))
       .first::<LocalUserViewTuple>(conn)?;
-    Ok(Self { person, counts, local_user })
+    Ok(Self {
+      person,
+      counts,
+      local_user,
+    })
   }
 
-  pub fn find_by_email_or_name(
-    conn: &PgConnection,
-    name_or_email: &str,
-  ) -> Result<Self, Error> {
+  pub fn find_by_email(conn: &PgConnection, from_email: &str) -> Result<Self, Error> {
     let (person, counts, local_user) = person::table
       .inner_join(person_aggregates::table)
       .inner_join(local_user::table)
-      .filter(person::name.ilike(name_or_email).or(local_user::email.ilike(name_or_email)))
-      .select((person::all_columns, person_aggregates::all_columns, local_user::all_columns))
+      .filter(local_user::email.eq(from_email))
+      .select((
+        person::all_columns,
+        person_aggregates::all_columns,
+        local_user::all_columns,
+      ))
       .first::<LocalUserViewTuple>(conn)?;
-    Ok(Self { person, counts, local_user })
+    Ok(Self {
+      person,
+      counts,
+      local_user,
+    })
   }
 }
 
@@ -71,8 +112,16 @@ impl LocalUserSettingsView {
       .find(person_id)
       .inner_join(person_aggregates::table)
       .inner_join(local_user::table)
-      .select((Person::safe_columns_tuple(), person_aggregates::all_columns, LocalUser::safe_settings_columns_tuple()))
+      .select((
+        Person::safe_columns_tuple(),
+        person_aggregates::all_columns,
+        LocalUser::safe_settings_columns_tuple(),
+      ))
       .first::<LocalUserSettingsViewTuple>(conn)?;
-    Ok(Self { person, counts, local_user })
+    Ok(Self {
+      person,
+      counts,
+      local_user,
+    })
   }
 }
index 192a3d7b108469c77dec289f7602d01bb019ebc1..e8221c72c9de78ad772d6ad1ed023b2bd515dee9 100644 (file)
@@ -1,12 +1,12 @@
 use diesel::{result::Error, *};
 use lemmy_db_queries::{limit_and_offset, MaybeOptional, ToSafe, ViewToVec};
 use lemmy_db_schema::{
-  schema::{community, post, post_report, person, person_alias_1, person_alias_2},
+  schema::{community, person, person_alias_1, person_alias_2, post, post_report},
   source::{
     community::{Community, CommunitySafe},
+    person::{Person, PersonAlias1, PersonAlias2, PersonSafe, PersonSafeAlias1, PersonSafeAlias2},
     post::Post,
     post_report::PostReport,
-    person::{PersonAlias1, PersonAlias2, PersonSafe, PersonSafeAlias1, PersonSafeAlias2, Person},
   },
 };
 use serde::Serialize;
@@ -41,7 +41,9 @@ impl PostReportView {
       .inner_join(community::table.on(post::community_id.eq(community::id)))
       .inner_join(person::table.on(post_report::creator_id.eq(person::id)))
       .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
-      .left_join(person_alias_2::table.on(post_report::resolver_id.eq(person_alias_2::id.nullable())))
+      .left_join(
+        person_alias_2::table.on(post_report::resolver_id.eq(person_alias_2::id.nullable())),
+      )
       .select((
         post_report::all_columns,
         post::all_columns,
@@ -126,7 +128,9 @@ impl<'a> PostReportQueryBuilder<'a> {
       .inner_join(community::table.on(post::community_id.eq(community::id)))
       .inner_join(person::table.on(post_report::creator_id.eq(person::id)))
       .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id)))
-      .left_join(person_alias_2::table.on(post_report::resolver_id.eq(person_alias_2::id.nullable())))
+      .left_join(
+        person_alias_2::table.on(post_report::resolver_id.eq(person_alias_2::id.nullable())),
+      )
       .select((
         post_report::all_columns,
         post::all_columns,
index 4aca33286c8ded38b3286684f1cbb4346b0b20de..2db35fff433ec20f82d8ec28ffa402a3f0a657d6 100644 (file)
@@ -15,17 +15,17 @@ use lemmy_db_schema::{
     community,
     community_follower,
     community_person_ban,
+    person,
     post,
     post_aggregates,
     post_like,
     post_read,
     post_saved,
-    person,
   },
   source::{
-    community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
+    community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
+    person::{Person, PersonSafe},
     post::{Post, PostRead, PostSaved},
-    person::{PersonSafe, Person},
   },
 };
 use log::debug;
@@ -433,7 +433,7 @@ mod tests {
     ListingType,
     SortType,
   };
-  use lemmy_db_schema::source::{community::*, post::*, person::*};
+  use lemmy_db_schema::source::{community::*, person::*, post::*};
   use serial_test::serial;
 
   #[test]
@@ -638,11 +638,17 @@ mod tests {
       expected_post_listing_with_user,
       read_post_listings_with_person[0]
     );
-    assert_eq!(expected_post_listing_with_user, read_post_listing_with_person);
+    assert_eq!(
+      expected_post_listing_with_user,
+      read_post_listing_with_person
+    );
     assert_eq!(1, read_post_listings_with_person.len());
 
     // Without the user
-    assert_eq!(expected_post_listing_no_person, read_post_listings_no_person[0]);
+    assert_eq!(
+      expected_post_listing_no_person,
+      read_post_listings_no_person[0]
+    );
     assert_eq!(expected_post_listing_no_person, read_post_listing_no_person);
     assert_eq!(1, read_post_listings_no_person.len());
 
index 29b1e46442502bb3d898521d0d84e3e8be5bd70f..e4dd3d3f4f70ce2477e6df1cc23ea06b8a77fc5b 100644 (file)
@@ -1,10 +1,10 @@
 use diesel::{pg::Pg, result::Error, *};
 use lemmy_db_queries::{limit_and_offset, MaybeOptional, ToSafe, ViewToVec};
 use lemmy_db_schema::{
-  schema::{private_message, person, person_alias_1},
+  schema::{person, person_alias_1, private_message},
   source::{
+    person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
     private_message::PrivateMessage,
-    person::{PersonAlias1, PersonSafe, PersonSafeAlias1, Person},
   },
 };
 use log::debug;
index 391cf84b18b5d927f79df3675b9575203f180d09..87fded01b184ef27517f1fb6964f6a7e6f13349e 100644 (file)
@@ -1,10 +1,10 @@
 use diesel::{result::Error, *};
 use lemmy_db_queries::{aggregates::site_aggregates::SiteAggregates, ToSafe};
 use lemmy_db_schema::{
-  schema::{site, site_aggregates, person},
+  schema::{person, site, site_aggregates},
   source::{
+    person::{Person, PersonSafe},
     site::Site,
-    person::{PersonSafe, Person},
   },
 };
 use serde::Serialize;
index 6673acb536aff7692236bddb50cbc6b198f349c9..337c28cd073db5cdc1992221acc133b60e96e8ca 100644 (file)
@@ -4,7 +4,7 @@ use lemmy_db_schema::{
   schema::{community, community_follower, person},
   source::{
     community::{Community, CommunitySafe},
-    person::{PersonSafe, Person},
+    person::{Person, PersonSafe},
   },
 };
 use serde::Serialize;
@@ -22,7 +22,10 @@ impl CommunityFollowerView {
     let res = community_follower::table
       .inner_join(community::table)
       .inner_join(person::table)
-      .select((Community::safe_columns_tuple(), Person::safe_columns_tuple()))
+      .select((
+        Community::safe_columns_tuple(),
+        Person::safe_columns_tuple(),
+      ))
       .filter(community_follower::community_id.eq(community_id))
       .order_by(community_follower::published)
       .load::<CommunityFollowerViewTuple>(conn)?;
@@ -34,7 +37,10 @@ impl CommunityFollowerView {
     let res = community_follower::table
       .inner_join(community::table)
       .inner_join(person::table)
-      .select((Community::safe_columns_tuple(), Person::safe_columns_tuple()))
+      .select((
+        Community::safe_columns_tuple(),
+        Person::safe_columns_tuple(),
+      ))
       .filter(community_follower::person_id.eq(person_id))
       .order_by(community_follower::published)
       .load::<CommunityFollowerViewTuple>(conn)?;
index 7cc208472e128829be6c7ae8c156cefb91b1ae7c..bdddf917f4625e051b94e06dff485bb15a293f1f 100644 (file)
@@ -4,7 +4,7 @@ use lemmy_db_schema::{
   schema::{community, community_moderator, person},
   source::{
     community::{Community, CommunitySafe},
-    person::{PersonSafe, Person},
+    person::{Person, PersonSafe},
   },
 };
 use serde::Serialize;
@@ -22,7 +22,10 @@ impl CommunityModeratorView {
     let res = community_moderator::table
       .inner_join(community::table)
       .inner_join(person::table)
-      .select((Community::safe_columns_tuple(), Person::safe_columns_tuple()))
+      .select((
+        Community::safe_columns_tuple(),
+        Person::safe_columns_tuple(),
+      ))
       .filter(community_moderator::community_id.eq(community_id))
       .order_by(community_moderator::published)
       .load::<CommunityModeratorViewTuple>(conn)?;
@@ -34,7 +37,10 @@ impl CommunityModeratorView {
     let res = community_moderator::table
       .inner_join(community::table)
       .inner_join(person::table)
-      .select((Community::safe_columns_tuple(), Person::safe_columns_tuple()))
+      .select((
+        Community::safe_columns_tuple(),
+        Person::safe_columns_tuple(),
+      ))
       .filter(community_moderator::person_id.eq(person_id))
       .order_by(community_moderator::published)
       .load::<CommunityModeratorViewTuple>(conn)?;
index 651fcbf8ea060bd7f8a14503692cf1a16514a42c..c63d15a0fe9028873e69deb077a1bfbbb3133430 100644 (file)
@@ -4,7 +4,7 @@ use lemmy_db_schema::{
   schema::{community, community_person_ban, person},
   source::{
     community::{Community, CommunitySafe},
-    person::{PersonSafe, Person},
+    person::{Person, PersonSafe},
   },
 };
 use serde::Serialize;
@@ -24,7 +24,10 @@ impl CommunityPersonBanView {
     let (community, person) = community_person_ban::table
       .inner_join(community::table)
       .inner_join(person::table)
-      .select((Community::safe_columns_tuple(), Person::safe_columns_tuple()))
+      .select((
+        Community::safe_columns_tuple(),
+        Person::safe_columns_tuple(),
+      ))
       .filter(community_person_ban::community_id.eq(from_community_id))
       .filter(community_person_ban::person_id.eq(from_person_id))
       .order_by(community_person_ban::published)
index 47d0b1e225fee3ff4f1543647c403fcfbaff2991..2e7f1746d48629cd24a6569013f90aa9057e31f7 100644 (file)
@@ -15,7 +15,7 @@ use lemmy_db_schema::{
   schema::{community, community_aggregates, community_follower, person},
   source::{
     community::{Community, CommunityFollower, CommunitySafe},
-    person::{PersonSafe, Person},
+    person::{Person, PersonSafe},
   },
 };
 use serde::Serialize;
@@ -78,8 +78,9 @@ impl CommunityView {
       &mut CommunityModeratorView::for_community(conn, community_id)
         .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?,
     );
-    mods_and_admins
-      .append(&mut PersonViewSafe::admins(conn).map(|v| v.into_iter().map(|a| a.person.id).collect())?);
+    mods_and_admins.append(
+      &mut PersonViewSafe::admins(conn).map(|v| v.into_iter().map(|a| a.person.id).collect())?,
+    );
     Ok(mods_and_admins)
   }
 
index 5d7ee983302667141a4e246d5a0e03793e51debe..daa6599b25eff3b919e05c9d8a98f218ae5dff40 100644 (file)
@@ -17,17 +17,17 @@ use lemmy_db_schema::{
     community,
     community_follower,
     community_person_ban,
-    post,
     person,
     person_alias_1,
     person_mention,
+    post,
   },
   source::{
     comment::{Comment, CommentSaved},
-    community::{Community, CommunityFollower, CommunitySafe, CommunityPersonBan},
-    post::Post,
-    person::{PersonAlias1, PersonSafe, PersonSafeAlias1, Person},
+    community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
+    person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
     person_mention::PersonMention,
+    post::Post,
   },
 };
 use serde::Serialize;
index ff936d6de5d5e05afb94faf9f02f93d568e5e8fe..920e59009d6222794f89c93eafade8d39d96eae2 100644 (file)
@@ -9,8 +9,8 @@ use lemmy_db_queries::{
   ViewToVec,
 };
 use lemmy_db_schema::{
-  schema::{person, person_aggregates, local_user},
-  source::person::{PersonSafe, Person},
+  schema::{local_user, person, person_aggregates},
+  source::person::{Person, PersonSafe},
 };
 use serde::Serialize;
 
index 32988c1900cf7a9581a427d612df96f3daec3c29..8fabe74092eceddfbd0a2d8f90e4dbdb3dc0d89d 100644 (file)
@@ -5,7 +5,7 @@ use lemmy_db_schema::{
   source::{
     community::{Community, CommunitySafe},
     moderator::ModAddCommunity,
-    person::{PersonAlias1, PersonSafe, PersonSafeAlias1, Person},
+    person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
   },
 };
 use serde::Serialize;
@@ -31,7 +31,9 @@ impl ModAddCommunityView {
     let mut query = mod_add_community::table
       .inner_join(person::table.on(mod_add_community::mod_person_id.eq(person::id)))
       .inner_join(community::table)
-      .inner_join(person_alias_1::table.on(mod_add_community::other_person_id.eq(person_alias_1::id)))
+      .inner_join(
+        person_alias_1::table.on(mod_add_community::other_person_id.eq(person_alias_1::id)),
+      )
       .select((
         mod_add_community::all_columns,
         Person::safe_columns_tuple(),
index e4a665c5e748ec15cb40743d90d9a49d8b0155fd..a6ce447227bd46f6ae8aa80c6fb78bb23e994dbf 100644 (file)
@@ -4,7 +4,7 @@ use lemmy_db_schema::{
   schema::{mod_add, person, person_alias_1},
   source::{
     moderator::ModAdd,
-    person::{PersonAlias1, PersonSafe, PersonSafeAlias1, Person},
+    person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
   },
 };
 use serde::Serialize;
index a60ede61be6a1d9d28fc6d744c22cecb7ff9af7c..2d16edb0422c6c03d945613745141b473133b72d 100644 (file)
@@ -5,7 +5,7 @@ use lemmy_db_schema::{
   source::{
     community::{Community, CommunitySafe},
     moderator::ModBanFromCommunity,
-    person::{PersonAlias1, PersonSafe, PersonSafeAlias1, Person},
+    person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
   },
 };
 use serde::Serialize;
@@ -18,7 +18,12 @@ pub struct ModBanFromCommunityView {
   pub banned_person: PersonSafeAlias1,
 }
 
-type ModBanFromCommunityViewTuple = (ModBanFromCommunity, PersonSafe, CommunitySafe, PersonSafeAlias1);
+type ModBanFromCommunityViewTuple = (
+  ModBanFromCommunity,
+  PersonSafe,
+  CommunitySafe,
+  PersonSafeAlias1,
+);
 
 impl ModBanFromCommunityView {
   pub fn list(
index 2c55d5149b6c8246c38a7a4b302ac1f6cd883d70..2a3c1864f88115910c213fdf972d590e555cd49a 100644 (file)
@@ -4,7 +4,7 @@ use lemmy_db_schema::{
   schema::{mod_ban, person, person_alias_1},
   source::{
     moderator::ModBan,
-    person::{PersonAlias1, PersonSafe, PersonSafeAlias1, Person},
+    person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
   },
 };
 use serde::Serialize;
index 9369ba99b23d3b6e60597e0a906ba9f09a36c34f..5f5e7346eeb4e130366fb5dbf0c488a8949d9461 100644 (file)
@@ -1,12 +1,12 @@
 use diesel::{result::Error, *};
 use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
-  schema::{community, mod_lock_post, post, person},
+  schema::{community, mod_lock_post, person, post},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModLockPost,
+    person::{Person, PersonSafe},
     post::Post,
-    person::{PersonSafe, Person},
   },
 };
 use serde::Serialize;
index 9633f2009c025705be4acbc9e7ccd86790a0f448..2e8dfccc00fe049fa0ebf9812ac6105b13e1cd3e 100644 (file)
@@ -1,13 +1,13 @@
 use diesel::{result::Error, *};
 use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
-  schema::{comment, community, mod_remove_comment, post, person, person_alias_1},
+  schema::{comment, community, mod_remove_comment, person, person_alias_1, post},
   source::{
     comment::Comment,
     community::{Community, CommunitySafe},
     moderator::ModRemoveComment,
+    person::{Person, PersonAlias1, PersonSafe, PersonSafeAlias1},
     post::Post,
-    person::{PersonAlias1, PersonSafe, PersonSafeAlias1, Person},
   },
 };
 use serde::Serialize;
index 6d49acbe5d1e17dc1fc6dc261a4a1a46ca42f1fa..767bcdc40ab89b6469032bfcebd0e12a958dbc2b 100644 (file)
@@ -5,7 +5,7 @@ use lemmy_db_schema::{
   source::{
     community::{Community, CommunitySafe},
     moderator::ModRemoveCommunity,
-    person::{PersonSafe, Person},
+    person::{Person, PersonSafe},
   },
 };
 use serde::Serialize;
index 8530656cc29e36a5f99ff64ea52f41c9bab45a59..7456ff8a699c8718c530cbb7b7a25d0a76160b18 100644 (file)
@@ -1,12 +1,12 @@
 use diesel::{result::Error, *};
 use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
-  schema::{community, mod_remove_post, post, person},
+  schema::{community, mod_remove_post, person, post},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModRemovePost,
+    person::{Person, PersonSafe},
     post::Post,
-    person::{PersonSafe, Person},
   },
 };
 use serde::Serialize;
index 9f4ea4af6303efa02c31d2626109573b8cc5d575..c0629a4e35d7929a29528389ad281d3d23b1445c 100644 (file)
@@ -1,12 +1,12 @@
 use diesel::{result::Error, *};
 use lemmy_db_queries::{limit_and_offset, ToSafe, ViewToVec};
 use lemmy_db_schema::{
-  schema::{community, mod_sticky_post, post, person},
+  schema::{community, mod_sticky_post, person, post},
   source::{
     community::{Community, CommunitySafe},
     moderator::ModStickyPost,
+    person::{Person, PersonSafe},
     post::Post,
-    person::{PersonSafe, Person},
   },
 };
 use serde::Serialize;
index 009b7afb6257841937046f049703dab5bde66393..bd67fe699da6509b9ccf662129cc25f240b94765 100644 (file)
@@ -19,9 +19,9 @@ use lemmy_db_schema::{
   source::{
     comment::Comment,
     community::{Community, CommunityForm},
+    person::{Person, PersonForm},
     post::Post,
     private_message::PrivateMessage,
-    user::{UserForm, User_},
   },
 };
 use lemmy_utils::{apub::generate_actor_keypair, settings::structs::Settings, LemmyError};
@@ -40,52 +40,42 @@ pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), LemmyError> {
 }
 
 fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
-  use lemmy_db_schema::schema::user_::dsl::*;
+  use lemmy_db_schema::schema::person::dsl::*;
 
   info!("Running user_updates_2020_04_02");
 
   // Update the actor_id, private_key, and public_key, last_refreshed_at
-  let incorrect_users = user_
+  let incorrect_persons = person
     .filter(actor_id.like("http://changeme_%"))
     .filter(local.eq(true))
-    .load::<User_>(conn)?;
+    .load::<Person>(conn)?;
 
-  for cuser in &incorrect_users {
+  for cperson in &incorrect_persons {
     let keypair = generate_actor_keypair()?;
 
-    let form = UserForm {
-      name: cuser.name.to_owned(),
-      email: Some(cuser.email.to_owned()),
-      matrix_user_id: Some(cuser.matrix_user_id.to_owned()),
-      avatar: Some(cuser.avatar.to_owned()),
-      banner: Some(cuser.banner.to_owned()),
-      password_encrypted: cuser.password_encrypted.to_owned(),
-      preferred_username: Some(cuser.preferred_username.to_owned()),
-      published: Some(cuser.published),
+    let form = PersonForm {
+      name: cperson.name.to_owned(),
+      avatar: None,
+      banner: None,
+      preferred_username: None,
+      published: None,
       updated: None,
-      admin: cuser.admin,
-      banned: Some(cuser.banned),
-      show_nsfw: cuser.show_nsfw,
-      theme: cuser.theme.to_owned(),
-      default_sort_type: cuser.default_sort_type,
-      default_listing_type: cuser.default_listing_type,
-      lang: cuser.lang.to_owned(),
-      show_avatars: cuser.show_avatars,
-      send_notifications_to_email: cuser.send_notifications_to_email,
-      actor_id: Some(generate_apub_endpoint(EndpointType::Person, &cuser.name)?),
-      bio: Some(cuser.bio.to_owned()),
-      local: cuser.local,
-      private_key: Some(keypair.private_key),
-      public_key: Some(keypair.public_key),
+      banned: None,
+      deleted: None,
+      actor_id: Some(generate_apub_endpoint(EndpointType::Person, &cperson.name)?),
+      bio: None,
+      local: None,
+      private_key: Some(Some(keypair.private_key)),
+      public_key: Some(Some(keypair.public_key)),
       last_refreshed_at: Some(naive_now()),
       inbox_url: None,
       shared_inbox_url: None,
     };
 
-    User_::update(&conn, cuser.id, &form)?;
+    Person::update(&conn, cperson.id, &form)?;
   }
 
-  info!("{} user rows updated.", incorrect_users.len());
+  info!("{} person rows updated.", incorrect_persons.len());
 
   Ok(())
 }
@@ -231,20 +221,20 @@ fn post_thumbnail_url_updates_2020_07_27(conn: &PgConnection) -> Result<(), Lemm
 fn apub_columns_2021_02_02(conn: &PgConnection) -> Result<(), LemmyError> {
   info!("Running apub_columns_2021_02_02");
   {
-    use lemmy_db_schema::schema::user_::dsl::*;
-    let users = user_
+    use lemmy_db_schema::schema::person::dsl::*;
+    let persons = person
       .filter(inbox_url.like("http://changeme_%"))
-      .load::<User_>(conn)?;
+      .load::<Person>(conn)?;
 
-    for u in &users {
-      let inbox_url_ = generate_inbox_url(&u.actor_id)?;
-      let shared_inbox_url_ = generate_shared_inbox_url(&u.actor_id)?;
-      diesel::update(user_.find(u.id))
+    for p in &persons {
+      let inbox_url_ = generate_inbox_url(&p.actor_id)?;
+      let shared_inbox_url_ = generate_shared_inbox_url(&p.actor_id)?;
+      diesel::update(person.find(p.id))
         .set((
           inbox_url.eq(inbox_url_),
           shared_inbox_url.eq(shared_inbox_url_),
         ))
-        .get_result::<User_>(conn)?;
+        .get_result::<Person>(conn)?;
     }
   }