Browse Source

community join room endpoint

feature/join-room-endpoints
John Doe 1 year ago
parent
commit
7d81eb266b
  1. 10
      server/lemmy_api_structs/src/community.rs
  2. 24
      server/src/api/community.rs
  3. 1
      server/src/websocket/chat_server.rs
  4. 1
      server/src/websocket/mod.rs

10
server/lemmy_api_structs/src/community.rs

@ -131,3 +131,13 @@ pub struct TransferCommunity {
pub user_id: i32,
pub auth: String,
}
#[derive(Serialize, Deserialize)]
pub struct CommunityJoinRoom {
pub community_id: i32,
}
#[derive(Serialize, Deserialize)]
pub struct CommunityJoinRoomResponse {
pub community_id: i32,
}

24
server/src/api/community.rs

@ -883,6 +883,30 @@ impl Perform for TransferCommunity {
}
}
#[async_trait::async_trait(?Send)]
impl Perform for CommunityJoinRoom {
type Response = CommunityJoinRoomResponse;
async fn perform(
&self,
context: &Data<LemmyContext>,
websocket_id: Option<ConnectionId>,
) -> Result<CommunityJoinRoomResponse, LemmyError> {
let data: &CommunityJoinRoom = &self;
if let Some(ws_id) = websocket_id {
context.chat_server().do_send(JoinCommunityRoom {
community_id: data.community_id,
id: ws_id,
});
}
Ok(CommunityJoinRoomResponse {
community_id: data.community_id,
})
}
}
pub fn send_community_websocket(
res: &CommunityResponse,
context: &Data<LemmyContext>,

1
server/src/websocket/chat_server.rs

@ -508,6 +508,7 @@ impl ChatServer {
UserOperation::FeaturePost => do_user_operation::<FeaturePost>(args).await,
UserOperation::LeaveRooms => do_user_operation::<LeaveRooms>(args).await,
UserOperation::PostJoin => do_user_operation::<PostJoin>(args).await,
UserOperation::CommunityJoinRoom => do_user_operation::<CommunityJoinRoom>(args).await,
}
}
}

1
server/src/websocket/mod.rs

@ -80,4 +80,5 @@ pub enum UserOperation {
FeaturePost,
LeaveRooms,
PostJoin,
CommunityJoinRoom,
}
Loading…
Cancel
Save