cc: vec![community.followers_url()],
kind: AnnounceType::Announce,
common: ActivityCommonFields {
- context: lemmy_context()?.into(),
+ context: lemmy_context(),
id: generate_activity_id(AnnounceType::Announce)?,
actor: community.actor_id(),
unparsed: Default::default(),
cc: [community.actor_id()],
r#type: Default::default(),
common: ActivityCommonFields {
- context: lemmy_context()?.into(),
+ context: lemmy_context(),
id: id.clone(),
actor: actor.actor_id(),
unparsed: Default::default(),
cc: [community.actor_id()],
r#type: Default::default(),
common: ActivityCommonFields {
- context: lemmy_context()?.into(),
+ context: lemmy_context(),
id: id.clone(),
actor: actor.actor_id(),
unparsed: Default::default(),
note.into_any_base()?,
);
create
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(CreateType::Create)?)
.set_to(public())
.set_many_ccs(maa.ccs.to_owned())
note.into_any_base()?,
);
update
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public())
.set_many_ccs(maa.ccs.to_owned())
self.ap_id.to_owned().into_inner(),
);
delete
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
delete
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
delete.into_any_base()?,
);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
remove
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
remove
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
remove.into_any_base()?,
);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
like
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
dislike
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
like
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
like.into_any_base()?,
);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
follow.into_any_base()?,
);
accept
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(AcceptType::Accept)?)
.set_to(person.actor_id());
self.to_apub(context.pool()).await?.into_any_base()?,
);
update
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public())
.set_many_ccs(vec![self.actor_id()]);
if self.local {
let mut delete = Delete::new(self.actor_id(), self.actor_id());
delete
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![self.followers_url()]);
else {
let mut delete = Delete::new(mod_.actor_id(), self.actor_id());
delete
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![self.actor_id()]);
if self.local {
let mut delete = Delete::new(self.actor_id(), self.actor_id());
delete
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![self.followers_url()]);
let mut undo = Undo::new(self.actor_id(), delete.into_any_base()?);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![self.followers_url()]);
else {
let mut delete = Delete::new(mod_.actor_id(), self.actor_id());
delete
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![self.actor_id()]);
let mut undo = Undo::new(mod_.actor_id(), delete.into_any_base()?);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![self.actor_id()]);
async fn send_remove(&self, context: &LemmyContext) -> Result<(), LemmyError> {
let mut remove = Remove::new(self.actor_id(), self.actor_id());
remove
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![self.followers_url()]);
async fn send_undo_remove(&self, context: &LemmyContext) -> Result<(), LemmyError> {
let mut remove = Remove::new(self.actor_id(), self.actor_id());
remove
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![self.followers_url()]);
// Undo that fake activity
let mut undo = Undo::new(self.actor_id(), remove.into_any_base()?);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![self.followers_url()]);
}
let mut announce = Announce::new(self.actor_id(), activity);
announce
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(AnnounceType::Announce)?)
.set_to(public())
.set_many_ccs(ccs);
) -> Result<(), LemmyError> {
let mut add = Add::new(actor.actor_id(), added_mod.actor_id());
add
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(AddType::Add)?)
.set_to(public())
.set_many_ccs(vec![self.actor_id()])
) -> Result<(), LemmyError> {
let mut remove = Remove::new(actor.actor_id(), removed_mod.actor_id());
remove
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![self.actor_id()])
) -> Result<(), LemmyError> {
let mut block = Block::new(actor.actor_id(), blocked_user.actor_id());
block
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(BlockType::Block)?)
.set_to(public())
.set_many_ccs(vec![self.actor_id()]);
) -> Result<(), LemmyError> {
let mut block = Block::new(actor.actor_id(), unblocked_user.actor_id());
block
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(BlockType::Block)?)
.set_to(public())
.set_many_ccs(vec![self.actor_id()]);
// Undo that fake activity
let mut undo = Undo::new(actor.actor_id(), block.into_any_base()?);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![self.actor_id()]);
let mut follow = Follow::new(self.actor_id(), community.actor_id());
follow
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(FollowType::Follow)?)
.set_to(community.actor_id());
let mut follow = Follow::new(self.actor_id(), community.actor_id());
follow
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(FollowType::Follow)?)
.set_to(community.actor_id());
follow.into_any_base()?,
);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(community.actor_id());
self.ap_id.to_owned().into_inner(),
);
delete
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
delete
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
delete.into_any_base()?,
);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
remove
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
remove
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
remove.into_any_base()?,
);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
like
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
dislike
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
self.ap_id.to_owned().into_inner(),
);
like
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
like.into_any_base()?,
);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.actor_id()]);
);
create
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(CreateType::Create)?)
.set_to(recipient.actor_id());
note.into_any_base()?,
);
update
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UpdateType::Update)?)
.set_to(recipient.actor_id());
self.ap_id.to_owned().into_inner(),
);
delete
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(recipient.actor_id());
self.ap_id.to_owned().into_inner(),
);
delete
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(recipient.actor_id());
delete.into_any_base()?,
);
undo
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(recipient.actor_id());
-use activitystreams::{base::AnyBase, context};
-use lemmy_utils::LemmyError;
+use activitystreams::{base::AnyBase, context, primitives::OneOrMany};
use serde_json::json;
use url::Url;
-pub fn lemmy_context() -> Result<Vec<AnyBase>, LemmyError> {
+pub fn lemmy_context() -> OneOrMany<AnyBase> {
let context_ext = AnyBase::from_arbitrary_json(json!(
{
"sc": "http://schema.org#",
"type": "sc:Text",
"id": "as:alsoKnownAs"
},
- }))?;
- Ok(vec![
+ }))
+ .expect("parse context");
+ OneOrMany::from(vec![
AnyBase::from(context()),
context_ext,
- AnyBase::from(Url::parse("https://w3id.org/security/v1")?),
+ AnyBase::from(Url::parse("https://w3id.org/security/v1").expect("parse context")),
])
}
let mut collection = UnorderedCollection::new();
collection
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(community.followers_url.into())
.set_total_items(community_followers.len() as u64);
Ok(create_apub_response(&collection))
let mut collection = OrderedCollection::new();
collection
.set_many_items(activities)
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(community.get_outbox_url()?)
.set_total_items(len as u64);
Ok(create_apub_response(&collection))
let mut collection = OrderedCollection::new();
collection
.set_id(community.inbox_url.into())
- .set_many_contexts(lemmy_context()?);
+ .set_many_contexts(lemmy_context());
Ok(create_apub_response(&collection))
}
.set_id(generate_moderators_url(&community.actor_id)?.into())
.set_total_items(moderators.len() as u64)
.set_many_items(moderators)
- .set_many_contexts(lemmy_context()?);
+ .set_many_contexts(lemmy_context());
Ok(create_apub_response(&collection))
}
let mut collection = OrderedCollection::new();
collection
.set_many_items(Vec::<Url>::new())
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(person.get_outbox_url()?)
.set_total_items(0_u64);
Ok(create_apub_response(&collection))
let mut collection = OrderedCollection::new();
collection
.set_id(person.inbox_url.into())
- .set_many_contexts(lemmy_context()?);
+ .set_many_contexts(lemmy_context());
Ok(create_apub_response(&collection))
}
comment
// Not needed when the Post is embedded in a collection (like for community outbox)
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(self.ap_id.to_owned().into_inner())
.set_published(convert_datetime(self.published))
// NOTE: included community id for compatibility with lemmy v0.9.9
let mut group = ApObject::new(Group::new());
group
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(self.actor_id.to_owned().into())
.set_name(self.title.to_owned())
.set_published(convert_datetime(self.published))
Self: Sized;
}
+#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+pub enum MediaTypeMarkdown {
+ #[serde(rename = "text/markdown")]
+ Markdown,
+}
+
+#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+pub enum MediaTypeHtml {
+ #[serde(rename = "text/html")]
+ Markdown,
+}
+
+#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct Source {
+ content: String,
+ media_type: MediaTypeMarkdown,
+}
+
/// Updated is actually the deletion time
fn create_tombstone<T>(
deleted: bool,
let mut person = ApObject::new(actor);
person
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(self.actor_id.to_owned().into_inner())
.set_published(convert_datetime(self.published));
activities::extract_community,
extensions::context::lemmy_context,
fetcher::person::get_or_fetch_and_upsert_person,
- objects::{create_tombstone, FromApub, ToApub},
+ objects::{create_tombstone, FromApub, MediaTypeHtml, MediaTypeMarkdown, Source, ToApub},
};
use activitystreams::{
base::AnyBase,
use lemmy_websocket::LemmyContext;
use url::Url;
-#[async_trait::async_trait(?Send)]
-impl ToApub for Post {
- type ApubType = Page;
-
- // Turn a Lemmy post into an ActivityPub page that can be sent out over the network.
- async fn to_apub(&self, pool: &DbPool) -> Result<Page, LemmyError> {
- let creator_id = self.creator_id;
- let creator = blocking(pool, move |conn| Person::read(conn, creator_id)).await??;
- let community_id = self.community_id;
- let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
-
- let source = self.body.clone().map(|body| Source {
- content: body,
- media_type: MediaTypeMarkdown::Markdown,
- });
- let image = self.thumbnail_url.clone().map(|thumb| ImageObject {
- content: ImageType::Image,
- url: thumb.into(),
- });
-
- let page = Page {
- context: lemmy_context()?.into(),
- r#type: PageType::Page,
- id: self.ap_id.clone().into(),
- attributed_to: creator.actor_id.into(),
- to: [community.actor_id.into(), public()],
- name: self.name.clone(),
- content: self.body.as_ref().map(|b| markdown_to_html(b)),
- media_type: MediaTypeHtml::Markdown,
- source,
- url: self.url.clone().map(|u| u.into()),
- image,
- comments_enabled: Some(!self.locked),
- sensitive: Some(self.nsfw),
- stickied: Some(self.stickied),
- published: convert_datetime(self.published),
- updated: self.updated.map(convert_datetime),
- unparsed: Default::default(),
- };
- Ok(page)
- }
-
- fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
- create_tombstone(
- self.deleted,
- self.ap_id.to_owned().into(),
- self.updated,
- PageType::Page,
- )
- }
-}
-
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
-pub enum MediaTypeMarkdown {
- #[serde(rename = "text/markdown")]
- Markdown,
-}
-
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
-pub enum MediaTypeHtml {
- #[serde(rename = "text/html")]
- Markdown,
-}
-
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct Source {
- content: String,
- media_type: MediaTypeMarkdown,
-}
-
-#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
-#[serde(rename_all = "camelCase")]
-pub struct ImageObject {
- content: ImageType,
- url: Url,
-}
-
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Page {
unparsed: Unparsed,
}
+#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct ImageObject {
+ content: ImageType,
+ url: Url,
+}
+
impl Page {
/// Only mods can change the post's stickied/locked status. So if either of these is changed from
/// the current value, it is a mod action and needs to be verified as such.
}
}
+#[async_trait::async_trait(?Send)]
+impl ToApub for Post {
+ type ApubType = Page;
+
+ // Turn a Lemmy post into an ActivityPub page that can be sent out over the network.
+ async fn to_apub(&self, pool: &DbPool) -> Result<Page, LemmyError> {
+ let creator_id = self.creator_id;
+ let creator = blocking(pool, move |conn| Person::read(conn, creator_id)).await??;
+ let community_id = self.community_id;
+ let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
+
+ let source = self.body.clone().map(|body| Source {
+ content: body,
+ media_type: MediaTypeMarkdown::Markdown,
+ });
+ let image = self.thumbnail_url.clone().map(|thumb| ImageObject {
+ content: ImageType::Image,
+ url: thumb.into(),
+ });
+
+ let page = Page {
+ context: lemmy_context(),
+ r#type: PageType::Page,
+ id: self.ap_id.clone().into(),
+ attributed_to: creator.actor_id.into(),
+ to: [community.actor_id.into(), public()],
+ name: self.name.clone(),
+ content: self.body.as_ref().map(|b| markdown_to_html(b)),
+ media_type: MediaTypeHtml::Markdown,
+ source,
+ url: self.url.clone().map(|u| u.into()),
+ image,
+ comments_enabled: Some(!self.locked),
+ sensitive: Some(self.nsfw),
+ stickied: Some(self.stickied),
+ published: convert_datetime(self.published),
+ updated: self.updated.map(convert_datetime),
+ unparsed: Default::default(),
+ };
+ Ok(page)
+ }
+
+ fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
+ create_tombstone(
+ self.deleted,
+ self.ap_id.to_owned().into(),
+ self.updated,
+ PageType::Page,
+ )
+ }
+}
+
#[async_trait::async_trait(?Send)]
impl FromApub for Post {
type ApubType = Page;
let recipient = blocking(pool, move |conn| Person::read(conn, recipient_id)).await??;
private_message
- .set_many_contexts(lemmy_context()?)
+ .set_many_contexts(lemmy_context())
.set_id(self.ap_id.to_owned().into_inner())
.set_published(convert_datetime(self.published))
.set_to(recipient.actor_id.into_inner())