Update activitystreams library to latest version #71
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
apub::{
|
||||
activities::{populate_object_props, send_activity_to_community},
|
||||
activities::send_activity_to_community,
|
||||
create_apub_response, create_apub_tombstone_response, create_tombstone,
|
||||
extensions::page_extension::PageExtension,
|
||||
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
||||
|
@ -10,16 +10,14 @@ use crate::{
|
|||
routes::DbPoolParam,
|
||||
DbPool, LemmyError,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
|
||||
BaseBox,
|
||||
};
|
||||
use activitystreams_ext::Ext1;
|
||||
use activitystreams_new::{
|
||||
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
|
||||
context,
|
||||
object::{kind::PageType, Image, Page, Tombstone},
|
||||
prelude::*,
|
||||
primitives::{XsdAnyUri, XsdDateTime},
|
||||
public,
|
||||
};
|
||||
use actix_web::{body::Body, client::Client, web, HttpResponse};
|
||||
use lemmy_db::{
|
||||
|
@ -30,6 +28,7 @@ use lemmy_db::{
|
|||
};
|
||||
use lemmy_utils::{convert_datetime, get_apub_protocol_string, settings::Settings};
|
||||
use serde::Deserialize;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PostQuery {
|
||||
|
@ -265,16 +264,12 @@ impl ApubObjectType for Post {
|
|||
|
||||
let id = format!("{}/create/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
|
||||
let mut create = Create::new();
|
||||
populate_object_props(
|
||||
&mut create.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
let mut create = Create::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
||||
create
|
||||
.create_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
send_activity_to_community(
|
||||
creator,
|
||||
|
@ -302,16 +297,12 @@ impl ApubObjectType for Post {
|
|||
|
||||
let id = format!("{}/update/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
|
||||
let mut update = Update::new();
|
||||
populate_object_props(
|
||||
&mut update.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
let mut update = Update::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
||||
update
|
||||
.update_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
send_activity_to_community(
|
||||
creator,
|
||||
|
@ -337,18 +328,12 @@ impl ApubObjectType for Post {
|
|||
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
||||
|
||||
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
let mut delete = Delete::default();
|
||||
|
||||
populate_object_props(
|
||||
&mut delete.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
|
||||
let mut delete = Delete::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
||||
delete
|
||||
.delete_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
send_activity_to_community(
|
||||
creator,
|
||||
|
@ -374,34 +359,22 @@ impl ApubObjectType for Post {
|
|||
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
||||
|
||||
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
let mut delete = Delete::default();
|
||||
|
||||
populate_object_props(
|
||||
&mut delete.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
|
||||
let mut delete = Delete::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
||||
delete
|
||||
.delete_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
// TODO
|
||||
// Undo that fake activity
|
||||
let undo_id = format!("{}/undo/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
let mut undo = Undo::default();
|
||||
|
||||
populate_object_props(
|
||||
&mut undo.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&undo_id,
|
||||
)?;
|
||||
|
||||
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
|
||||
undo
|
||||
.undo_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(delete)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&undo_id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
send_activity_to_community(
|
||||
creator,
|
||||
|
@ -427,18 +400,12 @@ impl ApubObjectType for Post {
|
|||
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
||||
|
||||
let id = format!("{}/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
let mut remove = Remove::default();
|
||||
|
||||
populate_object_props(
|
||||
&mut remove.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
|
||||
let mut remove = Remove::new(mod_.actor_id.to_owned(), page.into_any_base()?);
|
||||
remove
|
||||
.remove_props
|
||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
send_activity_to_community(
|
||||
mod_,
|
||||
|
@ -464,33 +431,21 @@ impl ApubObjectType for Post {
|
|||
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
||||
|
||||
let id = format!("{}/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
let mut remove = Remove::default();
|
||||
|
||||
populate_object_props(
|
||||
&mut remove.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
|
||||
let mut remove = Remove::new(mod_.actor_id.to_owned(), page.into_any_base()?);
|
||||
remove
|
||||
.remove_props
|
||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
// Undo that fake activity
|
||||
let undo_id = format!("{}/undo/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
let mut undo = Undo::default();
|
||||
|
||||
populate_object_props(
|
||||
&mut undo.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&undo_id,
|
||||
)?;
|
||||
|
||||
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
|
||||
undo
|
||||
.undo_props
|
||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(remove)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&undo_id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
send_activity_to_community(
|
||||
mod_,
|
||||
|
@ -520,16 +475,12 @@ impl ApubLikeableType for Post {
|
|||
|
||||
let id = format!("{}/like/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
|
||||
let mut like = Like::new();
|
||||
populate_object_props(
|
||||
&mut like.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
let mut like = Like::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
||||
like
|
||||
.like_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
send_activity_to_community(
|
||||
&creator,
|
||||
|
@ -556,16 +507,12 @@ impl ApubLikeableType for Post {
|
|||
|
||||
let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
|
||||
let mut dislike = Dislike::new();
|
||||
populate_object_props(
|
||||
&mut dislike.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
let mut dislike = Dislike::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
||||
dislike
|
||||
.dislike_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
send_activity_to_community(
|
||||
&creator,
|
||||
|
@ -592,32 +539,22 @@ impl ApubLikeableType for Post {
|
|||
|
||||
let id = format!("{}/like/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
|
||||
let mut like = Like::new();
|
||||
populate_object_props(
|
||||
&mut like.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
let mut like = Like::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
||||
like
|
||||
.like_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(page)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
// TODO
|
||||
// Undo that fake activity
|
||||
let undo_id = format!("{}/undo/like/{}", self.ap_id, uuid::Uuid::new_v4());
|
||||
let mut undo = Undo::default();
|
||||
|
||||
populate_object_props(
|
||||
&mut undo.object_props,
|
||||
vec![community.get_followers_url()],
|
||||
&undo_id,
|
||||
)?;
|
||||
|
||||
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
|
||||
undo
|
||||
.undo_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(like)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&undo_id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![community.get_followers_url()]);
|
||||
|
||||
send_activity_to_community(
|
||||
&creator,
|
||||
|
|
Loading…
Reference in New Issue