mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-14 16:57:24 +00:00
Some apub fixes
This commit is contained in:
parent
313f315896
commit
9b7be1afb6
5 changed files with 27 additions and 33 deletions
|
@ -350,7 +350,7 @@ async fn fetch_remote_community(
|
|||
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?;
|
||||
|
@ -358,6 +358,7 @@ async fn fetch_remote_community(
|
|||
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)
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
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,
|
||||
|
@ -34,8 +31,8 @@ pub async fn receive_announce(
|
|||
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();
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
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,
|
||||
},
|
||||
|
@ -44,8 +44,8 @@ pub async fn receive_remove(
|
|||
) -> 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());
|
||||
}
|
||||
|
||||
|
|
|
@ -209,7 +209,7 @@ async fn receive_undo_remove_comment(
|
|||
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()?;
|
||||
|
||||
|
@ -322,7 +322,7 @@ async fn receive_undo_remove_post(
|
|||
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()?;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ use activitystreams::{
|
|||
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;
|
||||
|
@ -68,13 +68,12 @@ pub async fn shared_inbox(
|
|||
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()?;
|
||||
|
@ -117,18 +116,15 @@ where
|
|||
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>(
|
||||
|
|
Loading…
Reference in a new issue