Migrate community activities
This commit is contained in:
parent
7c55a84184
commit
5417cb8476
|
@ -10,13 +10,12 @@ use crate::{
|
|||
routes::DbPoolParam,
|
||||
DbPool, LemmyError,
|
||||
};
|
||||
use activitystreams::{
|
||||
activity::{Accept, Announce, Delete, Remove, Undo},
|
||||
Activity, Base, BaseBox,
|
||||
};
|
||||
use activitystreams::{activity::Announce, BaseBox};
|
||||
use activitystreams::{Activity, Base};
|
||||
use activitystreams_ext::Ext2;
|
||||
use activitystreams_new::{
|
||||
activity::Follow,
|
||||
activity::{Accept, Delete, Remove, Undo},
|
||||
actor::{kind::GroupType, ApActor, Endpoints, Group},
|
||||
base::BaseExt,
|
||||
collection::UnorderedCollection,
|
||||
|
@ -24,6 +23,7 @@ use activitystreams_new::{
|
|||
object::Tombstone,
|
||||
prelude::*,
|
||||
primitives::{XsdAnyUri, XsdDateTime},
|
||||
public,
|
||||
};
|
||||
use actix_web::{body::Body, client::Client, web, HttpResponse};
|
||||
use itertools::Itertools;
|
||||
|
@ -128,23 +128,19 @@ impl ActorType for Community {
|
|||
/// As a local community, accept the follow request from a remote user.
|
||||
async fn send_accept_follow(
|
||||
&self,
|
||||
follow: &Follow,
|
||||
follow: Follow,
|
||||
client: &Client,
|
||||
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();
|
||||
accept
|
||||
.object_props
|
||||
.set_context_xsd_any_uri(context())?
|
||||
.set_id(id)?;
|
||||
accept
|
||||
.accept_props
|
||||
.set_actor_xsd_any_uri(self.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(follow.clone())?)?;
|
||||
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(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(to.clone());
|
||||
|
||||
insert_activity(self.creator_id, accept.clone(), true, pool).await?;
|
||||
|
||||
|
@ -162,17 +158,12 @@ impl ActorType for Community {
|
|||
|
||||
let id = format!("{}/delete/{}", self.actor_id, uuid::Uuid::new_v4());
|
||||
|
||||
let mut delete = Delete::default();
|
||||
populate_object_props(
|
||||
&mut delete.object_props,
|
||||
vec![self.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
|
||||
let mut delete = Delete::new(creator.actor_id.to_owned(), group.into_any_base()?);
|
||||
delete
|
||||
.delete_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(group)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![self.get_followers_url()]);
|
||||
|
||||
insert_activity(self.creator_id, delete.clone(), true, pool).await?;
|
||||
|
||||
|
@ -195,33 +186,22 @@ impl ActorType for Community {
|
|||
|
||||
let id = format!("{}/delete/{}", self.actor_id, uuid::Uuid::new_v4());
|
||||
|
||||
let mut delete = Delete::default();
|
||||
populate_object_props(
|
||||
&mut delete.object_props,
|
||||
vec![self.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
|
||||
let mut delete = Delete::new(creator.actor_id.to_owned(), group.into_any_base()?);
|
||||
delete
|
||||
.delete_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(group)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.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::default();
|
||||
|
||||
populate_object_props(
|
||||
&mut undo.object_props,
|
||||
vec![self.get_followers_url()],
|
||||
&undo_id,
|
||||
)?;
|
||||
|
||||
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
|
||||
undo
|
||||
.undo_props
|
||||
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
|
||||
.set_object_base_box(delete)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&undo_id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![self.get_followers_url()]);
|
||||
|
||||
insert_activity(self.creator_id, undo.clone(), true, pool).await?;
|
||||
|
||||
|
@ -244,17 +224,12 @@ impl ActorType for Community {
|
|||
|
||||
let id = format!("{}/remove/{}", self.actor_id, uuid::Uuid::new_v4());
|
||||
|
||||
let mut remove = Remove::default();
|
||||
populate_object_props(
|
||||
&mut remove.object_props,
|
||||
vec![self.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
|
||||
let mut remove = Remove::new(mod_.actor_id.to_owned(), group.into_any_base()?);
|
||||
remove
|
||||
.remove_props
|
||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(group)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![self.get_followers_url()]);
|
||||
|
||||
insert_activity(mod_.id, remove.clone(), true, pool).await?;
|
||||
|
||||
|
@ -277,32 +252,21 @@ impl ActorType for Community {
|
|||
|
||||
let id = format!("{}/remove/{}", self.actor_id, uuid::Uuid::new_v4());
|
||||
|
||||
let mut remove = Remove::default();
|
||||
populate_object_props(
|
||||
&mut remove.object_props,
|
||||
vec![self.get_followers_url()],
|
||||
&id,
|
||||
)?;
|
||||
|
||||
let mut remove = Remove::new(mod_.actor_id.to_owned(), group.into_any_base()?);
|
||||
remove
|
||||
.remove_props
|
||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(BaseBox::from_concrete(group)?)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&id)?)
|
||||
.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::default();
|
||||
|
||||
populate_object_props(
|
||||
&mut undo.object_props,
|
||||
vec![self.get_followers_url()],
|
||||
&undo_id,
|
||||
)?;
|
||||
|
||||
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
|
||||
undo
|
||||
.undo_props
|
||||
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
|
||||
.set_object_base_box(remove)?;
|
||||
.set_context(context())
|
||||
.set_id(XsdAnyUri::from_str(&undo_id)?)
|
||||
.set_to(public())
|
||||
.set_many_ccs(vec![self.get_followers_url()]);
|
||||
|
||||
insert_activity(mod_.id, undo.clone(), true, pool).await?;
|
||||
|
||||
|
@ -358,7 +322,7 @@ impl FromApub for CommunityForm {
|
|||
|
||||
/// Parse an ActivityPub group received from another instance into a Lemmy community.
|
||||
async fn from_apub(group: &GroupExt, client: &Client, pool: &DbPool) -> Result<Self, LemmyError> {
|
||||
let creator_and_moderator_uris = group.attributed_to().unwrap();
|
||||
let creator_and_moderator_uris = group.inner.attributed_to().unwrap();
|
||||
let creator_uri = creator_and_moderator_uris
|
||||
.as_many()
|
||||
.unwrap()
|
||||
|
@ -371,23 +335,34 @@ impl FromApub for CommunityForm {
|
|||
let creator = get_or_fetch_and_upsert_remote_user(creator_uri, client, pool).await?;
|
||||
|
||||
Ok(CommunityForm {
|
||||
name: group.name().unwrap().as_single_xsd_string().unwrap().into(),
|
||||
name: group
|
||||
.inner
|
||||
.name()
|
||||
.unwrap()
|
||||
.as_single_xsd_string()
|
||||
.unwrap()
|
||||
.into(),
|
||||
title: group.inner.preferred_username().unwrap().to_string(),
|
||||
// TODO: should be parsed as html and tags like <script> removed (or use markdown source)
|
||||
// -> same for post.content etc
|
||||
description: group
|
||||
.inner
|
||||
.content()
|
||||
.map(|s| s.as_single_xsd_string().unwrap().into()),
|
||||
category_id: group.ext_one.category.identifier.parse::<i32>()?,
|
||||
creator_id: creator.id,
|
||||
removed: None,
|
||||
published: group
|
||||
.inner
|
||||
.published()
|
||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
||||
updated: group.updated().map(|u| u.as_ref().to_owned().naive_local()),
|
||||
updated: group
|
||||
.inner
|
||||
.updated()
|
||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
||||
deleted: None,
|
||||
nsfw: group.ext_one.sensitive,
|
||||
actor_id: group.id().unwrap().to_string(),
|
||||
actor_id: group.inner.id().unwrap().to_string(),
|
||||
local: false,
|
||||
private_key: None,
|
||||
public_key: Some(group.ext_two.to_owned().public_key.public_key_pem),
|
||||
|
|
|
@ -107,7 +107,7 @@ async fn handle_follow(
|
|||
})
|
||||
.await?;
|
||||
|
||||
community.send_accept_follow(&follow, &client, &db).await?;
|
||||
community.send_accept_follow(follow, &client, &db).await?;
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ pub trait ActorType {
|
|||
#[allow(unused_variables)]
|
||||
async fn send_accept_follow(
|
||||
&self,
|
||||
follow: &Follow,
|
||||
follow: Follow,
|
||||
client: &Client,
|
||||
pool: &DbPool,
|
||||
) -> Result<(), LemmyError>;
|
||||
|
|
|
@ -171,7 +171,7 @@ impl ActorType for User_ {
|
|||
|
||||
async fn send_accept_follow(
|
||||
&self,
|
||||
_follow: &Follow,
|
||||
_follow: Follow,
|
||||
_client: &Client,
|
||||
_pool: &DbPool,
|
||||
) -> Result<(), LemmyError> {
|
||||
|
@ -225,6 +225,7 @@ impl FromApub for UserForm {
|
|||
matrix_user_id: None,
|
||||
actor_id: person.id().unwrap().to_string(),
|
||||
bio: person
|
||||
.inner
|
||||
.summary()
|
||||
.map(|s| s.as_single_xsd_string().unwrap().into()),
|
||||
local: false,
|
||||
|
|
Loading…
Reference in New Issue