]> Untitled Git - lemmy.git/blob - crates/apub/src/fetcher/deletable_apub_object.rs
Check user accepted before sending jwt in password reset (fixes #2591) (#2597)
[lemmy.git] / crates / apub / src / fetcher / deletable_apub_object.rs
1 use crate::fetcher::post_or_comment::PostOrComment;
2 use lemmy_db_queries::source::{
3   comment::Comment_,
4   community::Community_,
5   person::Person_,
6   post::Post_,
7 };
8 use lemmy_db_schema::source::{
9   comment::Comment,
10   community::Community,
11   person::Person,
12   post::Post,
13   site::Site,
14 };
15 use lemmy_utils::LemmyError;
16 use lemmy_websocket::LemmyContext;
17
18 // TODO: merge this trait with ApubObject (means that db_schema needs to depend on apub_lib)
19 #[async_trait::async_trait(?Send)]
20 pub trait DeletableApubObject {
21   // TODO: pass in tombstone with summary field, to decide between remove/delete
22   async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError>;
23 }
24
25 #[async_trait::async_trait(?Send)]
26 impl DeletableApubObject for Community {
27   async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
28     let id = self.id;
29       Community::update_deleted(context.pool(), id, true)
30     .await?;
31     Ok(())
32   }
33 }
34
35 #[async_trait::async_trait(?Send)]
36 impl DeletableApubObject for Person {
37   async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
38     let id = self.id;
39     Person::delete_account(context.pool(), id).await?;
40     Ok(())
41   }
42 }
43
44 #[async_trait::async_trait(?Send)]
45 impl DeletableApubObject for Post {
46   async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
47     let id = self.id;
48       Post::update_deleted(context.pool(), id, true)
49     .await?;
50     Ok(())
51   }
52 }
53
54 #[async_trait::async_trait(?Send)]
55 impl DeletableApubObject for Comment {
56   async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
57     let id = self.id;
58       Comment::update_deleted(context.pool(), id, true)
59     .await?;
60     Ok(())
61   }
62 }
63
64 #[async_trait::async_trait(?Send)]
65 impl DeletableApubObject for PostOrComment {
66   async fn delete(self, context: &LemmyContext) -> Result<(), LemmyError> {
67     match self {
68       PostOrComment::Comment(c) => {
69           Comment::update_deleted(context.pool(), c.id, true)
70         .await?;
71       }
72       PostOrComment::Post(p) => {
73           Post::update_deleted(context.pool(), p.id, true)
74         .await?;
75       }
76     }
77
78     Ok(())
79   }
80 }
81
82 #[async_trait::async_trait(?Send)]
83 impl DeletableApubObject for Site {
84   async fn delete(self, _context: &LemmyContext) -> Result<(), LemmyError> {
85     // not implemented, ignore
86     Ok(())
87   }
88 }