Start filling user outbox
This commit is contained in:
parent
dd9e845e66
commit
bde25478e5
|
@ -1,26 +1,38 @@
|
|||
use diesel::PgConnection;
|
||||
use serde_json;
|
||||
|
||||
use activity_pub::actor::Actor;
|
||||
use activity_pub::object::Object;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Activity {}
|
||||
pub enum Activity {
|
||||
Create(CreatePayload)
|
||||
}
|
||||
impl Activity {
|
||||
pub fn serialize(&self) -> serde_json::Value {
|
||||
json!({})
|
||||
match self {
|
||||
Activity::Create(data) => json!({
|
||||
"type": "Create",
|
||||
"by": data.by,
|
||||
"object": data.object
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create<T: Object, U: Actor>(by: &U, obj: T, conn: &PgConnection) -> Activity {
|
||||
Activity::Create(CreatePayload::new(serde_json::Value::String(by.compute_id(conn)), obj.serialize()))
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct Create<'a, T, U> where T: Actor + 'static, U: Object {
|
||||
by: &'a T,
|
||||
object: U
|
||||
#[derive(Clone)]
|
||||
pub struct CreatePayload {
|
||||
by: serde_json::Value,
|
||||
object: serde_json::Value
|
||||
}
|
||||
|
||||
impl<'a, T: Actor, U: Object> Create<'a, T, U> {
|
||||
#[allow(dead_code)]
|
||||
pub fn new(by: &T, obj: U) -> Create<T, U> {
|
||||
Create {
|
||||
impl CreatePayload {
|
||||
pub fn new(by: serde_json::Value, obj: serde_json::Value) -> CreatePayload {
|
||||
CreatePayload {
|
||||
by: by,
|
||||
object: obj
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use diesel::PgConnection;
|
||||
|
||||
use activity_pub::{activity_pub, ActivityPub, context};
|
||||
use activity_pub::activity::Create;
|
||||
// use activity_pub::activity::Create;
|
||||
use activity_pub::object::{Attribuable, Object};
|
||||
use models::instance::Instance;
|
||||
|
||||
|
@ -66,8 +66,8 @@ pub trait Actor {
|
|||
)
|
||||
}
|
||||
|
||||
fn create<T>(&self, obj: T) -> Create<Self, T> where T: Object + Attribuable, Self: Actor + Sized {
|
||||
obj.set_attribution::<Self>(self);
|
||||
Create::<Self, T>::new(self, obj)
|
||||
}
|
||||
// fn create<T>(&self, obj: T) -> Create<Self, T> where T: Object + Attribuable, Self: Actor + Sized {
|
||||
// obj.set_attribution::<Self>(self);
|
||||
// Create::<Self, T>::new(self, obj)
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
use serde_json;
|
||||
|
||||
use activity_pub::actor::Actor;
|
||||
|
||||
pub trait Object {}
|
||||
pub trait Object {
|
||||
fn serialize(&self) -> serde_json::Value;
|
||||
}
|
||||
|
||||
pub trait Attribuable {
|
||||
fn set_attribution<T>(&self, by: &T) where T: Actor;
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
use diesel::{self, PgConnection, QueryDsl, RunQueryDsl, ExpressionMethods};
|
||||
|
||||
use models::posts::Post;
|
||||
use models::users::User;
|
||||
use schema::post_authors;
|
||||
|
||||
#[derive(Queryable, Identifiable)]
|
||||
#[derive(Queryable, Identifiable, Associations)]
|
||||
#[belongs_to(Post)]
|
||||
#[belongs_to(User, foreign_key = "author_id")]
|
||||
pub struct PostAuthor {
|
||||
pub id: i32,
|
||||
pub post_id: i32,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
|
||||
use serde_json;
|
||||
|
||||
use activity_pub::object::Object;
|
||||
use schema::posts;
|
||||
|
||||
#[derive(Queryable, Identifiable)]
|
||||
|
@ -48,3 +50,9 @@ impl Post {
|
|||
.into_iter().nth(0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Post {
|
||||
fn serialize(&self) -> serde_json::Value {
|
||||
json!({})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use bcrypt;
|
||||
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
||||
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, BelongingToDsl, PgConnection};
|
||||
use diesel::dsl::any;
|
||||
use rocket::request::{self, FromRequest, Request};
|
||||
use rocket::outcome::IntoOutcome;
|
||||
|
||||
|
@ -9,6 +10,8 @@ use activity_pub::outbox::Outbox;
|
|||
use activity_pub::webfinger::Webfinger;
|
||||
use db_conn::DbConn;
|
||||
use models::instance::Instance;
|
||||
use models::post_authors::PostAuthor;
|
||||
use models::posts::Post;
|
||||
use schema::users;
|
||||
|
||||
pub const AUTH_COOKIE: &'static str = "user_id";
|
||||
|
@ -98,11 +101,15 @@ impl User {
|
|||
}
|
||||
|
||||
pub fn outbox(&self, conn: &PgConnection) -> Outbox {
|
||||
Outbox::new(self.compute_outbox(conn), self.get_activities())
|
||||
Outbox::new(self.compute_outbox(conn), self.get_activities(conn))
|
||||
}
|
||||
|
||||
fn get_activities(&self) -> Vec<Activity> {
|
||||
vec![]
|
||||
fn get_activities(&self, conn: &PgConnection) -> Vec<Activity> {
|
||||
use schema::posts;
|
||||
use schema::post_authors;
|
||||
let posts_by_self = PostAuthor::belonging_to(self).select(post_authors::post_id);
|
||||
let posts = posts::table.filter(posts::id.eq(any(posts_by_self))).load::<Post>(conn).unwrap();
|
||||
posts.into_iter().map(|p| Activity::create(self, p, conn)).collect::<Vec<Activity>>()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue