diff options
author | Colin Reeder <vpzomtrrfrt@gmail.com> | 2020-10-28 22:31:39 -0600 |
---|---|---|
committer | Colin Reeder <vpzomtrrfrt@gmail.com> | 2020-10-28 22:31:39 -0600 |
commit | c0668f9840df0eade09a56526a1c1691a06a41a1 (patch) | |
tree | 4f2cc1ce842a63972c7664a1931e3e6c87ef3f70 | |
parent | 0f6a95883de01c409bc737463f99f977fc000c0b (diff) |
Clean up comment handling and probably fix targets
-rw-r--r-- | src/apub_util.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 70 | ||||
-rw-r--r-- | src/routes/api/posts.rs | 2 |
3 files changed, 47 insertions, 27 deletions
diff --git a/src/apub_util.rs b/src/apub_util.rs index 2a74768..c0ff949 100644 --- a/src/apub_util.rs +++ b/src/apub_util.rs @@ -1791,7 +1791,7 @@ async fn handle_recieved_post( if community_is_local { if let Some(row) = row { let post_local_id = PostLocalID(row.get(0)); - crate::on_community_add_post(community_local_id, post_local_id, object_id, ctx); + crate::on_local_community_add_post(community_local_id, post_local_id, object_id, ctx); } } diff --git a/src/main.rs b/src/main.rs index 33bcd80..beb9dd3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -674,7 +674,7 @@ pub fn render_markdown(src: &str) -> String { output } -pub fn on_community_add_post( +pub fn on_local_community_add_post( community: CommunityLocalID, post_local_id: PostLocalID, post_ap_id: url::Url, @@ -684,7 +684,7 @@ pub fn on_community_add_post( crate::apub_util::spawn_announce_community_post(community, post_local_id, post_ap_id, ctx); } -pub fn on_community_add_comment( +pub fn on_local_community_add_comment( community: CommunityLocalID, comment_local_id: CommentLocalID, comment_ap_id: url::Url, @@ -733,9 +733,9 @@ pub fn on_post_add_comment(comment: CommentInfo<'static>, ctx: Arc<crate::RouteC } ).await?; - if let Some(row) = res.0 { - let community_local: bool = row.get(1); - let post_local: bool = row.get(4); + if let Some(post_row) = res.0 { + let community_local: bool = post_row.get(1); + let post_local: bool = post_row.get(4); let post_ap_id = if post_local { Some(crate::apub_util::get_local_post_apub_id( @@ -743,7 +743,8 @@ pub fn on_post_add_comment(comment: CommentInfo<'static>, ctx: Arc<crate::RouteC &ctx.host_url_apub, )) } else { - row.get::<_, Option<&str>>(5) + post_row + .get::<_, Option<&str>>(5) .map(std::str::FromStr::from_str) .transpose()? }; @@ -764,7 +765,7 @@ pub fn on_post_add_comment(comment: CommentInfo<'static>, ctx: Arc<crate::RouteC post_or_parent_author_ap_inbox, ) = match comment.parent { None => { - let author_id = UserLocalID(row.get(6)); + let author_id = UserLocalID(post_row.get(6)); if post_local { ( None, @@ -781,11 +782,13 @@ pub fn on_post_add_comment(comment: CommentInfo<'static>, ctx: Arc<crate::RouteC None, Some(author_id), Some(false), - row.get::<_, Option<_>>(7) + post_row + .get::<_, Option<_>>(7) .map(std::str::FromStr::from_str) .transpose()? .map(Cow::Owned), - row.get::<_, Option<_>>(8) + post_row + .get::<_, Option<_>>(8) .map(std::str::FromStr::from_str) .transpose()? .map(Cow::Owned), @@ -852,33 +855,50 @@ pub fn on_post_add_comment(comment: CommentInfo<'static>, ctx: Arc<crate::RouteC } } + // should always be Some if let Some(post_ap_id) = post_ap_id { + let community_id = CommunityLocalID(post_row.get(0)); if community_local { - let community = CommunityLocalID(row.get(0)); - crate::on_community_add_comment(community, comment.id, comment_ap_id, ctx); - } else if comment.ap_id == APIDOrLocal::Local { - let community_ap_id = std::str::FromStr::from_str(row.get(2))?; - let community_inbox = std::str::FromStr::from_str(row.get(3))?; + crate::on_local_community_add_comment( + community_id, + comment.id, + comment_ap_id, + ctx.clone(), + ); + } + if comment.ap_id == APIDOrLocal::Local { let mut inboxes = HashSet::new(); - inboxes.insert(community_inbox); + if !community_local { + let community_inbox = std::str::FromStr::from_str(post_row.get(3))?; + inboxes.insert(community_inbox); + } - if post_or_parent_author_local == Some(true) { + if post_or_parent_author_local == Some(false) { if let Some(post_or_parent_author_ap_inbox) = post_or_parent_author_ap_inbox { inboxes.insert(post_or_parent_author_ap_inbox.into_owned()); } } - crate::apub_util::spawn_enqueue_send_comment( - inboxes, - comment, - community_ap_id, - post_ap_id.into(), - parent_ap_id.map(|x| x.deref().clone()), - post_or_parent_author_ap_id.map(|x| x.into_owned().into()), - ctx, - ); + if !inboxes.is_empty() { + let community_ap_id = if community_local { + apub_util::get_local_community_apub_id(community_id, &ctx.host_url_apub) + .into() + } else { + std::str::FromStr::from_str(post_row.get(2))? + }; + + crate::apub_util::spawn_enqueue_send_comment( + inboxes, + comment, + community_ap_id, + post_ap_id.into(), + parent_ap_id.map(|x| x.deref().clone()), + post_or_parent_author_ap_id.map(|x| x.into_owned().into()), + ctx, + ); + } } } } diff --git a/src/routes/api/posts.rs b/src/routes/api/posts.rs index 4f4c373..f20d74b 100644 --- a/src/routes/api/posts.rs +++ b/src/routes/api/posts.rs @@ -239,7 +239,7 @@ async fn route_unstable_posts_create( crate::spawn_task(async move { if community_local { - crate::on_community_add_post( + crate::on_local_community_add_post( post.community, post.id, crate::apub_util::get_local_post_apub_id(post.id, &ctx.host_url_apub).into(), |