Get rid of the legacy activity_pub::object module
This commit is contained in:
parent
65e819c425
commit
ab7bef1490
@ -14,7 +14,6 @@ use self::sign::Signable;
|
|||||||
|
|
||||||
pub mod actor;
|
pub mod actor;
|
||||||
pub mod inbox;
|
pub mod inbox;
|
||||||
pub mod object;
|
|
||||||
pub mod request;
|
pub mod request;
|
||||||
pub mod sign;
|
pub mod sign;
|
||||||
|
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
use diesel::PgConnection;
|
|
||||||
use serde_json;
|
|
||||||
|
|
||||||
pub trait Object {
|
|
||||||
fn serialize(&self, conn: &PgConnection) -> serde_json::Value;
|
|
||||||
|
|
||||||
fn compute_id(&self, conn: &PgConnection) -> String;
|
|
||||||
}
|
|
@ -9,8 +9,7 @@ use serde_json;
|
|||||||
use activity_pub::{
|
use activity_pub::{
|
||||||
ap_url, Id, IntoId, PUBLIC_VISIBILTY,
|
ap_url, Id, IntoId, PUBLIC_VISIBILTY,
|
||||||
actor::Actor,
|
actor::Actor,
|
||||||
inbox::{FromActivity, Notify},
|
inbox::{FromActivity, Notify}
|
||||||
object::Object
|
|
||||||
};
|
};
|
||||||
use models::{
|
use models::{
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
@ -105,6 +104,10 @@ impl Comment {
|
|||||||
json["author"] = self.get_author(conn).to_json(conn);
|
json["author"] = self.get_author(conn).to_json(conn);
|
||||||
json
|
json
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn compute_id(&self, conn: &PgConnection) -> String {
|
||||||
|
ap_url(format!("{}#comment-{}", self.get_post(conn).compute_id(conn), self.id))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromActivity<Note> for Comment {
|
impl FromActivity<Note> for Comment {
|
||||||
@ -146,31 +149,3 @@ impl Notify<Note> for Comment {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object for Comment {
|
|
||||||
fn serialize(&self, conn: &PgConnection) -> serde_json::Value {
|
|
||||||
let mut to = self.get_author(conn).get_followers(conn).into_iter().map(|f| f.ap_url).collect::<Vec<String>>();
|
|
||||||
to.append(&mut self.get_post(conn).get_receivers_urls(conn));
|
|
||||||
to.push(PUBLIC_VISIBILTY.to_string());
|
|
||||||
|
|
||||||
json!({
|
|
||||||
"id": self.compute_id(conn),
|
|
||||||
"type": "Note",
|
|
||||||
"summary": self.spoiler_text,
|
|
||||||
"content": self.content,
|
|
||||||
"inReplyTo": self.in_response_to_id.map_or_else(|| self.get_post(conn).ap_url, |id| {
|
|
||||||
let comm = Comment::get(conn, id).unwrap();
|
|
||||||
comm.ap_url.clone().unwrap_or(comm.compute_id(conn))
|
|
||||||
}),
|
|
||||||
"published": self.creation_date,
|
|
||||||
"attributedTo": self.get_author(conn).compute_id(conn),
|
|
||||||
"to": to,
|
|
||||||
"cc": [],
|
|
||||||
"sensitive": self.sensitive,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compute_id(&self, conn: &PgConnection) -> String {
|
|
||||||
ap_url(format!("{}#comment-{}", self.get_post(conn).compute_id(conn), self.id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
use activitypub::activity;
|
use activitypub::activity;
|
||||||
use chrono;
|
use chrono;
|
||||||
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||||
use serde_json;
|
|
||||||
|
|
||||||
use activity_pub::{
|
use activity_pub::{
|
||||||
Id,
|
Id,
|
||||||
IntoId,
|
IntoId,
|
||||||
actor::Actor,
|
actor::Actor,
|
||||||
inbox::{FromActivity, Deletable, Notify},
|
inbox::{FromActivity, Deletable, Notify}
|
||||||
object::Object
|
|
||||||
};
|
};
|
||||||
use models::{
|
use models::{
|
||||||
notifications::*,
|
notifications::*,
|
||||||
@ -68,6 +66,14 @@ impl Like {
|
|||||||
|
|
||||||
act
|
act
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn compute_id(&self, conn: &PgConnection) -> String {
|
||||||
|
format!(
|
||||||
|
"{}/like/{}",
|
||||||
|
User::get(conn, self.user_id).unwrap().compute_id(conn),
|
||||||
|
Post::get(conn, self.post_id).unwrap().compute_id(conn)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromActivity<activity::Like> for Like {
|
impl FromActivity<activity::Like> for Like {
|
||||||
@ -111,19 +117,3 @@ impl Deletable for Like {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object for Like {
|
|
||||||
fn serialize(&self, conn: &PgConnection) -> serde_json::Value {
|
|
||||||
json!({
|
|
||||||
"id": self.compute_id(conn)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn compute_id(&self, conn: &PgConnection) -> String {
|
|
||||||
format!(
|
|
||||||
"{}/like/{}",
|
|
||||||
User::get(conn, self.user_id).unwrap().compute_id(conn),
|
|
||||||
Post::get(conn, self.post_id).unwrap().compute_id(conn)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -10,8 +10,7 @@ use BASE_URL;
|
|||||||
use activity_pub::{
|
use activity_pub::{
|
||||||
PUBLIC_VISIBILTY, ap_url, Id, IntoId,
|
PUBLIC_VISIBILTY, ap_url, Id, IntoId,
|
||||||
actor::Actor,
|
actor::Actor,
|
||||||
inbox::FromActivity,
|
inbox::FromActivity
|
||||||
object::Object
|
|
||||||
};
|
};
|
||||||
use models::{
|
use models::{
|
||||||
blogs::Blog,
|
blogs::Blog,
|
||||||
@ -177,6 +176,10 @@ impl Post {
|
|||||||
"date": self.creation_date.timestamp()
|
"date": self.creation_date.timestamp()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn compute_id(&self, conn: &PgConnection) -> String {
|
||||||
|
ap_url(format!("{}/~/{}/{}/", BASE_URL.as_str(), self.get_blog(conn).actor_id, self.slug))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromActivity<Article> for Post {
|
impl FromActivity<Article> for Post {
|
||||||
@ -198,33 +201,3 @@ impl IntoId for Post {
|
|||||||
Id::new(self.ap_url.clone())
|
Id::new(self.ap_url.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Object for Post {
|
|
||||||
fn compute_id(&self, conn: &PgConnection) -> String {
|
|
||||||
ap_url(format!("{}/~/{}/{}/", BASE_URL.as_str(), self.get_blog(conn).actor_id, self.slug))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn serialize(&self, conn: &PgConnection) -> serde_json::Value {
|
|
||||||
let mut to = self.get_receivers_urls(conn);
|
|
||||||
to.push(PUBLIC_VISIBILTY.to_string());
|
|
||||||
|
|
||||||
json!({
|
|
||||||
"type": "Article",
|
|
||||||
"id": self.compute_id(conn),
|
|
||||||
"attributedTo": self.get_authors(conn)[0].compute_id(conn),
|
|
||||||
"name": self.title,
|
|
||||||
"content": self.content,
|
|
||||||
"actor": self.get_authors(conn)[0].compute_id(conn),
|
|
||||||
"published": self.creation_date,
|
|
||||||
// TODO: "image": "image",
|
|
||||||
// TODO: "preview": "preview",
|
|
||||||
// TODO: "replies": "replies",
|
|
||||||
// TODO: "summary": "summary",
|
|
||||||
"tag": [],
|
|
||||||
// TODO: "updated": "updated",
|
|
||||||
"url": self.compute_id(conn),
|
|
||||||
"to": to,
|
|
||||||
"cc": []
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -2,7 +2,7 @@ use activitypub::activity::{Announce, Undo};
|
|||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||||
|
|
||||||
use activity_pub::{Id, IntoId, actor::Actor, inbox::{FromActivity, Notify, Deletable}, object::Object};
|
use activity_pub::{Id, IntoId, actor::Actor, inbox::{FromActivity, Notify, Deletable}};
|
||||||
use models::{notifications::*, posts::Post, users::User};
|
use models::{notifications::*, posts::Post, users::User};
|
||||||
use schema::reshares;
|
use schema::reshares;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ use rocket::response::{Redirect, Flash};
|
|||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
|
||||||
use activity_pub::{broadcast, context, activity_pub, ActivityPub, object::Object};
|
use activity_pub::{broadcast, context, activity_pub, ActivityPub};
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::{
|
use models::{
|
||||||
blogs::*,
|
blogs::*,
|
||||||
@ -44,7 +44,7 @@ fn activity_details(blog: String, slug: String, conn: DbConn) -> ActivityPub {
|
|||||||
let blog = Blog::find_by_fqn(&*conn, blog).unwrap();
|
let blog = Blog::find_by_fqn(&*conn, blog).unwrap();
|
||||||
let post = Post::find_by_slug(&*conn, slug, blog.id).unwrap();
|
let post = Post::find_by_slug(&*conn, slug, blog.id).unwrap();
|
||||||
|
|
||||||
let mut act = post.serialize(&*conn);
|
let mut act = serde_json::to_value(post.into_activity(&*conn)).unwrap();
|
||||||
act["@context"] = context();
|
act["@context"] = context();
|
||||||
activity_pub(act)
|
activity_pub(act)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user