use crate::{
apub::{
- community::do_announce,
- extensions::signatures::sign,
- insert_activity,
- is_apub_id_valid,
+ community::do_announce, extensions::signatures::sign, insert_activity, is_apub_id_valid,
ActorType,
},
request::retry_custom,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::base::AnyBase;
use actix_web::client::Client;
use lemmy_db::{community::Community, user::User_};
+use lemmy_utils::{get_apub_protocol_string, settings::Settings};
use log::debug;
-use url::Url;
+use url::{ParseError, Url};
+use uuid::Uuid;
pub async fn send_activity_to_community(
creator: &User_,
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)
+}
use crate::{
apub::{
- activities::send_activity_to_community,
- create_apub_response,
- create_apub_tombstone_response,
- create_tombstone,
- fetch_webfinger_url,
+ activities::{generate_activity_id, send_activity_to_community},
+ create_apub_response, create_apub_tombstone_response, create_tombstone, fetch_webfinger_url,
fetcher::{
- get_or_fetch_and_insert_remote_comment,
- get_or_fetch_and_insert_remote_post,
+ get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post,
get_or_fetch_and_upsert_remote_user,
},
- ActorType,
- ApubLikeableType,
- ApubObjectType,
- FromApub,
- ToApub,
+ ActorType, ApubLikeableType, ApubObjectType, FromApub, ToApub,
},
blocking,
routes::DbPoolParam,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
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,
context,
link::Mention,
}
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- create_tombstone(
- self.deleted,
- &self.ap_id,
- self.updated,
- NoteType::Note.to_string(),
- )
+ create_tombstone(self.deleted, &self.ap_id, self.updated, NoteType::Note)
}
}
let maa =
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()?);
create
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(CreateType::Create)?)
.set_to(public())
.set_many_ccs(maa.addressed_ccs.to_owned())
// Set the mention tags
let maa =
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()?);
update
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public())
.set_many_ccs(maa.addressed_ccs.to_owned())
// Set the mention tags
let community_id = post.community_id;
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()?);
delete
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
// 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()?);
delete
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(DeleteType::Delete)?)
.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::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo
.set_context(context())
- .set_id(Url::parse(&undo_id)?)
+ .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = post.community_id;
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()?);
remove
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
// 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()?);
remove
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(RemoveType::Remove)?)
.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::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
undo
.set_context(context())
- .set_id(Url::parse(&undo_id)?)
+ .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = post.community_id;
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()?);
like
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = post.community_id;
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()?);
dislike
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = post.community_id;
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()?);
like
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(DislikeType::Dislike)?)
.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::new(creator.actor_id.to_owned(), like.into_any_base()?);
undo
.set_context(context())
- .set_id(Url::parse(&undo_id)?)
+ .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
use crate::{
apub::{
- activities::send_activity,
- create_apub_response,
- create_apub_tombstone_response,
- create_tombstone,
+ activities::{generate_activity_id, send_activity},
+ create_apub_response, create_apub_tombstone_response, create_tombstone,
extensions::group_extensions::GroupExtension,
fetcher::get_or_fetch_and_upsert_remote_user,
- get_shared_inbox,
- insert_activity,
- ActorType,
- FromApub,
- GroupExt,
- ToApub,
+ get_shared_inbox, insert_activity, ActorType, FromApub, GroupExt, ToApub,
},
blocking,
routes::DbPoolParam,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_ext::Ext2;
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},
base::{AnyBase, BaseExt},
collection::UnorderedCollection,
}
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- create_tombstone(
- self.deleted,
- &self.actor_id,
- self.updated,
- GroupType::Group.to_string(),
- )
+ create_tombstone(self.deleted, &self.actor_id, self.updated, GroupType::Group)
}
}
pool: &DbPool,
) -> Result<(), LemmyError> {
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 to = format!("{}/inbox", actor_uri);
accept
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(AcceptType::Accept)?)
.set_to(to.clone());
insert_activity(self.creator_id, accept.clone(), true, pool).await?;
) -> Result<(), LemmyError> {
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()?);
delete
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
) -> Result<(), LemmyError> {
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()?);
delete
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
// TODO
// 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()?);
undo
.set_context(context())
- .set_id(Url::parse(&undo_id)?)
+ .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
) -> Result<(), LemmyError> {
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()?);
remove
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
) -> Result<(), LemmyError> {
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()?);
remove
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
// 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()?);
undo
.set_context(context())
- .set_id(Url::parse(&undo_id)?)
+ .set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
client: &Client,
pool: &DbPool,
) -> Result<(), LemmyError> {
- let id = format!("{}/announce/{}", community.actor_id, uuid::Uuid::new_v4());
let mut announce = Announce::new(community.actor_id.to_owned(), activity);
announce
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(AnnounceType::Announce)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
use crate::{
api::site::SearchResponse,
apub::{
- is_apub_id_valid,
- ActorType,
- FromApub,
- GroupExt,
- PageExt,
- PersonExt,
- APUB_JSON_CONTENT_TYPE,
+ is_apub_id_valid, ActorType, FromApub, GroupExt, PageExt, PersonExt, APUB_JSON_CONTENT_TYPE,
},
blocking,
request::{retry, RecvError},
routes::nodeinfo::{NodeInfo, NodeInfoWellKnown},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::{base::BaseExt, object::Note, prelude::*};
use actix_web::client::Client;
post_view::PostView,
user::{UserForm, User_},
user_view::UserView,
- Crud,
- Joinable,
- SearchType,
+ Crud, Joinable, SearchType,
};
use lemmy_utils::get_apub_protocol_string;
use log::debug;
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,
+ create::receive_create, delete::receive_delete, dislike::receive_dislike, like::receive_like,
+ remove::receive_remove, undo::receive_undo, update::receive_update,
},
shared_inbox::receive_unhandled_activity,
},
routes::ChatServerParam,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::{activity::*, base::AnyBase, prelude::ExtendsExt};
use actix_web::{client::Client, HttpResponse};
},
apub::{
inbox::shared_inbox::{
- announce_if_community_is_local,
- get_user_from_activity,
- receive_unhandled_activity,
+ announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
},
- ActorType,
- FromApub,
- PageExt,
+ ActorType, FromApub, PageExt,
},
blocking,
routes::ChatServerParam,
server::{SendComment, SendPost},
UserOperation,
},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::{activity::Create, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse};
apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{
- announce_if_community_is_local,
- get_user_from_activity,
- receive_unhandled_activity,
+ announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
},
- ActorType,
- FromApub,
- GroupExt,
- PageExt,
+ ActorType, FromApub, GroupExt, PageExt,
},
blocking,
routes::ChatServerParam,
server::{SendComment, SendCommunityRoomMessage, SendPost},
UserOperation,
},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::{activity::Delete, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse};
apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{
- announce_if_community_is_local,
- get_user_from_activity,
- receive_unhandled_activity,
+ announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
},
- ActorType,
- FromApub,
- PageExt,
+ ActorType, FromApub, PageExt,
},
blocking,
routes::ChatServerParam,
server::{SendComment, SendPost},
UserOperation,
},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::{activity::Dislike, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse};
apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{
- announce_if_community_is_local,
- get_user_from_activity,
- receive_unhandled_activity,
+ announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
},
- ActorType,
- FromApub,
- PageExt,
+ ActorType, FromApub, PageExt,
},
blocking,
routes::ChatServerParam,
server::{SendComment, SendPost},
UserOperation,
},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::{activity::Like, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse};
apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{
- announce_if_community_is_local,
- get_user_from_activity,
- receive_unhandled_activity,
+ announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
},
- ActorType,
- FromApub,
- GroupExt,
- PageExt,
+ ActorType, FromApub, GroupExt, PageExt,
},
blocking,
routes::ChatServerParam,
server::{SendComment, SendCommunityRoomMessage, SendPost},
UserOperation,
},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::{activity::Remove, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse};
apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{
- announce_if_community_is_local,
- get_user_from_activity,
- receive_unhandled_activity,
+ announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
},
- ActorType,
- FromApub,
- GroupExt,
- PageExt,
+ ActorType, FromApub, GroupExt, PageExt,
},
blocking,
routes::ChatServerParam,
server::{SendComment, SendCommunityRoomMessage, SendPost},
UserOperation,
},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::{activity::*, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse};
naive_now,
post::{Post, PostForm, PostLike, PostLikeForm},
post_view::PostView,
- Crud,
- Likeable,
+ Crud, Likeable,
};
pub async fn receive_undo(
apub::{
fetcher::{get_or_fetch_and_insert_remote_comment, get_or_fetch_and_insert_remote_post},
inbox::shared_inbox::{
- announce_if_community_is_local,
- get_user_from_activity,
- receive_unhandled_activity,
+ announce_if_community_is_local, get_user_from_activity, receive_unhandled_activity,
},
- ActorType,
- FromApub,
- PageExt,
+ ActorType, FromApub, PageExt,
},
blocking,
routes::ChatServerParam,
server::{SendComment, SendPost},
UserOperation,
},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::{activity::Update, base::AnyBase, object::Note, prelude::*};
use actix_web::{client::Client, HttpResponse};
apub::{
extensions::signatures::verify,
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
- insert_activity,
- ActorType,
+ insert_activity, ActorType,
},
blocking,
routes::{ChatServerParam, DbPoolParam},
community::do_announce,
extensions::signatures::verify,
fetcher::{
- get_or_fetch_and_upsert_remote_actor,
- get_or_fetch_and_upsert_remote_community,
+ get_or_fetch_and_upsert_remote_actor, get_or_fetch_and_upsert_remote_community,
get_or_fetch_and_upsert_remote_user,
},
inbox::activities::{
- announce::receive_announce,
- create::receive_create,
- delete::receive_delete,
- dislike::receive_dislike,
- like::receive_like,
- remove::receive_remove,
- undo::receive_undo,
+ announce::receive_announce, create::receive_create, delete::receive_delete,
+ dislike::receive_dislike, like::receive_like, remove::receive_remove, undo::receive_undo,
update::receive_update,
},
insert_activity,
},
routes::{ChatServerParam, DbPoolParam},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::{
activity::{ActorAndObject, ActorAndObjectRef},
apub::{
extensions::signatures::verify,
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
- insert_activity,
- FromApub,
+ insert_activity, FromApub,
},
blocking,
routes::{ChatServerParam, DbPoolParam},
websocket::{server::SendUserRoomMessage, UserOperation},
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_new::{
activity::{Accept, Create, Delete, Undo, Update},
private_message::{PrivateMessage, PrivateMessageForm},
private_message_view::PrivateMessageView,
user::User_,
- Crud,
- Followable,
+ Crud, Followable,
};
use log::debug;
use serde::Deserialize;
blocking,
request::{retry, RecvError},
routes::webfinger::WebFingerResponse,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_ext::{Ext1, Ext2};
use activitystreams_new::{
}
/// Updated is actually the deletion time
-fn create_tombstone(
+fn create_tombstone<T>(
deleted: bool,
object_id: &str,
updated: Option<NaiveDateTime>,
- former_type: String,
-) -> Result<Tombstone, LemmyError> {
+ former_type: T,
+) -> Result<Tombstone, LemmyError>
+where
+ T: ToString,
+{
if deleted {
if let Some(updated) = updated {
let mut tombstone = Tombstone::new();
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));
Ok(tombstone)
} else {
use crate::{
apub::{
- activities::send_activity_to_community,
- create_apub_response,
- create_apub_tombstone_response,
- create_tombstone,
+ activities::{generate_activity_id, 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},
- ActorType,
- ApubLikeableType,
- ApubObjectType,
- FromApub,
- PageExt,
- ToApub,
+ ActorType, ApubLikeableType, ApubObjectType, FromApub, PageExt, ToApub,
},
blocking,
routes::DbPoolParam,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_ext::Ext1;
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,
object::{kind::PageType, Image, Page, Tombstone},
prelude::*,
}
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- create_tombstone(
- self.deleted,
- &self.ap_id,
- self.updated,
- PageType::Page.to_string(),
- )
+ create_tombstone(self.deleted, &self.ap_id, self.updated, PageType::Page)
}
}
let community_id = self.community_id;
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()?);
create
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(CreateType::Create)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = self.community_id;
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()?);
update
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = self.community_id;
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()?);
delete
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = self.community_id;
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()?);
delete
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(DeleteType::Delete)?)
.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::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo
.set_context(context())
- .set_id(Url::parse(&undo_id)?)
+ .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = self.community_id;
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()?);
remove
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = self.community_id;
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()?);
remove
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(RemoveType::Remove)?)
.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::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
undo
.set_context(context())
- .set_id(Url::parse(&undo_id)?)
+ .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = self.community_id;
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()?);
like
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = self.community_id;
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()?);
dislike
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
let community_id = self.community_id;
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()?);
like
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(LikeType::Like)?)
.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::new(creator.actor_id.to_owned(), like.into_any_base()?);
undo
.set_context(context())
- .set_id(Url::parse(&undo_id)?)
+ .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
use crate::{
apub::{
- activities::send_activity,
+ activities::{generate_activity_id, send_activity},
create_tombstone,
fetcher::get_or_fetch_and_upsert_remote_user,
- insert_activity,
- ApubObjectType,
- FromApub,
- ToApub,
+ insert_activity, ApubObjectType, FromApub, ToApub,
},
- blocking,
- DbPool,
- LemmyError,
+ blocking, DbPool, LemmyError,
};
use activitystreams_new::{
- activity::{Create, Delete, Undo, Update},
+ activity::{
+ kind::{CreateType, DeleteType, UndoType, UpdateType},
+ Create, Delete, Undo, Update,
+ },
context,
object::{kind::NoteType, Note, Tombstone},
prelude::*,
}
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- create_tombstone(
- self.deleted,
- &self.ap_id,
- self.updated,
- NoteType::Note.to_string(),
- )
+ create_tombstone(self.deleted, &self.ap_id, self.updated, NoteType::Note)
}
}
pool: &DbPool,
) -> Result<(), LemmyError> {
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 = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??;
let to = format!("{}/inbox", recipient.actor_id);
create
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(CreateType::Create)?)
.set_to(to.clone());
insert_activity(creator.id, create.clone(), true, pool).await?;
pool: &DbPool,
) -> Result<(), LemmyError> {
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 = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??;
let to = format!("{}/inbox", recipient.actor_id);
update
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(UpdateType::Update)?)
.set_to(to.clone());
insert_activity(creator.id, update.clone(), true, pool).await?;
pool: &DbPool,
) -> Result<(), LemmyError> {
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 = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??;
let to = format!("{}/inbox", recipient.actor_id);
delete
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(to.clone());
insert_activity(creator.id, delete.clone(), true, pool).await?;
pool: &DbPool,
) -> Result<(), LemmyError> {
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 = blocking(pool, move |conn| User_::read(conn, recipient_id)).await??;
let to = format!("{}/inbox", recipient.actor_id);
delete
.set_context(context())
- .set_id(Url::parse(&id)?)
+ .set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(to.clone());
- // TODO
// 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()?);
undo
.set_context(context())
- .set_id(Url::parse(&undo_id)?)
+ .set_id(generate_activity_id(UndoType::Undo)?)
.set_to(to.clone());
insert_activity(creator.id, undo.clone(), true, pool).await?;
use crate::{
apub::{
- activities::send_activity,
- create_apub_response,
- insert_activity,
- ActorType,
- FromApub,
- PersonExt,
- ToApub,
+ activities::{generate_activity_id, send_activity},
+ create_apub_response, insert_activity, ActorType, FromApub, PersonExt, ToApub,
},
blocking,
routes::DbPoolParam,
- DbPool,
- LemmyError,
+ DbPool, LemmyError,
};
use activitystreams_ext::Ext1;
use activitystreams_new::{
- activity::{Follow, Undo},
+ activity::{
+ kind::{FollowType, UndoType},
+ Follow, Undo,
+ },
actor::{ApActor, Endpoints, Person},
context,
object::{Image, Tombstone},
client: &Client,
pool: &DbPool,
) -> 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);
- 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);
insert_activity(self.id, follow.clone(), true, pool).await?;
client: &Client,
pool: &DbPool,
) -> 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);
- 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);
- // TODO
// 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()?);
- 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?;