let outbox_items = outbox.items().unwrap().clone();
for o in outbox_items.many().unwrap() {
let page = PageExt::from_any_base(o)?.unwrap();
- let post = PostForm::from_apub(&page, client, pool, Some(apub_id.to_owned())).await?;
+ let post = PostForm::from_apub(&page, client, pool, None).await?;
let post_ap_id = post.ap_id.clone();
// Check whether the post already exists in the local db
let existing = blocking(pool, move |conn| Post::read_from_apub_id(conn, &post_ap_id)).await?;
Ok(e) => blocking(pool, move |conn| Post::update(conn, e.id, &post)).await??,
Err(_) => blocking(pool, move |conn| Post::create(conn, &post)).await??,
};
+ // TODO: we need to send a websocket update here
}
Ok(community)
use crate::{
- apub::{
- inbox::{
- activities::{
- create::receive_create,
- delete::receive_delete,
- dislike::receive_dislike,
- like::receive_like,
- remove::receive_remove,
- undo::receive_undo,
- update::receive_update,
- },
- shared_inbox::{get_community_from_activity, receive_unhandled_activity},
+ apub::inbox::{
+ activities::{
+ create::receive_create,
+ delete::receive_delete,
+ dislike::receive_dislike,
+ like::receive_like,
+ remove::receive_remove,
+ undo::receive_undo,
+ update::receive_update,
},
- ActorType,
+ shared_inbox::{get_community_id_from_activity, receive_unhandled_activity},
},
routes::ChatServerParam,
DbPool,
let announce = Announce::from_any_base(activity)?.unwrap();
// ensure that announce and community come from the same instance
- let community = get_community_from_activity(&announce, client, pool).await?;
- announce.id(community.actor_id()?.domain().unwrap())?;
+ let community = get_community_id_from_activity(&announce)?;
+ announce.id(community.domain().unwrap())?;
let kind = announce.object().as_single_kind_str();
let object = announce.object();
fetcher::{get_or_fetch_and_insert_comment, get_or_fetch_and_insert_post},
inbox::shared_inbox::{
announce_if_community_is_local,
- get_community_from_activity,
+ get_community_id_from_activity,
get_user_from_activity,
receive_unhandled_activity,
},
) -> Result<HttpResponse, LemmyError> {
let remove = Remove::from_any_base(activity)?.unwrap();
let actor = get_user_from_activity(&remove, client, pool).await?;
- let community = get_community_from_activity(&remove, client, pool).await?;
- if actor.actor_id()?.domain() != community.actor_id()?.domain() {
+ let community = get_community_id_from_activity(&remove)?;
+ if actor.actor_id()?.domain() != community.domain() {
return Err(anyhow!("Remove activities are only allowed on local objects").into());
}
let mod_ = get_user_from_activity(remove, client, pool).await?;
let note = Note::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
- let comment_ap_id = CommentForm::from_apub(¬e, client, pool, Some(mod_.actor_id()?))
+ let comment_ap_id = CommentForm::from_apub(¬e, client, pool, None)
.await?
.get_ap_id()?;
let mod_ = get_user_from_activity(remove, client, pool).await?;
let page = PageExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
- let post_ap_id = PostForm::from_apub(&page, client, pool, Some(mod_.actor_id()?))
+ let post_ap_id = PostForm::from_apub(&page, client, pool, None)
.await?
.get_ap_id()?;
prelude::*,
};
use actix_web::{client::Client, web, HttpRequest, HttpResponse};
-use lemmy_db::{community::Community, user::User_};
+use lemmy_db::user::User_;
use log::debug;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
debug!("Shared inbox received activity: {}", json);
let sender = &activity.actor()?.to_owned().single_xsd_any_uri().unwrap();
- // TODO: pass this actor in instead of using get_user_from_activity()
- let actor = get_or_fetch_and_upsert_actor(sender, &client, &pool).await?;
-
- // TODO: i dont think this works for Announce/Undo activities
- //let community = get_community_id_from_activity(&activity).await;
+ let community = get_community_id_from_activity(&activity)?;
check_is_apub_id_valid(sender)?;
+ check_is_apub_id_valid(&community)?;
+
+ let actor = get_or_fetch_and_upsert_actor(sender, &client, &pool).await?;
verify(&request, actor.as_ref())?;
let any_base = activity.clone().into_any_base()?;
get_or_fetch_and_upsert_user(&user_uri, client, pool).await
}
-pub(in crate::apub::inbox) async fn get_community_from_activity<T, A>(
+pub(in crate::apub::inbox) fn get_community_id_from_activity<T, A>(
activity: &T,
- client: &Client,
- pool: &DbPool,
-) -> Result<Community, LemmyError>
+) -> Result<Url, LemmyError>
where
T: AsBase<A> + ActorAndObjectRef + AsObject<A>,
{
let cc = activity.cc().unwrap();
let cc = cc.as_many().unwrap();
- let community_uri = cc.first().unwrap().as_xsd_any_uri().unwrap().to_owned();
- get_or_fetch_and_upsert_community(&community_uri, client, pool).await
+ Ok(cc.first().unwrap().as_xsd_any_uri().unwrap().to_owned())
}
pub(in crate::apub::inbox) async fn announce_if_community_is_local<T, Kind>(