Change the way that to
is set in apub
This commit is contained in:
parent
2ad60379e4
commit
7cfcf0acec
16 changed files with 169 additions and 156 deletions
|
@ -1,15 +1,12 @@
|
||||||
use crate::{
|
use crate::activities::receive::{
|
||||||
activities::receive::{
|
create::receive_create,
|
||||||
create::receive_create,
|
delete::receive_delete,
|
||||||
delete::receive_delete,
|
dislike::receive_dislike,
|
||||||
dislike::receive_dislike,
|
like::receive_like,
|
||||||
like::receive_like,
|
receive_unhandled_activity,
|
||||||
receive_unhandled_activity,
|
remove::receive_remove,
|
||||||
remove::receive_remove,
|
undo::receive_undo,
|
||||||
undo::receive_undo,
|
update::receive_update,
|
||||||
update::receive_update,
|
|
||||||
},
|
|
||||||
inbox::shared_inbox::get_community_id_from_activity,
|
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
activity::*,
|
activity::*,
|
||||||
|
@ -28,8 +25,12 @@ pub async fn receive_announce(
|
||||||
let announce = Announce::from_any_base(activity)?.context(location_info!())?;
|
let announce = Announce::from_any_base(activity)?.context(location_info!())?;
|
||||||
|
|
||||||
// ensure that announce and community come from the same instance
|
// ensure that announce and community come from the same instance
|
||||||
let community = get_community_id_from_activity(&announce)?;
|
let community_id = announce
|
||||||
announce.id(community.domain().context(location_info!())?)?;
|
.actor()?
|
||||||
|
.to_owned()
|
||||||
|
.single_xsd_any_uri()
|
||||||
|
.context(location_info!())?;
|
||||||
|
announce.id(community_id.domain().context(location_info!())?)?;
|
||||||
|
|
||||||
let kind = announce.object().as_single_kind_str();
|
let kind = announce.object().as_single_kind_str();
|
||||||
let object = announce.object();
|
let object = announce.object();
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
|
activities::receive::{
|
||||||
inbox::shared_inbox::get_user_from_activity,
|
announce_if_community_is_local,
|
||||||
|
get_actor_as_user,
|
||||||
|
receive_unhandled_activity,
|
||||||
|
},
|
||||||
ActorType,
|
ActorType,
|
||||||
FromApub,
|
FromApub,
|
||||||
PageExt,
|
PageExt,
|
||||||
|
@ -29,7 +32,7 @@ pub async fn receive_create(
|
||||||
let create = Create::from_any_base(activity)?.context(location_info!())?;
|
let create = Create::from_any_base(activity)?.context(location_info!())?;
|
||||||
|
|
||||||
// ensure that create and actor come from the same instance
|
// ensure that create and actor come from the same instance
|
||||||
let user = get_user_from_activity(&create, context).await?;
|
let user = get_actor_as_user(&create, context).await?;
|
||||||
create.id(user.actor_id()?.domain().context(location_info!())?)?;
|
create.id(user.actor_id()?.domain().context(location_info!())?)?;
|
||||||
|
|
||||||
match create.object().as_single_kind_str() {
|
match create.object().as_single_kind_str() {
|
||||||
|
@ -43,7 +46,7 @@ async fn receive_create_post(
|
||||||
create: Create,
|
create: Create,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(&create, context).await?;
|
let user = get_actor_as_user(&create, context).await?;
|
||||||
let page = PageExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
|
let page = PageExt::from_any_base(create.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -76,7 +79,7 @@ async fn receive_create_comment(
|
||||||
create: Create,
|
create: Create,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(&create, context).await?;
|
let user = get_actor_as_user(&create, context).await?;
|
||||||
let note = Note::from_any_base(create.object().to_owned().one().context(location_info!())?)?
|
let note = Note::from_any_base(create.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
|
activities::receive::{
|
||||||
|
announce_if_community_is_local,
|
||||||
|
get_actor_as_user,
|
||||||
|
receive_unhandled_activity,
|
||||||
|
},
|
||||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||||
inbox::shared_inbox::get_user_from_activity,
|
|
||||||
ActorType,
|
ActorType,
|
||||||
FromApub,
|
FromApub,
|
||||||
GroupExt,
|
GroupExt,
|
||||||
|
@ -50,7 +53,7 @@ async fn receive_delete_post(
|
||||||
delete: Delete,
|
delete: Delete,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(&delete, context).await?;
|
let user = get_actor_as_user(&delete, context).await?;
|
||||||
let page = PageExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
let page = PageExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -109,7 +112,7 @@ async fn receive_delete_comment(
|
||||||
delete: Delete,
|
delete: Delete,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(&delete, context).await?;
|
let user = get_actor_as_user(&delete, context).await?;
|
||||||
let note = Note::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
let note = Note::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -169,7 +172,7 @@ async fn receive_delete_community(
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let group = GroupExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
let group = GroupExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let user = get_user_from_activity(&delete, context).await?;
|
let user = get_actor_as_user(&delete, context).await?;
|
||||||
|
|
||||||
let community_actor_id = CommunityForm::from_apub(&group, context, Some(user.actor_id()?))
|
let community_actor_id = CommunityForm::from_apub(&group, context, Some(user.actor_id()?))
|
||||||
.await?
|
.await?
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
|
activities::receive::{
|
||||||
|
announce_if_community_is_local,
|
||||||
|
get_actor_as_user,
|
||||||
|
receive_unhandled_activity,
|
||||||
|
},
|
||||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||||
inbox::shared_inbox::get_user_from_activity,
|
|
||||||
FromApub,
|
FromApub,
|
||||||
PageExt,
|
PageExt,
|
||||||
};
|
};
|
||||||
|
@ -49,7 +52,7 @@ async fn receive_dislike_post(
|
||||||
dislike: Dislike,
|
dislike: Dislike,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(&dislike, context).await?;
|
let user = get_actor_as_user(&dislike, context).await?;
|
||||||
let page = PageExt::from_any_base(
|
let page = PageExt::from_any_base(
|
||||||
dislike
|
dislike
|
||||||
.object()
|
.object()
|
||||||
|
@ -107,7 +110,7 @@ async fn receive_dislike_comment(
|
||||||
.context(location_info!())?,
|
.context(location_info!())?,
|
||||||
)?
|
)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let user = get_user_from_activity(&dislike, context).await?;
|
let user = get_actor_as_user(&dislike, context).await?;
|
||||||
|
|
||||||
let comment = CommentForm::from_apub(¬e, context, None).await?;
|
let comment = CommentForm::from_apub(¬e, context, None).await?;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
|
activities::receive::{
|
||||||
|
announce_if_community_is_local,
|
||||||
|
get_actor_as_user,
|
||||||
|
receive_unhandled_activity,
|
||||||
|
},
|
||||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||||
inbox::shared_inbox::get_user_from_activity,
|
|
||||||
FromApub,
|
FromApub,
|
||||||
PageExt,
|
PageExt,
|
||||||
};
|
};
|
||||||
|
@ -36,7 +39,7 @@ pub async fn receive_like(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn receive_like_post(like: Like, context: &LemmyContext) -> Result<HttpResponse, LemmyError> {
|
async fn receive_like_post(like: Like, context: &LemmyContext) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(&like, context).await?;
|
let user = get_actor_as_user(&like, context).await?;
|
||||||
let page = PageExt::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
let page = PageExt::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -82,7 +85,7 @@ async fn receive_like_comment(
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let note = Note::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
let note = Note::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let user = get_user_from_activity(&like, context).await?;
|
let user = get_actor_as_user(&like, context).await?;
|
||||||
|
|
||||||
let comment = CommentForm::from_apub(¬e, context, None).await?;
|
let comment = CommentForm::from_apub(¬e, context, None).await?;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
use crate::{fetcher::get_or_fetch_and_upsert_community, ActorType};
|
use crate::{
|
||||||
|
fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user},
|
||||||
|
ActorType,
|
||||||
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
base::{Extends, ExtendsExt},
|
activity::{ActorAndObjectRef, ActorAndObjectRefExt},
|
||||||
|
base::{AsBase, Extends, ExtendsExt},
|
||||||
object::{AsObject, ObjectExt},
|
object::{AsObject, ObjectExt},
|
||||||
};
|
};
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
|
@ -63,3 +67,15 @@ where
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(in crate) async fn get_actor_as_user<T, A>(
|
||||||
|
activity: &T,
|
||||||
|
context: &LemmyContext,
|
||||||
|
) -> Result<User_, LemmyError>
|
||||||
|
where
|
||||||
|
T: AsBase<A> + ActorAndObjectRef,
|
||||||
|
{
|
||||||
|
let actor = activity.actor()?;
|
||||||
|
let user_uri = actor.as_single_xsd_any_uri().context(location_info!())?;
|
||||||
|
get_or_fetch_and_upsert_user(&user_uri, context).await
|
||||||
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
|
activities::receive::{
|
||||||
|
announce_if_community_is_local,
|
||||||
|
get_actor_as_user,
|
||||||
|
receive_unhandled_activity,
|
||||||
|
},
|
||||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||||
inbox::shared_inbox::{get_community_id_from_activity, get_user_from_activity},
|
|
||||||
ActorType,
|
ActorType,
|
||||||
FromApub,
|
FromApub,
|
||||||
GroupExt,
|
GroupExt,
|
||||||
|
@ -38,9 +41,18 @@ pub async fn receive_remove(
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let remove = Remove::from_any_base(activity)?.context(location_info!())?;
|
let remove = Remove::from_any_base(activity)?.context(location_info!())?;
|
||||||
let actor = get_user_from_activity(&remove, context).await?;
|
let actor = get_actor_as_user(&remove, context).await?;
|
||||||
let community = get_community_id_from_activity(&remove)?;
|
let cc = remove
|
||||||
if actor.actor_id()?.domain() != community.domain() {
|
.cc()
|
||||||
|
.map(|c| c.as_many())
|
||||||
|
.flatten()
|
||||||
|
.context(location_info!())?;
|
||||||
|
let community_id = cc
|
||||||
|
.first()
|
||||||
|
.map(|c| c.as_xsd_any_uri())
|
||||||
|
.flatten()
|
||||||
|
.context(location_info!())?;
|
||||||
|
if actor.actor_id()?.domain() != community_id.domain() {
|
||||||
return Err(anyhow!("Remove receive are only allowed on local objects").into());
|
return Err(anyhow!("Remove receive are only allowed on local objects").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +68,7 @@ async fn receive_remove_post(
|
||||||
remove: Remove,
|
remove: Remove,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_ = get_user_from_activity(&remove, context).await?;
|
let mod_ = get_actor_as_user(&remove, context).await?;
|
||||||
let page = PageExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
let page = PageExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -115,7 +127,7 @@ async fn receive_remove_comment(
|
||||||
remove: Remove,
|
remove: Remove,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_ = get_user_from_activity(&remove, context).await?;
|
let mod_ = get_actor_as_user(&remove, context).await?;
|
||||||
let note = Note::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
let note = Note::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -173,7 +185,7 @@ async fn receive_remove_community(
|
||||||
remove: Remove,
|
remove: Remove,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_ = get_user_from_activity(&remove, context).await?;
|
let mod_ = get_actor_as_user(&remove, context).await?;
|
||||||
let group = GroupExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
let group = GroupExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::receive::{
|
activities::receive::{
|
||||||
announce_if_community_is_local,
|
announce_if_community_is_local,
|
||||||
|
get_actor_as_user,
|
||||||
receive_unhandled_activity,
|
receive_unhandled_activity,
|
||||||
undo_comment::*,
|
undo_comment::*,
|
||||||
undo_post::*,
|
undo_post::*,
|
||||||
},
|
},
|
||||||
inbox::shared_inbox::get_user_from_activity,
|
|
||||||
ActorType,
|
ActorType,
|
||||||
FromApub,
|
FromApub,
|
||||||
GroupExt,
|
GroupExt,
|
||||||
|
@ -141,7 +141,7 @@ async fn receive_undo_delete_community(
|
||||||
delete: &Delete,
|
delete: &Delete,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(delete, context).await?;
|
let user = get_actor_as_user(delete, context).await?;
|
||||||
let group = GroupExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
let group = GroupExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ async fn receive_undo_remove_community(
|
||||||
remove: &Remove,
|
remove: &Remove,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_ = get_user_from_activity(remove, context).await?;
|
let mod_ = get_actor_as_user(remove, context).await?;
|
||||||
let group = GroupExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
let group = GroupExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::receive::announce_if_community_is_local,
|
activities::receive::{announce_if_community_is_local, get_actor_as_user},
|
||||||
fetcher::get_or_fetch_and_insert_comment,
|
fetcher::get_or_fetch_and_insert_comment,
|
||||||
inbox::shared_inbox::get_user_from_activity,
|
|
||||||
ActorType,
|
ActorType,
|
||||||
FromApub,
|
FromApub,
|
||||||
};
|
};
|
||||||
|
@ -24,7 +23,7 @@ pub(crate) async fn receive_undo_like_comment(
|
||||||
like: &Like,
|
like: &Like,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(like, context).await?;
|
let user = get_actor_as_user(like, context).await?;
|
||||||
let note = Note::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
let note = Note::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -69,7 +68,7 @@ pub(crate) async fn receive_undo_dislike_comment(
|
||||||
dislike: &Dislike,
|
dislike: &Dislike,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(dislike, context).await?;
|
let user = get_actor_as_user(dislike, context).await?;
|
||||||
let note = Note::from_any_base(
|
let note = Note::from_any_base(
|
||||||
dislike
|
dislike
|
||||||
.object()
|
.object()
|
||||||
|
@ -120,7 +119,7 @@ pub(crate) async fn receive_undo_delete_comment(
|
||||||
delete: &Delete,
|
delete: &Delete,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(delete, context).await?;
|
let user = get_actor_as_user(delete, context).await?;
|
||||||
let note = Note::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
let note = Note::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -179,7 +178,7 @@ pub(crate) async fn receive_undo_remove_comment(
|
||||||
remove: &Remove,
|
remove: &Remove,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_ = get_user_from_activity(remove, context).await?;
|
let mod_ = get_actor_as_user(remove, context).await?;
|
||||||
let note = Note::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
let note = Note::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::receive::announce_if_community_is_local,
|
activities::receive::{announce_if_community_is_local, get_actor_as_user},
|
||||||
fetcher::get_or_fetch_and_insert_post,
|
fetcher::get_or_fetch_and_insert_post,
|
||||||
inbox::shared_inbox::get_user_from_activity,
|
|
||||||
ActorType,
|
ActorType,
|
||||||
FromApub,
|
FromApub,
|
||||||
PageExt,
|
PageExt,
|
||||||
|
@ -25,7 +24,7 @@ pub(crate) async fn receive_undo_like_post(
|
||||||
like: &Like,
|
like: &Like,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(like, context).await?;
|
let user = get_actor_as_user(like, context).await?;
|
||||||
let page = PageExt::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
let page = PageExt::from_any_base(like.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -64,7 +63,7 @@ pub(crate) async fn receive_undo_dislike_post(
|
||||||
dislike: &Dislike,
|
dislike: &Dislike,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(dislike, context).await?;
|
let user = get_actor_as_user(dislike, context).await?;
|
||||||
let page = PageExt::from_any_base(
|
let page = PageExt::from_any_base(
|
||||||
dislike
|
dislike
|
||||||
.object()
|
.object()
|
||||||
|
@ -109,7 +108,7 @@ pub(crate) async fn receive_undo_delete_post(
|
||||||
delete: &Delete,
|
delete: &Delete,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(delete, context).await?;
|
let user = get_actor_as_user(delete, context).await?;
|
||||||
let page = PageExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
let page = PageExt::from_any_base(delete.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -169,7 +168,7 @@ pub(crate) async fn receive_undo_remove_post(
|
||||||
remove: &Remove,
|
remove: &Remove,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let mod_ = get_user_from_activity(remove, context).await?;
|
let mod_ = get_actor_as_user(remove, context).await?;
|
||||||
let page = PageExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
let page = PageExt::from_any_base(remove.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
|
activities::receive::{
|
||||||
|
announce_if_community_is_local,
|
||||||
|
get_actor_as_user,
|
||||||
|
receive_unhandled_activity,
|
||||||
|
},
|
||||||
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
|
||||||
inbox::shared_inbox::get_user_from_activity,
|
|
||||||
ActorType,
|
ActorType,
|
||||||
FromApub,
|
FromApub,
|
||||||
PageExt,
|
PageExt,
|
||||||
|
@ -31,7 +34,7 @@ pub async fn receive_update(
|
||||||
let update = Update::from_any_base(activity)?.context(location_info!())?;
|
let update = Update::from_any_base(activity)?.context(location_info!())?;
|
||||||
|
|
||||||
// ensure that update and actor come from the same instance
|
// ensure that update and actor come from the same instance
|
||||||
let user = get_user_from_activity(&update, context).await?;
|
let user = get_actor_as_user(&update, context).await?;
|
||||||
update.id(user.actor_id()?.domain().context(location_info!())?)?;
|
update.id(user.actor_id()?.domain().context(location_info!())?)?;
|
||||||
|
|
||||||
match update.object().as_single_kind_str() {
|
match update.object().as_single_kind_str() {
|
||||||
|
@ -45,7 +48,7 @@ async fn receive_update_post(
|
||||||
update: Update,
|
update: Update,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let user = get_user_from_activity(&update, context).await?;
|
let user = get_actor_as_user(&update, context).await?;
|
||||||
let page = PageExt::from_any_base(update.object().to_owned().one().context(location_info!())?)?
|
let page = PageExt::from_any_base(update.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
|
|
||||||
|
@ -84,7 +87,7 @@ async fn receive_update_comment(
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let note = Note::from_any_base(update.object().to_owned().one().context(location_info!())?)?
|
let note = Note::from_any_base(update.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let user = get_user_from_activity(&update, context).await?;
|
let user = get_actor_as_user(&update, context).await?;
|
||||||
|
|
||||||
let comment = CommentForm::from_apub(¬e, context, Some(user.actor_id()?)).await?;
|
let comment = CommentForm::from_apub(¬e, context, Some(user.actor_id()?)).await?;
|
||||||
|
|
||||||
|
|
|
@ -54,14 +54,17 @@ impl ApubObjectType for Comment {
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
let maa = collect_non_local_mentions_and_addresses(&self.content, &community, context).await?;
|
let mut maa =
|
||||||
|
collect_non_local_mentions_and_addresses(&self.content, &community, context).await?;
|
||||||
|
let mut ccs = vec![community.actor_id()?];
|
||||||
|
ccs.append(&mut maa.addressed_ccs);
|
||||||
|
|
||||||
let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
create
|
create
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(CreateType::Create)?)
|
.set_id(generate_activity_id(CreateType::Create)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(maa.addressed_ccs.to_owned())
|
.set_many_ccs(ccs)
|
||||||
// Set the mention tags
|
// Set the mention tags
|
||||||
.set_many_tags(maa.get_tags()?);
|
.set_many_tags(maa.get_tags()?);
|
||||||
|
|
||||||
|
@ -83,14 +86,17 @@ impl ApubObjectType for Comment {
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
let maa = collect_non_local_mentions_and_addresses(&self.content, &community, context).await?;
|
let mut maa =
|
||||||
|
collect_non_local_mentions_and_addresses(&self.content, &community, context).await?;
|
||||||
|
let mut ccs = vec![community.actor_id()?];
|
||||||
|
ccs.append(&mut maa.addressed_ccs);
|
||||||
|
|
||||||
let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
update
|
update
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(UpdateType::Update)?)
|
.set_id(generate_activity_id(UpdateType::Update)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(maa.addressed_ccs.to_owned())
|
.set_many_ccs(ccs)
|
||||||
// Set the mention tags
|
// Set the mention tags
|
||||||
.set_many_tags(maa.get_tags()?);
|
.set_many_tags(maa.get_tags()?);
|
||||||
|
|
||||||
|
@ -116,7 +122,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(DeleteType::Delete)?)
|
.set_id(generate_activity_id(DeleteType::Delete)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(&creator, &community, delete, context).await?;
|
send_to_community(&creator, &community, delete, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -144,7 +150,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(DeleteType::Delete)?)
|
.set_id(generate_activity_id(DeleteType::Delete)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
// Undo that fake activity
|
// Undo that fake activity
|
||||||
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
|
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
|
||||||
|
@ -152,7 +158,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(UndoType::Undo)?)
|
.set_id(generate_activity_id(UndoType::Undo)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(&creator, &community, undo, context).await?;
|
send_to_community(&creator, &community, undo, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -175,7 +181,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(RemoveType::Remove)?)
|
.set_id(generate_activity_id(RemoveType::Remove)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(&mod_, &community, remove, context).await?;
|
send_to_community(&mod_, &community, remove, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -199,7 +205,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(RemoveType::Remove)?)
|
.set_id(generate_activity_id(RemoveType::Remove)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
// Undo that fake activity
|
// Undo that fake activity
|
||||||
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
|
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
|
||||||
|
@ -207,7 +213,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(UndoType::Undo)?)
|
.set_id(generate_activity_id(UndoType::Undo)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(&mod_, &community, undo, context).await?;
|
send_to_community(&mod_, &community, undo, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -233,7 +239,7 @@ impl ApubLikeableType for Comment {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(LikeType::Like)?)
|
.set_id(generate_activity_id(LikeType::Like)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(&creator, &community, like, context).await?;
|
send_to_community(&creator, &community, like, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -256,7 +262,7 @@ impl ApubLikeableType for Comment {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(DislikeType::Dislike)?)
|
.set_id(generate_activity_id(DislikeType::Dislike)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(&creator, &community, dislike, context).await?;
|
send_to_community(&creator, &community, dislike, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -283,7 +289,7 @@ impl ApubLikeableType for Comment {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(DislikeType::Dislike)?)
|
.set_id(generate_activity_id(DislikeType::Dislike)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
// Undo that fake activity
|
// Undo that fake activity
|
||||||
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
|
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
|
||||||
|
@ -291,7 +297,7 @@ impl ApubLikeableType for Comment {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(UndoType::Undo)?)
|
.set_id(generate_activity_id(UndoType::Undo)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(&creator, &community, undo, context).await?;
|
send_to_community(&creator, &community, undo, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl ApubObjectType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(CreateType::Create)?)
|
.set_id(generate_activity_id(CreateType::Create)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(creator, &community, create, context).await?;
|
send_to_community(creator, &community, create, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -63,7 +63,7 @@ impl ApubObjectType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(UpdateType::Update)?)
|
.set_id(generate_activity_id(UpdateType::Update)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(creator, &community, update, context).await?;
|
send_to_community(creator, &community, update, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -83,7 +83,7 @@ impl ApubObjectType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(DeleteType::Delete)?)
|
.set_id(generate_activity_id(DeleteType::Delete)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(creator, &community, delete, context).await?;
|
send_to_community(creator, &community, delete, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -107,7 +107,7 @@ impl ApubObjectType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(DeleteType::Delete)?)
|
.set_id(generate_activity_id(DeleteType::Delete)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
// Undo that fake activity
|
// Undo that fake activity
|
||||||
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
|
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
|
||||||
|
@ -115,7 +115,7 @@ impl ApubObjectType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(UndoType::Undo)?)
|
.set_id(generate_activity_id(UndoType::Undo)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(creator, &community, undo, context).await?;
|
send_to_community(creator, &community, undo, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -135,7 +135,7 @@ impl ApubObjectType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(RemoveType::Remove)?)
|
.set_id(generate_activity_id(RemoveType::Remove)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(mod_, &community, remove, context).await?;
|
send_to_community(mod_, &community, remove, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -155,7 +155,7 @@ impl ApubObjectType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(RemoveType::Remove)?)
|
.set_id(generate_activity_id(RemoveType::Remove)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
// Undo that fake activity
|
// Undo that fake activity
|
||||||
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
|
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
|
||||||
|
@ -163,7 +163,7 @@ impl ApubObjectType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(UndoType::Undo)?)
|
.set_id(generate_activity_id(UndoType::Undo)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(mod_, &community, undo, context).await?;
|
send_to_community(mod_, &community, undo, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -186,7 +186,7 @@ impl ApubLikeableType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(LikeType::Like)?)
|
.set_id(generate_activity_id(LikeType::Like)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(&creator, &community, like, context).await?;
|
send_to_community(&creator, &community, like, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -206,7 +206,7 @@ impl ApubLikeableType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(DislikeType::Dislike)?)
|
.set_id(generate_activity_id(DislikeType::Dislike)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(&creator, &community, dislike, context).await?;
|
send_to_community(&creator, &community, dislike, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -230,7 +230,7 @@ impl ApubLikeableType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(LikeType::Like)?)
|
.set_id(generate_activity_id(LikeType::Like)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
// Undo that fake activity
|
// Undo that fake activity
|
||||||
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
|
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
|
||||||
|
@ -238,7 +238,7 @@ impl ApubLikeableType for Post {
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(UndoType::Undo)?)
|
.set_id(generate_activity_id(UndoType::Undo)?)
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.get_followers_url()?]);
|
.set_many_ccs(vec![community.actor_id()?]);
|
||||||
|
|
||||||
send_to_community(&creator, &community, undo, context).await?;
|
send_to_community(&creator, &community, undo, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -30,13 +30,13 @@ impl ApubObjectType for PrivateMessage {
|
||||||
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
|
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
|
||||||
|
|
||||||
let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
let to = recipient.get_inbox_url()?;
|
|
||||||
create
|
create
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(CreateType::Create)?)
|
.set_id(generate_activity_id(CreateType::Create)?)
|
||||||
.set_to(to.clone());
|
.set_to(recipient.actor_id()?);
|
||||||
|
|
||||||
send_activity_single_dest(create, creator, to, context).await?;
|
send_activity_single_dest(create, creator, recipient.get_inbox_url()?, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,13 +48,12 @@ impl ApubObjectType for PrivateMessage {
|
||||||
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
|
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
|
||||||
|
|
||||||
let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
let to = recipient.get_inbox_url()?;
|
|
||||||
update
|
update
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(UpdateType::Update)?)
|
.set_id(generate_activity_id(UpdateType::Update)?)
|
||||||
.set_to(to.clone());
|
.set_to(recipient.actor_id()?);
|
||||||
|
|
||||||
send_activity_single_dest(update, creator, to, context).await?;
|
send_activity_single_dest(update, creator, recipient.get_inbox_url()?, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,13 +64,12 @@ impl ApubObjectType for PrivateMessage {
|
||||||
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
|
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
|
||||||
|
|
||||||
let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
let to = recipient.get_inbox_url()?;
|
|
||||||
delete
|
delete
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(DeleteType::Delete)?)
|
.set_id(generate_activity_id(DeleteType::Delete)?)
|
||||||
.set_to(to.clone());
|
.set_to(recipient.actor_id()?);
|
||||||
|
|
||||||
send_activity_single_dest(delete, creator, to, context).await?;
|
send_activity_single_dest(delete, creator, recipient.get_inbox_url()?, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,20 +84,19 @@ impl ApubObjectType for PrivateMessage {
|
||||||
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
|
let recipient = blocking(context.pool(), move |conn| User_::read(conn, recipient_id)).await??;
|
||||||
|
|
||||||
let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
|
||||||
let to = recipient.get_inbox_url()?;
|
|
||||||
delete
|
delete
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(DeleteType::Delete)?)
|
.set_id(generate_activity_id(DeleteType::Delete)?)
|
||||||
.set_to(to.clone());
|
.set_to(recipient.actor_id()?);
|
||||||
|
|
||||||
// Undo that fake activity
|
// Undo that fake activity
|
||||||
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
|
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
|
||||||
undo
|
undo
|
||||||
.set_context(activitystreams::context())
|
.set_context(activitystreams::context())
|
||||||
.set_id(generate_activity_id(UndoType::Undo)?)
|
.set_id(generate_activity_id(UndoType::Undo)?)
|
||||||
.set_to(to.clone());
|
.set_to(recipient.actor_id()?);
|
||||||
|
|
||||||
send_activity_single_dest(undo, creator, to, context).await?;
|
send_activity_single_dest(undo, creator, recipient.get_inbox_url()?, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ use url::Url;
|
||||||
pub async fn send_activity_single_dest<T, Kind>(
|
pub async fn send_activity_single_dest<T, Kind>(
|
||||||
activity: T,
|
activity: T,
|
||||||
creator: &dyn ActorType,
|
creator: &dyn ActorType,
|
||||||
to: Url,
|
inbox: Url,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<(), LemmyError>
|
) -> Result<(), LemmyError>
|
||||||
where
|
where
|
||||||
|
@ -39,13 +39,17 @@ where
|
||||||
Kind: Serialize,
|
Kind: Serialize,
|
||||||
<T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static,
|
<T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
if check_is_apub_id_valid(&to).is_ok() {
|
if check_is_apub_id_valid(&inbox).is_ok() {
|
||||||
debug!("Sending activity {:?} to {}", &activity.id_unchecked(), &to);
|
debug!(
|
||||||
|
"Sending activity {:?} to {}",
|
||||||
|
&activity.id_unchecked(),
|
||||||
|
&inbox
|
||||||
|
);
|
||||||
send_activity_internal(
|
send_activity_internal(
|
||||||
context.activity_queue(),
|
context.activity_queue(),
|
||||||
activity,
|
activity,
|
||||||
creator,
|
creator,
|
||||||
vec![to],
|
vec![inbox],
|
||||||
context.pool(),
|
context.pool(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
|
@ -69,7 +73,7 @@ where
|
||||||
// dont send to the local instance, nor to the instance where the activity originally came from,
|
// dont send to the local instance, nor to the instance where the activity originally came from,
|
||||||
// because that would result in a database error (same data inserted twice)
|
// because that would result in a database error (same data inserted twice)
|
||||||
let community_shared_inbox = community.get_shared_inbox_url()?;
|
let community_shared_inbox = community.get_shared_inbox_url()?;
|
||||||
let to: Vec<Url> = community
|
let follower_inboxes: Vec<Url> = community
|
||||||
.get_follower_inboxes(context.pool())
|
.get_follower_inboxes(context.pool())
|
||||||
.await?
|
.await?
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -89,7 +93,7 @@ where
|
||||||
context.activity_queue(),
|
context.activity_queue(),
|
||||||
activity,
|
activity,
|
||||||
community,
|
community,
|
||||||
to,
|
follower_inboxes,
|
||||||
context.pool(),
|
context.pool(),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
|
@ -177,7 +181,7 @@ async fn send_activity_internal<T, Kind>(
|
||||||
activity_sender: &QueueHandle,
|
activity_sender: &QueueHandle,
|
||||||
activity: T,
|
activity: T,
|
||||||
actor: &dyn ActorType,
|
actor: &dyn ActorType,
|
||||||
to: Vec<Url>,
|
inboxes: Vec<Url>,
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
insert_into_db: bool,
|
insert_into_db: bool,
|
||||||
) -> Result<(), LemmyError>
|
) -> Result<(), LemmyError>
|
||||||
|
@ -186,7 +190,7 @@ where
|
||||||
Kind: Serialize,
|
Kind: Serialize,
|
||||||
<T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static,
|
<T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
if !Settings::get().federation.enabled || to.is_empty() {
|
if !Settings::get().federation.enabled || inboxes.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,10 +203,10 @@ where
|
||||||
insert_activity(actor.user_id(), activity.clone(), true, pool).await?;
|
insert_activity(actor.user_id(), activity.clone(), true, pool).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for t in to {
|
for i in inboxes {
|
||||||
let message = SendActivityTask {
|
let message = SendActivityTask {
|
||||||
activity: serialised_activity.to_owned(),
|
activity: serialised_activity.to_owned(),
|
||||||
to: t,
|
inbox: i,
|
||||||
actor_id: actor.actor_id()?,
|
actor_id: actor.actor_id()?,
|
||||||
private_key: actor.private_key().context(location_info!())?,
|
private_key: actor.private_key().context(location_info!())?,
|
||||||
};
|
};
|
||||||
|
@ -215,7 +219,7 @@ where
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
struct SendActivityTask {
|
struct SendActivityTask {
|
||||||
activity: String,
|
activity: String,
|
||||||
to: Url,
|
inbox: Url,
|
||||||
actor_id: Url,
|
actor_id: Url,
|
||||||
private_key: String,
|
private_key: String,
|
||||||
}
|
}
|
||||||
|
@ -235,7 +239,7 @@ impl ActixJob for SendActivityTask {
|
||||||
let result = sign_and_send(
|
let result = sign_and_send(
|
||||||
&state.client,
|
&state.client,
|
||||||
headers,
|
headers,
|
||||||
&self.to,
|
&self.inbox,
|
||||||
self.activity.clone(),
|
self.activity.clone(),
|
||||||
&self.actor_id,
|
&self.actor_id,
|
||||||
self.private_key.to_owned(),
|
self.private_key.to_owned(),
|
||||||
|
@ -247,7 +251,7 @@ impl ActixJob for SendActivityTask {
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
"Failed to send activity {} to {}",
|
"Failed to send activity {} to {}",
|
||||||
&self.activity,
|
&self.activity,
|
||||||
self.to
|
self.inbox
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -11,24 +11,17 @@ use crate::{
|
||||||
},
|
},
|
||||||
check_is_apub_id_valid,
|
check_is_apub_id_valid,
|
||||||
extensions::signatures::verify,
|
extensions::signatures::verify,
|
||||||
fetcher::{get_or_fetch_and_upsert_actor, get_or_fetch_and_upsert_user},
|
fetcher::get_or_fetch_and_upsert_actor,
|
||||||
insert_activity,
|
insert_activity,
|
||||||
};
|
};
|
||||||
use activitystreams::{
|
use activitystreams::{activity::ActorAndObject, prelude::*};
|
||||||
activity::{ActorAndObject, ActorAndObjectRef},
|
|
||||||
base::AsBase,
|
|
||||||
object::AsObject,
|
|
||||||
prelude::*,
|
|
||||||
};
|
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use lemmy_db::user::User_;
|
|
||||||
use lemmy_utils::{location_info, LemmyError};
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
|
@ -55,22 +48,20 @@ pub async fn shared_inbox(
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let activity = input.into_inner();
|
let activity = input.into_inner();
|
||||||
|
|
||||||
let sender = &activity
|
let actor = activity
|
||||||
.actor()?
|
.actor()?
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.single_xsd_any_uri()
|
.single_xsd_any_uri()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let community = get_community_id_from_activity(&activity)?;
|
|
||||||
debug!(
|
debug!(
|
||||||
"Shared inbox received activity {:?} from {}",
|
"Shared inbox received activity {:?} from {}",
|
||||||
&activity.id_unchecked(),
|
&activity.id_unchecked(),
|
||||||
&sender
|
&actor
|
||||||
);
|
);
|
||||||
|
|
||||||
check_is_apub_id_valid(sender)?;
|
check_is_apub_id_valid(&actor)?;
|
||||||
check_is_apub_id_valid(&community)?;
|
|
||||||
|
|
||||||
let actor = get_or_fetch_and_upsert_actor(sender, &context).await?;
|
let actor = get_or_fetch_and_upsert_actor(&actor, &context).await?;
|
||||||
verify(&request, actor.as_ref())?;
|
verify(&request, actor.as_ref())?;
|
||||||
|
|
||||||
let any_base = activity.clone().into_any_base()?;
|
let any_base = activity.clone().into_any_base()?;
|
||||||
|
@ -89,30 +80,3 @@ pub async fn shared_inbox(
|
||||||
insert_activity(actor.user_id(), activity.clone(), false, context.pool()).await?;
|
insert_activity(actor.user_id(), activity.clone(), false, context.pool()).await?;
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(in crate) async fn get_user_from_activity<T, A>(
|
|
||||||
activity: &T,
|
|
||||||
context: &LemmyContext,
|
|
||||||
) -> Result<User_, LemmyError>
|
|
||||||
where
|
|
||||||
T: AsBase<A> + ActorAndObjectRef,
|
|
||||||
{
|
|
||||||
let actor = activity.actor()?;
|
|
||||||
let user_uri = actor.as_single_xsd_any_uri().context(location_info!())?;
|
|
||||||
get_or_fetch_and_upsert_user(&user_uri, context).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(in crate) fn get_community_id_from_activity<T, A>(activity: &T) -> Result<Url, LemmyError>
|
|
||||||
where
|
|
||||||
T: AsBase<A> + ActorAndObjectRef + AsObject<A>,
|
|
||||||
{
|
|
||||||
let cc = activity.cc().context(location_info!())?;
|
|
||||||
let cc = cc.as_many().context(location_info!())?;
|
|
||||||
Ok(
|
|
||||||
cc.first()
|
|
||||||
.context(location_info!())?
|
|
||||||
.as_xsd_any_uri()
|
|
||||||
.context(location_info!())?
|
|
||||||
.to_owned(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue