]> Untitled Git - lemmy.git/blobdiff - src/api/post.rs
Isomorphic docker (#1124)
[lemmy.git] / src / api / post.rs
similarity index 97%
rename from server/src/api/post.rs
rename to src/api/post.rs
index a1801d0f2adb2ba2d9749349fa7b4466ddf690b2..d38c10c9de7aeb4d45af550884e41472cbcdf006 100644 (file)
@@ -3,7 +3,7 @@ use crate::{
   apub::{ApubLikeableType, ApubObjectType},
   fetch_iframely_and_pictrs_data,
   websocket::{
-    messages::{GetPostUsersOnline, JoinCommunityRoom, JoinPostRoom, SendPost},
+    messages::{GetPostUsersOnline, JoinPostRoom, SendPost},
     UserOperation,
   },
   LemmyContext,
@@ -159,7 +159,7 @@ impl Perform for GetPost {
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
+    _websocket_id: Option<ConnectionId>,
   ) -> Result<GetPostResponse, LemmyError> {
     let data: &GetPost = &self;
     let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
@@ -197,13 +197,6 @@ impl Perform for GetPost {
     })
     .await??;
 
-    if let Some(id) = websocket_id {
-      context.chat_server().do_send(JoinPostRoom {
-        post_id: data.id,
-        id,
-      });
-    }
-
     let online = context
       .chat_server()
       .send(GetPostUsersOnline { post_id: data.id })
@@ -228,7 +221,7 @@ impl Perform for GetPosts {
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
-    websocket_id: Option<ConnectionId>,
+    _websocket_id: Option<ConnectionId>,
   ) -> Result<GetPostsResponse, LemmyError> {
     let data: &GetPosts = &self;
     let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
@@ -268,18 +261,6 @@ impl Perform for GetPosts {
       Err(_e) => return Err(APIError::err("couldnt_get_posts").into()),
     };
 
-    if let Some(id) = websocket_id {
-      // You don't need to join the specific community room, bc this is already handled by
-      // GetCommunity
-      if data.community_id.is_none() {
-        // 0 is the "all" community
-        context.chat_server().do_send(JoinCommunityRoom {
-          community_id: 0,
-          id,
-        });
-      }
-    }
-
     Ok(GetPostsResponse { posts })
   }
 }
@@ -739,3 +720,25 @@ impl Perform for SavePost {
     Ok(PostResponse { post: post_view })
   }
 }
+
+#[async_trait::async_trait(?Send)]
+impl Perform for PostJoin {
+  type Response = PostJoinResponse;
+
+  async fn perform(
+    &self,
+    context: &Data<LemmyContext>,
+    websocket_id: Option<ConnectionId>,
+  ) -> Result<PostJoinResponse, LemmyError> {
+    let data: &PostJoin = &self;
+
+    if let Some(ws_id) = websocket_id {
+      context.chat_server().do_send(JoinPostRoom {
+        post_id: data.post_id,
+        id: ws_id,
+      });
+    }
+
+    Ok(PostJoinResponse { joined: true })
+  }
+}