Start filling user outbox
This commit is contained in:
@@ -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!({})
|
||||
}
|
||||
}
|
||||
|
||||
+11
-4
@@ -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>>()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user