]> Untitled Git - lemmy.git/blobdiff - crates/api/src/lib.rs
First pass at adding comment trees. (#2362)
[lemmy.git] / crates / api / src / lib.rs
index 26a41d3d22b350af5e2cd715d1ef9f5f8e00d0c3..026045dd2a0c7f368f8fcb8f4491f958fda18391 100644 (file)
@@ -1,7 +1,7 @@
 use actix_web::{web, web::Data};
 use captcha::Captcha;
 use lemmy_api_common::{comment::*, community::*, person::*, post::*, site::*, websocket::*};
-use lemmy_utils::{ConnectionId, LemmyError};
+use lemmy_utils::{error::LemmyError, ConnectionId};
 use lemmy_websocket::{serialize_websocket_message, LemmyContext, UserOperation};
 use serde::Deserialize;
 
@@ -48,6 +48,9 @@ pub async fn match_websocket_operation(
       do_websocket_operation::<ApproveRegistrationApplication>(context, id, op, data).await
     }
     UserOperation::BanPerson => do_websocket_operation::<BanPerson>(context, id, op, data).await,
+    UserOperation::GetBannedPersons => {
+      do_websocket_operation::<GetBannedPersons>(context, id, op, data).await
+    }
     UserOperation::BlockPerson => {
       do_websocket_operation::<BlockPerson>(context, id, op, data).await
     }
@@ -57,6 +60,9 @@ pub async fn match_websocket_operation(
     UserOperation::MarkPersonMentionAsRead => {
       do_websocket_operation::<MarkPersonMentionAsRead>(context, id, op, data).await
     }
+    UserOperation::MarkCommentReplyAsRead => {
+      do_websocket_operation::<MarkCommentReplyAsRead>(context, id, op, data).await
+    }
     UserOperation::MarkAllAsRead => {
       do_websocket_operation::<MarkAllAsRead>(context, id, op, data).await
     }
@@ -64,7 +70,7 @@ pub async fn match_websocket_operation(
       do_websocket_operation::<PasswordReset>(context, id, op, data).await
     }
     UserOperation::PasswordChange => {
-      do_websocket_operation::<PasswordChange>(context, id, op, data).await
+      do_websocket_operation::<PasswordChangeAfterReset>(context, id, op, data).await
     }
     UserOperation::UserJoin => do_websocket_operation::<UserJoin>(context, id, op, data).await,
     UserOperation::PostJoin => do_websocket_operation::<PostJoin>(context, id, op, data).await,
@@ -95,11 +101,15 @@ pub async fn match_websocket_operation(
 
     // Site ops
     UserOperation::GetModlog => do_websocket_operation::<GetModlog>(context, id, op, data).await,
-    UserOperation::GetSiteConfig => {
-      do_websocket_operation::<GetSiteConfig>(context, id, op, data).await
+    UserOperation::PurgePerson => {
+      do_websocket_operation::<PurgePerson>(context, id, op, data).await
+    }
+    UserOperation::PurgeCommunity => {
+      do_websocket_operation::<PurgeCommunity>(context, id, op, data).await
     }
-    UserOperation::SaveSiteConfig => {
-      do_websocket_operation::<SaveSiteConfig>(context, id, op, data).await
+    UserOperation::PurgePost => do_websocket_operation::<PurgePost>(context, id, op, data).await,
+    UserOperation::PurgeComment => {
+      do_websocket_operation::<PurgeComment>(context, id, op, data).await
     }
     UserOperation::Search => do_websocket_operation::<Search>(context, id, op, data).await,
     UserOperation::ResolveObject => {
@@ -108,9 +118,7 @@ pub async fn match_websocket_operation(
     UserOperation::TransferCommunity => {
       do_websocket_operation::<TransferCommunity>(context, id, op, data).await
     }
-    UserOperation::TransferSite => {
-      do_websocket_operation::<TransferSite>(context, id, op, data).await
-    }
+    UserOperation::LeaveAdmin => do_websocket_operation::<LeaveAdmin>(context, id, op, data).await,
 
     // Community ops
     UserOperation::FollowCommunity => {
@@ -150,9 +158,6 @@ pub async fn match_websocket_operation(
     }
 
     // Comment ops
-    UserOperation::MarkCommentAsRead => {
-      do_websocket_operation::<MarkCommentAsRead>(context, id, op, data).await
-    }
     UserOperation::SaveComment => {
       do_websocket_operation::<SaveComment>(context, id, op, data).await
     }
@@ -205,26 +210,27 @@ pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> String {
 
 #[cfg(test)]
 mod tests {
-  use lemmy_api_common::check_validator_time;
+  use lemmy_api_common::utils::check_validator_time;
   use lemmy_db_schema::{
-    establish_unpooled_connection,
     source::{
       local_user::{LocalUser, LocalUserForm},
       person::{Person, PersonForm},
       secret::Secret,
     },
     traits::Crud,
+    utils::establish_unpooled_connection,
   };
-  use lemmy_utils::{claims::Claims, settings::structs::Settings};
+  use lemmy_utils::{claims::Claims, settings::SETTINGS};
 
   #[test]
   fn test_should_not_validate_user_token_after_password_change() {
     let conn = establish_unpooled_connection();
     let secret = Secret::init(&conn).unwrap();
-    let settings = Settings::init().unwrap();
+    let settings = &SETTINGS.to_owned();
 
     let new_person = PersonForm {
       name: "Gerry9812".into(),
+      public_key: Some("pubkey".to_string()),
       ..PersonForm::default()
     };