Fixing some minor websocket things.

pull/1344/head
Dessalines 2021-01-07 01:17:42 -05:00
parent ceae7eb47a
commit b9b51c2dfc
3 changed files with 30 additions and 58 deletions

View File

@ -152,7 +152,7 @@ impl Perform for CreateComment {
comment_view.comment.read = true; comment_view.comment.read = true;
} }
let mut res = CommentResponse { let res = CommentResponse {
comment_view, comment_view,
recipient_ids, recipient_ids,
form_id: data.form_id.to_owned(), form_id: data.form_id.to_owned(),
@ -164,11 +164,6 @@ impl Perform for CreateComment {
websocket_id, websocket_id,
}); });
// strip out the recipient_ids, so that
// users don't get double notifs
// TODO Do this in a different way
res.recipient_ids = Vec::new();
Ok(res) Ok(res)
} }
} }
@ -233,7 +228,7 @@ impl Perform for EditComment {
}) })
.await??; .await??;
let mut res = CommentResponse { let res = CommentResponse {
comment_view, comment_view,
recipient_ids, recipient_ids,
form_id: data.form_id.to_owned(), form_id: data.form_id.to_owned(),
@ -245,11 +240,6 @@ impl Perform for EditComment {
websocket_id, websocket_id,
}); });
// strip out the recipient_ids, so that
// users don't get double notifs
// TODO again
res.recipient_ids = Vec::new();
Ok(res) Ok(res)
} }
} }
@ -318,7 +308,7 @@ impl Perform for DeleteComment {
) )
.await?; .await?;
let mut res = CommentResponse { let res = CommentResponse {
comment_view, comment_view,
recipient_ids, recipient_ids,
form_id: None, // TODO a comment delete might clear forms? form_id: None, // TODO a comment delete might clear forms?
@ -330,11 +320,6 @@ impl Perform for DeleteComment {
websocket_id, websocket_id,
}); });
// strip out the recipient_ids, so that
// users don't get double notifs
// TODO again
res.recipient_ids = Vec::new();
Ok(res) Ok(res)
} }
} }
@ -414,7 +399,7 @@ impl Perform for RemoveComment {
) )
.await?; .await?;
let mut res = CommentResponse { let res = CommentResponse {
comment_view, comment_view,
recipient_ids, recipient_ids,
form_id: None, // TODO maybe this might clear other forms form_id: None, // TODO maybe this might clear other forms
@ -426,11 +411,6 @@ impl Perform for RemoveComment {
websocket_id, websocket_id,
}); });
// strip out the recipient_ids, so that
// users don't get double notifs
// TODO again
res.recipient_ids = Vec::new();
Ok(res) Ok(res)
} }
} }
@ -602,7 +582,7 @@ impl Perform for CreateCommentLike {
}) })
.await??; .await??;
let mut res = CommentResponse { let res = CommentResponse {
comment_view: liked_comment, comment_view: liked_comment,
recipient_ids, recipient_ids,
form_id: None, form_id: None,
@ -614,11 +594,6 @@ impl Perform for CreateCommentLike {
websocket_id, websocket_id,
}); });
// strip out the recipient_ids, so that
// users don't get double notifs
res.recipient_ids = Vec::new();
// TODO why
Ok(res) Ok(res)
} }
} }

View File

@ -853,15 +853,13 @@ fn send_community_websocket(
websocket_id: Option<ConnectionId>, websocket_id: Option<ConnectionId>,
op: UserOperation, op: UserOperation,
) { ) {
// TODO is there any way around this?
// 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_view.user_id = None; res_sent.community_view.subscribed = false;
// res_sent.community.subscribed = None;
context.chat_server().do_send(SendCommunityRoomMessage { context.chat_server().do_send(SendCommunityRoomMessage {
op, op,
response: res.to_owned(), response: res_sent,
community_id: res.community_view.community.id, community_id: res.community_view.community.id,
websocket_id, websocket_id,
}); });

View File

@ -328,15 +328,14 @@ impl ChatServer {
comment: &CommentResponse, comment: &CommentResponse,
websocket_id: Option<ConnectionId>, websocket_id: Option<ConnectionId>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let comment_reply_sent = comment.clone(); let mut comment_reply_sent = comment.clone();
// TODO what is this here
// comment_reply_sent.comment_view.my_vote = None;
// comment_reply_sent.comment.user_id = None;
let mut comment_post_sent = comment_reply_sent.clone(); // Strip out my specific user info
comment_post_sent.recipient_ids = Vec::new(); comment_reply_sent.comment_view.my_vote = None;
// Send it to the post room // Send it to the post room
let mut comment_post_sent = comment_reply_sent.clone();
comment_post_sent.recipient_ids = Vec::new();
self.send_post_room_message( self.send_post_room_message(
user_operation, user_operation,
&comment_post_sent, &comment_post_sent,
@ -344,16 +343,6 @@ impl ChatServer {
websocket_id, websocket_id,
)?; )?;
// Send it to the recipient(s) including the mentioned users
for recipient_id in &comment_reply_sent.recipient_ids {
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, websocket_id)?; self.send_community_room_message(user_operation, &comment_post_sent, 0, websocket_id)?;
self.send_community_room_message( self.send_community_room_message(
@ -363,6 +352,18 @@ impl ChatServer {
websocket_id, websocket_id,
)?; )?;
// Remove the form id here to separate mentions / user messages from post or community comments
comment_reply_sent.form_id = None;
// Send it to the recipient(s) including the mentioned users
for recipient_id in &comment_reply_sent.recipient_ids {
self.send_user_room_message(
user_operation,
&comment_reply_sent,
*recipient_id,
websocket_id,
)?;
}
Ok(()) Ok(())
} }
@ -375,19 +376,17 @@ impl ChatServer {
let community_id = post_res.post_view.community.id; let community_id = post_res.post_view.community.id;
// Don't send my data with it // Don't send my data with it
// TODO no idea what to do here let mut post_sent = post_res.clone();
// let mut post_sent = post_res.clone(); post_sent.post_view.my_vote = None;
// post_sent.post.my_vote = 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_res, 0, websocket_id)?; self.send_community_room_message(user_operation, &post_sent, 0, websocket_id)?;
self.send_community_room_message(user_operation, &post_res, community_id, websocket_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( self.send_post_room_message(
user_operation, user_operation,
&post_res, &post_sent,
post_res.post_view.post.id, post_res.post_view.post.id,
websocket_id, websocket_id,
)?; )?;