Remove useless functions from activity_pub::actor::Actor
This commit is contained in:
parent
7812b9bc8f
commit
606a3d12c7
|
@ -1,44 +1,15 @@
|
|||
use diesel::PgConnection;
|
||||
use serde_json;
|
||||
|
||||
use activity_pub::ap_url;
|
||||
use models::instance::Instance;
|
||||
|
||||
pub enum ActorType {
|
||||
Person,
|
||||
Blog
|
||||
}
|
||||
|
||||
impl ToString for ActorType {
|
||||
fn to_string(&self) -> String {
|
||||
String::from(match self {
|
||||
ActorType::Person => "Person",
|
||||
ActorType::Blog => "Blog"
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Actor: Sized {
|
||||
fn get_box_prefix() -> &'static str;
|
||||
|
||||
fn get_actor_id(&self) -> String;
|
||||
|
||||
fn get_display_name(&self) -> String;
|
||||
|
||||
fn get_summary(&self) -> String;
|
||||
|
||||
fn get_instance(&self, conn: &PgConnection) -> Instance;
|
||||
|
||||
fn get_actor_type() -> ActorType;
|
||||
|
||||
fn get_inbox_url(&self) -> String;
|
||||
|
||||
fn get_shared_inbox_url(&self) -> Option<String>;
|
||||
|
||||
fn custom_props(&self, _conn: &PgConnection) -> serde_json::Map<String, serde_json::Value> {
|
||||
serde_json::Map::new()
|
||||
}
|
||||
|
||||
fn compute_outbox(&self, conn: &PgConnection) -> String {
|
||||
self.compute_box(conn, "outbox")
|
||||
}
|
||||
|
@ -59,6 +30,4 @@ pub trait Actor: Sized {
|
|||
user = self.get_actor_id()
|
||||
))
|
||||
}
|
||||
|
||||
fn from_url(conn: &PgConnection, url: String) -> Option<Self>;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ use webfinger::*;
|
|||
|
||||
use activity_pub::{
|
||||
ActivityStream, Id, IntoId,
|
||||
actor::{Actor as APActor, ActorType},
|
||||
actor::{Actor as APActor},
|
||||
inbox::WithInbox,
|
||||
sign
|
||||
};
|
||||
|
@ -199,6 +199,15 @@ impl Blog {
|
|||
]
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: see User::from_url for correct behavior
|
||||
pub fn from_url(conn: &PgConnection, url: String) -> Option<Blog> {
|
||||
blogs::table.filter(blogs::ap_url.eq(url))
|
||||
.limit(1)
|
||||
.load::<Blog>(conn)
|
||||
.expect("Error loading blog from url")
|
||||
.into_iter().nth(0)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoId for Blog {
|
||||
|
@ -229,37 +238,9 @@ impl APActor for Blog {
|
|||
self.actor_id.to_string()
|
||||
}
|
||||
|
||||
fn get_display_name(&self) -> String {
|
||||
self.title.clone()
|
||||
}
|
||||
|
||||
fn get_summary(&self) -> String {
|
||||
self.summary.clone()
|
||||
}
|
||||
|
||||
fn get_instance(&self, conn: &PgConnection) -> Instance {
|
||||
Instance::get(conn, self.instance_id).unwrap()
|
||||
}
|
||||
|
||||
fn get_actor_type () -> ActorType {
|
||||
ActorType::Blog
|
||||
}
|
||||
|
||||
fn get_inbox_url(&self) -> String {
|
||||
self.inbox_url.clone()
|
||||
}
|
||||
|
||||
fn get_shared_inbox_url(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
|
||||
fn from_url(conn: &PgConnection, url: String) -> Option<Blog> {
|
||||
blogs::table.filter(blogs::ap_url.eq(url))
|
||||
.limit(1)
|
||||
.load::<Blog>(conn)
|
||||
.expect("Error loading blog from url")
|
||||
.into_iter().nth(0)
|
||||
}
|
||||
}
|
||||
|
||||
impl sign::Signer for Blog {
|
||||
|
|
|
@ -9,7 +9,6 @@ use serde_json;
|
|||
|
||||
use activity_pub::{
|
||||
ap_url, Id, IntoId, PUBLIC_VISIBILTY,
|
||||
actor::Actor,
|
||||
inbox::{FromActivity, Notify}
|
||||
};
|
||||
use models::{
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use activitypub::{Actor, activity::{Accept, Follow as FollowAct}};
|
||||
use diesel::{self, PgConnection, ExpressionMethods, QueryDsl, RunQueryDsl};
|
||||
|
||||
use activity_pub::{broadcast, Id, IntoId, actor::Actor as ApActor, inbox::{FromActivity, Notify, WithInbox}, sign::Signer};
|
||||
use activity_pub::{broadcast, Id, IntoId, inbox::{FromActivity, Notify, WithInbox}, sign::Signer};
|
||||
use models::{
|
||||
blogs::Blog,
|
||||
notifications::*,
|
||||
|
|
|
@ -5,7 +5,6 @@ use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
|||
use activity_pub::{
|
||||
Id,
|
||||
IntoId,
|
||||
actor::Actor,
|
||||
inbox::{FromActivity, Deletable, Notify}
|
||||
};
|
||||
use models::{
|
||||
|
|
|
@ -2,7 +2,7 @@ use activitypub::activity::{Announce, Undo};
|
|||
use chrono::NaiveDateTime;
|
||||
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||
|
||||
use activity_pub::{Id, IntoId, actor::Actor, inbox::{FromActivity, Notify, Deletable}};
|
||||
use activity_pub::{Id, IntoId, inbox::{FromActivity, Notify, Deletable}};
|
||||
use models::{notifications::*, posts::Post, users::User};
|
||||
use schema::reshares;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ use webfinger::*;
|
|||
use BASE_URL;
|
||||
use activity_pub::{
|
||||
ap_url, ActivityStream, Id, IntoId,
|
||||
actor::{ActorType, Actor as APActor},
|
||||
actor::{Actor as APActor},
|
||||
inbox::{Inbox, WithInbox},
|
||||
sign::{Signer, gen_keypair}
|
||||
};
|
||||
|
@ -308,8 +308,8 @@ impl User {
|
|||
pub fn into_activity(&self, _conn: &PgConnection) -> Person {
|
||||
let mut actor = Person::default();
|
||||
actor.object_props.set_id_string(self.ap_url.clone()).expect("User::into_activity: id error");
|
||||
actor.object_props.set_name_string(self.get_display_name()).expect("User::into_activity: name error");
|
||||
actor.object_props.set_summary_string(self.get_summary()).expect("User::into_activity: summary error");
|
||||
actor.object_props.set_name_string(self.display_name.clone()).expect("User::into_activity: name error");
|
||||
actor.object_props.set_summary_string(self.summary.get().clone()).expect("User::into_activity: summary error");
|
||||
actor.object_props.set_url_string(self.ap_url.clone()).expect("User::into_activity: url error");
|
||||
actor.ap_actor_props.set_inbox_string(self.inbox_url.clone()).expect("User::into_activity: inbox error");
|
||||
actor.ap_actor_props.set_outbox_string(self.outbox_url.clone()).expect("User::into_activity: outbox error");
|
||||
|
@ -350,6 +350,18 @@ impl User {
|
|||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_url(conn: &PgConnection, url: String) -> Option<User> {
|
||||
User::find_by_ap_url(conn, url.clone()).or_else(|| {
|
||||
// The requested user was not in the DB
|
||||
// We try to fetch it if it is remote
|
||||
if Url::parse(url.as_ref()).unwrap().host_str().unwrap() != BASE_URL.as_str() {
|
||||
Some(User::fetch_from_url(conn, url).unwrap())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'r> FromRequest<'a, 'r> for User {
|
||||
|
@ -374,52 +386,9 @@ impl APActor for User {
|
|||
self.username.to_string()
|
||||
}
|
||||
|
||||
fn get_display_name(&self) -> String {
|
||||
self.display_name.clone()
|
||||
}
|
||||
|
||||
fn get_summary(&self) -> String {
|
||||
self.summary.get().clone()
|
||||
}
|
||||
|
||||
fn get_instance(&self, conn: &PgConnection) -> Instance {
|
||||
Instance::get(conn, self.instance_id).unwrap()
|
||||
}
|
||||
|
||||
fn get_actor_type() -> ActorType {
|
||||
ActorType::Person
|
||||
}
|
||||
|
||||
fn get_inbox_url(&self) -> String {
|
||||
self.inbox_url.clone()
|
||||
}
|
||||
|
||||
fn get_shared_inbox_url(&self) -> Option<String> {
|
||||
self.shared_inbox_url.clone()
|
||||
}
|
||||
|
||||
fn custom_props(&self, conn: &PgConnection) -> serde_json::Map<String, serde_json::Value> {
|
||||
let mut res = serde_json::Map::new();
|
||||
res.insert("publicKey".to_string(), json!({
|
||||
"id": self.get_key_id(),
|
||||
"owner": self.ap_url,
|
||||
"publicKeyPem": self.public_key
|
||||
}));
|
||||
res.insert("followers".to_string(), serde_json::Value::String(self.compute_box(conn, "followers")));
|
||||
res
|
||||
}
|
||||
|
||||
fn from_url(conn: &PgConnection, url: String) -> Option<User> {
|
||||
User::find_by_ap_url(conn, url.clone()).or_else(|| {
|
||||
// The requested user was not in the DB
|
||||
// We try to fetch it if it is remote
|
||||
if Url::parse(url.as_ref()).unwrap().host_str().unwrap() != BASE_URL.as_str() {
|
||||
Some(User::fetch_from_url(conn, url).unwrap())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoId for User {
|
||||
|
|
Loading…
Reference in New Issue