Implement helper functions for websocket message sending

This commit is contained in:
Felix Ableitner 2021-08-13 19:30:19 +02:00
parent bc6294a834
commit 2d346a1487
34 changed files with 501 additions and 795 deletions

2
Cargo.lock generated
View file

@ -1944,6 +1944,8 @@ dependencies = [
"lemmy_api_common", "lemmy_api_common",
"lemmy_db_queries", "lemmy_db_queries",
"lemmy_db_schema", "lemmy_db_schema",
"lemmy_db_views",
"lemmy_db_views_actor",
"lemmy_utils", "lemmy_utils",
"log", "log",
"rand 0.8.4", "rand 0.8.4",

View file

@ -18,7 +18,7 @@ use lemmy_db_queries::{source::comment::Comment_, Likeable, Saveable};
use lemmy_db_schema::{source::comment::*, LocalUserId}; use lemmy_db_schema::{source::comment::*, LocalUserId};
use lemmy_db_views::{comment_view::CommentView, local_user_view::LocalUserView}; use lemmy_db_views::{comment_view::CommentView, local_user_view::LocalUserView};
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperation}; use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperation};
use std::convert::TryInto; use std::convert::TryInto;
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
@ -206,26 +206,15 @@ impl Perform for CreateCommentLike {
.await?; .await?;
} }
// Have to refetch the comment to get the current state send_comment_ws_message(
let comment_id = data.comment_id; data.comment_id,
let person_id = local_user_view.person.id; UserOperation::CreateCommentLike,
let liked_comment = blocking(context.pool(), move |conn| {
CommentView::read(conn, comment_id, Some(person_id))
})
.await??;
let res = CommentResponse {
comment_view: liked_comment,
recipient_ids,
form_id: None,
};
context.chat_server().do_send(SendComment {
op: UserOperation::CreateCommentLike,
comment: res.clone(),
websocket_id, websocket_id,
}); None,
Some(local_user_view.person.id),
Ok(res) recipient_ids,
context,
)
.await
} }
} }

View file

@ -24,7 +24,7 @@ use lemmy_db_queries::{source::post::Post_, Crud, Likeable, Saveable};
use lemmy_db_schema::source::{moderator::*, post::*}; use lemmy_db_schema::source::{moderator::*, post::*};
use lemmy_db_views::post_view::PostView; use lemmy_db_views::post_view::PostView;
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperation}; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperation};
use std::convert::TryInto; use std::convert::TryInto;
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
@ -96,23 +96,14 @@ impl Perform for CreatePostLike {
// Mark the post as read // Mark the post as read
mark_post_as_read(person_id, post_id, context.pool()).await?; mark_post_as_read(person_id, post_id, context.pool()).await?;
let post_id = data.post_id; send_post_ws_message(
let person_id = local_user_view.person.id; data.post_id,
let post_view = blocking(context.pool(), move |conn| { UserOperation::CreatePostLike,
PostView::read(conn, post_id, Some(person_id))
})
.await?
.map_err(|_| ApiError::err("couldnt_find_post"))?;
let res = PostResponse { post_view };
context.chat_server().do_send(SendPost {
op: UserOperation::CreatePostLike,
post: res.clone(),
websocket_id, websocket_id,
}); Some(local_user_view.person.id),
context,
Ok(res) )
.await
} }
} }
@ -171,22 +162,14 @@ impl Perform for LockPost {
) )
.await?; .await?;
// Refetch the post send_post_ws_message(
let post_id = data.post_id; data.post_id,
let post_view = blocking(context.pool(), move |conn| { UserOperation::LockPost,
PostView::read(conn, post_id, Some(local_user_view.person.id))
})
.await??;
let res = PostResponse { post_view };
context.chat_server().do_send(SendPost {
op: UserOperation::LockPost,
post: res.clone(),
websocket_id, websocket_id,
}); Some(local_user_view.person.id),
context,
Ok(res) )
.await
} }
} }
@ -249,22 +232,14 @@ impl Perform for StickyPost {
) )
.await?; .await?;
// Refetch the post send_post_ws_message(
let post_id = data.post_id; data.post_id,
let post_view = blocking(context.pool(), move |conn| { UserOperation::StickyPost,
PostView::read(conn, post_id, Some(local_user_view.person.id))
})
.await??;
let res = PostResponse { post_view };
context.chat_server().do_send(SendPost {
op: UserOperation::StickyPost,
post: res.clone(),
websocket_id, websocket_id,
}); Some(local_user_view.person.id),
context,
Ok(res) )
.await
} }
} }

View file

@ -7,9 +7,8 @@ use lemmy_api_common::{
}; };
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud}; use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_db_schema::source::private_message::PrivateMessage;
use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView};
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendUserRoomMessage, LemmyContext, UserOperation}; use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperation};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl Perform for MarkPrivateMessageAsRead { impl Perform for MarkPrivateMessageAsRead {
@ -43,32 +42,7 @@ impl Perform for MarkPrivateMessageAsRead {
.map_err(|_| ApiError::err("couldnt_update_private_message"))?; .map_err(|_| ApiError::err("couldnt_update_private_message"))?;
// No need to send an apub update // No need to send an apub update
let private_message_id = data.private_message_id; let op = UserOperation::MarkPrivateMessageAsRead;
let private_message_view = blocking(context.pool(), move |conn| { send_pm_ws_message(data.private_message_id, op, websocket_id, context).await
PrivateMessageView::read(conn, private_message_id)
})
.await??;
let res = PrivateMessageResponse {
private_message_view,
};
// Send notifications to the local recipient, if one exists
let recipient_id = orig_private_message.recipient_id;
if let Ok(local_recipient) = blocking(context.pool(), move |conn| {
LocalUserView::read_person(conn, recipient_id)
})
.await?
{
let local_recipient_id = local_recipient.local_user.id;
context.chat_server().do_send(SendUserRoomMessage {
op: UserOperation::MarkPrivateMessageAsRead,
response: res.clone(),
local_recipient_id,
websocket_id,
});
}
Ok(res)
} }
} }

View file

@ -20,14 +20,13 @@ use lemmy_apub::{
}; };
use lemmy_db_queries::{source::comment::Comment_, Crud, Likeable}; use lemmy_db_queries::{source::comment::Comment_, Crud, Likeable};
use lemmy_db_schema::source::comment::*; use lemmy_db_schema::source::comment::*;
use lemmy_db_views::comment_view::CommentView;
use lemmy_utils::{ use lemmy_utils::{
utils::{remove_slurs, scrape_text_for_mentions}, utils::{remove_slurs, scrape_text_for_mentions},
ApiError, ApiError,
ConnectionId, ConnectionId,
LemmyError, LemmyError,
}; };
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for CreateComment { impl PerformCrud for CreateComment {
@ -137,37 +136,25 @@ impl PerformCrud for CreateComment {
) )
.await?; .await?;
let person_id = local_user_view.person.id;
let mut comment_view = blocking(context.pool(), move |conn| {
CommentView::read(conn, inserted_comment.id, Some(person_id))
})
.await??;
// If its a comment to yourself, mark it as read // If its a comment to yourself, mark it as read
let comment_id = comment_view.comment.id; if local_user_view.person.id == inserted_comment.creator_id {
if local_user_view.person.id == comment_view.get_recipient_id() { let comment_id = inserted_comment.id;
blocking(context.pool(), move |conn| { blocking(context.pool(), move |conn| {
Comment::update_read(conn, comment_id, true) Comment::update_read(conn, comment_id, true)
}) })
.await? .await?
.map_err(|_| ApiError::err("couldnt_update_comment"))?; .map_err(|_| ApiError::err("couldnt_update_comment"))?;
comment_view.comment.read = true;
} }
let mut res = CommentResponse { send_comment_ws_message(
comment_view, inserted_comment.id,
recipient_ids, UserOperationCrud::CreateComment,
form_id: data.form_id.to_owned(),
};
context.chat_server().do_send(SendComment {
op: UserOperationCrud::CreateComment,
comment: res.clone(),
websocket_id, websocket_id,
}); data.form_id.to_owned(),
Some(local_user_view.person.id),
res.recipient_ids = Vec::new(); // Necessary to avoid doubles recipient_ids,
context,
Ok(res) )
.await
} }
} }

