Add helper function to generate proper activity IDs

This commit is contained in:
Felix Ableitner 2020-07-28 18:47:26 +02:00
parent e605d58888
commit 494fcfdb8f
19 changed files with 152 additions and 296 deletions

View File

@ -1,20 +1,18 @@
use crate::{ use crate::{
apub::{ apub::{
community::do_announce, community::do_announce, extensions::signatures::sign, insert_activity, is_apub_id_valid,
extensions::signatures::sign,
insert_activity,
is_apub_id_valid,
ActorType, ActorType,
}, },
request::retry_custom, request::retry_custom,
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::base::AnyBase; use activitystreams_new::base::AnyBase;
use actix_web::client::Client; use actix_web::client::Client;
use lemmy_db::{community::Community, user::User_}; use lemmy_db::{community::Community, user::User_};
use lemmy_utils::{get_apub_protocol_string, settings::Settings};
use log::debug; use log::debug;
use url::Url; use url::{ParseError, Url};
use uuid::Uuid;
pub async fn send_activity_to_community( pub async fn send_activity_to_community(
creator: &User_, creator: &User_,
@ -68,3 +66,17 @@ pub async fn send_activity(
Ok(()) Ok(())
} }
pub(in crate::apub) fn generate_activity_id<T>(kind: T) -> Result<Url, ParseError>
where
T: ToString,
{
let id = format!(
"{}://{}/activities/{}/{}",
get_apub_protocol_string(),
Settings::get().hostname,
kind.to_string().to_lowercase(),
Uuid::new_v4()
);
Url::parse(&id)
}

View File

@ -1,28 +1,22 @@
use crate::{ use crate::{
apub::{ apub::{
activities::send_activity_to_community, activities::{generate_activity_id, send_activity_to_community},
create_apub_response, create_apub_response, create_apub_tombstone_response, create_tombstone, fetch_webfinger_url,
create_apub_tombstone_response,
create_tombstone,
fetch_webfinger_url,
fetcher::{ fetcher::{
get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post,
get_or_fetch_and_insert_remote_post,
get_or_fetch_and_upsert_remote_user, get_or_fetch_and_upsert_remote_user,
}, },
ActorType, ActorType, ApubLikeableType, ApubObjectType, FromApub, ToApub,
ApubLikeableType,
ApubObjectType,
FromApub,
ToApub,
}, },
blocking, blocking,
routes::DbPoolParam, routes::DbPoolParam,
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{ use activitystreams_new::{
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update}, activity::{
kind::{CreateType, DeleteType, DislikeType, LikeType, RemoveType, UndoType, UpdateType},
Create, Delete, Dislike, Like, Remove, Undo, Update,
},
base::AnyBase, base::AnyBase,
context, context,
link::Mention, link::Mention,
@ -109,12 +103,7 @@ impl ToApub for Comment {
} }
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> { fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
create_tombstone( create_tombstone(self.deleted, &self.ap_id, self.updated, NoteType::Note)
self.deleted,
&self.ap_id,
self.updated,
NoteType::Note.to_string(),
)
} }
} }
@ -204,11 +193,10 @@ impl ApubObjectType for Comment {
let maa = let maa =
collect_non_local_mentions_and_addresses(&self.content, &community, client, pool).await?; collect_non_local_mentions_and_addresses(&self.content, &community, client, pool).await?;
let id = format!("{}/create/{}", self.ap_id, uuid::Uuid::new_v4());
let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?); let mut create = Create::new(creator.actor_id.to_owned(), note.into_any_base()?);
create create
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(CreateType::Create)?)
.set_to(public()) .set_to(public())
.set_many_ccs(maa.addressed_ccs.to_owned()) .set_many_ccs(maa.addressed_ccs.to_owned())
// Set the mention tags // Set the mention tags
@ -244,11 +232,10 @@ impl ApubObjectType for Comment {
let maa = let maa =
collect_non_local_mentions_and_addresses(&self.content, &community, client, pool).await?; collect_non_local_mentions_and_addresses(&self.content, &community, client, pool).await?;
let id = format!("{}/update/{}", self.ap_id, uuid::Uuid::new_v4());
let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?); let mut update = Update::new(creator.actor_id.to_owned(), note.into_any_base()?);
update update
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public()) .set_to(public())
.set_many_ccs(maa.addressed_ccs.to_owned()) .set_many_ccs(maa.addressed_ccs.to_owned())
// Set the mention tags // Set the mention tags
@ -280,11 +267,10 @@ impl ApubObjectType for Comment {
let community_id = post.community_id; let community_id = post.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; 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::new(creator.actor_id.to_owned(), note.into_any_base()?); let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
delete delete
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -315,21 +301,18 @@ impl ApubObjectType for Comment {
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
// Generate a fake delete activity, with the correct object // Generate a fake delete activity, with the correct object
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?); let mut delete = Delete::new(creator.actor_id.to_owned(), note.into_any_base()?);
delete delete
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
// TODO
// Undo that fake activity // Undo that fake activity
let undo_id = format!("{}/undo/delete/{}", self.ap_id, uuid::Uuid::new_v4());
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo undo
.set_context(context()) .set_context(context())
.set_id(Url::parse(&undo_id)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -359,11 +342,10 @@ impl ApubObjectType for Comment {
let community_id = post.community_id; let community_id = post.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; 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::new(mod_.actor_id.to_owned(), note.into_any_base()?); let mut remove = Remove::new(mod_.actor_id.to_owned(), note.into_any_base()?);
remove remove
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -394,20 +376,18 @@ impl ApubObjectType for Comment {
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
// Generate a fake delete activity, with the correct object // Generate a fake delete activity, with the correct object
let id = format!("{}/remove/{}", self.ap_id, uuid::Uuid::new_v4());
let mut remove = Remove::new(mod_.actor_id.to_owned(), note.into_any_base()?); let mut remove = Remove::new(mod_.actor_id.to_owned(), note.into_any_base()?);
remove remove
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
// Undo that fake activity // Undo that fake activity
let undo_id = format!("{}/undo/remove/{}", self.ap_id, uuid::Uuid::new_v4());
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?); let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
undo undo
.set_context(context()) .set_context(context())
.set_id(Url::parse(&undo_id)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -440,12 +420,10 @@ impl ApubLikeableType for Comment {
let community_id = post.community_id; let community_id = post.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
let id = format!("{}/like/{}", self.ap_id, uuid::Uuid::new_v4());
let mut like = Like::new(creator.actor_id.to_owned(), note.into_any_base()?); let mut like = Like::new(creator.actor_id.to_owned(), note.into_any_base()?);
like like
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(LikeType::Like)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -475,12 +453,10 @@ impl ApubLikeableType for Comment {
let community_id = post.community_id; let community_id = post.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4());
let mut dislike = Dislike::new(creator.actor_id.to_owned(), note.into_any_base()?); let mut dislike = Dislike::new(creator.actor_id.to_owned(), note.into_any_base()?);
dislike dislike
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -510,22 +486,18 @@ impl ApubLikeableType for Comment {
let community_id = post.community_id; let community_id = post.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4());
let mut like = Like::new(creator.actor_id.to_owned(), note.into_any_base()?); let mut like = Like::new(creator.actor_id.to_owned(), note.into_any_base()?);
like like
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
// TODO
// Undo that fake activity // Undo that fake activity
let undo_id = format!("{}/undo/like/{}", self.ap_id, uuid::Uuid::new_v4());
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
undo undo
.set_context(context()) .set_context(context())
.set_id(Url::parse(&undo_id)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);

View File

@ -1,26 +1,21 @@
use crate::{ use crate::{
apub::{ apub::{
activities::send_activity, activities::{generate_activity_id, send_activity},
create_apub_response, create_apub_response, create_apub_tombstone_response, create_tombstone,
create_apub_tombstone_response,
create_tombstone,
extensions::group_extensions::GroupExtension, extensions::group_extensions::GroupExtension,
fetcher::get_or_fetch_and_upsert_remote_user, fetcher::get_or_fetch_and_upsert_remote_user,
get_shared_inbox, get_shared_inbox, insert_activity, ActorType, FromApub, GroupExt, ToApub,
insert_activity,
ActorType,
FromApub,
GroupExt,
ToApub,
}, },
blocking, blocking,
routes::DbPoolParam, routes::DbPoolParam,
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_ext::Ext2; use activitystreams_ext::Ext2;
use activitystreams_new::{ use activitystreams_new::{
activity::{Accept, Announce, Delete, Follow, Remove, Undo}, activity::{
kind::{AcceptType, AnnounceType, DeleteType, LikeType, RemoveType, UndoType},
Accept, Announce, Delete, Follow, Remove, Undo,
},
actor::{kind::GroupType, ApActor, Endpoints, Group}, actor::{kind::GroupType, ApActor, Endpoints, Group},
base::{AnyBase, BaseExt}, base::{AnyBase, BaseExt},
collection::UnorderedCollection, collection::UnorderedCollection,
@ -107,12 +102,7 @@ impl ToApub for Community {
} }
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> { fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
create_tombstone( create_tombstone(self.deleted, &self.actor_id, self.updated, GroupType::Group)
self.deleted,
&self.actor_id,
self.updated,
GroupType::Group.to_string(),
)
} }
} }
@ -137,13 +127,12 @@ impl ActorType for Community {
pool: &DbPool, pool: &DbPool,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let actor_uri = follow.actor()?.as_single_xsd_any_uri().unwrap().to_string(); let actor_uri = follow.actor()?.as_single_xsd_any_uri().unwrap().to_string();
let id = format!("{}/accept/{}", self.actor_id, uuid::Uuid::new_v4());
let mut accept = Accept::new(self.actor_id.to_owned(), follow.into_any_base()?); let mut accept = Accept::new(self.actor_id.to_owned(), follow.into_any_base()?);
let to = format!("{}/inbox", actor_uri); let to = format!("{}/inbox", actor_uri);
accept accept
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(AcceptType::Accept)?)
.set_to(to.clone()); .set_to(to.clone());
insert_activity(self.creator_id, accept.clone(), true, pool).await?; insert_activity(self.creator_id, accept.clone(), true, pool).await?;
@ -160,12 +149,10 @@ impl ActorType for Community {
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let group = self.to_apub(pool).await?; let group = self.to_apub(pool).await?;
let id = format!("{}/delete/{}", self.actor_id, uuid::Uuid::new_v4());
let mut delete = Delete::new(creator.actor_id.to_owned(), group.into_any_base()?); let mut delete = Delete::new(creator.actor_id.to_owned(), group.into_any_base()?);
delete delete
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()]);
@ -188,22 +175,19 @@ impl ActorType for Community {
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let group = self.to_apub(pool).await?; let group = self.to_apub(pool).await?;
let id = format!("{}/delete/{}", self.actor_id, uuid::Uuid::new_v4());
let mut delete = Delete::new(creator.actor_id.to_owned(), group.into_any_base()?); let mut delete = Delete::new(creator.actor_id.to_owned(), group.into_any_base()?);
delete delete
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()]);
// TODO // TODO
// Undo that fake activity // Undo that fake activity
let undo_id = format!("{}/undo/delete/{}", self.actor_id, uuid::Uuid::new_v4());
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo undo
.set_context(context()) .set_context(context())
.set_id(Url::parse(&undo_id)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()]);
@ -226,12 +210,10 @@ impl ActorType for Community {
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let group = self.to_apub(pool).await?; let group = self.to_apub(pool).await?;
let id = format!("{}/remove/{}", self.actor_id, uuid::Uuid::new_v4());
let mut remove = Remove::new(mod_.actor_id.to_owned(), group.into_any_base()?); let mut remove = Remove::new(mod_.actor_id.to_owned(), group.into_any_base()?);
remove remove
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()]);
@ -254,21 +236,18 @@ impl ActorType for Community {
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let group = self.to_apub(pool).await?; let group = self.to_apub(pool).await?;
let id = format!("{}/remove/{}", self.actor_id, uuid::Uuid::new_v4());
let mut remove = Remove::new(mod_.actor_id.to_owned(), group.into_any_base()?); let mut remove = Remove::new(mod_.actor_id.to_owned(), group.into_any_base()?);
remove remove
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()]);
// Undo that fake activity // Undo that fake activity
let undo_id = format!("{}/undo/remove/{}", self.actor_id, uuid::Uuid::new_v4());
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?); let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
undo undo
.set_context(context()) .set_context(context())
.set_id(Url::parse(&undo_id)?) .set_id(generate_activity_id(LikeType::Like)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![self.get_followers_url()]); .set_many_ccs(vec![self.get_followers_url()]);
@ -435,11 +414,10 @@ pub async fn do_announce(
client: &Client, client: &Client,
pool: &DbPool, pool: &DbPool,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let id = format!("{}/announce/{}", community.actor_id, uuid::Uuid::new_v4());
let mut announce = Announce::new(community.actor_id.to_owned(), activity); let mut announce = Announce::new(community.actor_id.to_owned(), activity);
announce announce
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(AnnounceType::Announce)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);

