]> Untitled Git - lemmy.git/commitdiff
Fixed bug where comments with mentions were treated as private message
authorFelix Ableitner <me@nutomic.com>
Mon, 9 Nov 2020 18:18:23 +0000 (19:18 +0100)
committerFelix Ableitner <me@nutomic.com>
Mon, 9 Nov 2020 18:18:23 +0000 (19:18 +0100)
lemmy_apub/src/activities/receive/private_message.rs
lemmy_apub/src/inbox/user_inbox.rs

index 80fb0b70f53c95067090e6550a788b13f47b2b03..31037d1f635c4c2413f49ac4ca1d85c7dacdf5f7 100644 (file)
@@ -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
index 9173fec42167bfe3f690ff966a85db15c6b1c68f..624a2b234ed209db4d5ab132c72ab8f2fe4a5364 100644 (file)
@@ -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,