1 use crate::{get_user_from_jwt, Perform};
2 use actix_web::web::Data;
3 use lemmy_api_structs::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;
20 let user = get_user_from_jwt(&data.auth, context.pool()).await?;
22 if let Some(ws_id) = websocket_id {
23 context.chat_server().do_send(JoinUserRoom {
29 Ok(UserJoinResponse { joined: true })
33 #[async_trait::async_trait(?Send)]
34 impl Perform for CommunityJoin {
35 type Response = CommunityJoinResponse;
39 context: &Data<LemmyContext>,
40 websocket_id: Option<ConnectionId>,
41 ) -> Result<CommunityJoinResponse, LemmyError> {
42 let data: &CommunityJoin = &self;
44 if let Some(ws_id) = websocket_id {
45 context.chat_server().do_send(JoinCommunityRoom {
46 community_id: data.community_id,
51 Ok(CommunityJoinResponse { joined: true })
55 #[async_trait::async_trait(?Send)]
56 impl Perform for ModJoin {
57 type Response = ModJoinResponse;
61 context: &Data<LemmyContext>,
62 websocket_id: Option<ConnectionId>,
63 ) -> Result<ModJoinResponse, LemmyError> {
64 let data: &ModJoin = &self;
66 if let Some(ws_id) = websocket_id {
67 context.chat_server().do_send(JoinModRoom {
68 community_id: data.community_id,
73 Ok(ModJoinResponse { joined: true })
77 #[async_trait::async_trait(?Send)]
78 impl Perform for PostJoin {
79 type Response = PostJoinResponse;
83 context: &Data<LemmyContext>,
84 websocket_id: Option<ConnectionId>,
85 ) -> Result<PostJoinResponse, LemmyError> {
86 let data: &PostJoin = &self;
88 if let Some(ws_id) = websocket_id {
89 context.chat_server().do_send(JoinPostRoom {
90 post_id: data.post_id,
95 Ok(PostJoinResponse { joined: true })