1 use crate::{comment::CommentResponse, post::PostResponse, websocket::UserOperation};
2 use actix::{prelude::*, Recipient};
3 use lemmy_db_schema::newtypes::{CommunityId, LocalUserId, PostId};
4 use lemmy_utils::{ConnectionId, IpAddr};
5 use serde::{Deserialize, Serialize};
7 /// Chat server sends this messages to session
9 #[rtype(result = "()")]
10 pub struct WsMessage(pub String);
12 /// Message for chat server communications
14 /// New chat session is created
18 pub addr: Recipient<WsMessage>,
22 /// Session is disconnected
24 #[rtype(result = "()")]
25 pub struct Disconnect {
30 /// The messages sent to websocket clients
31 #[derive(Serialize, Deserialize, Message)]
32 #[rtype(result = "Result<String, std::convert::Infallible>")]
33 pub struct StandardMessage {
34 /// Id of the client session
41 #[rtype(result = "()")]
42 pub struct SendAllMessage<OP: ToString, Response> {
44 pub response: Response,
45 pub websocket_id: Option<ConnectionId>,
49 #[rtype(result = "()")]
50 pub struct SendUserRoomMessage<OP: ToString, Response> {
52 pub response: Response,
53 pub local_recipient_id: LocalUserId,
54 pub websocket_id: Option<ConnectionId>,
57 /// Send message to all users viewing the given community.
59 #[rtype(result = "()")]
60 pub struct SendCommunityRoomMessage<OP: ToString, Response> {
62 pub response: Response,
63 pub community_id: CommunityId,
64 pub websocket_id: Option<ConnectionId>,
67 /// Send message to mods of a given community. Set community_id = 0 to send to site admins.
69 #[rtype(result = "()")]
70 pub struct SendModRoomMessage<Response> {
71 pub op: UserOperation,
72 pub response: Response,
73 pub community_id: CommunityId,
74 pub websocket_id: Option<ConnectionId>,
78 #[rtype(result = "()")]
79 pub(crate) struct SendPost<OP: ToString> {
81 pub post: PostResponse,
82 pub websocket_id: Option<ConnectionId>,
86 #[rtype(result = "()")]
87 pub(crate) struct SendComment<OP: ToString> {
89 pub comment: CommentResponse,
90 pub websocket_id: Option<ConnectionId>,
94 #[rtype(result = "()")]
95 pub struct JoinUserRoom {
96 pub local_user_id: LocalUserId,
101 #[rtype(result = "()")]
102 pub struct JoinCommunityRoom {
103 pub community_id: CommunityId,
104 pub id: ConnectionId,
108 #[rtype(result = "()")]
109 pub struct JoinModRoom {
110 pub community_id: CommunityId,
111 pub id: ConnectionId,
115 #[rtype(result = "()")]
116 pub struct JoinPostRoom {
118 pub id: ConnectionId,
123 pub struct GetUsersOnline;
127 pub struct GetPostUsersOnline {
133 pub struct GetCommunityUsersOnline {
134 pub community_id: CommunityId,
137 #[derive(Message, Debug)]
138 #[rtype(result = "()")]
139 pub struct CaptchaItem {
142 pub expires: chrono::NaiveDateTime,
147 pub struct CheckCaptcha {