View file

@ -9,11 +9,11 @@ use lemmy_api_common::{
send_local_notifs, send_local_notifs,
}; };
use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove}; use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
use lemmy_db_queries::{source::comment::Comment_, Crud, DeleteableOrRemoveable}; use lemmy_db_queries::{source::comment::Comment_, Crud};
use lemmy_db_schema::source::{comment::*, community::Community, moderator::*}; use lemmy_db_schema::source::{comment::*, community::Community, moderator::*, post::Post};
use lemmy_db_views::comment_view::CommentView; use lemmy_db_views::comment_view::CommentView;
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for DeleteComment { impl PerformCrud for DeleteComment {
@ -67,45 +67,28 @@ impl PerformCrud for DeleteComment {
) )
.await?; .await?;
// Refetch it let post_id = updated_comment.post_id;
let comment_id = data.comment_id; let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
let person_id = local_user_view.person.id;
let mut comment_view = blocking(context.pool(), move |conn| {
CommentView::read(conn, comment_id, Some(person_id))
})
.await??;
// Blank out deleted or removed info
if deleted {
comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info();
}
// Build the recipients
let comment_view_2 = comment_view.clone();
let mentions = vec![];
let recipient_ids = send_local_notifs( let recipient_ids = send_local_notifs(
mentions, vec![],
updated_comment, updated_comment,
local_user_view.person.clone(), local_user_view.person.clone(),
comment_view_2.post, post,
context.pool(), context.pool(),
false, false,
) )
.await?; .await?;
let res = CommentResponse { send_comment_ws_message(
comment_view, data.comment_id,
recipient_ids, UserOperationCrud::DeleteComment,
form_id: None, // TODO a comment delete might clear forms?
};
context.chat_server().do_send(SendComment {
op: UserOperationCrud::DeleteComment,
comment: res.clone(),
websocket_id, websocket_id,
}); None, // TODO a comment delete might clear forms?
Some(local_user_view.person.id),
Ok(res) recipient_ids,
context,
)
.await
} }
} }
@ -177,45 +160,27 @@ impl PerformCrud for RemoveComment {
) )
.await?; .await?;
// Refetch it let post_id = updated_comment.post_id;
let comment_id = data.comment_id; let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
let person_id = local_user_view.person.id;
let mut comment_view = blocking(context.pool(), move |conn| {
CommentView::read(conn, comment_id, Some(person_id))
})
.await??;
// Blank out deleted or removed info
if removed {
comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info();
}
// Build the recipients
let comment_view_2 = comment_view.clone();
let mentions = vec![];
let recipient_ids = send_local_notifs( let recipient_ids = send_local_notifs(
mentions, vec![],
updated_comment, updated_comment,
local_user_view.person.clone(), local_user_view.person.clone(),
comment_view_2.post, post,
context.pool(), context.pool(),
false, false,
) )
.await?; .await?;
let res = CommentResponse { send_comment_ws_message(
comment_view, data.comment_id,
recipient_ids, UserOperationCrud::RemoveComment,
form_id: None, // TODO maybe this might clear other forms
};
context.chat_server().do_send(SendComment {
op: UserOperationCrud::RemoveComment,
comment: res.clone(),
websocket_id, websocket_id,
}); None, // TODO maybe this might clear other forms
Some(local_user_view.person.id),
Ok(res) recipient_ids,
context,
)
.await
} }
} }

View file

@ -11,7 +11,7 @@ use lemmy_apub::activities::{
comment::create_or_update::CreateOrUpdateComment, comment::create_or_update::CreateOrUpdateComment,
CreateOrUpdateType, CreateOrUpdateType,
}; };
use lemmy_db_queries::{source::comment::Comment_, DeleteableOrRemoveable}; use lemmy_db_queries::source::comment::Comment_;
use lemmy_db_schema::source::comment::*; use lemmy_db_schema::source::comment::*;
use lemmy_db_views::comment_view::CommentView; use lemmy_db_views::comment_view::CommentView;
use lemmy_utils::{ use lemmy_utils::{
@ -20,7 +20,7 @@ use lemmy_utils::{
ConnectionId, ConnectionId,
LemmyError, LemmyError,
}; };
use lemmy_websocket::{messages::SendComment, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for EditComment { impl PerformCrud for EditComment {
@ -83,30 +83,15 @@ impl PerformCrud for EditComment {
) )
.await?; .await?;
let comment_id = data.comment_id; send_comment_ws_message(
let person_id = local_user_view.person.id; data.comment_id,
let mut comment_view = blocking(context.pool(), move |conn| { UserOperationCrud::EditComment,
CommentView::read(conn, comment_id, Some(person_id))
})
.await??;
// Blank out deleted or removed info
if comment_view.comment.deleted || comment_view.comment.removed {
comment_view.comment = comment_view.comment.blank_out_deleted_or_removed_info();
}
let res = CommentResponse {
comment_view,
recipient_ids,
form_id: data.form_id.to_owned(),
};
context.chat_server().do_send(SendComment {
op: UserOperationCrud::EditComment,
comment: res.clone(),
websocket_id, websocket_id,
}); data.form_id.to_owned(),
None,
Ok(res) recipient_ids,
context,
)
.await
} }
} }

View file

@ -1,18 +1,15 @@
use crate::{community::send_community_websocket, PerformCrud}; use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt, is_admin}; use lemmy_api_common::{blocking, community::*, get_local_user_view_from_jwt, is_admin};
use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove}; use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
use lemmy_db_queries::{source::community::Community_, Crud, DeleteableOrRemoveable}; use lemmy_db_queries::{source::community::Community_, Crud};
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
community::*, community::*,
moderator::{ModRemoveCommunity, ModRemoveCommunityForm}, moderator::{ModRemoveCommunity, ModRemoveCommunityForm},
}; };
use lemmy_db_views_actor::{ use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
community_moderator_view::CommunityModeratorView,
community_view::CommunityView,
};
use lemmy_utils::{utils::naive_from_unix, ApiError, ConnectionId, LemmyError}; use lemmy_utils::{utils::naive_from_unix, ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for DeleteCommunity { impl PerformCrud for DeleteCommunity {
@ -57,28 +54,14 @@ impl PerformCrud for DeleteCommunity {
) )
.await?; .await?;
let community_id = data.community_id; send_community_ws_message(
let person_id = local_user_view.person.id; data.community_id,
let mut community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, Some(person_id))
})
.await??;
// Blank out deleted or removed info
if deleted {
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
}
let res = CommunityResponse { community_view };
send_community_websocket(
&res,
context,
websocket_id,
UserOperationCrud::DeleteCommunity, UserOperationCrud::DeleteCommunity,
); websocket_id,
Some(local_user_view.person.id),
Ok(res) context,
)
.await
} }
} }
@ -131,27 +114,13 @@ impl PerformCrud for RemoveCommunity {
) )
.await?; .await?;
let community_id = data.community_id; send_community_ws_message(
let person_id = local_user_view.person.id; data.community_id,
let mut community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, Some(person_id))
})
.await??;
// Blank out deleted or removed info
if removed {
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
}
let res = CommunityResponse { community_view };
send_community_websocket(
&res,
context,
websocket_id,
UserOperationCrud::RemoveCommunity, UserOperationCrud::RemoveCommunity,
); websocket_id,
Some(local_user_view.person.id),
Ok(res) context,
)
.await
} }
} }

View file

