Add NodeInfo endpoints (fixes #11)
This commit is contained in:
+11
-1
@@ -3,7 +3,7 @@ use activitypub::{
|
||||
object::{Note, properties::ObjectProperties}
|
||||
};
|
||||
use chrono;
|
||||
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods};
|
||||
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods, dsl::any};
|
||||
use serde_json;
|
||||
|
||||
use activity_pub::{
|
||||
@@ -12,6 +12,7 @@ use activity_pub::{
|
||||
object::Object
|
||||
};
|
||||
use models::{
|
||||
instance::Instance,
|
||||
posts::Post,
|
||||
users::User
|
||||
};
|
||||
@@ -110,6 +111,15 @@ impl Comment {
|
||||
act.object_props.set_id_string(format!("{}/activity", self.ap_url.clone().unwrap())).unwrap();
|
||||
act
|
||||
}
|
||||
|
||||
pub fn count_local(conn: &PgConnection) -> usize {
|
||||
use schema::users;
|
||||
let local_authors = users::table.filter(users::instance_id.eq(Instance::local_id(conn))).select(users::id);
|
||||
comments::table.filter(comments::author_id.eq(any(local_authors)))
|
||||
.load::<Comment>(conn)
|
||||
.expect("Couldn't load local comments")
|
||||
.len()
|
||||
}
|
||||
}
|
||||
|
||||
impl Object for Comment {
|
||||
|
||||
+13
-2
@@ -1,8 +1,7 @@
|
||||
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;
|
||||
use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods, BelongingToDsl, dsl::any};
|
||||
use serde_json;
|
||||
|
||||
use BASE_URL;
|
||||
@@ -13,6 +12,7 @@ use activity_pub::{
|
||||
};
|
||||
use models::{
|
||||
blogs::Blog,
|
||||
instance::Instance,
|
||||
likes::Like,
|
||||
post_authors::PostAuthor,
|
||||
reshares::Reshare,
|
||||
@@ -61,6 +61,17 @@ impl Post {
|
||||
.into_iter().nth(0)
|
||||
}
|
||||
|
||||
pub fn count_local(conn: &PgConnection) -> usize {
|
||||
use schema::post_authors;
|
||||
use schema::users;
|
||||
let local_authors = users::table.filter(users::instance_id.eq(Instance::local_id(conn))).select(users::id);
|
||||
let local_posts_id = post_authors::table.filter(post_authors::author_id.eq(any(local_authors))).select(post_authors::post_id);
|
||||
posts::table.filter(posts::id.eq(any(local_posts_id)))
|
||||
.load::<Post>(conn)
|
||||
.expect("Couldn't load local posts")
|
||||
.len()
|
||||
}
|
||||
|
||||
pub fn find_by_slug(conn: &PgConnection, slug: String) -> Option<Post> {
|
||||
posts::table.filter(posts::slug.eq(slug))
|
||||
.limit(1)
|
||||
|
||||
@@ -119,6 +119,13 @@ impl User {
|
||||
.into_iter().nth(0)
|
||||
}
|
||||
|
||||
pub fn count_local(conn: &PgConnection) -> usize {
|
||||
users::table.filter(users::instance_id.eq(Instance::local_id(conn)))
|
||||
.load::<User>(conn)
|
||||
.expect("Couldn't load local users")
|
||||
.len()
|
||||
}
|
||||
|
||||
pub fn find_by_email(conn: &PgConnection, email: String) -> Option<User> {
|
||||
users::table.filter(users::email.eq(email))
|
||||
.limit(1)
|
||||
|
||||
Reference in New Issue
Block a user