mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-12 15:34:00 +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();
|
let outbox_items = outbox.items().unwrap().clone();
|
||||||
for o in outbox_items.many().unwrap() {
|
for o in outbox_items.many().unwrap() {
|
||||||
let page = PageExt::from_any_base(o)?.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();
|
let post_ap_id = post.ap_id.clone();
|
||||||
// Check whether the post already exists in the local db
|
// 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?;
|
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??,
|
Ok(e) => blocking(pool, move |conn| Post::update(conn, e.id, &post)).await??,
|
||||||
Err(_) => blocking(pool, move |conn| Post::create(conn, &post)).await??,
|
Err(_) => blocking(pool, move |conn| Post::create(conn, &post)).await??,
|
||||||
};
|
};
|
||||||
|
// TODO: we need to send a websocket update here
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(community)
|
Ok(community)
|
||||||
|
|
|
@ -1,18 +1,15 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
apub::{
|
apub::inbox::{
|
||||||
inbox::{
|
activities::{
|
||||||
activities::{
|
create::receive_create,
|
||||||
create::receive_create,
|
delete::receive_delete,
|
||||||
delete::receive_delete,
|
dislike::receive_dislike,
|
||||||
dislike::receive_dislike,
|
like::receive_like,
|
||||||
like::receive_like,
|
remove::receive_remove,
|
||||||
remove::receive_remove,
|
undo::receive_undo,
|
||||||
undo::receive_undo,
|
update::receive_update,
|
||||||
update::receive_update,
|
|
||||||
},
|
|
||||||
shared_inbox::{get_community_from_activity, receive_unhandled_activity},
|
|
||||||
},
|
},
|
||||||
ActorType,
|
shared_inbox::{get_community_id_from_activity, receive_unhandled_activity},
|
||||||
},
|
},
|
||||||
routes::ChatServerParam,
|
routes::ChatServerParam,
|
||||||
DbPool,
|
DbPool,
|
||||||
|
@ -34,8 +31,8 @@ pub async fn receive_announce(
|
||||||
let announce = Announce::from_any_base(activity)?.unwrap();
|
let announce = Announce::from_any_base(activity)?.unwrap();
|
||||||
|
|
||||||
// ensure that announce and community come from the same instance
|
// ensure that announce and community come from the same instance
|
||||||
let community = get_community_from_activity(&announce, client, pool).await?;
|
let community = get_community_id_from_activity(&announce)?;
|
||||||
announce.id(community.actor_id()?.domain().unwrap())?;
|
announce.id(community.domain().unwrap())?;
|
||||||
|
|
||||||
let kind = announce.object().as_single_kind_str();
|
let kind = announce.object().as_single_kind_str();
|
||||||
let object = announce.object();
|
let object = announce.object();
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
||||||
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::{
|
inbox::shared_inbox::{
|
||||||
announce_if_community_is_local,
|
announce_if_community_is_local,
|
||||||
get_community_from_activity,
|
get_community_id_from_activity,
|
||||||
get_user_from_activity,
|
get_user_from_activity,
|
||||||
receive_unhandled_activity,
|
receive_unhandled_activity,
|
||||||
},
|
},
|
||||||
|
@ -44,8 +44,8 @@ pub async fn receive_remove(
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let remove = Remove::from_any_base(activity)?.unwrap();
|
let remove = Remove::from_any_base(activity)?.unwrap();
|
||||||
let actor = get_user_from_activity(&remove, client, pool).await?;
|
let actor = get_user_from_activity(&remove, client, pool).await?;
|
||||||
let community = get_community_from_activity(&remove, client, pool).await?;
|
let community = get_community_id_from_activity(&remove)?;
|
||||||
if actor.actor_id()?.domain() != community.actor_id()?.domain() {
|
if actor.actor_id()?.domain() != community.domain() {
|
||||||
return Err(anyhow!("Remove activities are only allowed on local objects").into());
|
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 mod_ = get_user_from_activity(remove, client, pool).await?;
|
||||||
let note = Note::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
|
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?
|
.await?
|
||||||
.get_ap_id()?;
|
.get_ap_id()?;
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ async fn receive_undo_remove_post(
|
||||||
let mod_ = get_user_from_activity(remove, client, pool).await?;
|
let mod_ = get_user_from_activity(remove, client, pool).await?;
|
||||||
let page = PageExt::from_any_base(remove.object().to_owned().one().unwrap())?.unwrap();
|
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?
|
.await?
|
||||||
.get_ap_id()?;
|
.get_ap_id()?;
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ use activitystreams::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
use actix_web::{client::Client, web, HttpRequest, HttpResponse};
|
use actix_web::{client::Client, web, HttpRequest, HttpResponse};
|
||||||
use lemmy_db::{community::Community, user::User_};
|
use lemmy_db::user::User_;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
@ -68,13 +68,12 @@ pub async fn shared_inbox(
|
||||||
debug!("Shared inbox received activity: {}", json);
|
debug!("Shared inbox received activity: {}", json);
|
||||||
|
|
||||||
let sender = &activity.actor()?.to_owned().single_xsd_any_uri().unwrap();
|
let sender = &activity.actor()?.to_owned().single_xsd_any_uri().unwrap();
|
||||||
// TODO: pass this actor in instead of using get_user_from_activity()
|
let community = get_community_id_from_activity(&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;
|
|
||||||
|
|
||||||
check_is_apub_id_valid(sender)?;
|
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())?;
|
verify(&request, actor.as_ref())?;
|
||||||
|
|
||||||
let any_base = activity.clone().into_any_base()?;
|
let any_base = activity.clone().into_any_base()?;
|
||||||
|
@ -117,18 +116,15 @@ where
|
||||||
get_or_fetch_and_upsert_user(&user_uri, client, pool).await
|
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,
|
activity: &T,
|
||||||
client: &Client,
|
) -> Result<Url, LemmyError>
|
||||||
pool: &DbPool,
|
|
||||||
) -> Result<Community, LemmyError>
|
|
||||||
where
|
where
|
||||||
T: AsBase<A> + ActorAndObjectRef + AsObject<A>,
|
T: AsBase<A> + ActorAndObjectRef + AsObject<A>,
|
||||||
{
|
{
|
||||||
let cc = activity.cc().unwrap();
|
let cc = activity.cc().unwrap();
|
||||||
let cc = cc.as_many().unwrap();
|
let cc = cc.as_many().unwrap();
|
||||||
let community_uri = cc.first().unwrap().as_xsd_any_uri().unwrap().to_owned();
|
Ok(cc.first().unwrap().as_xsd_any_uri().unwrap().to_owned())
|
||||||
get_or_fetch_and_upsert_community(&community_uri, client, pool).await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(in crate::apub::inbox) async fn announce_if_community_is_local<T, Kind>(
|
pub(in crate::apub::inbox) async fn announce_if_community_is_local<T, Kind>(
|
||||||
|
|
Loading…
Reference in a new issue