@ -1,27 +1,4 @@
use actix_web::web::Data;
use lemmy_api_common::community::CommunityResponse;
use lemmy_utils::ConnectionId;
use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperationCrud};
mod create; mod create;
mod delete; mod delete;
mod read; mod read;
mod update; mod update;
pub(in crate::community) fn send_community_websocket(
res: &CommunityResponse,
context: &Data<LemmyContext>,
websocket_id: Option<ConnectionId>,
op: UserOperationCrud,
) {
// Strip out the person id and subscribed when sending to others
let mut res_sent = res.clone();
res_sent.community_view.subscribed = false;
context.chat_server().do_send(SendCommunityRoomMessage {
op,
response: res_sent,
community_id: res.community_view.community.id,
websocket_id,
});
}

View file

@ -1,4 +1,4 @@
use crate::{community::send_community_websocket, PerformCrud}; use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{ use lemmy_api_common::{
blocking, blocking,
@ -6,18 +6,15 @@ use lemmy_api_common::{
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
}; };
use lemmy_apub::CommunityType; use lemmy_apub::CommunityType;
use lemmy_db_queries::{diesel_option_overwrite_to_url, Crud, DeleteableOrRemoveable}; use lemmy_db_queries::{diesel_option_overwrite_to_url, Crud};
use lemmy_db_schema::{ use lemmy_db_schema::{
naive_now, naive_now,
source::community::{Community, CommunityForm}, source::community::{Community, CommunityForm},
PersonId, PersonId,
}; };
use lemmy_db_views_actor::{ use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
community_moderator_view::CommunityModeratorView,
community_view::CommunityView,
};
use lemmy_utils::{utils::check_slurs_opt, ApiError, ConnectionId, LemmyError}; use lemmy_utils::{utils::check_slurs_opt, ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for EditCommunity { impl PerformCrud for EditCommunity {
@ -76,27 +73,7 @@ impl PerformCrud for EditCommunity {
.send_update(local_user_view.person.to_owned(), context) .send_update(local_user_view.person.to_owned(), context)
.await?; .await?;
let community_id = data.community_id; let op = UserOperationCrud::EditCommunity;
let person_id = local_user_view.person.id; send_community_ws_message(data.community_id, op, websocket_id, None, context).await
let mut community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, Some(person_id))
})
.await??;
// Blank out deleted or removed info
if community_view.community.deleted || community_view.community.removed {
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
}
let res = CommunityResponse { community_view };
send_community_websocket(
&res,
context,
websocket_id,
UserOperationCrud::EditCommunity,
);
Ok(res)
} }
} }

View file

@ -19,7 +19,6 @@ use lemmy_apub::{
}; };
use lemmy_db_queries::{source::post::Post_, Crud, Likeable}; use lemmy_db_queries::{source::post::Post_, Crud, Likeable};
use lemmy_db_schema::source::post::*; use lemmy_db_schema::source::post::*;
use lemmy_db_views::post_view::PostView;
use lemmy_utils::{ use lemmy_utils::{
request::fetch_iframely_and_pictrs_data, request::fetch_iframely_and_pictrs_data,
utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title}, utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title},
@ -27,7 +26,7 @@ use lemmy_utils::{
ConnectionId, ConnectionId,
LemmyError, LemmyError,
}; };
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for CreatePost { impl PerformCrud for CreatePost {
@ -129,22 +128,13 @@ impl PerformCrud for CreatePost {
) )
.await?; .await?;
// Refetch the view send_post_ws_message(
let inserted_post_id = inserted_post.id; inserted_post.id,
let post_view = blocking(context.pool(), move |conn| { UserOperationCrud::CreatePost,
PostView::read(conn, inserted_post_id, Some(local_user_view.person.id))
})
.await?
.map_err(|_| ApiError::err("couldnt_find_post"))?;
let res = PostResponse { post_view };
context.chat_server().do_send(SendPost {
op: UserOperationCrud::CreatePost,
post: res.clone(),
websocket_id, websocket_id,
}); Some(local_user_view.person.id),
context,
Ok(res) )
.await
} }
} }

View file

@ -8,11 +8,10 @@ use lemmy_api_common::{
post::*, post::*,
}; };
use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove}; use lemmy_apub::activities::deletion::{send_apub_delete, send_apub_remove};
use lemmy_db_queries::{source::post::Post_, Crud, DeleteableOrRemoveable}; use lemmy_db_queries::{source::post::Post_, Crud};
use lemmy_db_schema::source::{community::Community, moderator::*, post::*}; use lemmy_db_schema::source::{community::Community, moderator::*, post::*};
use lemmy_db_views::post_view::PostView;
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for DeletePost { impl PerformCrud for DeletePost {
@ -63,26 +62,14 @@ impl PerformCrud for DeletePost {
) )
.await?; .await?;
// Refetch the post send_post_ws_message(
let post_id = data.post_id; data.post_id,
let mut post_view = blocking(context.pool(), move |conn| { UserOperationCrud::DeletePost,
PostView::read(conn, post_id, Some(local_user_view.person.id))
})
.await??;
if deleted {
post_view.post = post_view.post.blank_out_deleted_or_removed_info();
}
let res = PostResponse { post_view };
context.chat_server().do_send(SendPost {
op: UserOperationCrud::DeletePost,
post: res.clone(),
websocket_id, websocket_id,
}); Some(local_user_view.person.id),
context,
Ok(res) )
.await
} }
} }
@ -151,27 +138,13 @@ impl PerformCrud for RemovePost {
) )
.await?; .await?;
// Refetch the post send_post_ws_message(
let post_id = data.post_id; data.post_id,
let person_id = local_user_view.person.id; UserOperationCrud::RemovePost,
let mut post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, post_id, Some(person_id))
})
.await??;
// Blank out deleted or removed info
if removed {
post_view.post = post_view.post.blank_out_deleted_or_removed_info();
}
let res = PostResponse { post_view };
context.chat_server().do_send(SendPost {
op: UserOperationCrud::RemovePost,
post: res.clone(),
websocket_id, websocket_id,
}); Some(local_user_view.person.id),
context,
Ok(res) )
.await
} }
} }

View file

@ -2,9 +2,8 @@ use crate::PerformCrud;
use actix_web::web::Data; use actix_web::web::Data;
use lemmy_api_common::{blocking, check_community_ban, get_local_user_view_from_jwt, post::*}; use lemmy_api_common::{blocking, check_community_ban, get_local_user_view_from_jwt, post::*};
use lemmy_apub::activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType}; use lemmy_apub::activities::{post::create_or_update::CreateOrUpdatePost, CreateOrUpdateType};
use lemmy_db_queries::{source::post::Post_, Crud, DeleteableOrRemoveable}; use lemmy_db_queries::{source::post::Post_, Crud};
use lemmy_db_schema::{naive_now, source::post::*}; use lemmy_db_schema::{naive_now, source::post::*};
use lemmy_db_views::post_view::PostView;
use lemmy_utils::{ use lemmy_utils::{
request::fetch_iframely_and_pictrs_data, request::fetch_iframely_and_pictrs_data,
utils::{check_slurs_opt, clean_url_params, is_valid_post_title}, utils::{check_slurs_opt, clean_url_params, is_valid_post_title},
@ -12,7 +11,7 @@ use lemmy_utils::{
ConnectionId, ConnectionId,
LemmyError, LemmyError,
}; };
use lemmy_websocket::{messages::SendPost, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for EditPost { impl PerformCrud for EditPost {
@ -100,25 +99,13 @@ impl PerformCrud for EditPost {
) )
.await?; .await?;
let post_id = data.post_id; send_post_ws_message(
let mut post_view = blocking(context.pool(), move |conn| { data.post_id,
PostView::read(conn, post_id, Some(local_user_view.person.id)) UserOperationCrud::EditPost,
})
.await??;
// Blank out deleted info
if post_view.post.deleted || post_view.post.removed {
post_view.post = post_view.post.blank_out_deleted_or_removed_info();
}
let res = PostResponse { post_view };
context.chat_server().do_send(SendPost {
op: UserOperationCrud::EditPost,
post: res.clone(),
websocket_id, websocket_id,
}); Some(local_user_view.person.id),
context,
Ok(res) )
.await
} }
} }

View file