View File

@ -1,19 +1,12 @@
use crate::{ use crate::{
api::site::SearchResponse, api::site::SearchResponse,
apub::{ apub::{
is_apub_id_valid, is_apub_id_valid, ActorType, FromApub, GroupExt, PageExt, PersonExt, APUB_JSON_CONTENT_TYPE,
ActorType,
FromApub,
GroupExt,
PageExt,
PersonExt,
APUB_JSON_CONTENT_TYPE,
}, },
blocking, blocking,
request::{retry, RecvError}, request::{retry, RecvError},
routes::nodeinfo::{NodeInfo, NodeInfoWellKnown}, routes::nodeinfo::{NodeInfo, NodeInfoWellKnown},
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{base::BaseExt, object::Note, prelude::*}; use activitystreams_new::{base::BaseExt, object::Note, prelude::*};
use actix_web::client::Client; use actix_web::client::Client;
@ -29,9 +22,7 @@ use lemmy_db::{
post_view::PostView, post_view::PostView,
user::{UserForm, User_}, user::{UserForm, User_},
user_view::UserView, user_view::UserView,
Crud, Crud, Joinable, SearchType,
Joinable,
SearchType,
}; };
use lemmy_utils::get_apub_protocol_string; use lemmy_utils::get_apub_protocol_string;
use log::debug; use log::debug;

View File

@ -1,19 +1,13 @@
use crate::{ use crate::{
apub::inbox::{ apub::inbox::{
activities::{ activities::{
create::receive_create, create::receive_create, delete::receive_delete, dislike::receive_dislike, like::receive_like,
delete::receive_delete, remove::receive_remove, undo::receive_undo, update::receive_update,
dislike::receive_dislike,
like::receive_like,
remove::receive_remove,
undo::receive_undo,
update::receive_update,
}, },
shared_inbox::receive_unhandled_activity, shared_inbox::receive_unhandled_activity,
}, },
routes::ChatServerParam, routes::ChatServerParam,
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{activity::*, base::AnyBase, prelude::ExtendsExt}; use activitystreams_new::{activity::*, base::AnyBase, prelude::ExtendsExt};
use actix_web::{client::Client, HttpResponse}; use actix_web::{client::Client, HttpResponse};

View File

@ -5,13 +5,9 @@ use crate::{
}, },
apub::{ apub::{
inbox::shared_inbox::{ inbox::shared_inbox::{
announce_if_community_is_local, announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
get_user_from_activity,
receive_unhandled_activity,
}, },
ActorType, ActorType, FromApub, PageExt,
FromApub,
PageExt,
}, },
blocking, blocking,
routes::ChatServerParam, routes::ChatServerParam,
@ -19,8 +15,7 @@ use crate::{
server::{SendComment, SendPost}, server::{SendComment, SendPost},
UserOperation, UserOperation,
}, },
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{activity::Create, base::AnyBase, object::Note, prelude::*}; use activitystreams_new::{activity::Create, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse}; use actix_web::{client::Client, HttpResponse};

View File

@ -3,14 +3,9 @@ use crate::{
apub::{ apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post}, fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{ inbox::shared_inbox::{
announce_if_community_is_local, announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
get_user_from_activity,
receive_unhandled_activity,
}, },
ActorType, ActorType, FromApub, GroupExt, PageExt,
FromApub,
GroupExt,
PageExt,
}, },
blocking, blocking,
routes::ChatServerParam, routes::ChatServerParam,
@ -18,8 +13,7 @@ use crate::{
server::{SendComment, SendCommunityRoomMessage, SendPost}, server::{SendComment, SendCommunityRoomMessage, SendPost},
UserOperation, UserOperation,
}, },
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{activity::Delete, base::AnyBase, object::Note, prelude::*}; use activitystreams_new::{activity::Delete, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse}; use actix_web::{client::Client, HttpResponse};

