2 use actix_web::web::Data;
3 use lemmy_api_common::{
5 utils::get_local_user_view_from_jwt,
7 messages::{JoinCommunityRoom, JoinModRoom, JoinPostRoom, JoinUserRoom},
10 CommunityJoinResponse,
20 use lemmy_utils::{error::LemmyError, ConnectionId};
22 #[async_trait::async_trait(?Send)]
23 impl Perform for UserJoin {
24 type Response = UserJoinResponse;
26 #[tracing::instrument(skip(context, websocket_id))]
29 context: &Data<LemmyContext>,
30 websocket_id: Option<ConnectionId>,
31 ) -> Result<UserJoinResponse, LemmyError> {
32 let data: &UserJoin = self;
34 get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
36 if let Some(ws_id) = websocket_id {
37 context.chat_server().do_send(JoinUserRoom {
38 local_user_id: local_user_view.local_user.id,
43 Ok(UserJoinResponse { joined: true })
47 #[async_trait::async_trait(?Send)]
48 impl Perform for CommunityJoin {
49 type Response = CommunityJoinResponse;
51 #[tracing::instrument(skip(context, websocket_id))]
54 context: &Data<LemmyContext>,
55 websocket_id: Option<ConnectionId>,
56 ) -> Result<CommunityJoinResponse, LemmyError> {
57 let data: &CommunityJoin = self;
59 if let Some(ws_id) = websocket_id {
60 context.chat_server().do_send(JoinCommunityRoom {
61 community_id: data.community_id,
66 Ok(CommunityJoinResponse { joined: true })
70 #[async_trait::async_trait(?Send)]
71 impl Perform for ModJoin {
72 type Response = ModJoinResponse;
74 #[tracing::instrument(skip(context, websocket_id))]
77 context: &Data<LemmyContext>,
78 websocket_id: Option<ConnectionId>,
79 ) -> Result<ModJoinResponse, LemmyError> {
80 let data: &ModJoin = self;
82 if let Some(ws_id) = websocket_id {
83 context.chat_server().do_send(JoinModRoom {
84 community_id: data.community_id,
89 Ok(ModJoinResponse { joined: true })
93 #[async_trait::async_trait(?Send)]
94 impl Perform for PostJoin {
95 type Response = PostJoinResponse;
97 #[tracing::instrument(skip(context, websocket_id))]
100 context: &Data<LemmyContext>,
101 websocket_id: Option<ConnectionId>,
102 ) -> Result<PostJoinResponse, LemmyError> {
103 let data: &PostJoin = self;
105 if let Some(ws_id) = websocket_id {
106 context.chat_server().do_send(JoinPostRoom {
107 post_id: data.post_id,
112 Ok(PostJoinResponse { joined: true })