@ -16,9 +16,9 @@ use lemmy_apub::{
}; };
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud}; use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
use lemmy_db_schema::source::private_message::{PrivateMessage, PrivateMessageForm}; use lemmy_db_schema::source::private_message::{PrivateMessage, PrivateMessageForm};
use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView}; use lemmy_db_views::local_user_view::LocalUserView;
use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError}; use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendUserRoomMessage, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for CreatePrivateMessage { impl PerformCrud for CreatePrivateMessage {
@ -78,36 +78,27 @@ impl PerformCrud for CreatePrivateMessage {
) )
.await?; .await?;
let private_message_view = blocking(context.pool(), move |conn| { let res = send_pm_ws_message(
PrivateMessageView::read(conn, inserted_private_message.id) inserted_private_message.id,
}) UserOperationCrud::CreatePrivateMessage,
.await??; websocket_id,
context,
)
.await?;
let res = PrivateMessageResponse { // Send email to the local recipient, if one exists
private_message_view, if res.private_message_view.recipient.local {
};
// Send notifications to the local recipient, if one exists
let recipient_id = data.recipient_id; let recipient_id = data.recipient_id;
if let Ok(local_recipient) = blocking(context.pool(), move |conn| { let local_recipient = blocking(context.pool(), move |conn| {
LocalUserView::read_person(conn, recipient_id) LocalUserView::read_person(conn, recipient_id)
}) })
.await? .await??;
{
send_email_to_user( send_email_to_user(
&local_recipient, &local_recipient,
"Private Message from", "Private Message from",
"Private Message", "Private Message",
&content_slurs_removed, &content_slurs_removed,
); );
let local_recipient_id = local_recipient.local_user.id;
context.chat_server().do_send(SendUserRoomMessage {
op: UserOperationCrud::CreatePrivateMessage,
response: res.clone(),
local_recipient_id,
websocket_id,
});
} }
Ok(res) Ok(res)

View file

@ -11,9 +11,8 @@ use lemmy_apub::activities::private_message::{
}; };
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud, DeleteableOrRemoveable}; use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud, DeleteableOrRemoveable};
use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_db_schema::source::private_message::PrivateMessage;
use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView};
use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_utils::{ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendUserRoomMessage, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for DeletePrivateMessage { impl PerformCrud for DeletePrivateMessage {
@ -59,39 +58,7 @@ impl PerformCrud for DeletePrivateMessage {
.await?; .await?;
} }
let private_message_id = data.private_message_id; let op = UserOperationCrud::DeletePrivateMessage;
let mut private_message_view = blocking(context.pool(), move |conn| { send_pm_ws_message(data.private_message_id, op, websocket_id, context).await
PrivateMessageView::read(conn, private_message_id)
})
.await??;
// Blank out deleted or removed info
if deleted {
private_message_view.private_message = private_message_view
.private_message
.blank_out_deleted_or_removed_info();
}
let res = PrivateMessageResponse {
private_message_view,
};
// Send notifications to the local recipient, if one exists
let recipient_id = orig_private_message.recipient_id;
if let Ok(local_recipient) = blocking(context.pool(), move |conn| {
LocalUserView::read_person(conn, recipient_id)
})
.await?
{
let local_recipient_id = local_recipient.local_user.id;
context.chat_server().do_send(SendUserRoomMessage {
op: UserOperationCrud::DeletePrivateMessage,
response: res.clone(),
local_recipient_id,
websocket_id,
});
}
Ok(res)
} }
} }

View file

