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;
14 #[tracing::instrument(skip(context, websocket_id))]
17 context: &Data<LemmyContext>,
18 websocket_id: Option<ConnectionId>,
19 ) -> Result<UserJoinResponse, LemmyError> {
20 let data: &UserJoin = self;
22 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
24 if let Some(ws_id) = websocket_id {
25 context.chat_server().do_send(JoinUserRoom {
26 local_user_id: local_user_view.local_user.id,
31 Ok(UserJoinResponse { joined: true })
35 #[async_trait::async_trait(?Send)]
36 impl Perform for CommunityJoin {
37 type Response = CommunityJoinResponse;
39 #[tracing::instrument(skip(context, websocket_id))]
42 context: &Data<LemmyContext>,
43 websocket_id: Option<ConnectionId>,
44 ) -> Result<CommunityJoinResponse, LemmyError> {
45 let data: &CommunityJoin = self;
47 if let Some(ws_id) = websocket_id {
48 context.chat_server().do_send(JoinCommunityRoom {
49 community_id: data.community_id,
54 Ok(CommunityJoinResponse { joined: true })
58 #[async_trait::async_trait(?Send)]
59 impl Perform for ModJoin {
60 type Response = ModJoinResponse;
62 #[tracing::instrument(skip(context, websocket_id))]
65 context: &Data<LemmyContext>,
66 websocket_id: Option<ConnectionId>,
67 ) -> Result<ModJoinResponse, LemmyError> {
68 let data: &ModJoin = self;
70 if let Some(ws_id) = websocket_id {
71 context.chat_server().do_send(JoinModRoom {
72 community_id: data.community_id,
77 Ok(ModJoinResponse { joined: true })
81 #[async_trait::async_trait(?Send)]
82 impl Perform for PostJoin {
83 type Response = PostJoinResponse;
85 #[tracing::instrument(skip(context, websocket_id))]
88 context: &Data<LemmyContext>,
89 websocket_id: Option<ConnectionId>,
90 ) -> Result<PostJoinResponse, LemmyError> {
91 let data: &PostJoin = self;
93 if let Some(ws_id) = websocket_id {
94 context.chat_server().do_send(JoinPostRoom {
95 post_id: data.post_id,
100 Ok(PostJoinResponse { joined: true })