2020-09-24 13:53:21 +00:00
|
|
|
use crate::UserOperation;
|
|
|
|
use actix::{prelude::*, Recipient};
|
2021-03-25 19:19:40 +00:00
|
|
|
use lemmy_api_common::{comment::CommentResponse, post::PostResponse};
|
2021-10-16 13:33:38 +00:00
|
|
|
use lemmy_db_schema::newtypes::{CommunityId, LocalUserId, PostId};
|
2021-03-18 20:25:21 +00:00
|
|
|
use lemmy_utils::{ConnectionId, IpAddr};
|
2020-09-24 13:53:21 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
/// Chat server sends this messages to session
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
2021-02-22 18:04:32 +00:00
|
|
|
pub struct WsMessage(pub String);
|
2020-09-24 13:53:21 +00:00
|
|
|
|
|
|
|
/// Message for chat server communications
|
|
|
|
|
|
|
|
/// New chat session is created
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(usize)]
|
|
|
|
pub struct Connect {
|
2021-02-22 18:04:32 +00:00
|
|
|
pub addr: Recipient<WsMessage>,
|
|
|
|
pub ip: IpAddr,
|
2020-09-24 13:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Session is disconnected
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
|
|
|
pub struct Disconnect {
|
|
|
|
pub id: ConnectionId,
|
2021-02-22 18:04:32 +00:00
|
|
|
pub ip: IpAddr,
|
2020-09-24 13:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// The messages sent to websocket clients
|
|
|
|
#[derive(Serialize, Deserialize, Message)]
|
|
|
|
#[rtype(result = "Result<String, std::convert::Infallible>")]
|
|
|
|
pub struct StandardMessage {
|
|
|
|
/// Id of the client session
|
|
|
|
pub id: ConnectionId,
|
|
|
|
/// Peer message
|
|
|
|
pub msg: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
2021-03-25 19:30:15 +00:00
|
|
|
pub struct SendAllMessage<OP: ToString, Response> {
|
|
|
|
pub op: OP,
|
2020-09-24 13:53:21 +00:00
|
|
|
pub response: Response,
|
|
|
|
pub websocket_id: Option<ConnectionId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
2021-03-25 19:30:15 +00:00
|
|
|
pub struct SendUserRoomMessage<OP: ToString, Response> {
|
|
|
|
pub op: OP,
|
2020-09-24 13:53:21 +00:00
|
|
|
pub response: Response,
|
2021-03-12 20:18:03 +00:00
|
|
|
pub local_recipient_id: LocalUserId,
|
2020-09-24 13:53:21 +00:00
|
|
|
pub websocket_id: Option<ConnectionId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
2021-03-25 19:30:15 +00:00
|
|
|
pub struct SendCommunityRoomMessage<OP: ToString, Response> {
|
|
|
|
pub op: OP,
|
2020-09-24 13:53:21 +00:00
|
|
|
pub response: Response,
|
|
|
|
pub community_id: CommunityId,
|
|
|
|
pub websocket_id: Option<ConnectionId>,
|
|
|
|
}
|
|
|
|
|
2020-10-27 00:25:18 +00:00
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
|
|
|
pub struct SendModRoomMessage<Response> {
|
|
|
|
pub op: UserOperation,
|
|
|
|
pub response: Response,
|
|
|
|
pub community_id: CommunityId,
|
|
|
|
pub websocket_id: Option<ConnectionId>,
|
|
|
|
}
|
|
|
|
|
2020-09-24 13:53:21 +00:00
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
2021-08-17 18:04:58 +00:00
|
|
|
pub(crate) struct SendPost<OP: ToString> {
|
2021-03-25 19:30:15 +00:00
|
|
|
pub op: OP,
|
2020-09-24 13:53:21 +00:00
|
|
|
pub post: PostResponse,
|
|
|
|
pub websocket_id: Option<ConnectionId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
2021-08-17 18:04:58 +00:00
|
|
|
pub(crate) struct SendComment<OP: ToString> {
|
2021-03-25 19:30:15 +00:00
|
|
|
pub op: OP,
|
2020-09-24 13:53:21 +00:00
|
|
|
pub comment: CommentResponse,
|
|
|
|
pub websocket_id: Option<ConnectionId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
|
|
|
pub struct JoinUserRoom {
|
2021-03-12 15:54:47 +00:00
|
|
|
pub local_user_id: LocalUserId,
|
2020-09-24 13:53:21 +00:00
|
|
|
pub id: ConnectionId,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
|
|
|
pub struct JoinCommunityRoom {
|
|
|
|
pub community_id: CommunityId,
|
|
|
|
pub id: ConnectionId,
|
|
|
|
}
|
|
|
|
|
2020-10-27 00:25:18 +00:00
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
|
|
|
pub struct JoinModRoom {
|
|
|
|
pub community_id: CommunityId,
|
|
|
|
pub id: ConnectionId,
|
|
|
|
}
|
|
|
|
|
2020-09-24 13:53:21 +00:00
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(result = "()")]
|
|
|
|
pub struct JoinPostRoom {
|
|
|
|
pub post_id: PostId,
|
|
|
|
pub id: ConnectionId,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(usize)]
|
|
|
|
pub struct GetUsersOnline;
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(usize)]
|
|
|
|
pub struct GetPostUsersOnline {
|
|
|
|
pub post_id: PostId,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(usize)]
|
|
|
|
pub struct GetCommunityUsersOnline {
|
|
|
|
pub community_id: CommunityId,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message, Debug)]
|
|
|
|
#[rtype(result = "()")]
|
|
|
|
pub struct CaptchaItem {
|
|
|
|
pub uuid: String,
|
|
|
|
pub answer: String,
|
|
|
|
pub expires: chrono::NaiveDateTime,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Message)]
|
|
|
|
#[rtype(bool)]
|
|
|
|
pub struct CheckCaptcha {
|
|
|
|
pub uuid: String,
|
|
|
|
pub answer: String,
|
|
|
|
}
|