@ -9,11 +9,10 @@ use lemmy_apub::activities::{
private_message::create_or_update::CreateOrUpdatePrivateMessage, private_message::create_or_update::CreateOrUpdatePrivateMessage,
CreateOrUpdateType, CreateOrUpdateType,
}; };
use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud, DeleteableOrRemoveable}; use lemmy_db_queries::{source::private_message::PrivateMessage_, Crud};
use lemmy_db_schema::source::private_message::PrivateMessage; use lemmy_db_schema::source::private_message::PrivateMessage;
use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView};
use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError}; use lemmy_utils::{utils::remove_slurs, ApiError, ConnectionId, LemmyError};
use lemmy_websocket::{messages::SendUserRoomMessage, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for EditPrivateMessage { impl PerformCrud for EditPrivateMessage {
@ -55,39 +54,7 @@ impl PerformCrud for EditPrivateMessage {
) )
.await?; .await?;
let private_message_id = data.private_message_id; let op = UserOperationCrud::EditPrivateMessage;
let mut private_message_view = blocking(context.pool(), move |conn| { send_pm_ws_message(data.private_message_id, op, websocket_id, context).await
PrivateMessageView::read(conn, private_message_id)
})
.await??;
// Blank out deleted or removed info
if private_message_view.private_message.deleted {
private_message_view.private_message = private_message_view
.private_message
.blank_out_deleted_or_removed_info();
}
let res = PrivateMessageResponse {
private_message_view,
};
// Send notifications to the local recipient, if one exists
let recipient_id = orig_private_message.recipient_id;
if let Ok(local_recipient) = blocking(context.pool(), move |conn| {
LocalUserView::read_person(conn, recipient_id)
})
.await?
{
let local_recipient_id = local_recipient.local_user.id;
context.chat_server().do_send(SendUserRoomMessage {
op: UserOperationCrud::EditPrivateMessage,
response: res.clone(),
local_recipient_id,
websocket_id,
});
}
Ok(res)
} }
} }

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
activities::{ activities::{
comment::{collect_non_local_mentions, get_notif_recipients, send_websocket_message}, comment::{collect_non_local_mentions, get_notif_recipients},
community::announce::AnnouncableActivities, community::announce::AnnouncableActivities,
extract_community, extract_community,
generate_activity_id, generate_activity_id,
@ -24,7 +24,7 @@ use lemmy_apub_lib::{
use lemmy_db_queries::Crud; use lemmy_db_queries::Crud;
use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post}; use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_comment_ws_message, LemmyContext, UserOperationCrud};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;
@ -116,7 +116,11 @@ impl ActivityHandler for CreateOrUpdateComment {
CreateOrUpdateType::Create => UserOperationCrud::CreateComment, CreateOrUpdateType::Create => UserOperationCrud::CreateComment,
CreateOrUpdateType::Update => UserOperationCrud::EditComment, CreateOrUpdateType::Update => UserOperationCrud::EditComment,
}; };
send_websocket_message(comment.id, recipients, notif_type, context).await send_comment_ws_message(
comment.id, notif_type, None, None, None, recipients, context,
)
.await?;
Ok(())
} }
fn common(&self) -> &ActivityCommonFields { fn common(&self) -> &ActivityCommonFields {

View file

@ -5,21 +5,19 @@ use activitystreams::{
}; };
use anyhow::anyhow; use anyhow::anyhow;
use itertools::Itertools; use itertools::Itertools;
use lemmy_api_common::{blocking, comment::CommentResponse, send_local_notifs, WebFingerResponse}; use lemmy_api_common::{blocking, send_local_notifs, WebFingerResponse};
use lemmy_db_queries::{Crud, DbPool}; use lemmy_db_queries::{Crud, DbPool};
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{comment::Comment, community::Community, person::Person, post::Post}, source::{comment::Comment, community::Community, person::Person, post::Post},
CommentId,
LocalUserId, LocalUserId,
}; };
use lemmy_db_views::comment_view::CommentView;
use lemmy_utils::{ use lemmy_utils::{
request::{retry, RecvError}, request::{retry, RecvError},
settings::structs::Settings, settings::structs::Settings,
utils::{scrape_text_for_mentions, MentionData}, utils::{scrape_text_for_mentions, MentionData},
LemmyError, LemmyError,
}; };
use lemmy_websocket::{messages::SendComment, LemmyContext}; use lemmy_websocket::LemmyContext;
use log::debug; use log::debug;
use reqwest::Client; use reqwest::Client;
use url::Url; use url::Url;
@ -45,37 +43,6 @@ async fn get_notif_recipients(
send_local_notifs(mentions, comment.clone(), actor, post, context.pool(), true).await send_local_notifs(mentions, comment.clone(), actor, post, context.pool(), true).await
} }
// TODO: in many call sites we are setting an empty vec for recipient_ids, we should get the actual
// recipient actors from somewhere
pub(crate) async fn send_websocket_message<
OP: ToString + Send + lemmy_websocket::OperationType + 'static,
>(
comment_id: CommentId,
recipient_ids: Vec<LocalUserId>,
op: OP,
context: &LemmyContext,
) -> Result<(), LemmyError> {
// Refetch the view
let comment_view = blocking(context.pool(), move |conn| {
CommentView::read(conn, comment_id, None)
})
.await??;
let res = CommentResponse {
comment_view,
recipient_ids,
form_id: None,
};
context.chat_server().do_send(SendComment {
op,
comment: res,
websocket_id: None,
});
Ok(())
}
pub struct MentionsAndAddresses { pub struct MentionsAndAddresses {
pub ccs: Vec<Url>, pub ccs: Vec<Url>,
pub inboxes: Vec<Url>, pub inboxes: Vec<Url>,

View file

@ -1,10 +1,8 @@
use crate::{check_is_apub_id_valid, CommunityType}; use crate::{check_is_apub_id_valid, CommunityType};
use itertools::Itertools; use itertools::Itertools;
use lemmy_api_common::{blocking, community::CommunityResponse}; use lemmy_db_schema::source::community::Community;
use lemmy_db_schema::{source::community::Community, CommunityId};
use lemmy_db_views_actor::community_view::CommunityView;
use lemmy_utils::{settings::structs::Settings, LemmyError}; use lemmy_utils::{settings::structs::Settings, LemmyError};
use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext}; use lemmy_websocket::LemmyContext;
use url::Url; use url::Url;
pub mod add_mod; pub mod add_mod;
@ -13,30 +11,6 @@ pub mod block_user;
pub mod undo_block_user; pub mod undo_block_user;
pub mod update; pub mod update;
pub(crate) async fn send_websocket_message<
OP: ToString + Send + lemmy_websocket::OperationType + 'static,
>(
community_id: CommunityId,
op: OP,
context: &LemmyContext,
) -> Result<(), LemmyError> {
let community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, None)
})
.await??;
let res = CommunityResponse { community_view };
context.chat_server().do_send(SendCommunityRoomMessage {
op,
response: res,
community_id,
websocket_id: None,
});
Ok(())
}
async fn list_community_follower_inboxes( async fn list_community_follower_inboxes(
community: &Community, community: &Community,
additional_inboxes: Vec<Url>, additional_inboxes: Vec<Url>,

View file

@ -1,10 +1,5 @@
use crate::{ use crate::{
activities::{ activities::{verify_activity, verify_mod_action, verify_person_in_community},
community::send_websocket_message,
verify_activity,
verify_mod_action,
verify_person_in_community,
},
objects::community::Group, objects::community::Group,
}; };
use activitystreams::activity::kind::UpdateType; use activitystreams::activity::kind::UpdateType;
@ -13,7 +8,7 @@ use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
use lemmy_db_queries::{ApubObject, Crud}; use lemmy_db_queries::{ApubObject, Crud};
use lemmy_db_schema::source::community::{Community, CommunityForm}; use lemmy_db_schema::source::community::{Community, CommunityForm};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_community_ws_message, LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
/// This activity is received from a remote community mod, and updates the description or other /// This activity is received from a remote community mod, and updates the description or other
@ -71,12 +66,15 @@ impl ActivityHandler for UpdateCommunity {
}) })
.await??; .await??;
send_websocket_message( send_community_ws_message(
updated_community.id, updated_community.id,
UserOperationCrud::EditCommunity, UserOperationCrud::EditCommunity,
None,
None,
context, context,
) )
.await .await?;
Ok(())
} }
fn common(&self) -> &ActivityCommonFields { fn common(&self) -> &ActivityCommonFields {

View file

@ -1,13 +1,13 @@
use crate::{ use crate::{
activities::{ activities::{
comment::send_websocket_message as send_comment_message, community::announce::AnnouncableActivities,
community::{ deletion::{
announce::AnnouncableActivities, receive_delete_action,
send_websocket_message as send_community_message, verify_delete_activity,
DeletableObjects,
WebsocketMessages,
}, },
deletion::{send_apub_delete, verify_delete_activity, DeletableObjects},
generate_activity_id, generate_activity_id,
post::send_websocket_message as send_post_message,
verify_activity, verify_activity,
}, },
activity_queue::send_to_community_new, activity_queue::send_to_community_new,
@ -38,7 +38,11 @@ use lemmy_db_schema::source::{
post::Post, post::Post,
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{
send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
LemmyContext,
UserOperationCrud,
};
use url::Url; use url::Url;
/// This is very confusing, because there are four distinct cases to handle: /// This is very confusing, because there are four distinct cases to handle:
@ -99,7 +103,19 @@ impl ActivityHandler for Delete {
) )
.await .await
} else { } else {
self.receive_delete_action(context, request_counter).await receive_delete_action(
&self.object,
&self.common.actor,
WebsocketMessages {
community: UserOperationCrud::DeleteCommunity,
post: UserOperationCrud::DeletePost,
comment: UserOperationCrud::DeleteComment,
},
true,
context,
request_counter,
)
.await
} }
} }
@ -134,46 +150,6 @@ impl Delete {
let activity = AnnouncableActivities::Delete(delete); let activity = AnnouncableActivities::Delete(delete);
send_to_community_new(activity, &id, actor, community, vec![], context).await send_to_community_new(activity, &id, actor, community, vec![], context).await
} }
// TODO: would be nice if we could merge this and receive_delete_action() into a single method
// (or merge with receive_undo_delete_action() instead)
async fn receive_delete_action(
&self,
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
use UserOperationCrud::*;
match DeletableObjects::read_from_db(&self.object, context).await? {
DeletableObjects::Community(community) => {
if community.local {
let mod_ =
get_or_fetch_and_upsert_person(&self.common.actor, context, request_counter).await?;
let object = community.actor_id();
send_apub_delete(&mod_, &community.clone(), object, true, context).await?;
}
let deleted_community = blocking(context.pool(), move |conn| {
Community::update_deleted(conn, community.id, true)
})
.await??;
send_community_message(deleted_community.id, DeleteCommunity, context).await
}
DeletableObjects::Post(post) => {
let deleted_post = blocking(context.pool(), move |conn| {
Post::update_deleted(conn, post.id, true)
})
.await??;
send_post_message(deleted_post.id, DeletePost, context).await
}
DeletableObjects::Comment(comment) => {
let deleted_comment = blocking(context.pool(), move |conn| {
Comment::update_deleted(conn, comment.id, true)
})
.await??;
send_comment_message(deleted_comment.id, vec![], DeleteComment, context).await
}
}
}
} }
// TODO: reason is optional for compat with v0.11, make it mandatory after removing the migration // TODO: reason is optional for compat with v0.11, make it mandatory after removing the migration
@ -207,7 +183,7 @@ pub(in crate::activities) async fn receive_remove_action(
}) })
.await??; .await??;
send_community_message(deleted_community.id, RemoveCommunity, context).await send_community_ws_message(deleted_community.id, RemoveCommunity, None, None, context).await?;
} }
DeletableObjects::Post(post) => { DeletableObjects::Post(post) => {
let form = ModRemovePostForm { let form = ModRemovePostForm {
@ -224,7 +200,8 @@ pub(in crate::activities) async fn receive_remove_action(
Post::update_removed(conn, post.id, true) Post::update_removed(conn, post.id, true)
}) })
.await??; .await??;
send_post_message(removed_post.id, RemovePost, context).await
send_post_ws_message(removed_post.id, RemovePost, None, None, context).await?;
} }
DeletableObjects::Comment(comment) => { DeletableObjects::Comment(comment) => {
let form = ModRemoveCommentForm { let form = ModRemoveCommentForm {
@ -241,7 +218,9 @@ pub(in crate::activities) async fn receive_remove_action(
Comment::update_removed(conn, comment.id, true) Comment::update_removed(conn, comment.id, true)
}) })
.await??; .await??;
send_comment_message(removed_comment.id, vec![], RemoveComment, context).await
send_comment_ws_message_simple(removed_comment.id, RemoveComment, context).await?;
} }
} }
Ok(())
} }

