2020-05-16 14:04:08 +00:00
|
|
|
use crate::{
|
|
|
|
apub::{
|
2020-07-17 21:11:07 +00:00
|
|
|
activities::send_activity_to_community,
|
2020-07-27 15:42:15 +00:00
|
|
|
create_apub_response, create_apub_tombstone_response, create_tombstone,
|
2020-05-16 14:04:08 +00:00
|
|
|
extensions::page_extension::PageExtension,
|
|
|
|
fetcher::{get_or_fetch_and_upsert_remote_community, get_or_fetch_and_upsert_remote_user},
|
2020-07-27 15:42:15 +00:00
|
|
|
ActorType, ApubLikeableType, ApubObjectType, FromApub, PageExt, ToApub,
|
2020-05-16 14:04:08 +00:00
|
|
|
},
|
2020-07-01 12:54:29 +00:00
|
|
|
blocking,
|
2020-05-16 14:04:08 +00:00
|
|
|
routes::DbPoolParam,
|
2020-07-27 15:42:15 +00:00
|
|
|
DbPool, LemmyError,
|
2020-05-16 14:04:08 +00:00
|
|
|
};
|
2020-05-18 16:15:26 +00:00
|
|
|
use activitystreams_ext::Ext1;
|
2020-07-14 12:19:33 +00:00
|
|
|
use activitystreams_new::{
|
2020-07-17 21:11:07 +00:00
|
|
|
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
|
2020-07-14 12:19:33 +00:00
|
|
|
context,
|
|
|
|
object::{kind::PageType, Image, Page, Tombstone},
|
|
|
|
prelude::*,
|
2020-07-17 21:11:07 +00:00
|
|
|
public,
|
2020-07-14 12:19:33 +00:00
|
|
|
};
|
2020-07-01 12:54:29 +00:00
|
|
|
use actix_web::{body::Body, client::Client, web, HttpResponse};
|
2020-07-10 18:15:41 +00:00
|
|
|
use lemmy_db::{
|
|
|
|
community::Community,
|
|
|
|
post::{Post, PostForm},
|
|
|
|
user::User_,
|
|
|
|
Crud,
|
|
|
|
};
|
|
|
|
use lemmy_utils::{convert_datetime, get_apub_protocol_string, settings::Settings};
|
2020-06-01 14:17:20 +00:00
|
|
|
use serde::Deserialize;
|
2020-07-17 21:11:07 +00:00
|
|
|
use url::Url;
|
2020-03-16 18:19:04 +00:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub struct PostQuery {
|
|
|
|
post_id: String,
|
|
|
|
}
|
|
|
|
|
2020-04-17 15:33:55 +00:00
|
|
|
/// Return the post json over HTTP.
|
2020-03-16 18:19:04 +00:00
|
|
|
pub async fn get_apub_post(
|
2020-07-01 12:54:29 +00:00
|
|
|
info: web::Path<PostQuery>,
|
2020-04-24 14:04:36 +00:00
|
|
|
db: DbPoolParam,
|
2020-07-01 12:54:29 +00:00
|
|
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
2020-03-16 18:19:04 +00:00
|
|
|
let id = info.post_id.parse::<i32>()?;
|
2020-07-01 12:54:29 +00:00
|
|
|
let post = blocking(&db, move |conn| Post::read(conn, id)).await??;
|
|
|
|
|
2020-04-29 14:51:25 +00:00
|
|
|
if !post.deleted {
|
2020-07-01 12:54:29 +00:00
|
|
|
Ok(create_apub_response(&post.to_apub(&db).await?))
|
2020-04-29 14:51:25 +00:00
|
|
|
} else {
|
|
|
|
Ok(create_apub_tombstone_response(&post.to_tombstone()?))
|
|
|
|
}
|
2020-03-16 18:19:04 +00:00
|
|
|
}
|
2019-12-19 21:59:13 +00:00
|
|
|
|
2020-07-01 12:54:29 +00:00
|
|
|
#[async_trait::async_trait(?Send)]
|
2020-04-24 21:30:27 +00:00
|
|
|
impl ToApub for Post {
|
2020-05-05 00:04:48 +00:00
|
|
|
type Response = PageExt;
|
2020-04-24 21:30:27 +00:00
|
|
|
|
2020-04-17 15:33:55 +00:00
|
|
|
// Turn a Lemmy post into an ActivityPub page that can be sent out over the network.
|
2020-07-01 12:54:29 +00:00
|
|
|
async fn to_apub(&self, pool: &DbPool) -> Result<PageExt, LemmyError> {
|
2020-07-14 12:19:33 +00:00
|
|
|
let mut page = Page::new();
|
2020-07-01 12:54:29 +00:00
|
|
|
|
|
|
|
let creator_id = self.creator_id;
|
|
|
|
let creator = blocking(pool, move |conn| User_::read(conn, creator_id)).await??;
|
|
|
|
|
|
|
|
let community_id = self.community_id;
|
|
|
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
2019-12-19 21:59:13 +00:00
|
|
|
|
2020-07-14 12:19:33 +00:00
|
|
|
page
|
2020-03-14 00:05:42 +00:00
|
|
|
// Not needed when the Post is embedded in a collection (like for community outbox)
|
2020-05-05 00:04:48 +00:00
|
|
|
// TODO: need to set proper context defining sensitive/commentsEnabled fields
|
|
|
|
// https://git.asonix.dog/Aardwolf/activitystreams/issues/5
|
2020-07-14 12:19:33 +00:00
|
|
|
.set_context(context())
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_id(self.ap_id.parse::<Url>()?)
|
2020-04-13 13:06:41 +00:00
|
|
|
// Use summary field to be consistent with mastodon content warning.
|
2020-04-13 12:13:06 +00:00
|
|
|
// https://mastodon.xyz/@Louisa/103987265222901387.json
|
2020-07-14 12:19:33 +00:00
|
|
|
.set_summary(self.name.to_owned())
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_published(convert_datetime(self.published))
|
2020-07-14 12:19:33 +00:00
|
|
|
.set_to(community.actor_id)
|
|
|
|
.set_attributed_to(creator.actor_id);
|
2019-12-19 21:59:13 +00:00
|
|
|
|
|
|
|
if let Some(body) = &self.body {
|
2020-07-14 12:19:33 +00:00
|
|
|
page.set_content(body.to_owned());
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
|
|
|
|
2020-03-14 21:03:05 +00:00
|
|
|
// TODO: hacky code because we get self.url == Some("")
|
2020-05-05 00:04:48 +00:00
|
|
|
// https://github.com/LemmyNet/lemmy/issues/602
|
2020-03-16 18:19:04 +00:00
|
|
|
let url = self.url.as_ref().filter(|u| !u.is_empty());
|
|
|
|
if let Some(u) = url {
|
2020-07-14 12:19:33 +00:00
|
|
|
page.set_url(u.to_owned());
|
2020-05-16 03:40:36 +00:00
|
|
|
|
|
|
|
// Embeds
|
|
|
|
let mut page_preview = Page::new();
|
2020-07-14 12:19:33 +00:00
|
|
|
page_preview.set_url(u.to_owned());
|
2020-05-16 03:40:36 +00:00
|
|
|
|
|
|
|
if let Some(embed_title) = &self.embed_title {
|
2020-07-14 12:19:33 +00:00
|
|
|
page_preview.set_name(embed_title.to_owned());
|
2020-05-16 03:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(embed_description) = &self.embed_description {
|
2020-07-14 12:19:33 +00:00
|
|
|
page_preview.set_summary(embed_description.to_owned());
|
2020-05-16 03:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(embed_html) = &self.embed_html {
|
2020-07-14 12:19:33 +00:00
|
|
|
page_preview.set_content(embed_html.to_owned());
|
2020-05-16 03:40:36 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 12:19:33 +00:00
|
|
|
page.set_preview(page_preview.into_any_base()?);
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 00:23:20 +00:00
|
|
|
if let Some(thumbnail_url) = &self.thumbnail_url {
|
|
|
|
let full_url = format!(
|
|
|
|
"{}://{}/pictshare/{}",
|
|
|
|
get_apub_protocol_string(),
|
|
|
|
Settings::get().hostname,
|
|
|
|
thumbnail_url
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut image = Image::new();
|
2020-07-14 12:19:33 +00:00
|
|
|
image.set_url(full_url);
|
|
|
|
page.set_image(image.into_any_base()?);
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 00:01:25 +00:00
|
|
|
if let Some(u) = self.updated {
|
2020-07-17 21:11:07 +00:00
|
|
|
page.set_updated(convert_datetime(u));
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
|
|
|
|
2020-05-05 00:04:48 +00:00
|
|
|
let ext = PageExtension {
|
|
|
|
comments_enabled: !self.locked,
|
|
|
|
sensitive: self.nsfw,
|
2020-07-27 15:42:15 +00:00
|
|
|
stickied: self.stickied,
|
2020-05-05 00:04:48 +00:00
|
|
|
};
|
2020-05-18 16:15:26 +00:00
|
|
|
Ok(Ext1::new(page, ext))
|
2020-04-29 14:51:25 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 12:54:29 +00:00
|
|
|
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
|
2020-05-01 14:07:38 +00:00
|
|
|
create_tombstone(
|
|
|
|
self.deleted,
|
|
|
|
&self.ap_id,
|
|
|
|
self.updated,
|
2020-07-17 21:11:07 +00:00
|
|
|
PageType::Page.to_string(),
|
2020-05-01 14:07:38 +00:00
|
|
|
)
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
2020-04-03 09:00:24 +00:00
|
|
|
}
|
2020-04-03 05:02:43 +00:00
|
|
|
|
2020-07-01 12:54:29 +00:00
|
|
|
#[async_trait::async_trait(?Send)]
|
2020-04-24 21:30:27 +00:00
|
|
|
impl FromApub for PostForm {
|
2020-05-05 00:04:48 +00:00
|
|
|
type ApubType = PageExt;
|
2020-04-24 21:30:27 +00:00
|
|
|
|
2020-04-17 15:33:55 +00:00
|
|
|
/// Parse an ActivityPub page received from another instance into a Lemmy post.
|
2020-07-01 12:54:29 +00:00
|
|
|
async fn from_apub(
|
2020-07-13 13:56:58 +00:00
|
|
|
page: &PageExt,
|
2020-07-01 12:54:29 +00:00
|
|
|
client: &Client,
|
|
|
|
pool: &DbPool,
|
2020-07-17 21:11:07 +00:00
|
|
|
actor_id: &Url,
|
2020-07-01 12:54:29 +00:00
|
|
|
) -> Result<PostForm, LemmyError> {
|
2020-05-18 16:15:26 +00:00
|
|
|
let ext = &page.ext_one;
|
2020-07-14 12:19:33 +00:00
|
|
|
let creator_actor_id = page
|
|
|
|
.inner
|
2020-07-17 21:11:07 +00:00
|
|
|
.attributed_to()
|
2020-07-14 12:19:33 +00:00
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.as_single_xsd_any_uri()
|
2020-07-14 14:09:13 +00:00
|
|
|
.unwrap();
|
2020-07-01 12:54:29 +00:00
|
|
|
|
2020-07-14 12:19:33 +00:00
|
|
|
let creator = get_or_fetch_and_upsert_remote_user(creator_actor_id, client, pool).await?;
|
2020-07-01 12:54:29 +00:00
|
|
|
|
2020-07-14 12:19:33 +00:00
|
|
|
let community_actor_id = page
|
|
|
|
.inner
|
2020-07-17 21:11:07 +00:00
|
|
|
.to()
|
2020-07-14 12:19:33 +00:00
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.as_single_xsd_any_uri()
|
2020-07-17 21:11:07 +00:00
|
|
|
.unwrap();
|
2020-07-01 12:54:29 +00:00
|
|
|
|
|
|
|
let community =
|
2020-07-14 12:19:33 +00:00
|
|
|
get_or_fetch_and_upsert_remote_community(community_actor_id, client, pool).await?;
|
|
|
|
|
2020-07-17 21:11:07 +00:00
|
|
|
let thumbnail_url = match &page.inner.image() {
|
2020-07-14 12:19:33 +00:00
|
|
|
Some(any_image) => Image::from_any_base(any_image.to_owned().as_one().unwrap().to_owned())?
|
|
|
|
.unwrap()
|
2020-07-17 21:11:07 +00:00
|
|
|
.url()
|
2020-07-14 12:19:33 +00:00
|
|
|
.unwrap()
|
|
|
|
.as_single_xsd_any_uri()
|
2020-05-16 00:23:20 +00:00
|
|
|
.map(|u| u.to_string()),
|
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
|
2020-07-14 12:19:33 +00:00
|
|
|
let (embed_title, embed_description, embed_html) = match page.inner.preview() {
|
2020-05-16 03:40:36 +00:00
|
|
|
Some(preview) => {
|
2020-07-17 21:11:07 +00:00
|
|
|
let preview_page = Page::from_any_base(preview.one().unwrap().to_owned())?.unwrap();
|
2020-05-16 03:40:36 +00:00
|
|
|
let name = preview_page
|
2020-07-14 12:19:33 +00:00
|
|
|
.name()
|
2020-07-17 21:11:07 +00:00
|
|
|
.map(|n| n.as_one().unwrap().as_xsd_string().unwrap().to_string());
|
2020-05-16 03:40:36 +00:00
|
|
|
let summary = preview_page
|
2020-07-14 12:19:33 +00:00
|
|
|
.summary()
|
|
|
|
.map(|s| s.as_single_xsd_string().unwrap().to_string());
|
2020-05-16 03:40:36 +00:00
|
|
|
let content = preview_page
|
2020-07-14 12:19:33 +00:00
|
|
|
.content()
|
|
|
|
.map(|c| c.as_single_xsd_string().unwrap().to_string());
|
2020-05-16 03:40:36 +00:00
|
|
|
(name, summary, content)
|
|
|
|
}
|
|
|
|
None => (None, None, None),
|
|
|
|
};
|
|
|
|
|
2020-07-14 12:19:33 +00:00
|
|
|
let url = page
|
|
|
|
.inner
|
2020-07-17 21:11:07 +00:00
|
|
|
.url()
|
2020-07-14 12:19:33 +00:00
|
|
|
.as_ref()
|
|
|
|
.map(|u| u.as_single_xsd_string().unwrap().to_string());
|
|
|
|
let body = page
|
|
|
|
.inner
|
2020-07-17 21:11:07 +00:00
|
|
|
.content()
|
2020-07-14 12:19:33 +00:00
|
|
|
.as_ref()
|
|
|
|
.map(|c| c.as_single_xsd_string().unwrap().to_string());
|
2020-04-07 16:47:19 +00:00
|
|
|
Ok(PostForm {
|
2020-07-14 12:19:33 +00:00
|
|
|
name: page
|
|
|
|
.inner
|
2020-07-17 21:11:07 +00:00
|
|
|
.summary()
|
2020-07-14 12:19:33 +00:00
|
|
|
.as_ref()
|
|
|
|
.unwrap()
|
|
|
|
.as_single_xsd_string()
|
|
|
|
.unwrap()
|
|
|
|
.to_string(),
|
2020-05-16 03:40:36 +00:00
|
|
|
url,
|
2020-07-14 12:19:33 +00:00
|
|
|
body,
|
2020-04-07 21:02:32 +00:00
|
|
|
creator_id: creator.id,
|
2020-04-09 19:04:31 +00:00
|
|
|
community_id: community.id,
|
2020-05-05 00:04:48 +00:00
|
|
|
removed: None,
|
|
|
|
locked: Some(!ext.comments_enabled),
|
2020-07-14 12:19:33 +00:00
|
|
|
published: page
|
|
|
|
.inner
|
2020-07-17 21:11:07 +00:00
|
|
|
.published()
|
2020-07-14 12:19:33 +00:00
|
|
|
.as_ref()
|
2020-07-17 21:11:07 +00:00
|
|
|
.map(|u| u.to_owned().naive_local()),
|
2020-07-14 12:19:33 +00:00
|
|
|
updated: page
|
|
|
|
.inner
|
2020-07-17 21:11:07 +00:00
|
|
|
.updated()
|
2020-07-14 12:19:33 +00:00
|
|
|
.as_ref()
|
2020-07-17 21:11:07 +00:00
|
|
|
.map(|u| u.to_owned().naive_local()),
|
2020-05-05 00:04:48 +00:00
|
|
|
deleted: None,
|
|
|
|
nsfw: ext.sensitive,
|
2020-07-27 15:42:15 +00:00
|
|
|
stickied: Some(ext.stickied),
|
2020-05-16 03:40:36 +00:00
|
|
|
embed_title,
|
|
|
|
embed_description,
|
|
|
|
embed_html,
|
2020-05-16 00:23:20 +00:00
|
|
|
thumbnail_url,
|
2020-07-17 21:11:07 +00:00
|
|
|
ap_id: page
|
|
|
|
.inner
|
|
|
|
.id(actor_id.domain().unwrap())?
|
|
|
|
.unwrap()
|
|
|
|
.to_string(),
|
2020-04-07 16:47:19 +00:00
|
|
|
local: false,
|
2020-04-03 05:02:43 +00:00
|
|
|
})
|
|
|
|
}
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
2020-04-27 16:57:00 +00:00
|
|
|
|
2020-07-01 12:54:29 +00:00
|
|
|
#[async_trait::async_trait(?Send)]
|
2020-04-27 16:57:00 +00:00
|
|
|
impl ApubObjectType for Post {
|
|
|
|
/// Send out information about a newly created post, to the followers of the community.
|
2020-07-01 12:54:29 +00:00
|
|
|
async fn send_create(
|
|
|
|
&self,
|
|
|
|
creator: &User_,
|
|
|
|
client: &Client,
|
|
|
|
pool: &DbPool,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let page = self.to_apub(pool).await?;
|
|
|
|
|
|
|
|
let community_id = self.community_id;
|
|
|
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
|
|
|
|
2020-04-28 04:16:02 +00:00
|
|
|
let id = format!("{}/create/{}", self.ap_id, uuid::Uuid::new_v4());
|
|
|
|
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut create = Create::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
2020-04-27 16:57:00 +00:00
|
|
|
create
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-04-27 22:17:02 +00:00
|
|
|
|
2020-06-01 14:17:20 +00:00
|
|
|
send_activity_to_community(
|
|
|
|
creator,
|
|
|
|
&community,
|
|
|
|
vec![community.get_shared_inbox_url()],
|
2020-07-17 21:11:07 +00:00
|
|
|
create.into_any_base()?,
|
2020-07-01 12:54:29 +00:00
|
|
|
client,
|
|
|
|
pool,
|
|
|
|
)
|
|
|
|
.await?;
|
2020-04-27 16:57:00 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Send out information about an edited post, to the followers of the community.
|
2020-07-01 12:54:29 +00:00
|
|
|
async fn send_update(
|
|
|
|
&self,
|
|
|
|
creator: &User_,
|
|
|
|
client: &Client,
|
|
|
|
pool: &DbPool,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let page = self.to_apub(pool).await?;
|
|
|
|
|
|
|
|
let community_id = self.community_id;
|
|
|
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
|
|
|
|
2020-04-28 04:16:02 +00:00
|
|
|
let id = format!("{}/update/{}", self.ap_id, uuid::Uuid::new_v4());
|
|
|
|
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut update = Update::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
2020-04-27 16:57:00 +00:00
|
|
|
update
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-04-27 22:17:02 +00:00
|
|
|
|
2020-06-01 14:17:20 +00:00
|
|
|
send_activity_to_community(
|
|
|
|
creator,
|
|
|
|
&community,
|
|
|
|
vec![community.get_shared_inbox_url()],
|
2020-07-17 21:11:07 +00:00
|
|
|
update.into_any_base()?,
|
2020-07-01 12:54:29 +00:00
|
|
|
client,
|
|
|
|
pool,
|
|
|
|
)
|
|
|
|
.await?;
|
2020-04-27 16:57:00 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2020-04-29 14:51:25 +00:00
|
|
|
|
2020-07-01 12:54:29 +00:00
|
|
|
async fn send_delete(
|
|
|
|
&self,
|
|
|
|
creator: &User_,
|
|
|
|
client: &Client,
|
|
|
|
pool: &DbPool,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let page = self.to_apub(pool).await?;
|
|
|
|
|
|
|
|
let community_id = self.community_id;
|
|
|
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
|
|
|
|
2020-05-01 14:07:38 +00:00
|
|
|
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut delete = Delete::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
2020-04-29 14:51:25 +00:00
|
|
|
delete
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-04-29 14:51:25 +00:00
|
|
|
|
2020-06-01 14:17:20 +00:00
|
|
|
send_activity_to_community(
|
|
|
|
creator,
|
|
|
|
&community,
|
|
|
|
vec![community.get_shared_inbox_url()],
|
2020-07-17 21:11:07 +00:00
|
|
|
delete.into_any_base()?,
|
2020-07-01 12:54:29 +00:00
|
|
|
client,
|
|
|
|
pool,
|
|
|
|
)
|
|
|
|
.await?;
|
2020-05-01 19:01:29 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-07-01 12:54:29 +00:00
|
|
|
async fn send_undo_delete(
|
|
|
|
&self,
|
|
|
|
creator: &User_,
|
|
|
|
client: &Client,
|
|
|
|
pool: &DbPool,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let page = self.to_apub(pool).await?;
|
|
|
|
|
|
|
|
let community_id = self.community_id;
|
|
|
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
|
|
|
|
2020-05-01 19:01:29 +00:00
|
|
|
let id = format!("{}/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut delete = Delete::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
2020-05-01 19:01:29 +00:00
|
|
|
delete
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-05-01 19:01:29 +00:00
|
|
|
|
2020-05-03 14:22:25 +00:00
|
|
|
// TODO
|
2020-05-01 19:01:29 +00:00
|
|
|
// Undo that fake activity
|
|
|
|
let undo_id = format!("{}/undo/delete/{}", self.ap_id, uuid::Uuid::new_v4());
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
|
2020-05-01 19:01:29 +00:00
|
|
|
undo
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&undo_id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-05-01 19:01:29 +00:00
|
|
|
|
2020-06-01 14:17:20 +00:00
|
|
|
send_activity_to_community(
|
|
|
|
creator,
|
|
|
|
&community,
|
|
|
|
vec![community.get_shared_inbox_url()],
|
2020-07-17 21:11:07 +00:00
|
|
|
undo.into_any_base()?,
|
2020-07-01 12:54:29 +00:00
|
|
|
client,
|
|
|
|
pool,
|
|
|
|
)
|
|
|
|
.await?;
|
2020-05-03 14:00:59 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-07-01 12:54:29 +00:00
|
|
|
async fn send_remove(
|
|
|
|
&self,
|
|
|
|
mod_: &User_,
|
|
|
|
client: &Client,
|
|
|
|
pool: &DbPool,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let page = self.to_apub(pool).await?;
|
|
|
|
|
|
|
|
let community_id = self.community_id;
|
|
|
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
|
|
|
|
2020-05-03 14:00:59 +00:00
|
|
|
let id = format!("{}/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut remove = Remove::new(mod_.actor_id.to_owned(), page.into_any_base()?);
|
2020-05-03 14:00:59 +00:00
|
|
|
remove
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-05-03 14:00:59 +00:00
|
|
|
|
2020-06-01 14:17:20 +00:00
|
|
|
send_activity_to_community(
|
|
|
|
mod_,
|
|
|
|
&community,
|
|
|
|
vec![community.get_shared_inbox_url()],
|
2020-07-17 21:11:07 +00:00
|
|
|
remove.into_any_base()?,
|
2020-07-01 12:54:29 +00:00
|
|
|
client,
|
|
|
|
pool,
|
|
|
|
)
|
|
|
|
.await?;
|
2020-05-03 14:00:59 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2020-07-01 12:54:29 +00:00
|
|
|
|
|
|
|
async fn send_undo_remove(
|
|
|
|
&self,
|
|
|
|
mod_: &User_,
|
|
|
|
client: &Client,
|
|
|
|
pool: &DbPool,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let page = self.to_apub(pool).await?;
|
|
|
|
|
|
|
|
let community_id = self.community_id;
|
|
|
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
|
|
|
|
2020-05-03 14:00:59 +00:00
|
|
|
let id = format!("{}/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut remove = Remove::new(mod_.actor_id.to_owned(), page.into_any_base()?);
|
2020-05-03 14:00:59 +00:00
|
|
|
remove
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-05-03 14:00:59 +00:00
|
|
|
|
|
|
|
// Undo that fake activity
|
|
|
|
let undo_id = format!("{}/undo/remove/{}", self.ap_id, uuid::Uuid::new_v4());
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
|
2020-05-03 14:00:59 +00:00
|
|
|
undo
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&undo_id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-05-03 14:00:59 +00:00
|
|
|
|
2020-06-01 14:17:20 +00:00
|
|
|
send_activity_to_community(
|
|
|
|
mod_,
|
|
|
|
&community,
|
|
|
|
vec![community.get_shared_inbox_url()],
|
2020-07-17 21:11:07 +00:00
|
|
|
undo.into_any_base()?,
|
2020-07-01 12:54:29 +00:00
|
|
|
client,
|
|
|
|
pool,
|
|
|
|
)
|
|
|
|
.await?;
|
2020-04-29 14:51:25 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2020-04-27 16:57:00 +00:00
|
|
|
}
|
2020-04-28 02:46:09 +00:00
|
|
|
|
2020-07-01 12:54:29 +00:00
|
|
|
#[async_trait::async_trait(?Send)]
|
2020-04-28 02:46:09 +00:00
|
|
|
impl ApubLikeableType for Post {
|
2020-07-01 12:54:29 +00:00
|
|
|
async fn send_like(
|
|
|
|
&self,
|
|
|
|
creator: &User_,
|
|
|
|
client: &Client,
|
|
|
|
pool: &DbPool,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let page = self.to_apub(pool).await?;
|
|
|
|
|
|
|
|
let community_id = self.community_id;
|
|
|
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
|
|
|
|
2020-04-28 04:16:02 +00:00
|
|
|
let id = format!("{}/like/{}", self.ap_id, uuid::Uuid::new_v4());
|
|
|
|
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut like = Like::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
2020-04-28 02:46:09 +00:00
|
|
|
like
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-04-28 02:46:09 +00:00
|
|
|
|
2020-06-01 14:17:20 +00:00
|
|
|
send_activity_to_community(
|
|
|
|
&creator,
|
|
|
|
&community,
|
|
|
|
vec![community.get_shared_inbox_url()],
|
2020-07-17 21:11:07 +00:00
|
|
|
like.into_any_base()?,
|
2020-07-01 12:54:29 +00:00
|
|
|
client,
|
|
|
|
pool,
|
|
|
|
)
|
|
|
|
.await?;
|
2020-04-28 02:46:09 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-07-01 12:54:29 +00:00
|
|
|
async fn send_dislike(
|
|
|
|
&self,
|
|
|
|
creator: &User_,
|
|
|
|
client: &Client,
|
|
|
|
pool: &DbPool,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let page = self.to_apub(pool).await?;
|
|
|
|
|
|
|
|
let community_id = self.community_id;
|
|
|
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
|
|
|
|
2020-04-28 04:16:02 +00:00
|
|
|
let id = format!("{}/dislike/{}", self.ap_id, uuid::Uuid::new_v4());
|
|
|
|
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut dislike = Dislike::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
2020-04-28 02:46:09 +00:00
|
|
|
dislike
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-04-28 02:46:09 +00:00
|
|
|
|
2020-06-01 14:17:20 +00:00
|
|
|
send_activity_to_community(
|
|
|
|
&creator,
|
|
|
|
&community,
|
|
|
|
vec![community.get_shared_inbox_url()],
|
2020-07-17 21:11:07 +00:00
|
|
|
dislike.into_any_base()?,
|
2020-07-01 12:54:29 +00:00
|
|
|
client,
|
|
|
|
pool,
|
|
|
|
)
|
|
|
|
.await?;
|
2020-04-28 02:46:09 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2020-05-04 00:34:04 +00:00
|
|
|
|
2020-07-01 12:54:29 +00:00
|
|
|
async fn send_undo_like(
|
|
|
|
&self,
|
|
|
|
creator: &User_,
|
|
|
|
client: &Client,
|
|
|
|
pool: &DbPool,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let page = self.to_apub(pool).await?;
|
|
|
|
|
|
|
|
let community_id = self.community_id;
|
|
|
|
let community = blocking(pool, move |conn| Community::read(conn, community_id)).await??;
|
|
|
|
|
2020-05-04 00:34:04 +00:00
|
|
|
let id = format!("{}/like/{}", self.ap_id, uuid::Uuid::new_v4());
|
|
|
|
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut like = Like::new(creator.actor_id.to_owned(), page.into_any_base()?);
|
2020-05-04 00:34:04 +00:00
|
|
|
like
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-05-04 00:34:04 +00:00
|
|
|
|
|
|
|
// TODO
|
|
|
|
// Undo that fake activity
|
|
|
|
let undo_id = format!("{}/undo/like/{}", self.ap_id, uuid::Uuid::new_v4());
|
2020-07-17 21:11:07 +00:00
|
|
|
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
|
2020-05-04 00:34:04 +00:00
|
|
|
undo
|
2020-07-17 21:11:07 +00:00
|
|
|
.set_context(context())
|
|
|
|
.set_id(Url::parse(&undo_id)?)
|
|
|
|
.set_to(public())
|
|
|
|
.set_many_ccs(vec![community.get_followers_url()]);
|
2020-05-04 00:34:04 +00:00
|
|
|
|
2020-06-01 14:17:20 +00:00
|
|
|
send_activity_to_community(
|
|
|
|
&creator,
|
|
|
|
&community,
|
|
|
|
vec![community.get_shared_inbox_url()],
|
2020-07-17 21:11:07 +00:00
|
|
|
undo.into_any_base()?,
|
2020-07-01 12:54:29 +00:00
|
|
|
client,
|
|
|
|
pool,
|
|
|
|
)
|
|
|
|
.await?;
|
2020-05-07 17:07:33 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|