View File

@ -3,13 +3,9 @@ use crate::{
apub::{ apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post}, fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{ inbox::shared_inbox::{
announce_if_community_is_local, announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
get_user_from_activity,
receive_unhandled_activity,
}, },
ActorType, ActorType, FromApub, PageExt,
FromApub,
PageExt,
}, },
blocking, blocking,
routes::ChatServerParam, routes::ChatServerParam,
@ -17,8 +13,7 @@ use crate::{
server::{SendComment, SendPost}, server::{SendComment, SendPost},
UserOperation, UserOperation,
}, },
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{activity::Dislike, base::AnyBase, object::Note, prelude::*}; use activitystreams_new::{activity::Dislike, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse}; use actix_web::{client::Client, HttpResponse};

View File

@ -3,13 +3,9 @@ use crate::{
apub::{ apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post}, fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{ inbox::shared_inbox::{
announce_if_community_is_local, announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
get_user_from_activity,
receive_unhandled_activity,
}, },
ActorType, ActorType, FromApub, PageExt,
FromApub,
PageExt,
}, },
blocking, blocking,
routes::ChatServerParam, routes::ChatServerParam,
@ -17,8 +13,7 @@ use crate::{
server::{SendComment, SendPost}, server::{SendComment, SendPost},
UserOperation, UserOperation,
}, },
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{activity::Like, base::AnyBase, object::Note, prelude::*}; use activitystreams_new::{activity::Like, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse}; use actix_web::{client::Client, HttpResponse};