View file

@ -4,17 +4,25 @@ use crate::{
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
}, },
fetcher::person::get_or_fetch_and_upsert_person,
ActorType, ActorType,
}; };
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields}; use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields};
use lemmy_db_queries::ApubObject; use lemmy_db_queries::{
source::{comment::Comment_, community::Community_, post::Post_},
ApubObject,
};
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{comment::Comment, community::Community, person::Person, post::Post}, source::{comment::Comment, community::Community, person::Person, post::Post},
DbUrl, DbUrl,
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext; use lemmy_websocket::{
send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
LemmyContext,
UserOperationCrud,
};
use url::Url; use url::Url;
pub mod delete; pub mod delete;
@ -150,3 +158,52 @@ async fn verify_delete_activity_post_or_comment(
} }
Ok(()) Ok(())
} }
struct WebsocketMessages {
community: UserOperationCrud,
post: UserOperationCrud,
comment: UserOperationCrud,
}
/// Write deletion or restoring of an object to the database, and send websocket message.
/// TODO: we should do something similar for receive_remove_action(), but its much more complicated
/// because of the mod log
async fn receive_delete_action(
object: &Url,
actor: &Url,
ws_messages: WebsocketMessages,
deleted: bool,
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
match DeletableObjects::read_from_db(object, context).await? {
DeletableObjects::Community(community) => {
if community.local {
let mod_ = get_or_fetch_and_upsert_person(actor, context, request_counter).await?;
let object = community.actor_id();
send_apub_delete(&mod_, &community.clone(), object, true, context).await?;
}
let community = blocking(context.pool(), move |conn| {
Community::update_deleted(conn, community.id, deleted)
})
.await??;
send_community_ws_message(community.id, ws_messages.community, None, None, context).await?;
}
DeletableObjects::Post(post) => {
let deleted_post = blocking(context.pool(), move |conn| {
Post::update_deleted(conn, post.id, deleted)
})
.await??;
send_post_ws_message(deleted_post.id, ws_messages.post, None, None, context).await?;
}
DeletableObjects::Comment(comment) => {
let deleted_comment = blocking(context.pool(), move |conn| {
Comment::update_deleted(conn, comment.id, deleted)
})
.await??;
send_comment_ws_message_simple(deleted_comment.id, ws_messages.comment, context).await?;
}
}
Ok(())
}

View file

@ -1,18 +1,18 @@
use crate::{ use crate::{
activities::{ activities::{
comment::send_websocket_message as send_comment_message, community::announce::AnnouncableActivities,
community::{ deletion::{
announce::AnnouncableActivities, delete::Delete,
send_websocket_message as send_community_message, receive_delete_action,
verify_delete_activity,
DeletableObjects,
WebsocketMessages,
}, },
deletion::{delete::Delete, send_apub_delete, verify_delete_activity, DeletableObjects},
generate_activity_id, generate_activity_id,
post::send_websocket_message as send_post_message,
verify_activity, verify_activity,
}, },
activity_queue::send_to_community_new, activity_queue::send_to_community_new,
extensions::context::lemmy_context, extensions::context::lemmy_context,
fetcher::person::get_or_fetch_and_upsert_person,
ActorType, ActorType,
}; };
use activitystreams::activity::kind::{DeleteType, UndoType}; use activitystreams::activity::kind::{DeleteType, UndoType};
@ -22,7 +22,11 @@ use lemmy_apub_lib::{values::PublicUrl, ActivityCommonFields, ActivityHandler};
use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_}; use lemmy_db_queries::source::{comment::Comment_, community::Community_, post::Post_};
use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post}; use lemmy_db_schema::source::{comment::Comment, community::Community, person::Person, post::Post};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{
send::{send_comment_ws_message_simple, send_community_ws_message, send_post_ws_message},
LemmyContext,
UserOperationCrud,
};
use url::Url; use url::Url;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
@ -66,8 +70,18 @@ impl ActivityHandler for UndoDelete {
if self.object.summary.is_some() { if self.object.summary.is_some() {
UndoDelete::receive_undo_remove_action(&self.object.object, context).await UndoDelete::receive_undo_remove_action(&self.object.object, context).await
} else { } else {
self receive_delete_action(
.receive_undo_delete_action(context, request_counter) &self.object.object,
&self.common.actor,
WebsocketMessages {
community: UserOperationCrud::EditCommunity,
post: UserOperationCrud::EditPost,
comment: UserOperationCrud::EditComment,
},
false,
context,
request_counter,
)
.await .await
} }
} }
@ -116,50 +130,6 @@ impl UndoDelete {
let activity = AnnouncableActivities::UndoDelete(undo); let activity = AnnouncableActivities::UndoDelete(undo);
send_to_community_new(activity, &id, actor, community, vec![], context).await send_to_community_new(activity, &id, actor, community, vec![], context).await
} }
async fn receive_undo_delete_action(
&self,
context: &LemmyContext,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
use UserOperationCrud::*;
let object = DeletableObjects::read_from_db(&self.object.object, context).await?;
match object {
DeletableObjects::Community(community) => {
if community.local {
let mod_ =
get_or_fetch_and_upsert_person(&self.common.actor, context, request_counter).await?;
send_apub_delete(
&mod_,
&community.clone(),
community.actor_id(),
false,
context,
)
.await?;
}
let deleted_community = blocking(context.pool(), move |conn| {
Community::update_deleted(conn, community.id, false)
})
.await??;
send_community_message(deleted_community.id, EditCommunity, context).await
}
DeletableObjects::Post(post) => {
let deleted_post = blocking(context.pool(), move |conn| {
Post::update_deleted(conn, post.id, false)
})
.await??;
send_post_message(deleted_post.id, EditPost, context).await
}
DeletableObjects::Comment(comment) => {
let deleted_comment = blocking(context.pool(), move |conn| {
Comment::update_deleted(conn, comment.id, false)
})
.await??;
send_comment_message(deleted_comment.id, vec![], EditComment, context).await
}
}
}
pub(in crate::activities) async fn receive_undo_remove_action( pub(in crate::activities) async fn receive_undo_remove_action(
object: &Url, object: &Url,
@ -175,23 +145,23 @@ impl UndoDelete {
Community::update_removed(conn, community.id, false) Community::update_removed(conn, community.id, false)
}) })
.await??; .await??;
send_community_ws_message(deleted_community.id, EditCommunity, None, None, context).await?;
send_community_message(deleted_community.id, EditCommunity, context).await
} }
DeletableObjects::Post(post) => { DeletableObjects::Post(post) => {
let removed_post = blocking(context.pool(), move |conn| { let removed_post = blocking(context.pool(), move |conn| {
Post::update_removed(conn, post.id, false) Post::update_removed(conn, post.id, false)
}) })
.await??; .await??;
send_post_message(removed_post.id, EditPost, context).await send_post_ws_message(removed_post.id, EditPost, None, None, context).await?;
} }
DeletableObjects::Comment(comment) => { DeletableObjects::Comment(comment) => {
let removed_comment = blocking(context.pool(), move |conn| { let removed_comment = blocking(context.pool(), move |conn| {
Comment::update_removed(conn, comment.id, false) Comment::update_removed(conn, comment.id, false)
}) })
.await??; .await??;
send_comment_message(removed_comment.id, vec![], EditComment, context).await send_comment_ws_message_simple(removed_comment.id, EditComment, context).await?;
} }
} }
Ok(())
} }
} }

View file

