Fixed bug where comments with mentions were treated as private message

This commit is contained in:
Felix Ableitner 2020-11-09 19:18:23 +01:00
parent b469b6d8d3
commit e1fd614dd1
2 changed files with 37 additions and 11 deletions

View file

@ -7,7 +7,7 @@ use crate::{
}; };
use activitystreams::{ use activitystreams::{
activity::{ActorAndObjectRefExt, Create, Delete, Undo, Update}, activity::{ActorAndObjectRefExt, Create, Delete, Undo, Update},
base::{AnyBase, AsBase, ExtendsExt}, base::{AsBase, ExtendsExt},
object::{AsObject, Note}, object::{AsObject, Note},
public, public,
}; };
@ -24,12 +24,10 @@ use url::Url;
pub(crate) async fn receive_create_private_message( pub(crate) async fn receive_create_private_message(
context: &LemmyContext, context: &LemmyContext,
activity: AnyBase, create: Create,
expected_domain: Url, expected_domain: Url,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> 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?; check_private_message_activity_valid(&create, context, request_counter).await?;
let note = Note::from_any_base( 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( pub(crate) async fn receive_update_private_message(
context: &LemmyContext, context: &LemmyContext,
activity: AnyBase, update: Update,
expected_domain: Url, expected_domain: Url,
request_counter: &mut i32, request_counter: &mut i32,
) -> Result<(), LemmyError> { ) -> 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?; check_private_message_activity_valid(&update, context, request_counter).await?;
let object = update let object = update

View file

@ -1,5 +1,6 @@
use crate::{ use crate::{
activities::receive::{ activities::receive::{
comment::{receive_create_comment, receive_update_comment},
community::{ community::{
receive_delete_community, receive_delete_community,
receive_remove_community, receive_remove_community,
@ -37,7 +38,7 @@ use crate::{
ActorType, ActorType,
}; };
use activitystreams::{ use activitystreams::{
activity::{Accept, ActorAndObject, Announce, Delete, Follow, Undo}, activity::{Accept, ActorAndObject, Announce, Create, Delete, Follow, Undo, Update},
base::AnyBase, base::AnyBase,
prelude::*, prelude::*,
}; };
@ -144,10 +145,10 @@ pub(crate) async fn user_receive_message(
receive_announce(&context, any_base, actor, request_counter).await? receive_announce(&context, any_base, actor, request_counter).await?
} }
UserValidTypes::Create => { 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 => { 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 => { UserValidTypes::Delete => {
receive_delete(context, any_base, &actor_url, request_counter).await? receive_delete(context, any_base, &actor_url, request_counter).await?
@ -226,7 +227,6 @@ async fn receive_announce(
return Ok(()); return Ok(());
} }
dbg!(&kind);
match kind { match kind {
Some("Create") => { Some("Create") => {
receive_create_for_community(context, inner_activity, &inner_id, request_counter).await 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( async fn receive_delete(
context: &LemmyContext, context: &LemmyContext,
any_base: AnyBase, any_base: AnyBase,