Fixing broken websocket sends. Removing WebSocketInfo (#1098)
This commit is contained in:
parent
2080534744
commit
2d5a50e80f
18 changed files with 342 additions and 420 deletions
|
@ -13,8 +13,8 @@ use crate::{
|
||||||
websocket::{
|
websocket::{
|
||||||
server::{JoinCommunityRoom, SendComment},
|
server::{JoinCommunityRoom, SendComment},
|
||||||
UserOperation,
|
UserOperation,
|
||||||
WebsocketInfo,
|
|
||||||
},
|
},
|
||||||
|
ConnectionId,
|
||||||
DbPool,
|
DbPool,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
LemmyError,
|
||||||
|
@ -129,7 +129,7 @@ impl Perform for CreateComment {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &CreateComment = &self;
|
let data: &CreateComment = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -226,17 +226,15 @@ impl Perform for CreateComment {
|
||||||
form_id: data.form_id.to_owned(),
|
form_id: data.form_id.to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendComment {
|
||||||
ws.chatserver.do_send(SendComment {
|
|
||||||
op: UserOperation::CreateComment,
|
op: UserOperation::CreateComment,
|
||||||
comment: res.clone(),
|
comment: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// strip out the recipient_ids, so that
|
// strip out the recipient_ids, so that
|
||||||
// users don't get double notifs
|
// users don't get double notifs
|
||||||
res.recipient_ids = Vec::new();
|
res.recipient_ids = Vec::new();
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -249,7 +247,7 @@ impl Perform for EditComment {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &EditComment = &self;
|
let data: &EditComment = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -311,17 +309,15 @@ impl Perform for EditComment {
|
||||||
form_id: data.form_id.to_owned(),
|
form_id: data.form_id.to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendComment {
|
||||||
ws.chatserver.do_send(SendComment {
|
|
||||||
op: UserOperation::EditComment,
|
op: UserOperation::EditComment,
|
||||||
comment: res.clone(),
|
comment: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// strip out the recipient_ids, so that
|
// strip out the recipient_ids, so that
|
||||||
// users don't get double notifs
|
// users don't get double notifs
|
||||||
res.recipient_ids = Vec::new();
|
res.recipient_ids = Vec::new();
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -334,7 +330,7 @@ impl Perform for DeleteComment {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &DeleteComment = &self;
|
let data: &DeleteComment = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -398,17 +394,15 @@ impl Perform for DeleteComment {
|
||||||
form_id: None,
|
form_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendComment {
|
||||||
ws.chatserver.do_send(SendComment {
|
|
||||||
op: UserOperation::DeleteComment,
|
op: UserOperation::DeleteComment,
|
||||||
comment: res.clone(),
|
comment: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// strip out the recipient_ids, so that
|
// strip out the recipient_ids, so that
|
||||||
// users don't get double notifs
|
// users don't get double notifs
|
||||||
res.recipient_ids = Vec::new();
|
res.recipient_ids = Vec::new();
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -421,7 +415,7 @@ impl Perform for RemoveComment {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &RemoveComment = &self;
|
let data: &RemoveComment = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -495,17 +489,15 @@ impl Perform for RemoveComment {
|
||||||
form_id: None,
|
form_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendComment {
|
||||||
ws.chatserver.do_send(SendComment {
|
|
||||||
op: UserOperation::RemoveComment,
|
op: UserOperation::RemoveComment,
|
||||||
comment: res.clone(),
|
comment: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// strip out the recipient_ids, so that
|
// strip out the recipient_ids, so that
|
||||||
// users don't get double notifs
|
// users don't get double notifs
|
||||||
res.recipient_ids = Vec::new();
|
res.recipient_ids = Vec::new();
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -518,7 +510,7 @@ impl Perform for MarkCommentAsRead {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &MarkCommentAsRead = &self;
|
let data: &MarkCommentAsRead = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -590,7 +582,7 @@ impl Perform for SaveComment {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &SaveComment = &self;
|
let data: &SaveComment = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -634,7 +626,7 @@ impl Perform for CreateCommentLike {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &CreateCommentLike = &self;
|
let data: &CreateCommentLike = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -726,17 +718,15 @@ impl Perform for CreateCommentLike {
|
||||||
form_id: None,
|
form_id: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendComment {
|
||||||
ws.chatserver.do_send(SendComment {
|
|
||||||
op: UserOperation::CreateCommentLike,
|
op: UserOperation::CreateCommentLike,
|
||||||
comment: res.clone(),
|
comment: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// strip out the recipient_ids, so that
|
// strip out the recipient_ids, so that
|
||||||
// users don't get double notifs
|
// users don't get double notifs
|
||||||
res.recipient_ids = Vec::new();
|
res.recipient_ids = Vec::new();
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -749,7 +739,7 @@ impl Perform for GetComments {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetCommentsResponse, LemmyError> {
|
) -> Result<GetCommentsResponse, LemmyError> {
|
||||||
let data: &GetComments = &self;
|
let data: &GetComments = &self;
|
||||||
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
|
@ -777,19 +767,17 @@ impl Perform for GetComments {
|
||||||
Err(_) => return Err(APIError::err("couldnt_get_comments").into()),
|
Err(_) => return Err(APIError::err("couldnt_get_comments").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
if let Some(id) = websocket_id {
|
||||||
// You don't need to join the specific community room, bc this is already handled by
|
// You don't need to join the specific community room, bc this is already handled by
|
||||||
// GetCommunity
|
// GetCommunity
|
||||||
if data.community_id.is_none() {
|
if data.community_id.is_none() {
|
||||||
if let Some(id) = ws.id {
|
|
||||||
// 0 is the "all" community
|
// 0 is the "all" community
|
||||||
ws.chatserver.do_send(JoinCommunityRoom {
|
context.chat_server().do_send(JoinCommunityRoom {
|
||||||
community_id: 0,
|
community_id: 0,
|
||||||
id,
|
id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(GetCommentsResponse { comments })
|
Ok(GetCommentsResponse { comments })
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ use crate::{
|
||||||
websocket::{
|
websocket::{
|
||||||
server::{GetCommunityUsersOnline, JoinCommunityRoom, SendCommunityRoomMessage},
|
server::{GetCommunityUsersOnline, JoinCommunityRoom, SendCommunityRoomMessage},
|
||||||
UserOperation,
|
UserOperation,
|
||||||
WebsocketInfo,
|
|
||||||
},
|
},
|
||||||
|
ConnectionId,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
|
@ -166,7 +166,7 @@ impl Perform for GetCommunity {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetCommunityResponse, LemmyError> {
|
) -> Result<GetCommunityResponse, LemmyError> {
|
||||||
let data: &GetCommunity = &self;
|
let data: &GetCommunity = &self;
|
||||||
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
|
@ -205,20 +205,17 @@ impl Perform for GetCommunity {
|
||||||
Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
|
Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let online = if let Some(ws) = websocket_info {
|
if let Some(id) = websocket_id {
|
||||||
if let Some(id) = ws.id {
|
context
|
||||||
ws.chatserver.do_send(JoinCommunityRoom {
|
.chat_server()
|
||||||
community_id: community.id,
|
.do_send(JoinCommunityRoom { community_id, id });
|
||||||
id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
ws.chatserver
|
|
||||||
|
let online = context
|
||||||
|
.chat_server()
|
||||||
.send(GetCommunityUsersOnline { community_id })
|
.send(GetCommunityUsersOnline { community_id })
|
||||||
.await
|
.await
|
||||||
.unwrap_or(1)
|
.unwrap_or(1);
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
let res = GetCommunityResponse {
|
let res = GetCommunityResponse {
|
||||||
community: community_view,
|
community: community_view,
|
||||||
|
@ -238,7 +235,7 @@ impl Perform for CreateCommunity {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &CreateCommunity = &self;
|
let data: &CreateCommunity = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -333,7 +330,7 @@ impl Perform for EditCommunity {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &EditCommunity = &self;
|
let data: &EditCommunity = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -403,7 +400,7 @@ impl Perform for EditCommunity {
|
||||||
community: community_view,
|
community: community_view,
|
||||||
};
|
};
|
||||||
|
|
||||||
send_community_websocket(&res, websocket_info, UserOperation::EditCommunity);
|
send_community_websocket(&res, context, websocket_id, UserOperation::EditCommunity);
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -416,7 +413,7 @@ impl Perform for DeleteCommunity {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &DeleteCommunity = &self;
|
let data: &DeleteCommunity = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -459,7 +456,7 @@ impl Perform for DeleteCommunity {
|
||||||
community: community_view,
|
community: community_view,
|
||||||
};
|
};
|
||||||
|
|
||||||
send_community_websocket(&res, websocket_info, UserOperation::DeleteCommunity);
|
send_community_websocket(&res, context, websocket_id, UserOperation::DeleteCommunity);
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -472,7 +469,7 @@ impl Perform for RemoveCommunity {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &RemoveCommunity = &self;
|
let data: &RemoveCommunity = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -527,7 +524,7 @@ impl Perform for RemoveCommunity {
|
||||||
community: community_view,
|
community: community_view,
|
||||||
};
|
};
|
||||||
|
|
||||||
send_community_websocket(&res, websocket_info, UserOperation::RemoveCommunity);
|
send_community_websocket(&res, context, websocket_id, UserOperation::RemoveCommunity);
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -540,7 +537,7 @@ impl Perform for ListCommunities {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ListCommunitiesResponse, LemmyError> {
|
) -> Result<ListCommunitiesResponse, LemmyError> {
|
||||||
let data: &ListCommunities = &self;
|
let data: &ListCommunities = &self;
|
||||||
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
|
@ -582,7 +579,7 @@ impl Perform for FollowCommunity {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &FollowCommunity = &self;
|
let data: &FollowCommunity = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -643,7 +640,7 @@ impl Perform for GetFollowedCommunities {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetFollowedCommunitiesResponse, LemmyError> {
|
) -> Result<GetFollowedCommunitiesResponse, LemmyError> {
|
||||||
let data: &GetFollowedCommunities = &self;
|
let data: &GetFollowedCommunities = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -670,7 +667,7 @@ impl Perform for BanFromCommunity {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<BanFromCommunityResponse, LemmyError> {
|
) -> Result<BanFromCommunityResponse, LemmyError> {
|
||||||
let data: &BanFromCommunity = &self;
|
let data: &BanFromCommunity = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -757,14 +754,12 @@ impl Perform for BanFromCommunity {
|
||||||
banned: data.ban,
|
banned: data.ban,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendCommunityRoomMessage {
|
||||||
ws.chatserver.do_send(SendCommunityRoomMessage {
|
|
||||||
op: UserOperation::BanFromCommunity,
|
op: UserOperation::BanFromCommunity,
|
||||||
response: res.clone(),
|
response: res.clone(),
|
||||||
community_id: data.community_id,
|
community_id,
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -777,7 +772,7 @@ impl Perform for AddModToCommunity {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<AddModToCommunityResponse, LemmyError> {
|
) -> Result<AddModToCommunityResponse, LemmyError> {
|
||||||
let data: &AddModToCommunity = &self;
|
let data: &AddModToCommunity = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -824,14 +819,12 @@ impl Perform for AddModToCommunity {
|
||||||
|
|
||||||
let res = AddModToCommunityResponse { moderators };
|
let res = AddModToCommunityResponse { moderators };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendCommunityRoomMessage {
|
||||||
ws.chatserver.do_send(SendCommunityRoomMessage {
|
|
||||||
op: UserOperation::AddModToCommunity,
|
op: UserOperation::AddModToCommunity,
|
||||||
response: res.clone(),
|
response: res.clone(),
|
||||||
community_id: data.community_id,
|
community_id,
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -844,7 +837,7 @@ impl Perform for TransferCommunity {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetCommunityResponse, LemmyError> {
|
) -> Result<GetCommunityResponse, LemmyError> {
|
||||||
let data: &TransferCommunity = &self;
|
let data: &TransferCommunity = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -957,20 +950,19 @@ impl Perform for TransferCommunity {
|
||||||
|
|
||||||
pub fn send_community_websocket(
|
pub fn send_community_websocket(
|
||||||
res: &CommunityResponse,
|
res: &CommunityResponse,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
context: &Data<LemmyContext>,
|
||||||
|
websocket_id: Option<ConnectionId>,
|
||||||
op: UserOperation,
|
op: UserOperation,
|
||||||
) {
|
) {
|
||||||
if let Some(ws) = websocket_info {
|
|
||||||
// Strip out the user id and subscribed when sending to others
|
// Strip out the user id and subscribed when sending to others
|
||||||
let mut res_sent = res.clone();
|
let mut res_sent = res.clone();
|
||||||
res_sent.community.user_id = None;
|
res_sent.community.user_id = None;
|
||||||
res_sent.community.subscribed = None;
|
res_sent.community.subscribed = None;
|
||||||
|
|
||||||
ws.chatserver.do_send(SendCommunityRoomMessage {
|
context.chat_server().do_send(SendCommunityRoomMessage {
|
||||||
op,
|
op,
|
||||||
response: res_sent,
|
response: res_sent,
|
||||||
community_id: res.community.id,
|
community_id: res.community.id,
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,4 @@
|
||||||
use crate::{
|
use crate::{api::claims::Claims, blocking, ConnectionId, DbPool, LemmyContext, LemmyError};
|
||||||
api::claims::Claims,
|
|
||||||
blocking,
|
|
||||||
websocket::WebsocketInfo,
|
|
||||||
DbPool,
|
|
||||||
LemmyContext,
|
|
||||||
LemmyError,
|
|
||||||
};
|
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use lemmy_db::{
|
use lemmy_db::{
|
||||||
community::*,
|
community::*,
|
||||||
|
@ -48,7 +41,7 @@ pub trait Perform {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError>;
|
) -> Result<Self::Response, LemmyError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ use crate::{
|
||||||
websocket::{
|
websocket::{
|
||||||
server::{GetPostUsersOnline, JoinCommunityRoom, JoinPostRoom, SendPost},
|
server::{GetPostUsersOnline, JoinCommunityRoom, JoinPostRoom, SendPost},
|
||||||
UserOperation,
|
UserOperation,
|
||||||
WebsocketInfo,
|
|
||||||
},
|
},
|
||||||
|
ConnectionId,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
|
@ -146,7 +146,7 @@ impl Perform for CreatePost {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &CreatePost = &self;
|
let data: &CreatePost = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -247,13 +247,11 @@ impl Perform for CreatePost {
|
||||||
|
|
||||||
let res = PostResponse { post: post_view };
|
let res = PostResponse { post: post_view };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendPost {
|
||||||
ws.chatserver.do_send(SendPost {
|
|
||||||
op: UserOperation::CreatePost,
|
op: UserOperation::CreatePost,
|
||||||
post: res.clone(),
|
post: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -266,7 +264,7 @@ impl Perform for GetPost {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetPostResponse, LemmyError> {
|
) -> Result<GetPostResponse, LemmyError> {
|
||||||
let data: &GetPost = &self;
|
let data: &GetPost = &self;
|
||||||
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
|
@ -304,20 +302,18 @@ impl Perform for GetPost {
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
let online = if let Some(ws) = websocket_info {
|
if let Some(id) = websocket_id {
|
||||||
if let Some(id) = ws.id {
|
context.chat_server().do_send(JoinPostRoom {
|
||||||
ws.chatserver.do_send(JoinPostRoom {
|
|
||||||
post_id: data.id,
|
post_id: data.id,
|
||||||
id,
|
id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ws.chatserver
|
|
||||||
|
let online = context
|
||||||
|
.chat_server()
|
||||||
.send(GetPostUsersOnline { post_id: data.id })
|
.send(GetPostUsersOnline { post_id: data.id })
|
||||||
.await
|
.await
|
||||||
.unwrap_or(1)
|
.unwrap_or(1);
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(GetPostResponse {
|
Ok(GetPostResponse {
|
||||||
|
@ -337,7 +333,7 @@ impl Perform for GetPosts {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetPostsResponse, LemmyError> {
|
) -> Result<GetPostsResponse, LemmyError> {
|
||||||
let data: &GetPosts = &self;
|
let data: &GetPosts = &self;
|
||||||
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
|
@ -377,19 +373,17 @@ impl Perform for GetPosts {
|
||||||
Err(_e) => return Err(APIError::err("couldnt_get_posts").into()),
|
Err(_e) => return Err(APIError::err("couldnt_get_posts").into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
if let Some(id) = websocket_id {
|
||||||
// You don't need to join the specific community room, bc this is already handled by
|
// You don't need to join the specific community room, bc this is already handled by
|
||||||
// GetCommunity
|
// GetCommunity
|
||||||
if data.community_id.is_none() {
|
if data.community_id.is_none() {
|
||||||
if let Some(id) = ws.id {
|
|
||||||
// 0 is the "all" community
|
// 0 is the "all" community
|
||||||
ws.chatserver.do_send(JoinCommunityRoom {
|
context.chat_server().do_send(JoinCommunityRoom {
|
||||||
community_id: 0,
|
community_id: 0,
|
||||||
id,
|
id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(GetPostsResponse { posts })
|
Ok(GetPostsResponse { posts })
|
||||||
}
|
}
|
||||||
|
@ -402,7 +396,7 @@ impl Perform for CreatePostLike {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &CreatePostLike = &self;
|
let data: &CreatePostLike = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -465,13 +459,11 @@ impl Perform for CreatePostLike {
|
||||||
|
|
||||||
let res = PostResponse { post: post_view };
|
let res = PostResponse { post: post_view };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendPost {
|
||||||
ws.chatserver.do_send(SendPost {
|
|
||||||
op: UserOperation::CreatePostLike,
|
op: UserOperation::CreatePostLike,
|
||||||
post: res.clone(),
|
post: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -484,7 +476,7 @@ impl Perform for EditPost {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &EditPost = &self;
|
let data: &EditPost = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -560,13 +552,11 @@ impl Perform for EditPost {
|
||||||
|
|
||||||
let res = PostResponse { post: post_view };
|
let res = PostResponse { post: post_view };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendPost {
|
||||||
ws.chatserver.do_send(SendPost {
|
|
||||||
op: UserOperation::EditPost,
|
op: UserOperation::EditPost,
|
||||||
post: res.clone(),
|
post: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -579,7 +569,7 @@ impl Perform for DeletePost {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &DeletePost = &self;
|
let data: &DeletePost = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -618,13 +608,11 @@ impl Perform for DeletePost {
|
||||||
|
|
||||||
let res = PostResponse { post: post_view };
|
let res = PostResponse { post: post_view };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendPost {
|
||||||
ws.chatserver.do_send(SendPost {
|
|
||||||
op: UserOperation::DeletePost,
|
op: UserOperation::DeletePost,
|
||||||
post: res.clone(),
|
post: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -637,7 +625,7 @@ impl Perform for RemovePost {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &RemovePost = &self;
|
let data: &RemovePost = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -687,13 +675,11 @@ impl Perform for RemovePost {
|
||||||
|
|
||||||
let res = PostResponse { post: post_view };
|
let res = PostResponse { post: post_view };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendPost {
|
||||||
ws.chatserver.do_send(SendPost {
|
|
||||||
op: UserOperation::RemovePost,
|
op: UserOperation::RemovePost,
|
||||||
post: res.clone(),
|
post: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -706,7 +692,7 @@ impl Perform for LockPost {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &LockPost = &self;
|
let data: &LockPost = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -747,13 +733,11 @@ impl Perform for LockPost {
|
||||||
|
|
||||||
let res = PostResponse { post: post_view };
|
let res = PostResponse { post: post_view };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendPost {
|
||||||
ws.chatserver.do_send(SendPost {
|
|
||||||
op: UserOperation::LockPost,
|
op: UserOperation::LockPost,
|
||||||
post: res.clone(),
|
post: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -766,7 +750,7 @@ impl Perform for StickyPost {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &StickyPost = &self;
|
let data: &StickyPost = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -811,13 +795,11 @@ impl Perform for StickyPost {
|
||||||
|
|
||||||
let res = PostResponse { post: post_view };
|
let res = PostResponse { post: post_view };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendPost {
|
||||||
ws.chatserver.do_send(SendPost {
|
|
||||||
op: UserOperation::StickyPost,
|
op: UserOperation::StickyPost,
|
||||||
post: res.clone(),
|
post: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -830,7 +812,7 @@ impl Perform for SavePost {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &SavePost = &self;
|
let data: &SavePost = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
|
@ -15,8 +15,8 @@ use crate::{
|
||||||
websocket::{
|
websocket::{
|
||||||
server::{GetUsersOnline, SendAllMessage},
|
server::{GetUsersOnline, SendAllMessage},
|
||||||
UserOperation,
|
UserOperation,
|
||||||
WebsocketInfo,
|
|
||||||
},
|
},
|
||||||
|
ConnectionId,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
|
@ -167,7 +167,7 @@ impl Perform for ListCategories {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ListCategoriesResponse, LemmyError> {
|
) -> Result<ListCategoriesResponse, LemmyError> {
|
||||||
let _data: &ListCategories = &self;
|
let _data: &ListCategories = &self;
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ impl Perform for GetModlog {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetModlogResponse, LemmyError> {
|
) -> Result<GetModlogResponse, LemmyError> {
|
||||||
let data: &GetModlog = &self;
|
let data: &GetModlog = &self;
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ impl Perform for CreateSite {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<SiteResponse, LemmyError> {
|
) -> Result<SiteResponse, LemmyError> {
|
||||||
let data: &CreateSite = &self;
|
let data: &CreateSite = &self;
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ impl Perform for EditSite {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<SiteResponse, LemmyError> {
|
) -> Result<SiteResponse, LemmyError> {
|
||||||
let data: &EditSite = &self;
|
let data: &EditSite = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -337,13 +337,11 @@ impl Perform for EditSite {
|
||||||
|
|
||||||
let res = SiteResponse { site: site_view };
|
let res = SiteResponse { site: site_view };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendAllMessage {
|
||||||
ws.chatserver.do_send(SendAllMessage {
|
|
||||||
op: UserOperation::EditSite,
|
op: UserOperation::EditSite,
|
||||||
response: res.clone(),
|
response: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -356,7 +354,7 @@ impl Perform for GetSite {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetSiteResponse, LemmyError> {
|
) -> Result<GetSiteResponse, LemmyError> {
|
||||||
let data: &GetSite = &self;
|
let data: &GetSite = &self;
|
||||||
|
|
||||||
|
@ -375,7 +373,7 @@ impl Perform for GetSite {
|
||||||
captcha_uuid: None,
|
captcha_uuid: None,
|
||||||
captcha_answer: None,
|
captcha_answer: None,
|
||||||
};
|
};
|
||||||
let login_response = register.perform(context, websocket_info.clone()).await?;
|
let login_response = register.perform(context, websocket_id).await?;
|
||||||
info!("Admin {} created", setup.admin_username);
|
info!("Admin {} created", setup.admin_username);
|
||||||
|
|
||||||
let create_site = CreateSite {
|
let create_site = CreateSite {
|
||||||
|
@ -388,7 +386,7 @@ impl Perform for GetSite {
|
||||||
enable_nsfw: true,
|
enable_nsfw: true,
|
||||||
auth: login_response.jwt,
|
auth: login_response.jwt,
|
||||||
};
|
};
|
||||||
create_site.perform(context, websocket_info.clone()).await?;
|
create_site.perform(context, websocket_id).await?;
|
||||||
info!("Site {} created", setup.site_name);
|
info!("Site {} created", setup.site_name);
|
||||||
Some(blocking(context.pool(), move |conn| SiteView::read(conn)).await??)
|
Some(blocking(context.pool(), move |conn| SiteView::read(conn)).await??)
|
||||||
} else {
|
} else {
|
||||||
|
@ -410,11 +408,11 @@ impl Perform for GetSite {
|
||||||
|
|
||||||
let banned = blocking(context.pool(), move |conn| UserView::banned(conn)).await??;
|
let banned = blocking(context.pool(), move |conn| UserView::banned(conn)).await??;
|
||||||
|
|
||||||
let online = if let Some(ws) = websocket_info {
|
let online = context
|
||||||
ws.chatserver.send(GetUsersOnline).await.unwrap_or(1)
|
.chat_server()
|
||||||
} else {
|
.send(GetUsersOnline)
|
||||||
0
|
.await
|
||||||
};
|
.unwrap_or(1);
|
||||||
|
|
||||||
let my_user = get_user_from_jwt_opt(&data.auth, context.pool())
|
let my_user = get_user_from_jwt_opt(&data.auth, context.pool())
|
||||||
.await?
|
.await?
|
||||||
|
@ -444,7 +442,7 @@ impl Perform for Search {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<SearchResponse, LemmyError> {
|
) -> Result<SearchResponse, LemmyError> {
|
||||||
let data: &Search = &self;
|
let data: &Search = &self;
|
||||||
|
|
||||||
|
@ -608,7 +606,7 @@ impl Perform for TransferSite {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetSiteResponse, LemmyError> {
|
) -> Result<GetSiteResponse, LemmyError> {
|
||||||
let data: &TransferSite = &self;
|
let data: &TransferSite = &self;
|
||||||
let mut user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let mut user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -671,7 +669,7 @@ impl Perform for GetSiteConfig {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetSiteConfigResponse, LemmyError> {
|
) -> Result<GetSiteConfigResponse, LemmyError> {
|
||||||
let data: &GetSiteConfig = &self;
|
let data: &GetSiteConfig = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -692,7 +690,7 @@ impl Perform for SaveSiteConfig {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetSiteConfigResponse, LemmyError> {
|
) -> Result<GetSiteConfigResponse, LemmyError> {
|
||||||
let data: &SaveSiteConfig = &self;
|
let data: &SaveSiteConfig = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
|
@ -14,8 +14,8 @@ use crate::{
|
||||||
websocket::{
|
websocket::{
|
||||||
server::{CaptchaItem, CheckCaptcha, JoinUserRoom, SendAllMessage, SendUserRoomMessage},
|
server::{CaptchaItem, CheckCaptcha, JoinUserRoom, SendAllMessage, SendUserRoomMessage},
|
||||||
UserOperation,
|
UserOperation,
|
||||||
WebsocketInfo,
|
|
||||||
},
|
},
|
||||||
|
ConnectionId,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
LemmyError,
|
LemmyError,
|
||||||
};
|
};
|
||||||
|
@ -303,7 +303,7 @@ impl Perform for Login {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &Login = &self;
|
let data: &Login = &self;
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ impl Perform for Register {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &Register = &self;
|
let data: &Register = &self;
|
||||||
|
|
||||||
|
@ -357,10 +357,8 @@ impl Perform for Register {
|
||||||
|
|
||||||
// If its not the admin, check the captcha
|
// If its not the admin, check the captcha
|
||||||
if !data.admin && Settings::get().captcha.enabled {
|
if !data.admin && Settings::get().captcha.enabled {
|
||||||
match websocket_info {
|
let check = context
|
||||||
Some(ws) => {
|
.chat_server()
|
||||||
let check = ws
|
|
||||||
.chatserver
|
|
||||||
.send(CheckCaptcha {
|
.send(CheckCaptcha {
|
||||||
uuid: data
|
uuid: data
|
||||||
.captcha_uuid
|
.captcha_uuid
|
||||||
|
@ -376,9 +374,6 @@ impl Perform for Register {
|
||||||
return Err(APIError::err("captcha_incorrect").into());
|
return Err(APIError::err("captcha_incorrect").into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => return Err(APIError::err("captcha_incorrect").into()),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
check_slurs(&data.username)?;
|
check_slurs(&data.username)?;
|
||||||
|
|
||||||
|
@ -515,8 +510,8 @@ impl Perform for GetCaptcha {
|
||||||
|
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
_context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let captcha_settings = Settings::get().captcha;
|
let captcha_settings = Settings::get().captcha;
|
||||||
|
|
||||||
|
@ -547,9 +542,8 @@ impl Perform for GetCaptcha {
|
||||||
expires: naive_now() + Duration::minutes(10), // expires in 10 minutes
|
expires: naive_now() + Duration::minutes(10), // expires in 10 minutes
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
// Stores the captcha item on the queue
|
||||||
ws.chatserver.do_send(captcha_item);
|
context.chat_server().do_send(captcha_item);
|
||||||
}
|
|
||||||
|
|
||||||
Ok(GetCaptchaResponse {
|
Ok(GetCaptchaResponse {
|
||||||
ok: Some(CaptchaResponse { png, uuid, wav }),
|
ok: Some(CaptchaResponse { png, uuid, wav }),
|
||||||
|
@ -564,7 +558,7 @@ impl Perform for SaveUserSettings {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &SaveUserSettings = &self;
|
let data: &SaveUserSettings = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -690,7 +684,7 @@ impl Perform for GetUserDetails {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetUserDetailsResponse, LemmyError> {
|
) -> Result<GetUserDetailsResponse, LemmyError> {
|
||||||
let data: &GetUserDetails = &self;
|
let data: &GetUserDetails = &self;
|
||||||
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
|
@ -788,7 +782,7 @@ impl Perform for AddAdmin {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<AddAdminResponse, LemmyError> {
|
) -> Result<AddAdminResponse, LemmyError> {
|
||||||
let data: &AddAdmin = &self;
|
let data: &AddAdmin = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -827,13 +821,11 @@ impl Perform for AddAdmin {
|
||||||
|
|
||||||
let res = AddAdminResponse { admins };
|
let res = AddAdminResponse { admins };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendAllMessage {
|
||||||
ws.chatserver.do_send(SendAllMessage {
|
|
||||||
op: UserOperation::AddAdmin,
|
op: UserOperation::AddAdmin,
|
||||||
response: res.clone(),
|
response: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -846,7 +838,7 @@ impl Perform for BanUser {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<BanUserResponse, LemmyError> {
|
) -> Result<BanUserResponse, LemmyError> {
|
||||||
let data: &BanUser = &self;
|
let data: &BanUser = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -909,13 +901,11 @@ impl Perform for BanUser {
|
||||||
banned: data.ban,
|
banned: data.ban,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendAllMessage {
|
||||||
ws.chatserver.do_send(SendAllMessage {
|
|
||||||
op: UserOperation::BanUser,
|
op: UserOperation::BanUser,
|
||||||
response: res.clone(),
|
response: res.clone(),
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -928,7 +918,7 @@ impl Perform for GetReplies {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetRepliesResponse, LemmyError> {
|
) -> Result<GetRepliesResponse, LemmyError> {
|
||||||
let data: &GetReplies = &self;
|
let data: &GetReplies = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -960,7 +950,7 @@ impl Perform for GetUserMentions {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetUserMentionsResponse, LemmyError> {
|
) -> Result<GetUserMentionsResponse, LemmyError> {
|
||||||
let data: &GetUserMentions = &self;
|
let data: &GetUserMentions = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -992,7 +982,7 @@ impl Perform for MarkUserMentionAsRead {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<UserMentionResponse, LemmyError> {
|
) -> Result<UserMentionResponse, LemmyError> {
|
||||||
let data: &MarkUserMentionAsRead = &self;
|
let data: &MarkUserMentionAsRead = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -1034,7 +1024,7 @@ impl Perform for MarkAllAsRead {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetRepliesResponse, LemmyError> {
|
) -> Result<GetRepliesResponse, LemmyError> {
|
||||||
let data: &MarkAllAsRead = &self;
|
let data: &MarkAllAsRead = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -1086,7 +1076,7 @@ impl Perform for DeleteAccount {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &DeleteAccount = &self;
|
let data: &DeleteAccount = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -1123,7 +1113,7 @@ impl Perform for PasswordReset {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PasswordResetResponse, LemmyError> {
|
) -> Result<PasswordResetResponse, LemmyError> {
|
||||||
let data: &PasswordReset = &self;
|
let data: &PasswordReset = &self;
|
||||||
|
|
||||||
|
@ -1171,7 +1161,7 @@ impl Perform for PasswordChange {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &PasswordChange = &self;
|
let data: &PasswordChange = &self;
|
||||||
|
|
||||||
|
@ -1212,7 +1202,7 @@ impl Perform for CreatePrivateMessage {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &CreatePrivateMessage = &self;
|
let data: &CreatePrivateMessage = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -1290,14 +1280,12 @@ impl Perform for CreatePrivateMessage {
|
||||||
|
|
||||||
let res = PrivateMessageResponse { message };
|
let res = PrivateMessageResponse { message };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendUserRoomMessage {
|
||||||
ws.chatserver.do_send(SendUserRoomMessage {
|
|
||||||
op: UserOperation::CreatePrivateMessage,
|
op: UserOperation::CreatePrivateMessage,
|
||||||
response: res.clone(),
|
response: res.clone(),
|
||||||
recipient_id: recipient_user.id,
|
recipient_id,
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -1310,7 +1298,7 @@ impl Perform for EditPrivateMessage {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &EditPrivateMessage = &self;
|
let data: &EditPrivateMessage = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -1349,14 +1337,12 @@ impl Perform for EditPrivateMessage {
|
||||||
|
|
||||||
let res = PrivateMessageResponse { message };
|
let res = PrivateMessageResponse { message };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendUserRoomMessage {
|
||||||
ws.chatserver.do_send(SendUserRoomMessage {
|
|
||||||
op: UserOperation::EditPrivateMessage,
|
op: UserOperation::EditPrivateMessage,
|
||||||
response: res.clone(),
|
response: res.clone(),
|
||||||
recipient_id,
|
recipient_id,
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -1369,7 +1355,7 @@ impl Perform for DeletePrivateMessage {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &DeletePrivateMessage = &self;
|
let data: &DeletePrivateMessage = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -1414,14 +1400,12 @@ impl Perform for DeletePrivateMessage {
|
||||||
|
|
||||||
let res = PrivateMessageResponse { message };
|
let res = PrivateMessageResponse { message };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendUserRoomMessage {
|
||||||
ws.chatserver.do_send(SendUserRoomMessage {
|
|
||||||
op: UserOperation::DeletePrivateMessage,
|
op: UserOperation::DeletePrivateMessage,
|
||||||
response: res.clone(),
|
response: res.clone(),
|
||||||
recipient_id,
|
recipient_id,
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -1434,7 +1418,7 @@ impl Perform for MarkPrivateMessageAsRead {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &MarkPrivateMessageAsRead = &self;
|
let data: &MarkPrivateMessageAsRead = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -1472,14 +1456,12 @@ impl Perform for MarkPrivateMessageAsRead {
|
||||||
|
|
||||||
let res = PrivateMessageResponse { message };
|
let res = PrivateMessageResponse { message };
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
context.chat_server().do_send(SendUserRoomMessage {
|
||||||
ws.chatserver.do_send(SendUserRoomMessage {
|
|
||||||
op: UserOperation::MarkPrivateMessageAsRead,
|
op: UserOperation::MarkPrivateMessageAsRead,
|
||||||
response: res.clone(),
|
response: res.clone(),
|
||||||
recipient_id,
|
recipient_id,
|
||||||
my_id: ws.id,
|
websocket_id,
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -1492,7 +1474,7 @@ impl Perform for GetPrivateMessages {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_info: Option<WebsocketInfo>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessagesResponse, LemmyError> {
|
) -> Result<PrivateMessagesResponse, LemmyError> {
|
||||||
let data: &GetPrivateMessages = &self;
|
let data: &GetPrivateMessages = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
@ -1521,19 +1503,17 @@ impl Perform for UserJoin {
|
||||||
async fn perform(
|
async fn perform(
|
||||||
&self,
|
&self,
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_info: Option<WebsocketInfo>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<UserJoinResponse, LemmyError> {
|
) -> Result<UserJoinResponse, LemmyError> {
|
||||||
let data: &UserJoin = &self;
|
let data: &UserJoin = &self;
|
||||||
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
let user = get_user_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
if let Some(ws) = websocket_info {
|
if let Some(ws_id) = websocket_id {
|
||||||
if let Some(id) = ws.id {
|
context.chat_server().do_send(JoinUserRoom {
|
||||||
ws.chatserver.do_send(JoinUserRoom {
|
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
id,
|
id: ws_id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(UserJoinResponse { user_id: user.id })
|
Ok(UserJoinResponse { user_id: user.id })
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ async fn receive_create_post(
|
||||||
context.chat_server().do_send(SendPost {
|
context.chat_server().do_send(SendPost {
|
||||||
op: UserOperation::CreatePost,
|
op: UserOperation::CreatePost,
|
||||||
post: res,
|
post: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(create, &user, context).await?;
|
announce_if_community_is_local(create, &user, context).await?;
|
||||||
|
@ -128,7 +128,7 @@ async fn receive_create_comment(
|
||||||
context.chat_server().do_send(SendComment {
|
context.chat_server().do_send(SendComment {
|
||||||
op: UserOperation::CreateComment,
|
op: UserOperation::CreateComment,
|
||||||
comment: res,
|
comment: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(create, &user, context).await?;
|
announce_if_community_is_local(create, &user, context).await?;
|
||||||
|
|
|
@ -100,7 +100,7 @@ async fn receive_delete_post(
|
||||||
context.chat_server().do_send(SendPost {
|
context.chat_server().do_send(SendPost {
|
||||||
op: UserOperation::EditPost,
|
op: UserOperation::EditPost,
|
||||||
post: res,
|
post: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(delete, &user, context).await?;
|
announce_if_community_is_local(delete, &user, context).await?;
|
||||||
|
@ -158,7 +158,7 @@ async fn receive_delete_comment(
|
||||||
context.chat_server().do_send(SendComment {
|
context.chat_server().do_send(SendComment {
|
||||||
op: UserOperation::EditComment,
|
op: UserOperation::EditComment,
|
||||||
comment: res,
|
comment: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(delete, &user, context).await?;
|
announce_if_community_is_local(delete, &user, context).await?;
|
||||||
|
@ -222,7 +222,7 @@ async fn receive_delete_community(
|
||||||
op: UserOperation::EditCommunity,
|
op: UserOperation::EditCommunity,
|
||||||
response: res,
|
response: res,
|
||||||
community_id,
|
community_id,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(delete, &user, context).await?;
|
announce_if_community_is_local(delete, &user, context).await?;
|
||||||
|
|
|
@ -85,7 +85,7 @@ async fn receive_dislike_post(
|
||||||
context.chat_server().do_send(SendPost {
|
context.chat_server().do_send(SendPost {
|
||||||
op: UserOperation::CreatePostLike,
|
op: UserOperation::CreatePostLike,
|
||||||
post: res,
|
post: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(dislike, &user, context).await?;
|
announce_if_community_is_local(dislike, &user, context).await?;
|
||||||
|
@ -142,7 +142,7 @@ async fn receive_dislike_comment(
|
||||||
context.chat_server().do_send(SendComment {
|
context.chat_server().do_send(SendComment {
|
||||||
op: UserOperation::CreateCommentLike,
|
op: UserOperation::CreateCommentLike,
|
||||||
comment: res,
|
comment: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(dislike, &user, context).await?;
|
announce_if_community_is_local(dislike, &user, context).await?;
|
||||||
|
|
|
@ -76,7 +76,7 @@ async fn receive_like_post(like: Like, context: &LemmyContext) -> Result<HttpRes
|
||||||
context.chat_server().do_send(SendPost {
|
context.chat_server().do_send(SendPost {
|
||||||
op: UserOperation::CreatePostLike,
|
op: UserOperation::CreatePostLike,
|
||||||
post: res,
|
post: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(like, &user, context).await?;
|
announce_if_community_is_local(like, &user, context).await?;
|
||||||
|
@ -127,7 +127,7 @@ async fn receive_like_comment(
|
||||||
context.chat_server().do_send(SendComment {
|
context.chat_server().do_send(SendComment {
|
||||||
op: UserOperation::CreateCommentLike,
|
op: UserOperation::CreateCommentLike,
|
||||||
comment: res,
|
comment: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(like, &user, context).await?;
|
announce_if_community_is_local(like, &user, context).await?;
|
||||||
|
|
|
@ -107,7 +107,7 @@ async fn receive_remove_post(
|
||||||
context.chat_server().do_send(SendPost {
|
context.chat_server().do_send(SendPost {
|
||||||
op: UserOperation::EditPost,
|
op: UserOperation::EditPost,
|
||||||
post: res,
|
post: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(remove, &mod_, context).await?;
|
announce_if_community_is_local(remove, &mod_, context).await?;
|
||||||
|
@ -165,7 +165,7 @@ async fn receive_remove_comment(
|
||||||
context.chat_server().do_send(SendComment {
|
context.chat_server().do_send(SendComment {
|
||||||
op: UserOperation::EditComment,
|
op: UserOperation::EditComment,
|
||||||
comment: res,
|
comment: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(remove, &mod_, context).await?;
|
announce_if_community_is_local(remove, &mod_, context).await?;
|
||||||
|
@ -229,7 +229,7 @@ async fn receive_remove_community(
|
||||||
op: UserOperation::EditCommunity,
|
op: UserOperation::EditCommunity,
|
||||||
response: res,
|
response: res,
|
||||||
community_id,
|
community_id,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(remove, &mod_, context).await?;
|
announce_if_community_is_local(remove, &mod_, context).await?;
|
||||||
|
|
|
@ -202,7 +202,7 @@ async fn receive_undo_delete_comment(
|
||||||
context.chat_server().do_send(SendComment {
|
context.chat_server().do_send(SendComment {
|
||||||
op: UserOperation::EditComment,
|
op: UserOperation::EditComment,
|
||||||
comment: res,
|
comment: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(undo, &user, context).await?;
|
announce_if_community_is_local(undo, &user, context).await?;
|
||||||
|
@ -261,7 +261,7 @@ async fn receive_undo_remove_comment(
|
||||||
context.chat_server().do_send(SendComment {
|
context.chat_server().do_send(SendComment {
|
||||||
op: UserOperation::EditComment,
|
op: UserOperation::EditComment,
|
||||||
comment: res,
|
comment: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(undo, &mod_, context).await?;
|
announce_if_community_is_local(undo, &mod_, context).await?;
|
||||||
|
@ -321,7 +321,7 @@ async fn receive_undo_delete_post(
|
||||||
context.chat_server().do_send(SendPost {
|
context.chat_server().do_send(SendPost {
|
||||||
op: UserOperation::EditPost,
|
op: UserOperation::EditPost,
|
||||||
post: res,
|
post: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(undo, &user, context).await?;
|
announce_if_community_is_local(undo, &user, context).await?;
|
||||||
|
@ -381,7 +381,7 @@ async fn receive_undo_remove_post(
|
||||||
context.chat_server().do_send(SendPost {
|
context.chat_server().do_send(SendPost {
|
||||||
op: UserOperation::EditPost,
|
op: UserOperation::EditPost,
|
||||||
post: res,
|
post: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(undo, &mod_, context).await?;
|
announce_if_community_is_local(undo, &mod_, context).await?;
|
||||||
|
@ -446,7 +446,7 @@ async fn receive_undo_delete_community(
|
||||||
op: UserOperation::EditCommunity,
|
op: UserOperation::EditCommunity,
|
||||||
response: res,
|
response: res,
|
||||||
community_id,
|
community_id,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(undo, &user, context).await?;
|
announce_if_community_is_local(undo, &user, context).await?;
|
||||||
|
@ -511,7 +511,7 @@ async fn receive_undo_remove_community(
|
||||||
op: UserOperation::EditCommunity,
|
op: UserOperation::EditCommunity,
|
||||||
response: res,
|
response: res,
|
||||||
community_id,
|
community_id,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(undo, &mod_, context).await?;
|
announce_if_community_is_local(undo, &mod_, context).await?;
|
||||||
|
@ -556,7 +556,7 @@ async fn receive_undo_like_comment(
|
||||||
context.chat_server().do_send(SendComment {
|
context.chat_server().do_send(SendComment {
|
||||||
op: UserOperation::CreateCommentLike,
|
op: UserOperation::CreateCommentLike,
|
||||||
comment: res,
|
comment: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(undo, &user, context).await?;
|
announce_if_community_is_local(undo, &user, context).await?;
|
||||||
|
@ -595,7 +595,7 @@ async fn receive_undo_like_post(
|
||||||
context.chat_server().do_send(SendPost {
|
context.chat_server().do_send(SendPost {
|
||||||
op: UserOperation::CreatePostLike,
|
op: UserOperation::CreatePostLike,
|
||||||
post: res,
|
post: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(undo, &user, context).await?;
|
announce_if_community_is_local(undo, &user, context).await?;
|
||||||
|
@ -646,7 +646,7 @@ async fn receive_undo_dislike_comment(
|
||||||
context.chat_server().do_send(SendComment {
|
context.chat_server().do_send(SendComment {
|
||||||
op: UserOperation::CreateCommentLike,
|
op: UserOperation::CreateCommentLike,
|
||||||
comment: res,
|
comment: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(undo, &user, context).await?;
|
announce_if_community_is_local(undo, &user, context).await?;
|
||||||
|
@ -691,7 +691,7 @@ async fn receive_undo_dislike_post(
|
||||||
context.chat_server().do_send(SendPost {
|
context.chat_server().do_send(SendPost {
|
||||||
op: UserOperation::CreatePostLike,
|
op: UserOperation::CreatePostLike,
|
||||||
post: res,
|
post: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(undo, &user, context).await?;
|
announce_if_community_is_local(undo, &user, context).await?;
|
||||||
|
|
|
@ -81,7 +81,7 @@ async fn receive_update_post(
|
||||||
context.chat_server().do_send(SendPost {
|
context.chat_server().do_send(SendPost {
|
||||||
op: UserOperation::EditPost,
|
op: UserOperation::EditPost,
|
||||||
post: res,
|
post: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(update, &user, context).await?;
|
announce_if_community_is_local(update, &user, context).await?;
|
||||||
|
@ -136,7 +136,7 @@ async fn receive_update_comment(
|
||||||
context.chat_server().do_send(SendComment {
|
context.chat_server().do_send(SendComment {
|
||||||
op: UserOperation::EditComment,
|
op: UserOperation::EditComment,
|
||||||
comment: res,
|
comment: res,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
announce_if_community_is_local(update, &user, context).await?;
|
announce_if_community_is_local(update, &user, context).await?;
|
||||||
|
|
|
@ -152,7 +152,7 @@ async fn receive_create_private_message(
|
||||||
op: UserOperation::CreatePrivateMessage,
|
op: UserOperation::CreatePrivateMessage,
|
||||||
response: res,
|
response: res,
|
||||||
recipient_id,
|
recipient_id,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
|
@ -201,7 +201,7 @@ async fn receive_update_private_message(
|
||||||
op: UserOperation::EditPrivateMessage,
|
op: UserOperation::EditPrivateMessage,
|
||||||
response: res,
|
response: res,
|
||||||
recipient_id,
|
recipient_id,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
|
@ -262,7 +262,7 @@ async fn receive_delete_private_message(
|
||||||
op: UserOperation::EditPrivateMessage,
|
op: UserOperation::EditPrivateMessage,
|
||||||
response: res,
|
response: res,
|
||||||
recipient_id,
|
recipient_id,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
|
@ -323,7 +323,7 @@ async fn receive_undo_delete_private_message(
|
||||||
op: UserOperation::EditPrivateMessage,
|
op: UserOperation::EditPrivateMessage,
|
||||||
response: res,
|
response: res,
|
||||||
recipient_id,
|
recipient_id,
|
||||||
my_id: None,
|
websocket_id: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().finish())
|
Ok(HttpResponse::Ok().finish())
|
||||||
|
|
|
@ -74,11 +74,12 @@ async fn main() -> Result<(), LemmyError> {
|
||||||
settings.bind, settings.port
|
settings.bind, settings.port
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create Http server with websocket support
|
|
||||||
HttpServer::new(move || {
|
|
||||||
let chat_server =
|
let chat_server =
|
||||||
ChatServer::startup(pool.clone(), rate_limiter.clone(), Client::default()).start();
|
ChatServer::startup(pool.clone(), rate_limiter.clone(), Client::default()).start();
|
||||||
let context = LemmyContext::create(pool.clone(), chat_server, Client::default());
|
|
||||||
|
// Create Http server with websocket support
|
||||||
|
HttpServer::new(move || {
|
||||||
|
let context = LemmyContext::create(pool.clone(), chat_server.to_owned(), Client::default());
|
||||||
let settings = Settings::get();
|
let settings = Settings::get();
|
||||||
let rate_limiter = rate_limiter.clone();
|
let rate_limiter = rate_limiter.clone();
|
||||||
App::new()
|
App::new()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{comment::*, community::*, post::*, site::*, user::*, Perform},
|
api::{comment::*, community::*, post::*, site::*, user::*, Perform},
|
||||||
rate_limit::RateLimit,
|
rate_limit::RateLimit,
|
||||||
websocket::WebsocketInfo,
|
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
};
|
};
|
||||||
use actix_web::{error::ErrorBadRequest, *};
|
use actix_web::{error::ErrorBadRequest, *};
|
||||||
|
@ -182,13 +181,8 @@ where
|
||||||
Request: Perform,
|
Request: Perform,
|
||||||
Request: Send + 'static,
|
Request: Send + 'static,
|
||||||
{
|
{
|
||||||
let ws_info = WebsocketInfo {
|
|
||||||
chatserver: context.chat_server().to_owned(),
|
|
||||||
id: None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let res = data
|
let res = data
|
||||||
.perform(&context, Some(ws_info))
|
.perform(&context, None)
|
||||||
.await
|
.await
|
||||||
.map(|json| HttpResponse::Ok().json(json))
|
.map(|json| HttpResponse::Ok().json(json))
|
||||||
.map_err(ErrorBadRequest)?;
|
.map_err(ErrorBadRequest)?;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
pub mod server;
|
pub mod server;
|
||||||
|
|
||||||
use crate::ConnectionId;
|
|
||||||
use actix::prelude::*;
|
use actix::prelude::*;
|
||||||
use diesel::{
|
use diesel::{
|
||||||
r2d2::{ConnectionManager, Pool},
|
r2d2::{ConnectionManager, Pool},
|
||||||
|
@ -10,7 +9,6 @@ use log::{error, info};
|
||||||
use rand::{rngs::ThreadRng, Rng};
|
use rand::{rngs::ThreadRng, Rng};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use server::ChatServer;
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
|
@ -77,9 +75,3 @@ pub enum UserOperation {
|
||||||
GetSiteConfig,
|
GetSiteConfig,
|
||||||
SaveSiteConfig,
|
SaveSiteConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct WebsocketInfo {
|
|
||||||
pub chatserver: Addr<ChatServer>,
|
|
||||||
pub id: Option<ConnectionId>,
|
|
||||||
}
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub struct StandardMessage {
|
||||||
pub struct SendAllMessage<Response> {
|
pub struct SendAllMessage<Response> {
|
||||||
pub op: UserOperation,
|
pub op: UserOperation,
|
||||||
pub response: Response,
|
pub response: Response,
|
||||||
pub my_id: Option<ConnectionId>,
|
pub websocket_id: Option<ConnectionId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Message)]
|
#[derive(Message)]
|
||||||
|
@ -67,7 +67,7 @@ pub struct SendUserRoomMessage<Response> {
|
||||||
pub op: UserOperation,
|
pub op: UserOperation,
|
||||||
pub response: Response,
|
pub response: Response,
|
||||||
pub recipient_id: UserId,
|
pub recipient_id: UserId,
|
||||||
pub my_id: Option<ConnectionId>,
|
pub websocket_id: Option<ConnectionId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Message)]
|
#[derive(Message)]
|
||||||
|
@ -76,7 +76,7 @@ pub struct SendCommunityRoomMessage<Response> {
|
||||||
pub op: UserOperation,
|
pub op: UserOperation,
|
||||||
pub response: Response,
|
pub response: Response,
|
||||||
pub community_id: CommunityId,
|
pub community_id: CommunityId,
|
||||||
pub my_id: Option<ConnectionId>,
|
pub websocket_id: Option<ConnectionId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Message)]
|
#[derive(Message)]
|
||||||
|
@ -84,7 +84,7 @@ pub struct SendCommunityRoomMessage<Response> {
|
||||||
pub struct SendPost {
|
pub struct SendPost {
|
||||||
pub op: UserOperation,
|
pub op: UserOperation,
|
||||||
pub post: PostResponse,
|
pub post: PostResponse,
|
||||||
pub my_id: Option<ConnectionId>,
|
pub websocket_id: Option<ConnectionId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Message)]
|
#[derive(Message)]
|
||||||
|
@ -92,7 +92,7 @@ pub struct SendPost {
|
||||||
pub struct SendComment {
|
pub struct SendComment {
|
||||||
pub op: UserOperation,
|
pub op: UserOperation,
|
||||||
pub comment: CommentResponse,
|
pub comment: CommentResponse,
|
||||||
pub my_id: Option<ConnectionId>,
|
pub websocket_id: Option<ConnectionId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Message)]
|
#[derive(Message)]
|
||||||
|
@ -285,7 +285,7 @@ impl ChatServer {
|
||||||
op: &UserOperation,
|
op: &UserOperation,
|
||||||
response: &Response,
|
response: &Response,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
my_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<(), LemmyError>
|
) -> Result<(), LemmyError>
|
||||||
where
|
where
|
||||||
Response: Serialize,
|
Response: Serialize,
|
||||||
|
@ -293,7 +293,7 @@ impl ChatServer {
|
||||||
let res_str = &to_json_string(op, response)?;
|
let res_str = &to_json_string(op, response)?;
|
||||||
if let Some(sessions) = self.post_rooms.get(&post_id) {
|
if let Some(sessions) = self.post_rooms.get(&post_id) {
|
||||||
for id in sessions {
|
for id in sessions {
|
||||||
if let Some(my_id) = my_id {
|
if let Some(my_id) = websocket_id {
|
||||||
if *id == my_id {
|
if *id == my_id {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -309,7 +309,7 @@ impl ChatServer {
|
||||||
op: &UserOperation,
|
op: &UserOperation,
|
||||||
response: &Response,
|
response: &Response,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
my_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<(), LemmyError>
|
) -> Result<(), LemmyError>
|
||||||
where
|
where
|
||||||
Response: Serialize,
|
Response: Serialize,
|
||||||
|
@ -317,7 +317,7 @@ impl ChatServer {
|
||||||
let res_str = &to_json_string(op, response)?;
|
let res_str = &to_json_string(op, response)?;
|
||||||
if let Some(sessions) = self.community_rooms.get(&community_id) {
|
if let Some(sessions) = self.community_rooms.get(&community_id) {
|
||||||
for id in sessions {
|
for id in sessions {
|
||||||
if let Some(my_id) = my_id {
|
if let Some(my_id) = websocket_id {
|
||||||
if *id == my_id {
|
if *id == my_id {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -332,14 +332,14 @@ impl ChatServer {
|
||||||
&self,
|
&self,
|
||||||
op: &UserOperation,
|
op: &UserOperation,
|
||||||
response: &Response,
|
response: &Response,
|
||||||
my_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<(), LemmyError>
|
) -> Result<(), LemmyError>
|
||||||
where
|
where
|
||||||
Response: Serialize,
|
Response: Serialize,
|
||||||
{
|
{
|
||||||
let res_str = &to_json_string(op, response)?;
|
let res_str = &to_json_string(op, response)?;
|
||||||
for id in self.sessions.keys() {
|
for id in self.sessions.keys() {
|
||||||
if let Some(my_id) = my_id {
|
if let Some(my_id) = websocket_id {
|
||||||
if *id == my_id {
|
if *id == my_id {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -354,7 +354,7 @@ impl ChatServer {
|
||||||
op: &UserOperation,
|
op: &UserOperation,
|
||||||
response: &Response,
|
response: &Response,
|
||||||
recipient_id: UserId,
|
recipient_id: UserId,
|
||||||
my_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<(), LemmyError>
|
) -> Result<(), LemmyError>
|
||||||
where
|
where
|
||||||
Response: Serialize,
|
Response: Serialize,
|
||||||
|
@ -362,7 +362,7 @@ impl ChatServer {
|
||||||
let res_str = &to_json_string(op, response)?;
|
let res_str = &to_json_string(op, response)?;
|
||||||
if let Some(sessions) = self.user_rooms.get(&recipient_id) {
|
if let Some(sessions) = self.user_rooms.get(&recipient_id) {
|
||||||
for id in sessions {
|
for id in sessions {
|
||||||
if let Some(my_id) = my_id {
|
if let Some(my_id) = websocket_id {
|
||||||
if *id == my_id {
|
if *id == my_id {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ impl ChatServer {
|
||||||
&self,
|
&self,
|
||||||
user_operation: &UserOperation,
|
user_operation: &UserOperation,
|
||||||
comment: &CommentResponse,
|
comment: &CommentResponse,
|
||||||
my_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let mut comment_reply_sent = comment.clone();
|
let mut comment_reply_sent = comment.clone();
|
||||||
comment_reply_sent.comment.my_vote = None;
|
comment_reply_sent.comment.my_vote = None;
|
||||||
|
@ -391,21 +391,26 @@ impl ChatServer {
|
||||||
user_operation,
|
user_operation,
|
||||||
&comment_post_sent,
|
&comment_post_sent,
|
||||||
comment_post_sent.comment.post_id,
|
comment_post_sent.comment.post_id,
|
||||||
my_id,
|
websocket_id,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Send it to the recipient(s) including the mentioned users
|
// Send it to the recipient(s) including the mentioned users
|
||||||
for recipient_id in &comment_reply_sent.recipient_ids {
|
for recipient_id in &comment_reply_sent.recipient_ids {
|
||||||
self.send_user_room_message(user_operation, &comment_reply_sent, *recipient_id, my_id)?;
|
self.send_user_room_message(
|
||||||
|
user_operation,
|
||||||
|
&comment_reply_sent,
|
||||||
|
*recipient_id,
|
||||||
|
websocket_id,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send it to the community too
|
// Send it to the community too
|
||||||
self.send_community_room_message(user_operation, &comment_post_sent, 0, my_id)?;
|
self.send_community_room_message(user_operation, &comment_post_sent, 0, websocket_id)?;
|
||||||
self.send_community_room_message(
|
self.send_community_room_message(
|
||||||
user_operation,
|
user_operation,
|
||||||
&comment_post_sent,
|
&comment_post_sent,
|
||||||
comment.comment.community_id,
|
comment.comment.community_id,
|
||||||
my_id,
|
websocket_id,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -415,7 +420,7 @@ impl ChatServer {
|
||||||
&self,
|
&self,
|
||||||
user_operation: &UserOperation,
|
user_operation: &UserOperation,
|
||||||
post: &PostResponse,
|
post: &PostResponse,
|
||||||
my_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let community_id = post.post.community_id;
|
let community_id = post.post.community_id;
|
||||||
|
|
||||||
|
@ -425,11 +430,11 @@ impl ChatServer {
|
||||||
post_sent.post.user_id = None;
|
post_sent.post.user_id = None;
|
||||||
|
|
||||||
// Send it to /c/all and that community
|
// Send it to /c/all and that community
|
||||||
self.send_community_room_message(user_operation, &post_sent, 0, my_id)?;
|
self.send_community_room_message(user_operation, &post_sent, 0, websocket_id)?;
|
||||||
self.send_community_room_message(user_operation, &post_sent, community_id, my_id)?;
|
self.send_community_room_message(user_operation, &post_sent, community_id, websocket_id)?;
|
||||||
|
|
||||||
// Send it to the post room
|
// Send it to the post room
|
||||||
self.send_post_room_message(user_operation, &post_sent, post.post.id, my_id)?;
|
self.send_post_room_message(user_operation, &post_sent, post.post.id, websocket_id)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -471,7 +476,7 @@ impl ChatServer {
|
||||||
client,
|
client,
|
||||||
};
|
};
|
||||||
let args = Args {
|
let args = Args {
|
||||||
context: &context,
|
context,
|
||||||
rate_limiter,
|
rate_limiter,
|
||||||
id: msg.id,
|
id: msg.id,
|
||||||
ip,
|
ip,
|
||||||
|
@ -565,7 +570,7 @@ impl ChatServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Args<'a> {
|
struct Args<'a> {
|
||||||
context: &'a LemmyContext,
|
context: LemmyContext,
|
||||||
rate_limiter: RateLimit,
|
rate_limiter: RateLimit,
|
||||||
id: ConnectionId,
|
id: ConnectionId,
|
||||||
ip: IPAddr,
|
ip: IPAddr,
|
||||||
|
@ -587,18 +592,13 @@ where
|
||||||
data,
|
data,
|
||||||
} = args;
|
} = args;
|
||||||
|
|
||||||
let ws_info = WebsocketInfo {
|
|
||||||
chatserver: context.chat_server().to_owned(),
|
|
||||||
id: Some(id),
|
|
||||||
};
|
|
||||||
|
|
||||||
let data = data.to_string();
|
let data = data.to_string();
|
||||||
let op2 = op.clone();
|
let op2 = op.clone();
|
||||||
|
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
let parsed_data: Data = serde_json::from_str(&data)?;
|
let parsed_data: Data = serde_json::from_str(&data)?;
|
||||||
let res = parsed_data
|
let res = parsed_data
|
||||||
.perform(&web::Data::new(context.to_owned()), Some(ws_info))
|
.perform(&web::Data::new(context), Some(id))
|
||||||
.await?;
|
.await?;
|
||||||
to_json_string(&op, &res)
|
to_json_string(&op, &res)
|
||||||
};
|
};
|
||||||
|
@ -692,7 +692,7 @@ where
|
||||||
|
|
||||||
fn handle(&mut self, msg: SendAllMessage<Response>, _: &mut Context<Self>) {
|
fn handle(&mut self, msg: SendAllMessage<Response>, _: &mut Context<Self>) {
|
||||||
self
|
self
|
||||||
.send_all_message(&msg.op, &msg.response, msg.my_id)
|
.send_all_message(&msg.op, &msg.response, msg.websocket_id)
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -705,7 +705,7 @@ where
|
||||||
|
|
||||||
fn handle(&mut self, msg: SendUserRoomMessage<Response>, _: &mut Context<Self>) {
|
fn handle(&mut self, msg: SendUserRoomMessage<Response>, _: &mut Context<Self>) {
|
||||||
self
|
self
|
||||||
.send_user_room_message(&msg.op, &msg.response, msg.recipient_id, msg.my_id)
|
.send_user_room_message(&msg.op, &msg.response, msg.recipient_id, msg.websocket_id)
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -718,7 +718,7 @@ where
|
||||||
|
|
||||||
fn handle(&mut self, msg: SendCommunityRoomMessage<Response>, _: &mut Context<Self>) {
|
fn handle(&mut self, msg: SendCommunityRoomMessage<Response>, _: &mut Context<Self>) {
|
||||||
self
|
self
|
||||||
.send_community_room_message(&msg.op, &msg.response, msg.community_id, msg.my_id)
|
.send_community_room_message(&msg.op, &msg.response, msg.community_id, msg.websocket_id)
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -727,7 +727,7 @@ impl Handler<SendPost> for ChatServer {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
|
|
||||||
fn handle(&mut self, msg: SendPost, _: &mut Context<Self>) {
|
fn handle(&mut self, msg: SendPost, _: &mut Context<Self>) {
|
||||||
self.send_post(&msg.op, &msg.post, msg.my_id).ok();
|
self.send_post(&msg.op, &msg.post, msg.websocket_id).ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,7 +735,9 @@ impl Handler<SendComment> for ChatServer {
|
||||||
type Result = ();
|
type Result = ();
|
||||||
|
|
||||||
fn handle(&mut self, msg: SendComment, _: &mut Context<Self>) {
|
fn handle(&mut self, msg: SendComment, _: &mut Context<Self>) {
|
||||||
self.send_comment(&msg.op, &msg.comment, msg.my_id).ok();
|
self
|
||||||
|
.send_comment(&msg.op, &msg.comment, msg.websocket_id)
|
||||||
|
.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue