Use the activitypub crate
This commit is contained in:
+1
-2
@@ -1,5 +1,4 @@
|
||||
use activitystreams_traits::{Actor, Object};
|
||||
use activitystreams_types::collection::OrderedCollection;
|
||||
use activitypub::{Actor, Object, collection::OrderedCollection};
|
||||
use reqwest::{
|
||||
Client,
|
||||
header::{Accept, qitem},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use activitystreams_types::{
|
||||
use activitypub::{
|
||||
activity::Create,
|
||||
object::{Note, properties::ObjectProperties}
|
||||
};
|
||||
@@ -105,8 +105,8 @@ impl Comment {
|
||||
|
||||
pub fn create_activity(&self, conn: &PgConnection) -> Create {
|
||||
let mut act = Create::default();
|
||||
act.set_actor_link(self.get_author(conn).into_id()).unwrap();
|
||||
act.set_object_object(self.into_activity(conn)).unwrap();
|
||||
act.create_props.set_actor_link(self.get_author(conn).into_id()).unwrap();
|
||||
act.create_props.set_object_object(self.into_activity(conn)).unwrap();
|
||||
act.object_props.set_id_string(format!("{}/activity", self.ap_url.clone().unwrap())).unwrap();
|
||||
act
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
use activitystreams_types::activity;
|
||||
use activitypub::activity;
|
||||
use chrono;
|
||||
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||
use serde_json;
|
||||
@@ -76,15 +76,15 @@ impl Like {
|
||||
diesel::delete(self).execute(conn).unwrap();
|
||||
|
||||
let mut act = activity::Undo::default();
|
||||
act.set_actor_link(User::get(conn, self.user_id).unwrap().into_id()).unwrap();
|
||||
act.set_object_object(self.into_activity(conn)).unwrap();
|
||||
act.undo_props.set_actor_link(User::get(conn, self.user_id).unwrap().into_id()).unwrap();
|
||||
act.undo_props.set_object_object(self.into_activity(conn)).unwrap();
|
||||
act
|
||||
}
|
||||
|
||||
pub fn into_activity(&self, conn: &PgConnection) -> activity::Like {
|
||||
let mut act = activity::Like::default();
|
||||
act.set_actor_link(User::get(conn, self.user_id).unwrap().into_id()).unwrap();
|
||||
act.set_object_link(Post::get(conn, self.post_id).unwrap().into_id()).unwrap();
|
||||
act.like_props.set_actor_link(User::get(conn, self.user_id).unwrap().into_id()).unwrap();
|
||||
act.like_props.set_object_link(Post::get(conn, self.post_id).unwrap().into_id()).unwrap();
|
||||
act.object_props.set_id_string(format!("{}/like/{}",
|
||||
User::get(conn, self.user_id).unwrap().ap_url,
|
||||
Post::get(conn, self.post_id).unwrap().ap_url
|
||||
|
||||
+4
-6
@@ -1,7 +1,5 @@
|
||||
use activitystreams_types::{
|
||||
activity::Create,
|
||||
object::{Article, properties::ObjectProperties}
|
||||
};
|
||||
use activitypub::activity::Create;
|
||||
use activitystreams_types::object::{Article, properties::ObjectProperties};
|
||||
use chrono::NaiveDateTime;
|
||||
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods, BelongingToDsl};
|
||||
use diesel::dsl::any;
|
||||
@@ -177,8 +175,8 @@ impl Post {
|
||||
pub fn create_activity(&self, conn: &PgConnection) -> Create {
|
||||
let mut act = Create::default();
|
||||
act.object_props.set_id_string(format!("{}/activity", self.ap_url)).unwrap();
|
||||
act.set_actor_link(Id::new(self.get_authors(conn)[0].clone().ap_url)).unwrap();
|
||||
act.set_object_object(self.into_activity(conn)).unwrap();
|
||||
act.create_props.set_actor_link(Id::new(self.get_authors(conn)[0].clone().ap_url)).unwrap();
|
||||
act.create_props.set_object_object(self.into_activity(conn)).unwrap();
|
||||
act
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use activitystreams_types::activity;
|
||||
use activitypub::activity;
|
||||
use chrono::NaiveDateTime;
|
||||
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||
|
||||
@@ -84,15 +84,15 @@ impl Reshare {
|
||||
diesel::delete(self).execute(conn).unwrap();
|
||||
|
||||
let mut act = activity::Undo::default();
|
||||
act.set_actor_link(User::get(conn, self.user_id).unwrap().into_id()).unwrap();
|
||||
act.set_object_object(self.into_activity(conn)).unwrap();
|
||||
act.undo_props.set_actor_link(User::get(conn, self.user_id).unwrap().into_id()).unwrap();
|
||||
act.undo_props.set_object_object(self.into_activity(conn)).unwrap();
|
||||
act
|
||||
}
|
||||
|
||||
pub fn into_activity(&self, conn: &PgConnection) -> activity::Announce {
|
||||
let mut act = activity::Announce::default();
|
||||
act.set_actor_link(User::get(conn, self.user_id).unwrap().into_id()).unwrap();
|
||||
act.set_object_link(Post::get(conn, self.post_id).unwrap().into_id()).unwrap();
|
||||
act.announce_props.set_actor_link(User::get(conn, self.user_id).unwrap().into_id()).unwrap();
|
||||
act.announce_props.set_object_link(Post::get(conn, self.post_id).unwrap().into_id()).unwrap();
|
||||
act.object_props.set_id_string(self.ap_url.clone()).unwrap();
|
||||
|
||||
act
|
||||
|
||||
+15
-28
@@ -1,9 +1,8 @@
|
||||
use activitystreams_traits::{Actor, Object, Link};
|
||||
use activitystreams_types::{
|
||||
actor::Person,
|
||||
use activitypub::{
|
||||
Actor, Object,
|
||||
actor::{Person, properties::ApActorProperties},
|
||||
collection::OrderedCollection,
|
||||
object::properties::ObjectProperties,
|
||||
CustomObject
|
||||
object::properties::ObjectProperties
|
||||
};
|
||||
use bcrypt;
|
||||
use chrono::NaiveDateTime;
|
||||
@@ -302,7 +301,7 @@ impl User {
|
||||
PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.clone().unwrap().as_ref()).unwrap()).unwrap()
|
||||
}
|
||||
|
||||
pub fn into_activity(&self, conn: &PgConnection) -> CustomObject<ApProps, Person> {
|
||||
pub fn into_activity(&self, conn: &PgConnection) -> Person {
|
||||
let mut actor = Person::default();
|
||||
actor.object_props = ObjectProperties {
|
||||
id: Some(serde_json::to_value(self.compute_id(conn)).unwrap()),
|
||||
@@ -311,34 +310,22 @@ impl User {
|
||||
url: Some(serde_json::to_value(self.compute_id(conn)).unwrap()),
|
||||
..ObjectProperties::default()
|
||||
};
|
||||
|
||||
CustomObject::new(actor, ApProps {
|
||||
inbox: Some(serde_json::to_value(self.compute_inbox(conn)).unwrap()),
|
||||
outbox: Some(serde_json::to_value(self.compute_outbox(conn)).unwrap()),
|
||||
actor.ap_actor_props = ApActorProperties {
|
||||
inbox: serde_json::to_value(self.compute_inbox(conn)).unwrap(),
|
||||
outbox: serde_json::to_value(self.compute_outbox(conn)).unwrap(),
|
||||
preferred_username: Some(serde_json::to_value(self.get_actor_id()).unwrap()),
|
||||
endpoints: Some(json!({
|
||||
"sharedInbox": ap_url(format!("{}/inbox", BASE_URL.as_str()))
|
||||
}))
|
||||
})
|
||||
})),
|
||||
followers: None,
|
||||
following: None,
|
||||
liked: None,
|
||||
streams: None
|
||||
};
|
||||
actor
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Default, Properties)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ApProps {
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
inbox: Option<serde_json::Value>,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
outbox: Option<serde_json::Value>,
|
||||
|
||||
#[activitystreams(ab(Object, Link))]
|
||||
preferred_username: Option<serde_json::Value>,
|
||||
|
||||
#[activitystreams(ab(Object))]
|
||||
endpoints: Option<serde_json::Value>
|
||||
}
|
||||
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for User {
|
||||
type Error = ();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user