Browse Source

Use activitystreams-ext

activitystreams-ext
Felix 2 years ago
parent
commit
d1aca27126
  1. 34
      server/Cargo.lock
  2. 6
      server/Cargo.toml
  3. 30
      server/src/apub/community.rs
  4. 8
      server/src/apub/fetcher.rs
  5. 8
      server/src/apub/mod.rs
  6. 28
      server/src/apub/post.rs
  7. 10
      server/src/apub/user.rs

34
server/Cargo.lock

@ -26,10 +26,20 @@ dependencies = [
"syn",
]
[[package]]
name = "activitystreams-ext"
version = "0.1.0"
source = "git+https://git.asonix.dog/asonix/activitystreams-ext#862426e504832256a6b26e1ec2198c0bda22139b"
dependencies = [
"activitystreams-new",
"serde 1.0.110",
"serde_json 1.0.53",
]
[[package]]
name = "activitystreams-new"
version = "0.1.0"
source = "git+https://git.asonix.dog/asonix/activitystreams-sketch#2fb52d32bbce9716c76e08579cf5c716366945fe"
source = "git+https://git.asonix.dog/asonix/activitystreams-sketch#2cd88752996d702b355f0cd2c8dc991af00b3cae"
dependencies = [
"activitystreams",
"serde 1.0.110",
@ -1565,6 +1575,7 @@ name = "lemmy_server"
version = "0.0.1"
dependencies = [
"activitystreams",
"activitystreams-ext",
"activitystreams-new",
"actix",
"actix-files",
@ -2093,18 +2104,18 @@ dependencies = [
[[package]]
name = "pin-project"
version = "0.4.16"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81d480cb4e89522ccda96d0eed9af94180b7a5f93fb28f66e1fd7d68431663d1"
checksum = "edc93aeee735e60ecb40cf740eb319ff23eab1c5748abfdb5c180e4ce49f7791"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "0.4.16"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a82996f11efccb19b685b14b5df818de31c1edcee3daa256ab5775dd98e72feb"
checksum = "e58db2081ba5b4c93bd6be09c40fd36cb9193a8336c384f3b40012e531aa7e40"
dependencies = [
"proc-macro2",
"quote",
@ -2131,9 +2142,9 @@ checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
[[package]]
name = "ppv-lite86"
version = "0.2.7"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1e4df3c96bec4c7ce0e32fe5960c98ffc869443ec9592a0411ca1ee96e5e2f0"
checksum = "237a5ed80e274dbc66f86bd59c1e25edc039660be53194b5fe0a482e0f2612ea"
[[package]]
name = "pq-sys"
@ -2183,9 +2194,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.5"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42934bc9c8ab0d3b273a16d8551c8f0fcff46be73276ca083ec2414c15c4ba5e"
checksum = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea"
dependencies = [
"proc-macro2",
]
@ -3028,8 +3039,9 @@ checksum = "a9b2228007eba4120145f785df0f6c92ea538f5a3635a612ecf4e334c8c1446d"
[[package]]
name = "typed-builder"
version = "0.5.1"
source = "git+https://git.asonix.dog/asonix/typed-builder#3dadcaaa6184ef720093c8f0632a7d423d2537b0"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85fc4459191c621a53ef6c6ca5642e6e0e5ccc61f3e5b8ad6b6ab5317f0200fb"
dependencies = [
"proc-macro2",
"quote",

6
server/Cargo.toml

@ -4,15 +4,13 @@ version = "0.0.1"
authors = ["Dessalines <happydooby@gmail.com>"]
edition = "2018"
[patch.crates-io]
typed-builder = { git = "https://git.asonix.dog/asonix/typed-builder" }
[dependencies]
diesel = { version = "1.4.4", features = ["postgres","chrono","r2d2","64-column-tables","serde_json"] }
diesel_migrations = "1.4.0"
dotenv = "0.15.0"
activitystreams = "0.6.2"
activitystreams-new = { version = "0.1.0", git = "https://git.asonix.dog/asonix/activitystreams-sketch" }
activitystreams-new = { git = "https://git.asonix.dog/asonix/activitystreams-sketch" }
activitystreams-ext = { git = "https://git.asonix.dog/asonix/activitystreams-ext" }
bcrypt = "0.8.0"
chrono = { version = "0.4.7", features = ["serde"] }
failure = "0.1.8"

30
server/src/apub/community.rs

@ -28,10 +28,10 @@ use activitystreams::{
collection::UnorderedCollection,
context,
endpoint::EndpointProperties,
ext::Extensible,
object::{properties::ObjectProperties, Tombstone},
BaseBox,
};
use activitystreams_ext::Ext3;
use actix_web::{body::Body, web::Path, HttpResponse, Result};
use diesel::PgConnection;
use failure::Error;
@ -91,12 +91,12 @@ impl ToApub for Community {
let group_extension = GroupExtension::new(conn, self.category_id, self.nsfw)?;
Ok(
group
.extend(group_extension)
.extend(actor_props)
.extend(self.get_public_key_ext()),
)
Ok(Ext3::new(
group,
group_extension,
actor_props,
self.get_public_key_ext(),
))
}
fn to_tombstone(&self) -> Result<Tombstone, Error> {
@ -161,7 +161,7 @@ impl ActorType for Community {
delete
.delete_props
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(group)?;
.set_object_base_box(BaseBox::from_concrete(group)?)?;
insert_activity(&conn, self.creator_id, &delete, true)?;
@ -186,7 +186,7 @@ impl ActorType for Community {
delete
.delete_props
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(group)?;
.set_object_base_box(BaseBox::from_concrete(group)?)?;
// TODO
// Undo that fake activity
@ -227,7 +227,7 @@ impl ActorType for Community {
remove
.remove_props
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(group)?;
.set_object_base_box(BaseBox::from_concrete(group)?)?;
insert_activity(&conn, mod_.id, &remove, true)?;
@ -252,7 +252,7 @@ impl ActorType for Community {
remove
.remove_props
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(group)?;
.set_object_base_box(BaseBox::from_concrete(group)?)?;
// Undo that fake activity
let undo_id = format!("{}/undo/remove/{}", self.actor_id, uuid::Uuid::new_v4());
@ -316,10 +316,10 @@ impl FromApub for CommunityForm {
/// Parse an ActivityPub group received from another instance into a Lemmy community.
fn from_apub(group: &GroupExt, conn: &PgConnection) -> Result<Self, Error> {
let group_extensions: &GroupExtension = &group.base.base.extension;
let oprops = &group.base.base.base.object_props;
let aprops = &group.base.extension;
let public_key: &PublicKey = &group.extension.public_key;
let group_extensions: &GroupExtension = &group.ext_one;
let oprops = &group.inner.object_props;
let aprops = &group.ext_two;
let public_key: &PublicKey = &group.ext_three.public_key;
let mut creator_and_moderator_uris = oprops.get_many_attributed_to_xsd_any_uris().unwrap();
let creator = creator_and_moderator_uris

8
server/src/apub/fetcher.rs

@ -125,12 +125,12 @@ pub fn search_by_apub_id(query: &str, conn: &PgConnection) -> Result<SearchRespo
};
match fetch_remote_object::<SearchAcceptedObjects>(&query_url)? {
SearchAcceptedObjects::Person(p) => {
let user_uri = p.base.base.object_props.get_id().unwrap().to_string();
let user_uri = p.inner.object_props.get_id().unwrap().to_string();
let user = get_or_fetch_and_upsert_remote_user(&user_uri, &conn)?;
response.users = vec![UserView::read(conn, user.id)?];
}
SearchAcceptedObjects::Group(g) => {
let community_uri = g.base.base.base.object_props.get_id().unwrap().to_string();
let community_uri = g.inner.object_props.get_id().unwrap().to_string();
let community = get_or_fetch_and_upsert_remote_community(&community_uri, &conn)?;
// TODO Maybe at some point in the future, fetch all the history of a community
// fetch_community_outbox(&c, conn)?;
@ -220,9 +220,7 @@ pub fn get_or_fetch_and_upsert_remote_community(
// Also add the community moderators too
let creator_and_moderator_uris = group
.base
.base
.base
.inner
.object_props
.get_many_attributed_to_xsd_any_uris()
.unwrap();

8
server/src/apub/mod.rs

@ -25,9 +25,9 @@ use crate::{
use activitystreams::{
activity::Follow,
actor::{properties::ApActorProperties, Group, Person},
ext::Ext,
object::{Page, Tombstone},
};
use activitystreams_ext::{Ext1, Ext2, Ext3};
use actix_web::{body::Body, HttpResponse, Result};
use chrono::NaiveDateTime;
use diesel::PgConnection;
@ -37,9 +37,9 @@ use log::debug;
use serde::Serialize;
use url::Url;
type GroupExt = Ext<Ext<Ext<Group, GroupExtension>, ApActorProperties>, PublicKeyExtension>;
type PersonExt = Ext<Ext<Person, ApActorProperties>, PublicKeyExtension>;
type PageExt = Ext<Page, PageExtension>;
type GroupExt = Ext3<Group, GroupExtension, ApActorProperties, PublicKeyExtension>;
type PersonExt = Ext2<Person, ApActorProperties, PublicKeyExtension>;
type PageExt = Ext1<Page, PageExtension>;
pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";

28
server/src/apub/post.rs

@ -26,9 +26,10 @@ use crate::{
use activitystreams::{
activity::{Create, Delete, Dislike, Like, Remove, Undo, Update},
context,
ext::Extensible,
object::{kind::PageType, properties::ObjectProperties, Page, Tombstone},
BaseBox,
};
use activitystreams_ext::Ext1;
use actix_web::{body::Body, web::Path, HttpResponse, Result};
use diesel::PgConnection;
use failure::Error;
@ -95,7 +96,7 @@ impl ToApub for Post {
comments_enabled: !self.locked,
sensitive: self.nsfw,
};
Ok(page.extend(ext))
Ok(Ext1::new(page, ext))
}
fn to_tombstone(&self) -> Result<Tombstone, Error> {
@ -113,9 +114,8 @@ impl FromApub for PostForm {
/// Parse an ActivityPub page received from another instance into a Lemmy post.
fn from_apub(page: &PageExt, conn: &PgConnection) -> Result<PostForm, Error> {
let ext = &page.extension;
let page = &page.base;
let oprops = &page.object_props;
let ext = &page.ext_one;
let oprops = &page.inner.object_props;
let creator_actor_id = &oprops.get_attributed_to_xsd_any_uri().unwrap().to_string();
let creator = get_or_fetch_and_upsert_remote_user(&creator_actor_id, &conn)?;
let community_actor_id = &oprops.get_to_xsd_any_uri().unwrap().to_string();
@ -164,7 +164,7 @@ impl ApubObjectType for Post {
create
.create_props
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
.set_object_base_box(BaseBox::from_concrete(page)?)?;
insert_activity(&conn, creator.id, &create, true)?;
@ -187,7 +187,7 @@ impl ApubObjectType for Post {
update
.update_props
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
.set_object_base_box(BaseBox::from_concrete(page)?)?;
insert_activity(&conn, creator.id, &update, true)?;
@ -210,7 +210,7 @@ impl ApubObjectType for Post {
delete
.delete_props
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
.set_object_base_box(BaseBox::from_concrete(page)?)?;
insert_activity(&conn, self.creator_id, &delete, true)?;
@ -234,7 +234,7 @@ impl ApubObjectType for Post {
delete
.delete_props
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
.set_object_base_box(BaseBox::from_concrete(page)?)?;
// TODO
// Undo that fake activity
@ -274,7 +274,7 @@ impl ApubObjectType for Post {
remove
.remove_props
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(page)?;
.set_object_base_box(BaseBox::from_concrete(page)?)?;
insert_activity(&conn, mod_.id, &remove, true)?;
@ -297,7 +297,7 @@ impl ApubObjectType for Post {
remove
.remove_props
.set_actor_xsd_any_uri(mod_.actor_id.to_owned())?
.set_object_base_box(page)?;
.set_object_base_box(BaseBox::from_concrete(page)?)?;
// Undo that fake activity
let undo_id = format!("{}/undo/remove/{}", self.ap_id, uuid::Uuid::new_v4());
@ -337,7 +337,7 @@ impl ApubLikeableType for Post {
like
.like_props
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
.set_object_base_box(BaseBox::from_concrete(page)?)?;
insert_activity(&conn, creator.id, &like, true)?;
@ -359,7 +359,7 @@ impl ApubLikeableType for Post {
dislike
.dislike_props
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
.set_object_base_box(BaseBox::from_concrete(page)?)?;
insert_activity(&conn, creator.id, &dislike, true)?;
@ -381,7 +381,7 @@ impl ApubLikeableType for Post {
like
.like_props
.set_actor_xsd_any_uri(creator.actor_id.to_owned())?
.set_object_base_box(page)?;
.set_object_base_box(BaseBox::from_concrete(page)?)?;
// TODO
// Undo that fake activity

10
server/src/apub/user.rs

@ -21,9 +21,9 @@ use activitystreams::{
actor::{properties::ApActorProperties, Person},
context,
endpoint::EndpointProperties,
ext::Extensible,
object::{properties::ObjectProperties, Tombstone},
};
use activitystreams_ext::Ext2;
use actix_web::{body::Body, web::Path, HttpResponse, Result};
use diesel::PgConnection;
use failure::Error;
@ -70,7 +70,7 @@ impl ToApub for User_ {
.set_following(self.get_following_url())?
.set_liked(self.get_liked_url())?;
Ok(person.extend(actor_props).extend(self.get_public_key_ext()))
Ok(Ext2::new(person, actor_props, self.get_public_key_ext()))
}
fn to_tombstone(&self) -> Result<Tombstone, Error> {
unimplemented!()
@ -177,9 +177,9 @@ impl FromApub for UserForm {
type ApubType = PersonExt;
/// Parse an ActivityPub person received from another instance into a Lemmy user.
fn from_apub(person: &PersonExt, _conn: &PgConnection) -> Result<Self, Error> {
let oprops = &person.base.base.object_props;
let aprops = &person.base.extension;
let public_key: &PublicKey = &person.extension.public_key;
let oprops = &person.inner.object_props;
let aprops = &person.ext_one;
let public_key: &PublicKey = &person.ext_two.public_key;
Ok(UserForm {
name: oprops.get_name_xsd_string().unwrap().to_string(),

Loading…
Cancel
Save