1 use crate::{comment::CommentResponse, post::PostResponse};
2 use actix::{prelude::*, Recipient};
3 use lemmy_utils::{CommunityId, ConnectionId, IPAddr, PostId, UserId};
4 use serde::{Deserialize, Serialize};
6 #[derive(EnumString, ToString, Debug, Clone)]
7 pub enum UserOperation {
36 GetFollowedCommunities,
40 MarkUserMentionAsRead,
60 MarkPrivateMessageAsRead,
70 /// Chat server sends this messages to session
72 #[rtype(result = "()")]
73 pub struct WSMessage(pub String);
75 /// Message for chat server communications
77 /// New chat session is created
81 pub addr: Recipient<WSMessage>,
85 /// Session is disconnected
87 #[rtype(result = "()")]
88 pub struct Disconnect {
93 /// The messages sent to websocket clients
94 #[derive(Serialize, Deserialize, Message)]
95 #[rtype(result = "Result<String, std::convert::Infallible>")]
96 pub struct StandardMessage {
97 /// Id of the client session
104 #[rtype(result = "()")]
105 pub struct SendAllMessage<Response> {
106 pub op: UserOperation,
107 pub response: Response,
108 pub websocket_id: Option<ConnectionId>,
112 #[rtype(result = "()")]
113 pub struct SendUserRoomMessage<Response> {
114 pub op: UserOperation,
115 pub response: Response,
116 pub recipient_id: UserId,
117 pub websocket_id: Option<ConnectionId>,
121 #[rtype(result = "()")]
122 pub struct SendCommunityRoomMessage<Response> {
123 pub op: UserOperation,
124 pub response: Response,
125 pub community_id: CommunityId,
126 pub websocket_id: Option<ConnectionId>,
130 #[rtype(result = "()")]
131 pub struct SendPost {
132 pub op: UserOperation,
133 pub post: PostResponse,
134 pub websocket_id: Option<ConnectionId>,
138 #[rtype(result = "()")]
139 pub struct SendComment {
140 pub op: UserOperation,
141 pub comment: CommentResponse,
142 pub websocket_id: Option<ConnectionId>,
146 #[rtype(result = "()")]
147 pub struct JoinUserRoom {
149 pub id: ConnectionId,
153 #[rtype(result = "()")]
154 pub struct JoinCommunityRoom {
155 pub community_id: CommunityId,
156 pub id: ConnectionId,
160 #[rtype(result = "()")]
161 pub struct JoinPostRoom {
163 pub id: ConnectionId,
168 pub struct GetUsersOnline;
172 pub struct GetPostUsersOnline {
178 pub struct GetCommunityUsersOnline {
179 pub community_id: CommunityId,
182 #[derive(Message, Debug)]
183 #[rtype(result = "()")]
184 pub struct CaptchaItem {
187 pub expires: chrono::NaiveDateTime,
192 pub struct CheckCaptcha {