@ -3,7 +3,6 @@ use crate::{
community::announce::AnnouncableActivities, community::announce::AnnouncableActivities,
extract_community, extract_community,
generate_activity_id, generate_activity_id,
post::send_websocket_message,
verify_activity, verify_activity,
verify_mod_action, verify_mod_action,
verify_person_in_community, verify_person_in_community,
@ -27,7 +26,7 @@ use lemmy_apub_lib::{
use lemmy_db_queries::Crud; use lemmy_db_queries::Crud;
use lemmy_db_schema::source::{community::Community, person::Person, post::Post}; use lemmy_db_schema::source::{community::Community, person::Person, post::Post};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
@ -126,7 +125,8 @@ impl ActivityHandler for CreateOrUpdatePost {
CreateOrUpdateType::Create => UserOperationCrud::CreatePost, CreateOrUpdateType::Create => UserOperationCrud::CreatePost,
CreateOrUpdateType::Update => UserOperationCrud::EditPost, CreateOrUpdateType::Update => UserOperationCrud::EditPost,
}; };
send_websocket_message(post.id, notif_type, context).await send_post_ws_message(post.id, notif_type, None, None, context).await?;
Ok(())
} }
fn common(&self) -> &ActivityCommonFields { fn common(&self) -> &ActivityCommonFields {

View file

@ -1,30 +1 @@
use lemmy_api_common::{blocking, post::PostResponse};
use lemmy_db_schema::PostId;
use lemmy_db_views::post_view::PostView;
use lemmy_utils::LemmyError;
use lemmy_websocket::{messages::SendPost, LemmyContext};
pub mod create_or_update; pub mod create_or_update;
pub(crate) async fn send_websocket_message<
OP: ToString + Send + lemmy_websocket::OperationType + 'static,
>(
post_id: PostId,
op: OP,
context: &LemmyContext,
) -> Result<(), LemmyError> {
let post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, post_id, None)
})
.await??;
let res = PostResponse { post_view };
context.chat_server().do_send(SendPost {
op,
post: res,
websocket_id: None,
});
Ok(())
}

View file

@ -1,11 +1,5 @@
use crate::{ use crate::{
activities::{ activities::{generate_activity_id, verify_activity, verify_person, CreateOrUpdateType},
generate_activity_id,
private_message::send_websocket_message,
verify_activity,
verify_person,
CreateOrUpdateType,
},
activity_queue::send_activity_new, activity_queue::send_activity_new,
extensions::context::lemmy_context, extensions::context::lemmy_context,
objects::{private_message::Note, FromApub, ToApub}, objects::{private_message::Note, FromApub, ToApub},
@ -16,7 +10,7 @@ use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler
use lemmy_db_queries::Crud; use lemmy_db_queries::Crud;
use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage}; use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
@ -83,7 +77,7 @@ impl ActivityHandler for CreateOrUpdatePrivateMessage {
CreateOrUpdateType::Create => UserOperationCrud::CreatePrivateMessage, CreateOrUpdateType::Create => UserOperationCrud::CreatePrivateMessage,
CreateOrUpdateType::Update => UserOperationCrud::EditPrivateMessage, CreateOrUpdateType::Update => UserOperationCrud::EditPrivateMessage,
}; };
send_websocket_message(private_message.id, notif_type, context).await?; send_pm_ws_message(private_message.id, notif_type, None, context).await?;
Ok(()) Ok(())
} }

View file

@ -1,10 +1,5 @@
use crate::{ use crate::{
activities::{ activities::{generate_activity_id, verify_activity, verify_person},
generate_activity_id,
private_message::send_websocket_message,
verify_activity,
verify_person,
},
activity_queue::send_activity_new, activity_queue::send_activity_new,
extensions::context::lemmy_context, extensions::context::lemmy_context,
ActorType, ActorType,
@ -15,7 +10,7 @@ use lemmy_apub_lib::{verify_domains_match, ActivityCommonFields, ActivityHandler
use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject, Crud}; use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject, Crud};
use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage}; use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
@ -84,9 +79,10 @@ impl ActivityHandler for DeletePrivateMessage {
}) })
.await??; .await??;
send_websocket_message( send_pm_ws_message(
deleted_private_message.id, deleted_private_message.id,
UserOperationCrud::DeletePrivateMessage, UserOperationCrud::DeletePrivateMessage,
None,
context, context,
) )
.await?; .await?;

View file

@ -1,41 +1,3 @@
use lemmy_api_common::{blocking, person::PrivateMessageResponse};
use lemmy_db_schema::PrivateMessageId;
use lemmy_db_views::{local_user_view::LocalUserView, private_message_view::PrivateMessageView};
use lemmy_utils::LemmyError;
use lemmy_websocket::{messages::SendUserRoomMessage, LemmyContext, UserOperationCrud};
pub mod create_or_update; pub mod create_or_update;
pub mod delete; pub mod delete;
pub mod undo_delete; pub mod undo_delete;
async fn send_websocket_message(
private_message_id: PrivateMessageId,
op: UserOperationCrud,
context: &LemmyContext,
) -> Result<(), LemmyError> {
let message = blocking(context.pool(), move |conn| {
PrivateMessageView::read(conn, private_message_id)
})
.await??;
let res = PrivateMessageResponse {
private_message_view: message,
};
// Send notifications to the local recipient, if one exists
let recipient_id = res.private_message_view.recipient.id;
let local_recipient_id = blocking(context.pool(), move |conn| {
LocalUserView::read_person(conn, recipient_id)
})
.await??
.local_user
.id;
context.chat_server().do_send(SendUserRoomMessage {
op,
response: res,
local_recipient_id,
websocket_id: None,
});
Ok(())
}

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
activities::{ activities::{
generate_activity_id, generate_activity_id,
private_message::{delete::DeletePrivateMessage, send_websocket_message}, private_message::delete::DeletePrivateMessage,
verify_activity, verify_activity,
verify_person, verify_person,
}, },
@ -20,7 +20,7 @@ use lemmy_apub_lib::{
use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject, Crud}; use lemmy_db_queries::{source::private_message::PrivateMessage_, ApubObject, Crud};
use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage}; use lemmy_db_schema::source::{person::Person, private_message::PrivateMessage};
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_pm_ws_message, LemmyContext, UserOperationCrud};
use url::Url; use url::Url;
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
@ -104,9 +104,10 @@ impl ActivityHandler for UndoDeletePrivateMessage {
}) })
.await??; .await??;
send_websocket_message( send_pm_ws_message(
deleted_private_message.id, deleted_private_message.id,
UserOperationCrud::EditPrivateMessage, UserOperationCrud::EditPrivateMessage,
None,
context, context,
) )
.await?; .await?;

View file

@ -1,8 +1,4 @@
use crate::activities::{ use crate::activities::voting::vote::VoteType;
comment::send_websocket_message as send_comment_message,
post::send_websocket_message as send_post_message,
voting::vote::VoteType,
};
use lemmy_api_common::blocking; use lemmy_api_common::blocking;
use lemmy_db_queries::Likeable; use lemmy_db_queries::Likeable;
use lemmy_db_schema::source::{ use lemmy_db_schema::source::{
@ -11,7 +7,11 @@ use lemmy_db_schema::source::{
post::{Post, PostLike, PostLikeForm}, post::{Post, PostLike, PostLikeForm},
}; };
use lemmy_utils::LemmyError; use lemmy_utils::LemmyError;
use lemmy_websocket::{LemmyContext, UserOperation}; use lemmy_websocket::{
send::{send_comment_ws_message_simple, send_post_ws_message},
LemmyContext,
UserOperation,
};
pub mod undo_vote; pub mod undo_vote;
pub mod vote; pub mod vote;
@ -36,13 +36,8 @@ async fn vote_comment(
}) })
.await??; .await??;
send_comment_message( send_comment_ws_message_simple(comment_id, UserOperation::CreateCommentLike, context).await?;
comment_id, Ok(())
vec![],
UserOperation::CreateCommentLike,
context,
)
.await
} }
async fn vote_post( async fn vote_post(
@ -64,7 +59,8 @@ async fn vote_post(
}) })
.await??; .await??;
send_post_message(post.id, UserOperation::CreatePostLike, context).await send_post_ws_message(post.id, UserOperation::CreatePostLike, None, None, context).await?;
Ok(())
} }
async fn undo_vote_comment( async fn undo_vote_comment(
@ -79,13 +75,8 @@ async fn undo_vote_comment(
}) })
.await??; .await??;
send_comment_message( send_comment_ws_message_simple(comment_id, UserOperation::CreateCommentLike, context).await?;
comment.id, Ok(())
vec![],
UserOperation::CreateCommentLike,
context,
)
.await
} }
async fn undo_vote_post( async fn undo_vote_post(
@ -99,5 +90,7 @@ async fn undo_vote_post(
PostLike::remove(conn, person_id, post_id) PostLike::remove(conn, person_id, post_id)
}) })
.await??; .await??;
send_post_message(post.id, UserOperation::CreatePostLike, context).await
send_post_ws_message(post_id, UserOperation::CreatePostLike, None, None, context).await?;
Ok(())
} }

