-use crate::{
- activities::receive::{
- create::receive_create,
- delete::receive_delete,
- dislike::receive_dislike,
- like::receive_like,
- receive_unhandled_activity,
- remove::receive_remove,
- undo::receive_undo,
- update::receive_update,
- },
- inbox::shared_inbox::get_community_id_from_activity,
+use crate::activities::receive::{
+ create::receive_create,
+ delete::receive_delete,
+ dislike::receive_dislike,
+ like::receive_like,
+ receive_unhandled_activity,
+ remove::receive_remove,
+ undo::receive_undo,
+ update::receive_update,
};
use activitystreams::{
activity::*,
let announce = Announce::from_any_base(activity)?.context(location_info!())?;
// ensure that announce and community come from the same instance
- let community = get_community_id_from_activity(&announce)?;
- announce.id(community.domain().context(location_info!())?)?;
+ let community_id = announce
+ .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 object = announce.object();
use crate::{
- activities::receive::{announce_if_community_is_local, receive_unhandled_activity},
- inbox::shared_inbox::get_user_from_activity,
+ activities::receive::{
+ announce_if_community_is_local,
+ get_actor_as_user,
+ receive_unhandled_activity,
+ },
ActorType,
FromApub,
PageExt,
let create = Create::from_any_base(activity)?.context(location_info!())?;
// 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!())?)?;
match create.object().as_single_kind_str() {
create: Create,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
create: Create,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
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},
- inbox::shared_inbox::get_user_from_activity,
ActorType,
FromApub,
GroupExt,
delete: Delete,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
delete: Delete,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
) -> Result<HttpResponse, LemmyError> {
let group = GroupExt::from_any_base(delete.object().to_owned().one().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()?))
.await?
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},
- inbox::shared_inbox::get_user_from_activity,
FromApub,
PageExt,
};
dislike: Dislike,
context: &LemmyContext,
) -> 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(
dislike
.object()
.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?;
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},
- inbox::shared_inbox::get_user_from_activity,
FromApub,
PageExt,
};
}
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!())?)?
.context(location_info!())?;
) -> Result<HttpResponse, LemmyError> {
let note = Note::from_any_base(like.object().to_owned().one().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?;
-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::{
- base::{Extends, ExtendsExt},
+ activity::{ActorAndObjectRef, ActorAndObjectRefExt},
+ base::{AsBase, Extends, ExtendsExt},
object::{AsObject, ObjectExt},
};
use actix_web::HttpResponse;
}
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
+}
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},
- inbox::shared_inbox::{get_community_id_from_activity, get_user_from_activity},
ActorType,
FromApub,
GroupExt,
context: &LemmyContext,
) -> Result<HttpResponse, LemmyError> {
let remove = Remove::from_any_base(activity)?.context(location_info!())?;
- let actor = get_user_from_activity(&remove, context).await?;
- let community = get_community_id_from_activity(&remove)?;
- if actor.actor_id()?.domain() != community.domain() {
+ let actor = get_actor_as_user(&remove, context).await?;
+ let cc = remove
+ .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());
}
remove: Remove,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
remove: Remove,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
remove: Remove,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
use crate::{
activities::receive::{
announce_if_community_is_local,
+ get_actor_as_user,
receive_unhandled_activity,
undo_comment::*,
undo_post::*,
},
- inbox::shared_inbox::get_user_from_activity,
ActorType,
FromApub,
GroupExt,
delete: &Delete,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
remove: &Remove,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
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,
- inbox::shared_inbox::get_user_from_activity,
ActorType,
FromApub,
};
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 note = Note::from_any_base(like.object().to_owned().one().context(location_info!())?)?
.context(location_info!())?;
dislike: &Dislike,
context: &LemmyContext,
) -> 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(
dislike
.object()
delete: &Delete,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
remove: &Remove,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
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,
- inbox::shared_inbox::get_user_from_activity,
ActorType,
FromApub,
PageExt,
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!())?)?
.context(location_info!())?;
dislike: &Dislike,
context: &LemmyContext,
) -> 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(
dislike
.object()
delete: &Delete,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
remove: &Remove,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
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},
- inbox::shared_inbox::get_user_from_activity,
ActorType,
FromApub,
PageExt,
let update = Update::from_any_base(activity)?.context(location_info!())?;
// 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!())?)?;
match update.object().as_single_kind_str() {
update: Update,
context: &LemmyContext,
) -> 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!())?)?
.context(location_info!())?;
) -> Result<HttpResponse, LemmyError> {
let note = Note::from_any_base(update.object().to_owned().one().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?;
})
.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()?);
create
.set_context(activitystreams::context())
.set_id(generate_activity_id(CreateType::Create)?)
.set_to(public())
- .set_many_ccs(maa.addressed_ccs.to_owned())
+ .set_many_ccs(ccs)
// Set the mention tags
.set_many_tags(maa.get_tags()?);
})
.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()?);
update
.set_context(activitystreams::context())
.set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public())
- .set_many_ccs(maa.addressed_ccs.to_owned())
+ .set_many_ccs(ccs)
// Set the mention tags
.set_many_tags(maa.get_tags()?);
.set_context(activitystreams::context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()?]);
+ .set_many_ccs(vec![community.actor_id()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
.set_context(activitystreams::context())
.set_id(generate_activity_id(UndoType::Undo)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()?]);
+ .set_many_ccs(vec![community.actor_id()?]);
// Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
.set_context(activitystreams::context())
.set_id(generate_activity_id(UndoType::Undo)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(LikeType::Like)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()?]);
+ .set_many_ccs(vec![community.actor_id()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
.set_context(activitystreams::context())
.set_id(generate_activity_id(UndoType::Undo)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(CreateType::Create)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(UpdateType::Update)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()?]);
+ .set_many_ccs(vec![community.actor_id()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
.set_context(activitystreams::context())
.set_id(generate_activity_id(UndoType::Undo)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()?]);
+ .set_many_ccs(vec![community.actor_id()?]);
// Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
.set_context(activitystreams::context())
.set_id(generate_activity_id(UndoType::Undo)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(LikeType::Like)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.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?;
Ok(())
.set_context(activitystreams::context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
- .set_many_ccs(vec![community.get_followers_url()?]);
+ .set_many_ccs(vec![community.actor_id()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
.set_context(activitystreams::context())
.set_id(generate_activity_id(UndoType::Undo)?)
.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?;
Ok(())
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 to = recipient.get_inbox_url()?;
+
create
.set_context(activitystreams::context())
.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(())
}
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 to = recipient.get_inbox_url()?;
update
.set_context(activitystreams::context())
.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(())
}
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 to = recipient.get_inbox_url()?;
delete
.set_context(activitystreams::context())
.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(())
}
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 to = recipient.get_inbox_url()?;
delete
.set_context(activitystreams::context())
.set_id(generate_activity_id(DeleteType::Delete)?)
- .set_to(to.clone());
+ .set_to(recipient.actor_id()?);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo
.set_context(activitystreams::context())
.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(())
}
pub async fn send_activity_single_dest<T, Kind>(
activity: T,
creator: &dyn ActorType,
- to: Url,
+ inbox: Url,
context: &LemmyContext,
) -> Result<(), LemmyError>
where
Kind: Serialize,
<T as Extends<Kind>>::Error: From<serde_json::Error> + Send + Sync + 'static,
{
- if check_is_apub_id_valid(&to).is_ok() {
- debug!("Sending activity {:?} to {}", &activity.id_unchecked(), &to);
+ if check_is_apub_id_valid(&inbox).is_ok() {
+ debug!(
+ "Sending activity {:?} to {}",
+ &activity.id_unchecked(),
+ &inbox
+ );
send_activity_internal(
context.activity_queue(),
activity,
creator,
- vec![to],
+ vec![inbox],
context.pool(),
true,
)
// 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)
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())
.await?
.iter()
context.activity_queue(),
activity,
community,
- to,
+ follower_inboxes,
context.pool(),
true,
)
activity_sender: &QueueHandle,
activity: T,
actor: &dyn ActorType,
- to: Vec<Url>,
+ inboxes: Vec<Url>,
pool: &DbPool,
insert_into_db: bool,
) -> Result<(), LemmyError>
Kind: Serialize,
<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(());
}
insert_activity(actor.user_id(), activity.clone(), true, pool).await?;
}
- for t in to {
+ for i in inboxes {
let message = SendActivityTask {
activity: serialised_activity.to_owned(),
- to: t,
+ inbox: i,
actor_id: actor.actor_id()?,
private_key: actor.private_key().context(location_info!())?,
};
#[derive(Clone, Debug, Deserialize, Serialize)]
struct SendActivityTask {
activity: String,
- to: Url,
+ inbox: Url,
actor_id: Url,
private_key: String,
}
let result = sign_and_send(
&state.client,
headers,
- &self.to,
+ &self.inbox,
self.activity.clone(),
&self.actor_id,
self.private_key.to_owned(),
return Err(anyhow!(
"Failed to send activity {} to {}",
&self.activity,
- self.to
+ self.inbox
));
}
Ok(())
},
check_is_apub_id_valid,
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,
};
-use activitystreams::{
- activity::{ActorAndObject, ActorAndObjectRef},
- base::AsBase,
- object::AsObject,
- prelude::*,
-};
+use activitystreams::{activity::ActorAndObject, prelude::*};
use actix_web::{web, HttpRequest, HttpResponse};
use anyhow::Context;
-use lemmy_db::user::User_;
use lemmy_utils::{location_info, LemmyError};
use lemmy_websocket::LemmyContext;
use log::debug;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
-use url::Url;
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, Deserialize, Serialize)]
#[serde(rename_all = "PascalCase")]
) -> Result<HttpResponse, LemmyError> {
let activity = input.into_inner();
- let sender = &activity
+ let actor = activity
.actor()?
.to_owned()
.single_xsd_any_uri()
.context(location_info!())?;
- let community = get_community_id_from_activity(&activity)?;
debug!(
"Shared inbox received activity {:?} from {}",
&activity.id_unchecked(),
- &sender
+ &actor
);
- check_is_apub_id_valid(sender)?;
- check_is_apub_id_valid(&community)?;
+ check_is_apub_id_valid(&actor)?;
- 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())?;
let any_base = activity.clone().into_any_base()?;
insert_activity(actor.user_id(), activity.clone(), false, context.pool()).await?;
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(),
- )
-}