From: Felix Ableitner Date: Mon, 9 Nov 2020 18:18:23 +0000 (+0100) Subject: Fixed bug where comments with mentions were treated as private message X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/readmes/%7B%7D/%22%7Burl%7D/%7BcanonicalUrl%7D?a=commitdiff_plain;h=e1fd614dd1ff561faefde7c8e60cdfa296f3b548;p=lemmy.git Fixed bug where comments with mentions were treated as private message --- diff --git a/lemmy_apub/src/activities/receive/private_message.rs b/lemmy_apub/src/activities/receive/private_message.rs index 80fb0b70..31037d1f 100644 --- a/lemmy_apub/src/activities/receive/private_message.rs +++ b/lemmy_apub/src/activities/receive/private_message.rs @@ -7,7 +7,7 @@ use crate::{ }; use activitystreams::{ activity::{ActorAndObjectRefExt, Create, Delete, Undo, Update}, - base::{AnyBase, AsBase, ExtendsExt}, + base::{AsBase, ExtendsExt}, object::{AsObject, Note}, public, }; @@ -24,12 +24,10 @@ use url::Url; pub(crate) async fn receive_create_private_message( context: &LemmyContext, - activity: AnyBase, + create: Create, expected_domain: Url, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let create = Create::from_any_base(activity)?.context(location_info!())?; - verify_activity_domains_valid(&create, &expected_domain, true)?; check_private_message_activity_valid(&create, context, request_counter).await?; let note = Note::from_any_base( @@ -70,12 +68,10 @@ pub(crate) async fn receive_create_private_message( pub(crate) async fn receive_update_private_message( context: &LemmyContext, - activity: AnyBase, + update: Update, expected_domain: Url, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let update = Update::from_any_base(activity)?.context(location_info!())?; - verify_activity_domains_valid(&update, &expected_domain, true)?; check_private_message_activity_valid(&update, context, request_counter).await?; let object = update diff --git a/lemmy_apub/src/inbox/user_inbox.rs b/lemmy_apub/src/inbox/user_inbox.rs index 9173fec4..624a2b23 100644 --- a/lemmy_apub/src/inbox/user_inbox.rs +++ b/lemmy_apub/src/inbox/user_inbox.rs @@ -1,5 +1,6 @@ use crate::{ activities::receive::{ + comment::{receive_create_comment, receive_update_comment}, community::{ receive_delete_community, receive_remove_community, @@ -37,7 +38,7 @@ use crate::{ ActorType, }; use activitystreams::{ - activity::{Accept, ActorAndObject, Announce, Delete, Follow, Undo}, + activity::{Accept, ActorAndObject, Announce, Create, Delete, Follow, Undo, Update}, base::AnyBase, prelude::*, }; @@ -144,10 +145,10 @@ pub(crate) async fn user_receive_message( receive_announce(&context, any_base, actor, request_counter).await? } UserValidTypes::Create => { - receive_create_private_message(&context, any_base, actor_url, request_counter).await? + receive_create(&context, any_base, actor_url, request_counter).await? } UserValidTypes::Update => { - receive_update_private_message(&context, any_base, actor_url, request_counter).await? + receive_update(&context, any_base, actor_url, request_counter).await? } UserValidTypes::Delete => { receive_delete(context, any_base, &actor_url, request_counter).await? @@ -226,7 +227,6 @@ async fn receive_announce( return Ok(()); } - dbg!(&kind); match kind { Some("Create") => { receive_create_for_community(context, inner_activity, &inner_id, request_counter).await @@ -249,6 +249,36 @@ async fn receive_announce( } } +async fn receive_create( + context: &LemmyContext, + activity: AnyBase, + expected_domain: Url, + request_counter: &mut i32, +) -> Result<(), LemmyError> { + let create = Create::from_any_base(activity)?.context(location_info!())?; + verify_activity_domains_valid(&create, &expected_domain, true)?; + if is_addressed_to_public(&create).is_ok() { + receive_create_comment(create, context, request_counter).await + } else { + receive_create_private_message(&context, create, expected_domain, request_counter).await + } +} + +async fn receive_update( + context: &LemmyContext, + activity: AnyBase, + expected_domain: Url, + request_counter: &mut i32, +) -> Result<(), LemmyError> { + let update = Update::from_any_base(activity)?.context(location_info!())?; + verify_activity_domains_valid(&update, &expected_domain, true)?; + if is_addressed_to_public(&update).is_ok() { + receive_update_comment(update, context, request_counter).await + } else { + receive_update_private_message(&context, update, expected_domain, request_counter).await + } +} + async fn receive_delete( context: &LemmyContext, any_base: AnyBase,