]> Untitled Git - lemmy.git/blob - lemmy_structs/src/websocket.rs
c5c6c5d607703daaed34cf6cd000089f09bf9b75
[lemmy.git] / lemmy_structs / src / websocket.rs
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};
5
6 #[derive(EnumString, ToString, Debug, Clone)]
7 pub enum UserOperation {
8   Login,
9   Register,
10   GetCaptcha,
11   CreateCommunity,
12   CreatePost,
13   ListCommunities,
14   ListCategories,
15   GetPost,
16   GetCommunity,
17   CreateComment,
18   EditComment,
19   DeleteComment,
20   RemoveComment,
21   MarkCommentAsRead,
22   SaveComment,
23   CreateCommentLike,
24   GetPosts,
25   CreatePostLike,
26   EditPost,
27   DeletePost,
28   RemovePost,
29   LockPost,
30   StickyPost,
31   SavePost,
32   EditCommunity,
33   DeleteCommunity,
34   RemoveCommunity,
35   FollowCommunity,
36   GetFollowedCommunities,
37   GetUserDetails,
38   GetReplies,
39   GetUserMentions,
40   MarkUserMentionAsRead,
41   GetModlog,
42   BanFromCommunity,
43   AddModToCommunity,
44   CreateSite,
45   EditSite,
46   GetSite,
47   AddAdmin,
48   BanUser,
49   Search,
50   MarkAllAsRead,
51   SaveUserSettings,
52   TransferCommunity,
53   TransferSite,
54   DeleteAccount,
55   PasswordReset,
56   PasswordChange,
57   CreatePrivateMessage,
58   EditPrivateMessage,
59   DeletePrivateMessage,
60   MarkPrivateMessageAsRead,
61   GetPrivateMessages,
62   UserJoin,
63   GetComments,
64   GetSiteConfig,
65   SaveSiteConfig,
66   PostJoin,
67   CommunityJoin,
68 }
69
70 /// Chat server sends this messages to session
71 #[derive(Message)]
72 #[rtype(result = "()")]
73 pub struct WSMessage(pub String);
74
75 /// Message for chat server communications
76
77 /// New chat session is created
78 #[derive(Message)]
79 #[rtype(usize)]
80 pub struct Connect {
81   pub addr: Recipient<WSMessage>,
82   pub ip: IPAddr,
83 }
84
85 /// Session is disconnected
86 #[derive(Message)]
87 #[rtype(result = "()")]
88 pub struct Disconnect {
89   pub id: ConnectionId,
90   pub ip: IPAddr,
91 }
92
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
98   pub id: ConnectionId,
99   /// Peer message
100   pub msg: String,
101 }
102
103 #[derive(Message)]
104 #[rtype(result = "()")]
105 pub struct SendAllMessage<Response> {
106   pub op: UserOperation,
107   pub response: Response,
108   pub websocket_id: Option<ConnectionId>,
109 }
110
111 #[derive(Message)]
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>,
118 }
119
120 #[derive(Message)]
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>,
127 }
128
129 #[derive(Message)]
130 #[rtype(result = "()")]
131 pub struct SendPost {
132   pub op: UserOperation,
133   pub post: PostResponse,
134   pub websocket_id: Option<ConnectionId>,
135 }
136
137 #[derive(Message)]
138 #[rtype(result = "()")]
139 pub struct SendComment {
140   pub op: UserOperation,
141   pub comment: CommentResponse,
142   pub websocket_id: Option<ConnectionId>,
143 }
144
145 #[derive(Message)]
146 #[rtype(result = "()")]
147 pub struct JoinUserRoom {
148   pub user_id: UserId,
149   pub id: ConnectionId,
150 }
151
152 #[derive(Message)]
153 #[rtype(result = "()")]
154 pub struct JoinCommunityRoom {
155   pub community_id: CommunityId,
156   pub id: ConnectionId,
157 }
158
159 #[derive(Message)]
160 #[rtype(result = "()")]
161 pub struct JoinPostRoom {
162   pub post_id: PostId,
163   pub id: ConnectionId,
164 }
165
166 #[derive(Message)]
167 #[rtype(usize)]
168 pub struct GetUsersOnline;
169
170 #[derive(Message)]
171 #[rtype(usize)]
172 pub struct GetPostUsersOnline {
173   pub post_id: PostId,
174 }
175
176 #[derive(Message)]
177 #[rtype(usize)]
178 pub struct GetCommunityUsersOnline {
179   pub community_id: CommunityId,
180 }
181
182 #[derive(Message, Debug)]
183 #[rtype(result = "()")]
184 pub struct CaptchaItem {
185   pub uuid: String,
186   pub answer: String,
187   pub expires: chrono::NaiveDateTime,
188 }
189
190 #[derive(Message)]
191 #[rtype(bool)]
192 pub struct CheckCaptcha {
193   pub uuid: String,
194   pub answer: String,
195 }