Local timeline
This commit is contained in:
parent
adcfd88471
commit
babb3a81f5
@ -113,6 +113,7 @@ impl Post {
|
|||||||
.expect("Error loading a page of posts for blog")
|
.expect("Error loading a page of posts for blog")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Give a page of all the recent posts known to this instance (= federated timeline)
|
||||||
pub fn get_recents_page(conn: &PgConnection, (min, max): (i32, i32)) -> Vec<Post> {
|
pub fn get_recents_page(conn: &PgConnection, (min, max): (i32, i32)) -> Vec<Post> {
|
||||||
posts::table.order(posts::creation_date.desc())
|
posts::table.order(posts::creation_date.desc())
|
||||||
.offset(min.into())
|
.offset(min.into())
|
||||||
@ -121,6 +122,20 @@ impl Post {
|
|||||||
.expect("Error loading recent posts page")
|
.expect("Error loading recent posts page")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Give a page of posts from a specific instance
|
||||||
|
pub fn get_instance_page(conn: &PgConnection, instance_id: i32, (min, max): (i32, i32)) -> Vec<Post> {
|
||||||
|
use schema::blogs;
|
||||||
|
|
||||||
|
let blog_ids = blogs::table.filter(blogs::instance_id.eq(instance_id)).select(blogs::id);
|
||||||
|
|
||||||
|
posts::table.order(posts::creation_date.desc())
|
||||||
|
.filter(posts::blog_id.eq(any(blog_ids)))
|
||||||
|
.offset(min.into())
|
||||||
|
.limit((max - min).into())
|
||||||
|
.load::<Post>(conn)
|
||||||
|
.expect("Error loading local posts page")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_authors(&self, conn: &PgConnection) -> Vec<User> {
|
pub fn get_authors(&self, conn: &PgConnection) -> Vec<User> {
|
||||||
use schema::users;
|
use schema::users;
|
||||||
use schema::post_authors;
|
use schema::post_authors;
|
||||||
|
@ -57,6 +57,8 @@ fn main() {
|
|||||||
|
|
||||||
routes::instance::paginated_index,
|
routes::instance::paginated_index,
|
||||||
routes::instance::index,
|
routes::instance::index,
|
||||||
|
routes::instance::paginated_local,
|
||||||
|
routes::instance::local,
|
||||||
routes::instance::admin,
|
routes::instance::admin,
|
||||||
routes::instance::update_settings,
|
routes::instance::update_settings,
|
||||||
routes::instance::shared_inbox,
|
routes::instance::shared_inbox,
|
||||||
|
@ -44,6 +44,24 @@ fn index(conn: DbConn, user: Option<User>) -> Template {
|
|||||||
paginated_index(conn, user, Page::first())
|
paginated_index(conn, user, Page::first())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/local?<page>")]
|
||||||
|
fn paginated_local(conn: DbConn, user: Option<User>, page: Page) -> Template {
|
||||||
|
let instance = Instance::get_local(&*conn).unwrap();
|
||||||
|
let articles = Post::get_instance_page(&*conn, instance.id, page.limits());
|
||||||
|
Template::render("instance/local", json!({
|
||||||
|
"account": user.map(|u| u.to_json(&*conn)),
|
||||||
|
"instance": instance,
|
||||||
|
"page": page.page,
|
||||||
|
"n_pages": Page::total(Post::count_local(&*conn) as i32),
|
||||||
|
"articles": articles.into_iter().map(|p| p.to_json(&*conn)).collect::<Vec<serde_json::Value>>()
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/local")]
|
||||||
|
fn local(conn: DbConn, user: Option<User>) -> Template {
|
||||||
|
paginated_local(conn, user, Page::first())
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/admin")]
|
#[get("/admin")]
|
||||||
fn admin(conn: DbConn, admin: Admin) -> Template {
|
fn admin(conn: DbConn, admin: Admin) -> Template {
|
||||||
Template::render("instance/admin", json!({
|
Template::render("instance/admin", json!({
|
||||||
|
17
templates/instance/local.html.tera
Normal file
17
templates/instance/local.html.tera
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{% extends "base" %}
|
||||||
|
{% import "macros" as macros %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{{ "Articles from {{ instance.name }}" | _(instance=instance) }}
|
||||||
|
{% endblock title %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>{{ "Articles from {{ instance.name }}" | _(instance=instance) }}</h1>
|
||||||
|
|
||||||
|
<div class="cards">
|
||||||
|
{% for article in articles %}
|
||||||
|
{{ macros::post_card(article=article) }}
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{{ macros::paginate(page=page, total=n_pages) }}
|
||||||
|
{% endblock content %}
|
Loading…
Reference in New Issue
Block a user