View File

@ -3,14 +3,9 @@ use crate::{
apub::{ apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post}, fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{ inbox::shared_inbox::{
announce_if_community_is_local, announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
get_user_from_activity,
receive_unhandled_activity,
}, },
ActorType, ActorType, FromApub, GroupExt, PageExt,
FromApub,
GroupExt,
PageExt,
}, },
blocking, blocking,
routes::ChatServerParam, routes::ChatServerParam,
@ -18,8 +13,7 @@ use crate::{
server::{SendComment, SendCommunityRoomMessage, SendPost}, server::{SendComment, SendCommunityRoomMessage, SendPost},
UserOperation, UserOperation,
}, },
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{activity::Remove, base::AnyBase, object::Note, prelude::*}; use activitystreams_new::{activity::Remove, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse}; use actix_web::{client::Client, HttpResponse};

View File

@ -3,14 +3,9 @@ use crate::{
apub::{ apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post}, fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{ inbox::shared_inbox::{
announce_if_community_is_local, announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
get_user_from_activity,
receive_unhandled_activity,
}, },
ActorType, ActorType, FromApub, GroupExt, PageExt,
FromApub,
GroupExt,
PageExt,
}, },
blocking, blocking,
routes::ChatServerParam, routes::ChatServerParam,
@ -18,8 +13,7 @@ use crate::{
server::{SendComment, SendCommunityRoomMessage, SendPost}, server::{SendComment, SendCommunityRoomMessage, SendPost},
UserOperation, UserOperation,
}, },
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{activity::*, base::AnyBase, object::Note, prelude::*}; use activitystreams_new::{activity::*, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse}; use actix_web::{client::Client, HttpResponse};
@ -31,8 +25,7 @@ use lemmy_db::{
naive_now, naive_now,
post::{Post, PostForm, PostLike, PostLikeForm}, post::{Post, PostForm, PostLike, PostLikeForm},
post_view::PostView, post_view::PostView,
Crud, Crud, Likeable,
Likeable,
}; };
pub async fn receive_undo( pub async fn receive_undo(

View File

@ -6,13 +6,9 @@ use crate::{
apub::{ apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post}, fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{ inbox::shared_inbox::{
announce_if_community_is_local, announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
get_user_from_activity,
receive_unhandled_activity,
}, },
ActorType, ActorType, FromApub, PageExt,
FromApub,
PageExt,
}, },
blocking, blocking,
routes::ChatServerParam, routes::ChatServerParam,
@ -20,8 +16,7 @@ use crate::{
server::{SendComment, SendPost}, server::{SendComment, SendPost},
UserOperation, UserOperation,
}, },
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{activity::Update, base::AnyBase, object::Note, prelude::*}; use activitystreams_new::{activity::Update, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse}; use actix_web::{client::Client, HttpResponse};