View file

@ -15,6 +15,8 @@ lemmy_utils = { version = "=0.11.3", path = "../utils" }
lemmy_api_common = { version = "=0.11.3", path = "../api_common" } lemmy_api_common = { version = "=0.11.3", path = "../api_common" }
lemmy_db_queries = { version = "=0.11.3", path = "../db_queries" } lemmy_db_queries = { version = "=0.11.3", path = "../db_queries" }
lemmy_db_schema = { version = "=0.11.3", path = "../db_schema" } lemmy_db_schema = { version = "=0.11.3", path = "../db_schema" }
lemmy_db_views = { version = "=0.11.3", path = "../db_views" }
lemmy_db_views_actor = { version = "=0.11.3", path = "../db_views_actor" }
reqwest = { version = "0.11.4", features = ["json"] } reqwest = { version = "0.11.4", features = ["json"] }
log = "0.4.14" log = "0.4.14"
rand = "0.8.4" rand = "0.8.4"

View file

@ -13,6 +13,7 @@ pub mod chat_server;
pub mod handlers; pub mod handlers;
pub mod messages; pub mod messages;
pub mod routes; pub mod routes;
pub mod send;
pub struct LemmyContext { pub struct LemmyContext {
pub pool: DbPool, pub pool: DbPool,

View file

@ -75,7 +75,7 @@ pub struct SendModRoomMessage<Response> {
#[derive(Message)] #[derive(Message)]
#[rtype(result = "()")] #[rtype(result = "()")]
pub struct SendPost<OP: ToString> { pub(crate) struct SendPost<OP: ToString> {
pub op: OP, pub op: OP,
pub post: PostResponse, pub post: PostResponse,
pub websocket_id: Option<ConnectionId>, pub websocket_id: Option<ConnectionId>,
@ -83,7 +83,7 @@ pub struct SendPost<OP: ToString> {
#[derive(Message)] #[derive(Message)]
#[rtype(result = "()")] #[rtype(result = "()")]
pub struct SendComment<OP: ToString> { pub(crate) struct SendComment<OP: ToString> {
pub op: OP, pub op: OP,
pub comment: CommentResponse, pub comment: CommentResponse,
pub websocket_id: Option<ConnectionId>, pub websocket_id: Option<ConnectionId>,

View file

@ -0,0 +1,162 @@
use crate::{
messages::{SendComment, SendCommunityRoomMessage, SendPost, SendUserRoomMessage},
LemmyContext,
OperationType,
};
use lemmy_api_common::{
blocking,
comment::CommentResponse,
community::CommunityResponse,
person::PrivateMessageResponse,
post::PostResponse,
};
use lemmy_db_queries::DeleteableOrRemoveable;
use lemmy_db_schema::{CommentId, CommunityId, LocalUserId, PersonId, PostId, PrivateMessageId};
use lemmy_db_views::{
comment_view::CommentView,
local_user_view::LocalUserView,
post_view::PostView,
private_message_view::PrivateMessageView,
};
use lemmy_db_views_actor::community_view::CommunityView;
use lemmy_utils::{ConnectionId, LemmyError};
pub async fn send_post_ws_message<OP: ToString + Send + OperationType + 'static>(
post_id: PostId,
op: OP,
websocket_id: Option<ConnectionId>,
person_id: Option<PersonId>,
context: &LemmyContext,
) -> Result<PostResponse, LemmyError> {
let mut post_view = blocking(context.pool(), move |conn| {
PostView::read(conn, post_id, person_id)
})
.await??;
if post_view.post.deleted || post_view.post.removed {
post_view.post = post_view.post.blank_out_deleted_or_removed_info();
}
let res = PostResponse { post_view };
context.chat_server().do_send(SendPost {
op,
post: res.clone(),
websocket_id,
});
Ok(res)
}
// TODO: in many call sites in apub crate, we are setting an empty vec for recipient_ids,
// we should get the actual recipient actors from somewhere
pub async fn send_comment_ws_message_simple<OP: ToString + Send + OperationType + 'static>(
comment_id: CommentId,
op: OP,
context: &LemmyContext,
) -> Result<CommentResponse, LemmyError> {
send_comment_ws_message(comment_id, op, None, None, None, vec![], context).await
}
pub async fn send_comment_ws_message<OP: ToString + Send + OperationType + 'static>(
comment_id: CommentId,
op: OP,
websocket_id: Option<ConnectionId>,
form_id: Option<String>,
person_id: Option<PersonId>,
recipient_ids: Vec<LocalUserId>,
context: &LemmyContext,
) -> Result<CommentResponse, LemmyError> {
let mut view = blocking(context.pool(), move |conn| {
CommentView::read(conn, comment_id, person_id)
})
.await??;
if view.comment.deleted || view.comment.removed {
view.comment = view.comment.blank_out_deleted_or_removed_info();
}
let res = CommentResponse {
comment_view: view,
recipient_ids,
form_id,
};
context.chat_server().do_send(SendComment {
op,
comment: res.clone(),
websocket_id,
});
Ok(res)
}
pub async fn send_community_ws_message<OP: ToString + Send + OperationType + 'static>(
community_id: CommunityId,
op: OP,
websocket_id: Option<ConnectionId>,
person_id: Option<PersonId>,
context: &LemmyContext,
) -> Result<CommunityResponse, LemmyError> {
let mut community_view = blocking(context.pool(), move |conn| {
CommunityView::read(conn, community_id, person_id)
})
.await??;
// Blank out deleted or removed info
if community_view.community.deleted || community_view.community.removed {
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
}
let res = CommunityResponse { community_view };
// Strip out the person id and subscribed when sending to others
let mut res_mut = res.clone();
res_mut.community_view.subscribed = false;
context.chat_server().do_send(SendCommunityRoomMessage {
op,
response: res_mut,
community_id: res.community_view.community.id,
websocket_id,
});
Ok(res)
}
pub async fn send_pm_ws_message<OP: ToString + Send + OperationType + 'static>(
private_message_id: PrivateMessageId,
op: OP,
websocket_id: Option<ConnectionId>,
context: &LemmyContext,
) -> Result<PrivateMessageResponse, LemmyError> {
let mut view = blocking(context.pool(), move |conn| {
PrivateMessageView::read(conn, private_message_id)
})
.await??;
// Blank out deleted or removed info
if view.private_message.deleted {
view.private_message = view.private_message.blank_out_deleted_or_removed_info();
}
let res = PrivateMessageResponse {
private_message_view: view,
};
// Send notifications to the local recipient, if one exists
if res.private_message_view.recipient.local {
let recipient_id = res.private_message_view.recipient.id;
let local_recipient = blocking(context.pool(), move |conn| {
LocalUserView::read_person(conn, recipient_id)
})
.await??;
context.chat_server().do_send(SendUserRoomMessage {
op,
response: res.clone(),
local_recipient_id: local_recipient.local_user.id,
websocket_id,
});
}
Ok(res)
}