2 use actix_web::web::Data;
3 use lemmy_api_common::{get_local_user_view_from_jwt, websocket::*};
4 use lemmy_utils::{ConnectionId, LemmyError};
6 messages::{JoinCommunityRoom, JoinModRoom, JoinPostRoom, JoinUserRoom},
10 #[async_trait::async_trait(?Send)]
11 impl Perform for UserJoin {
12 type Response = UserJoinResponse;
16 context: &Data<LemmyContext>,
17 websocket_id: Option<ConnectionId>,
18 ) -> Result<UserJoinResponse, LemmyError> {
19 let data: &UserJoin = self;
21 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
23 if let Some(ws_id) = websocket_id {
24 context.chat_server().do_send(JoinUserRoom {
25 local_user_id: local_user_view.local_user.id,
30 Ok(UserJoinResponse { joined: true })
34 #[async_trait::async_trait(?Send)]
35 impl Perform for CommunityJoin {
36 type Response = CommunityJoinResponse;
40 context: &Data<LemmyContext>,
41 websocket_id: Option<ConnectionId>,
42 ) -> Result<CommunityJoinResponse, LemmyError> {
43 let data: &CommunityJoin = self;
45 if let Some(ws_id) = websocket_id {
46 context.chat_server().do_send(JoinCommunityRoom {
47 community_id: data.community_id,
52 Ok(CommunityJoinResponse { joined: true })
56 #[async_trait::async_trait(?Send)]
57 impl Perform for ModJoin {
58 type Response = ModJoinResponse;
62 context: &Data<LemmyContext>,
63 websocket_id: Option<ConnectionId>,
64 ) -> Result<ModJoinResponse, LemmyError> {
65 let data: &ModJoin = self;
67 if let Some(ws_id) = websocket_id {
68 context.chat_server().do_send(JoinModRoom {
69 community_id: data.community_id,
74 Ok(ModJoinResponse { joined: true })
78 #[async_trait::async_trait(?Send)]
79 impl Perform for PostJoin {
80 type Response = PostJoinResponse;
84 context: &Data<LemmyContext>,
85 websocket_id: Option<ConnectionId>,
86 ) -> Result<PostJoinResponse, LemmyError> {
87 let data: &PostJoin = self;
89 if let Some(ws_id) = websocket_id {
90 context.chat_server().do_send(JoinPostRoom {
91 post_id: data.post_id,
96 Ok(PostJoinResponse { joined: true })