View File

@ -2,8 +2,7 @@ use crate::{
apub::{ apub::{
extensions::signatures::verify, extensions::signatures::verify,
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user}, fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
insert_activity, insert_activity, ActorType,
ActorType,
}, },
blocking, blocking,
routes::{ChatServerParam, DbPoolParam}, routes::{ChatServerParam, DbPoolParam},

View File

@ -3,25 +3,18 @@ use crate::{
community::do_announce, community::do_announce,
extensions::signatures::verify, extensions::signatures::verify,
fetcher::{ fetcher::{
get_or_fetch_and_upsert_remote_actor, get_or_fetch_and_upsert_remote_actor, get_or_fetch_and_upsert_remote_community,
get_or_fetch_and_upsert_remote_community,
get_or_fetch_and_upsert_remote_user, get_or_fetch_and_upsert_remote_user,
}, },
inbox::activities::{ inbox::activities::{
announce::receive_announce, announce::receive_announce, create::receive_create, delete::receive_delete,
create::receive_create, dislike::receive_dislike, like::receive_like, remove::receive_remove, undo::receive_undo,
delete::receive_delete,
dislike::receive_dislike,
like::receive_like,
remove::receive_remove,
undo::receive_undo,
update::receive_update, update::receive_update,
}, },
insert_activity, insert_activity,
}, },
routes::{ChatServerParam, DbPoolParam}, routes::{ChatServerParam, DbPoolParam},
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{ use activitystreams_new::{
activity::{ActorAndObject, ActorAndObjectRef}, activity::{ActorAndObject, ActorAndObjectRef},

View File

@ -3,14 +3,12 @@ use crate::{
apub::{ apub::{
extensions::signatures::verify, extensions::signatures::verify,
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user}, fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
insert_activity, insert_activity, FromApub,
FromApub,
}, },
blocking, blocking,
routes::{ChatServerParam, DbPoolParam}, routes::{ChatServerParam, DbPoolParam},
websocket::{server::SendUserRoomMessage, UserOperation}, websocket::{server::SendUserRoomMessage, UserOperation},
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_new::{ use activitystreams_new::{
activity::{Accept, Create, Delete, Undo, Update}, activity::{Accept, Create, Delete, Undo, Update},
@ -24,8 +22,7 @@ use lemmy_db::{
private_message::{PrivateMessage, PrivateMessageForm}, private_message::{PrivateMessage, PrivateMessageForm},
private_message_view::PrivateMessageView, private_message_view::PrivateMessageView,
user::User_, user::User_,
Crud, Crud, Followable,
Followable,
}; };
use log::debug; use log::debug;
use serde::Deserialize; use serde::Deserialize;

View File

@ -17,8 +17,7 @@ use crate::{
blocking, blocking,
request::{retry, RecvError}, request::{retry, RecvError},
routes::webfinger::WebFingerResponse, routes::webfinger::WebFingerResponse,
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_ext::{Ext1, Ext2}; use activitystreams_ext::{Ext1, Ext2};
use activitystreams_new::{ use activitystreams_new::{
@ -101,17 +100,20 @@ pub trait ToApub {
} }
/// Updated is actually the deletion time /// Updated is actually the deletion time
fn create_tombstone( fn create_tombstone<T>(
deleted: bool, deleted: bool,
object_id: &str, object_id: &str,
updated: Option<NaiveDateTime>, updated: Option<NaiveDateTime>,
former_type: String, former_type: T,
) -> Result<Tombstone, LemmyError> { ) -> Result<Tombstone, LemmyError>
where
T: ToString,
{
if deleted { if deleted {
if let Some(updated) = updated { if let Some(updated) = updated {
let mut tombstone = Tombstone::new(); let mut tombstone = Tombstone::new();
tombstone.set_id(object_id.parse()?); tombstone.set_id(object_id.parse()?);
tombstone.set_former_type(former_type); tombstone.set_former_type(former_type.to_string());
tombstone.set_deleted(convert_datetime(updated)); tombstone.set_deleted(convert_datetime(updated));
Ok(tombstone) Ok(tombstone)
} else { } else {

View File

@ -1,26 +1,21 @@
use crate::{ use crate::{
apub::{ apub::{
activities::send_activity_to_community, activities::{generate_activity_id, send_activity_to_community},
create_apub_response, create_apub_response, create_apub_tombstone_response, create_tombstone,
create_apub_tombstone_response,
create_tombstone,
extensions::page_extension::PageExtension, extensions::page_extension::PageExtension,
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user}, fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
ActorType, ActorType, ApubLikeableType, ApubObjectType, FromApub, PageExt, ToApub,
ApubLikeableType,
ApubObjectType,
FromApub,
PageExt,
ToApub,
}, },
blocking, blocking,
routes::DbPoolParam, routes::DbPoolParam,
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_ext::Ext1; use activitystreams_ext::Ext1;
use activitystreams_new::{ use activitystreams_new::{
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update}, activity::{
kind::{CreateType, DeleteType, DislikeType, LikeType, RemoveType, UndoType, UpdateType},
Create, Delete, Dislike, Like, Remove, Undo, Update,
},
context, context,
object::{kind::PageType, Image, Page, Tombstone}, object::{kind::PageType, Image, Page, Tombstone},
prelude::*, prelude::*,
@ -139,12 +134,7 @@ impl ToApub for Post {
} }
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> { fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
create_tombstone( create_tombstone(self.deleted, &self.ap_id, self.updated, PageType::Page)
self.deleted,
&self.ap_id,
self.updated,
PageType::Page.to_string(),
)
} }
} }
@ -274,12 +264,10 @@ impl ApubObjectType for Post {
let community_id = self.community_id; let community_id = self.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
let id = format!("{}/create/{}", self.ap_id, uuid::Uuid::new_v4());
let mut create = Create::new(creator.actor_id.to_owned(), page.into_any_base()?); let mut create = Create::new(creator.actor_id.to_owned(), page.into_any_base()?);
create create
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(CreateType::Create)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -307,12 +295,10 @@ impl ApubObjectType for Post {
let community_id = self.community_id; let community_id = self.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
let id = format!("{}/update/{}", self.ap_id, uuid::Uuid::new_v4());
let mut update = Update::new(creator.actor_id.to_owned(), page.into_any_base()?); let mut update = Update::new(creator.actor_id.to_owned(), page.into_any_base()?);
update update
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -339,11 +325,10 @@ impl ApubObjectType for Post {
let community_id = self.community_id; let community_id = self.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; 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::new(creator.actor_id.to_owned(), page.into_any_base()?); let mut delete = Delete::new(creator.actor_id.to_owned(), page.into_any_base()?);
delete delete
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -370,21 +355,18 @@ impl ApubObjectType for Post {
let community_id = self.community_id; let community_id = self.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; 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::new(creator.actor_id.to_owned(), page.into_any_base()?); let mut delete = Delete::new(creator.actor_id.to_owned(), page.into_any_base()?);
delete delete
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
// TODO
// Undo that fake activity // Undo that fake activity
let undo_id = format!("{}/undo/delete/{}", self.ap_id, uuid::Uuid::new_v4());
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo undo
.set_context(context()) .set_context(context())
.set_id(Url::parse(&undo_id)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -411,11 +393,10 @@ impl ApubObjectType for Post {
let community_id = self.community_id; let community_id = self.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; 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::new(mod_.actor_id.to_owned(), page.into_any_base()?); let mut remove = Remove::new(mod_.actor_id.to_owned(), page.into_any_base()?);
remove remove
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -442,20 +423,18 @@ impl ApubObjectType for Post {
let community_id = self.community_id; let community_id = self.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; 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::new(mod_.actor_id.to_owned(), page.into_any_base()?); let mut remove = Remove::new(mod_.actor_id.to_owned(), page.into_any_base()?);
remove remove
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
// Undo that fake activity // Undo that fake activity
let undo_id = format!("{}/undo/remove/{}", self.ap_id, uuid::Uuid::new_v4());
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?); let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
undo undo
.set_context(context()) .set_context(context())
.set_id(Url::parse(&undo_id)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -485,12 +464,10 @@ impl ApubLikeableType for Post {
let community_id = self.community_id; let community_id = self.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
let id = format!("{}/like/{}", self.ap_id, uuid::Uuid::new_v4());
let mut like = Like::new(creator.actor_id.to_owned(), page.into_any_base()?); let mut like = Like::new(creator.actor_id.to_owned(), page.into_any_base()?);
like like
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(LikeType::Like)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -517,12 +494,10 @@ impl ApubLikeableType for Post {
let community_id = self.community_id; let community_id = self.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4());
let mut dislike = Dislike::new(creator.actor_id.to_owned(), page.into_any_base()?); let mut dislike = Dislike::new(creator.actor_id.to_owned(), page.into_any_base()?);
dislike dislike
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
@ -549,22 +524,18 @@ impl ApubLikeableType for Post {
let community_id = self.community_id; let community_id = self.community_id;
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??; let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
let id = format!("{}/like/{}", self.ap_id, uuid::Uuid::new_v4());
let mut like = Like::new(creator.actor_id.to_owned(), page.into_any_base()?); let mut like = Like::new(creator.actor_id.to_owned(), page.into_any_base()?);
like like
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(LikeType::Like)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);
// TODO
// Undo that fake activity // Undo that fake activity
let undo_id = format!("{}/undo/like/{}", self.ap_id, uuid::Uuid::new_v4());
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
undo undo
.set_context(context()) .set_context(context())
.set_id(Url::parse(&undo_id)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public()) .set_to(public())
.set_many_ccs(vec![community.get_followers_url()]); .set_many_ccs(vec![community.get_followers_url()]);

View File

@ -1,19 +1,17 @@
use crate::{ use crate::{
apub::{ apub::{
activities::send_activity, activities::{generate_activity_id, send_activity},
create_tombstone, create_tombstone,
fetcher::get_or_fetch_and_upsert_remote_user, fetcher::get_or_fetch_and_upsert_remote_user,
insert_activity, insert_activity, ApubObjectType, FromApub, ToApub,
ApubObjectType,
FromApub,
ToApub,
}, },
blocking, blocking, DbPool, LemmyError,
DbPool,
LemmyError,
}; };
use activitystreams_new::{ use activitystreams_new::{
activity::{Create, Delete, Undo, Update}, activity::{
kind::{CreateType, DeleteType, UndoType, UpdateType},
Create, Delete, Undo, Update,
},
context, context,
object::{kind::NoteType, Note, Tombstone}, object::{kind::NoteType, Note, Tombstone},
prelude::*, prelude::*,
@ -56,12 +54,7 @@ impl ToApub for PrivateMessage {
} }
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> { fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
create_tombstone( create_tombstone(self.deleted, &self.ap_id, self.updated, NoteType::Note)
self.deleted,
&self.ap_id,
self.updated,
NoteType::Note.to_string(),
)
} }
} }
@ -118,7 +111,6 @@ impl ApubObjectType for PrivateMessage {
pool: &DbPool, pool: &DbPool,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let note = self.to_apub(pool).await?; let note = self.to_apub(pool).await?;
let id = format!("{}/create/{}", self.ap_id, uuid::Uuid::new_v4());
let recipient_id = self.recipient_id; let recipient_id = self.recipient_id;
let recipient = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??; let recipient = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??;
@ -127,7 +119,7 @@ impl ApubObjectType for PrivateMessage {
let to = format!("{}/inbox", recipient.actor_id); let to = format!("{}/inbox", recipient.actor_id);
create create
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(CreateType::Create)?)
.set_to(to.clone()); .set_to(to.clone());
insert_activity(creator.id, create.clone(), true, pool).await?; insert_activity(creator.id, create.clone(), true, pool).await?;
@ -144,7 +136,6 @@ impl ApubObjectType for PrivateMessage {
pool: &DbPool, pool: &DbPool,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let note = self.to_apub(pool).await?; let note = self.to_apub(pool).await?;
let id = format!("{}/update/{}", self.ap_id, uuid::Uuid::new_v4());
let recipient_id = self.recipient_id; let recipient_id = self.recipient_id;
let recipient = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??; let recipient = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??;
@ -153,7 +144,7 @@ impl ApubObjectType for PrivateMessage {
let to = format!("{}/inbox", recipient.actor_id); let to = format!("{}/inbox", recipient.actor_id);
update update
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(UpdateType::Update)?)
.set_to(to.clone()); .set_to(to.clone());
insert_activity(creator.id, update.clone(), true, pool).await?; insert_activity(creator.id, update.clone(), true, pool).await?;
@ -169,7 +160,6 @@ impl ApubObjectType for PrivateMessage {
pool: &DbPool, pool: &DbPool,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let note = self.to_apub(pool).await?; let note = self.to_apub(pool).await?;
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
let recipient_id = self.recipient_id; let recipient_id = self.recipient_id;
let recipient = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??; let recipient = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??;
@ -178,7 +168,7 @@ impl ApubObjectType for PrivateMessage {
let to = format!("{}/inbox", recipient.actor_id); let to = format!("{}/inbox", recipient.actor_id);
delete delete
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(to.clone()); .set_to(to.clone());
insert_activity(creator.id, delete.clone(), true, pool).await?; insert_activity(creator.id, delete.clone(), true, pool).await?;
@ -194,7 +184,6 @@ impl ApubObjectType for PrivateMessage {
pool: &DbPool, pool: &DbPool,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let note = self.to_apub(pool).await?; let note = self.to_apub(pool).await?;
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
let recipient_id = self.recipient_id; let recipient_id = self.recipient_id;
let recipient = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??; let recipient = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??;
@ -203,16 +192,14 @@ impl ApubObjectType for PrivateMessage {
let to = format!("{}/inbox", recipient.actor_id); let to = format!("{}/inbox", recipient.actor_id);
delete delete
.set_context(context()) .set_context(context())
.set_id(Url::parse(&id)?) .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(to.clone()); .set_to(to.clone());
// TODO
// Undo that fake activity // Undo that fake activity
let undo_id = format!("{}/undo/delete/{}", self.ap_id, uuid::Uuid::new_v4());
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?); let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo undo
.set_context(context()) .set_context(context())
.set_id(Url::parse(&undo_id)?) .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(to.clone()); .set_to(to.clone());
insert_activity(creator.id, undo.clone(), true, pool).await?; insert_activity(creator.id, undo.clone(), true, pool).await?;

View File

@ -1,21 +1,18 @@
use crate::{ use crate::{
apub::{ apub::{
activities::send_activity, activities::{generate_activity_id, send_activity},
create_apub_response, create_apub_response, insert_activity, ActorType, FromApub, PersonExt, ToApub,
insert_activity,
ActorType,
FromApub,
PersonExt,
ToApub,
}, },
blocking, blocking,
routes::DbPoolParam, routes::DbPoolParam,
DbPool, DbPool, LemmyError,
LemmyError,
}; };
use activitystreams_ext::Ext1; use activitystreams_ext::Ext1;
use activitystreams_new::{ use activitystreams_new::{
activity::{Follow, Undo}, activity::{
kind::{FollowType, UndoType},
Follow, Undo,
},
actor::{ApActor, Endpoints, Person}, actor::{ApActor, Endpoints, Person},
context, context,
object::{Image, Tombstone}, object::{Image, Tombstone},
@ -102,9 +99,10 @@ impl ActorType for User_ {
client: &Client, client: &Client,
pool: &DbPool, pool: &DbPool,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let id = format!("{}/follow/{}", self.actor_id, uuid::Uuid::new_v4());
let mut follow = Follow::new(self.actor_id.to_owned(), follow_actor_id); let mut follow = Follow::new(self.actor_id.to_owned(), follow_actor_id);
follow.set_context(context()).set_id(id.parse()?); follow
.set_context(context())
.set_id(generate_activity_id(FollowType::Follow)?);
let to = format!("{}/inbox", follow_actor_id); let to = format!("{}/inbox", follow_actor_id);
insert_activity(self.id, follow.clone(), true, pool).await?; insert_activity(self.id, follow.clone(), true, pool).await?;
@ -119,17 +117,18 @@ impl ActorType for User_ {
client: &Client, client: &Client,
pool: &DbPool, pool: &DbPool,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let id = format!("{}/follow/{}", self.actor_id, uuid::Uuid::new_v4());
let mut follow = Follow::new(self.actor_id.to_owned(), follow_actor_id); let mut follow = Follow::new(self.actor_id.to_owned(), follow_actor_id);
follow.set_context(context()).set_id(id.parse()?); follow
.set_context(context())
.set_id(generate_activity_id(FollowType::Follow)?);
let to = format!("{}/inbox", follow_actor_id); let to = format!("{}/inbox", follow_actor_id);
// TODO
// Undo that fake activity // Undo that fake activity
let undo_id = format!("{}/undo/follow/{}", self.actor_id, uuid::Uuid::new_v4());
let mut undo = Undo::new(Url::parse(&self.actor_id)?, follow.into_any_base()?); let mut undo = Undo::new(Url::parse(&self.actor_id)?, follow.into_any_base()?);
undo.set_context(context()).set_id(undo_id.parse()?); undo
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?);
insert_activity(self.id, undo.clone(), true, pool).await?; insert_activity(self.id, undo.clone(), true, pool).await?;