1 use crate::UserOperation;
2 use actix::{prelude::*, Recipient};
3 use lemmy_api_common::{comment::CommentResponse, post::PostResponse};
4 use lemmy_db_schema::newtypes::{CommunityId, LocalUserId, PostId};
5 use lemmy_utils::{ConnectionId, IpAddr};
6 use serde::{Deserialize, Serialize};
8 /// Chat server sends this messages to session
10 #[rtype(result = "()")]
11 pub struct WsMessage(pub String);
13 /// Message for chat server communications
15 /// New chat session is created
19 pub addr: Recipient<WsMessage>,
23 /// Session is disconnected
25 #[rtype(result = "()")]
26 pub struct Disconnect {
31 /// The messages sent to websocket clients
32 #[derive(Serialize, Deserialize, Message)]
33 #[rtype(result = "Result<String, std::convert::Infallible>")]
34 pub struct StandardMessage {
35 /// Id of the client session
42 #[rtype(result = "()")]
43 pub struct SendAllMessage<OP: ToString, Response> {
45 pub response: Response,
46 pub websocket_id: Option<ConnectionId>,
50 #[rtype(result = "()")]
51 pub struct SendUserRoomMessage<OP: ToString, Response> {
53 pub response: Response,
54 pub local_recipient_id: LocalUserId,
55 pub websocket_id: Option<ConnectionId>,
58 /// Send message to all users viewing the given community.
60 #[rtype(result = "()")]
61 pub struct SendCommunityRoomMessage<OP: ToString, Response> {
63 pub response: Response,
64 pub community_id: CommunityId,
65 pub websocket_id: Option<ConnectionId>,
68 /// Send message to mods of a given community. Set community_id = 0 to send to site admins.
70 #[rtype(result = "()")]
71 pub struct SendModRoomMessage<Response> {
72 pub op: UserOperation,
73 pub response: Response,
74 pub community_id: CommunityId,
75 pub websocket_id: Option<ConnectionId>,
79 #[rtype(result = "()")]
80 pub(crate) struct SendPost<OP: ToString> {
82 pub post: PostResponse,
83 pub websocket_id: Option<ConnectionId>,
87 #[rtype(result = "()")]
88 pub(crate) struct SendComment<OP: ToString> {
90 pub comment: CommentResponse,
91 pub websocket_id: Option<ConnectionId>,
95 #[rtype(result = "()")]
96 pub struct JoinUserRoom {
97 pub local_user_id: LocalUserId,
102 #[rtype(result = "()")]
103 pub struct JoinCommunityRoom {
104 pub community_id: CommunityId,
105 pub id: ConnectionId,
109 #[rtype(result = "()")]
110 pub struct JoinModRoom {
111 pub community_id: CommunityId,
112 pub id: ConnectionId,
116 #[rtype(result = "()")]
117 pub struct JoinPostRoom {
119 pub id: ConnectionId,
124 pub struct GetUsersOnline;
128 pub struct GetPostUsersOnline {
134 pub struct GetCommunityUsersOnline {
135 pub community_id: CommunityId,
138 #[derive(Message, Debug)]
139 #[rtype(result = "()")]
140 pub struct CaptchaItem {
143 pub expires: chrono::NaiveDateTime,
148 pub struct CheckCaptcha {