From b7ea154e510977257dae822d4643cba845a4e196 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Wed, 4 May 2022 21:21:58 +0900 Subject: [PATCH 01/11] Render 404 when page not found --- src/routes/errors.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/routes/errors.rs b/src/routes/errors.rs index 74dc4dd5..8d69d0b5 100644 --- a/src/routes/errors.rs +++ b/src/routes/errors.rs @@ -21,8 +21,9 @@ impl<'r> Responder<'r> for ErrorPage { warn!("{:?}", self.0); match self.0 { - Error::NotFound => Err(Status::NotFound), - Error::Unauthorized => Err(Status::NotFound), + Error::NotFound | Error::Unauthorized | Error::Db(diesel::result::Error::NotFound) => { + Err(Status::NotFound) + } _ => Err(Status::InternalServerError), } } From 712ee30a1f22d63b8bf8c7c3248d66fd5a9ed2f7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 May 2022 19:25:29 +0000 Subject: [PATCH 02/11] Bump openssl from 0.10.38 to 0.10.40 Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.38 to 0.10.40. - [Release notes](https://github.com/sfackler/rust-openssl/releases) - [Commits](https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.38...openssl-v0.10.40) --- updated-dependencies: - dependency-name: openssl dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 20 ++++++++++++++++---- plume-common/Cargo.toml | 2 +- plume-models/Cargo.toml | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51ebe624..0e0fad77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2825,18 +2825,30 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.38" +version = "0.10.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c7ae222234c30df141154f159066c5093ff73b63204dcda7121eb082fc56a95" +checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e" dependencies = [ "bitflags 1.3.2", "cfg-if 1.0.0", "foreign-types", "libc", "once_cell", + "openssl-macros", "openssl-sys", ] +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2 1.0.36", + "quote 1.0.15", + "syn 1.0.92", +] + [[package]] name = "openssl-probe" version = "0.1.5" @@ -2845,9 +2857,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.72" +version = "0.9.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e46109c383602735fa0a2e48dd2b7c892b048e1bf69e5c3b1d804b7d9c203cb" +checksum = "9d5fd19fb3e0a8191c1e34935718976a3e70c112ab9a24af6d7cadccd9d90bc0" dependencies = [ "autocfg 1.0.1", "cc", diff --git a/plume-common/Cargo.toml b/plume-common/Cargo.toml index 32db34d3..b14d41ba 100644 --- a/plume-common/Cargo.toml +++ b/plume-common/Cargo.toml @@ -12,7 +12,7 @@ array_tool = "1.0" base64 = "0.13" heck = "0.4.0" hex = "0.4" -openssl = "0.10.22" +openssl = "0.10.40" rocket = "0.4.6" reqwest = { version = "0.9", features = ["socks"] } serde = "1.0" diff --git a/plume-models/Cargo.toml b/plume-models/Cargo.toml index bb0e8925..925695ed 100644 --- a/plume-models/Cargo.toml +++ b/plume-models/Cargo.toml @@ -13,7 +13,7 @@ itertools = "0.10.3" lazy_static = "1.0" ldap3 = "0.10.4" migrations_internals= "1.4.0" -openssl = "0.10.22" +openssl = "0.10.40" rocket = "0.4.6" rocket_i18n = "0.4.1" reqwest = "0.9" From 853a1db02872182fde5c3b005f2f4b7f24919cb4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 May 2022 19:25:50 +0000 Subject: [PATCH 03/11] Bump serde_json from 1.0.80 to 1.0.81 Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.80 to 1.0.81. - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.80...v1.0.81) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- plume-common/Cargo.toml | 2 +- plume-models/Cargo.toml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 51ebe624..f3a3d6c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4114,9 +4114,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f972498cf015f7c0746cac89ebe1d6ef10c293b94175a243a2d9442c163d9944" +checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" dependencies = [ "itoa 1.0.1", "ryu", diff --git a/Cargo.toml b/Cargo.toml index 72f3b9c9..3244c1d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ rocket_contrib = { version = "0.4.5", features = ["json"] } rocket_i18n = "0.4.1" scheduled-thread-pool = "0.2.2" serde = "1.0" -serde_json = "1.0.80" +serde_json = "1.0.81" shrinkwraprs = "0.3.0" validator = { version = "0.15", features = ["derive"] } webfinger = "0.4.1" diff --git a/plume-common/Cargo.toml b/plume-common/Cargo.toml index 32db34d3..4ad24744 100644 --- a/plume-common/Cargo.toml +++ b/plume-common/Cargo.toml @@ -17,7 +17,7 @@ rocket = "0.4.6" reqwest = { version = "0.9", features = ["socks"] } serde = "1.0" serde_derive = "1.0" -serde_json = "1.0.80" +serde_json = "1.0.81" shrinkwraprs = "0.3.0" syntect = "4.5.0" tokio = "0.1.22" diff --git a/plume-models/Cargo.toml b/plume-models/Cargo.toml index bb0e8925..ad5a66ed 100644 --- a/plume-models/Cargo.toml +++ b/plume-models/Cargo.toml @@ -20,7 +20,7 @@ reqwest = "0.9" scheduled-thread-pool = "0.2.2" serde = "1.0" serde_derive = "1.0" -serde_json = "1.0.80" +serde_json = "1.0.81" tantivy = "0.13.3" url = "2.1" walkdir = "2.2" From f06f444a134a35ea7f20fc73a26358b86d9c2ff1 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 5 May 2022 11:28:22 +0900 Subject: [PATCH 04/11] Update CircleCI image See https://discuss.circleci.com/t/legacy-convenience-image-deprecation/41034 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index cd7f2d06..d6b208ec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,7 +11,7 @@ executors: default: false docker: - image: plumeorg/plume-buildenv:v0.4.0 - - image: <<#parameters.postgres>>circleci/postgres:9.6-alpine<><<^parameters.postgres>>alpine:latest<> + - image: <<#parameters.postgres>>cimg/postgres:14.2<><<^parameters.postgres>>alpine:latest<> environment: POSTGRES_USER: postgres POSTGRES_DB: plume From 116974f8112f6ea11a893272f6a9d41efeaae2fd Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 5 May 2022 16:29:52 +0900 Subject: [PATCH 05/11] Add comment about broadcast capacity --- plume-common/src/activity_pub/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index 68b98c83..50662d0c 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -146,6 +146,9 @@ where .build() .expect("Error while initializing tokio runtime for federation"); rt.block_on(async { + // TODO: should be determined dependent on database connections because + // after broadcasting, target instance sends request to this instance, + // and Plume accesses database at that time. let capacity = 6; let (tx, rx) = flume::bounded::(capacity); let mut handles = Vec::with_capacity(capacity); From de605deb1e950cd7692158c2f203bb2681eeba00 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 5 May 2022 16:35:03 +0900 Subject: [PATCH 06/11] Don't unwrap --- plume-common/src/activity_pub/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index 50662d0c..ba73ab19 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -201,7 +201,7 @@ where .expect("activity_pub::broadcast: request signature error"), ) .body(body); - tx.send_async(request_builder).await.unwrap(); + let _ = tx.send_async(request_builder).await; } drop(tx); join_all(handles).await; From 70b5bee00fb2a75eca37a222efa0c625d8f512f9 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 5 May 2022 16:48:51 +0900 Subject: [PATCH 07/11] Move My feed first in timelines --- plume-models/src/timeline/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plume-models/src/timeline/mod.rs b/plume-models/src/timeline/mod.rs index d6b2a59d..8f80310c 100644 --- a/plume-models/src/timeline/mod.rs +++ b/plume-models/src/timeline/mod.rs @@ -6,6 +6,7 @@ use crate::{ Connection, Error, Result, }; use diesel::{self, BoolExpressionMethods, ExpressionMethods, QueryDsl, RunQueryDsl}; +use std::cmp::Ordering; use std::ops::Deref; pub(crate) mod query; @@ -85,6 +86,16 @@ impl Timeline { .or(timeline_definition::user_id.is_null()), ) .load::(conn) + .map(|mut timelines| { + timelines.sort_by(|t1, t2| { + if t1.user_id.is_some() && t2.user_id.is_none() { + Ordering::Less + } else { + Ordering::Equal + } + }); + timelines + }) .map_err(Error::from) } else { timeline_definition::table From 118cfd7166a586688233ca723390bb2830bd7fe1 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 5 May 2022 18:14:55 +0900 Subject: [PATCH 08/11] Replace hard tabs with soft tabs --- templates/timelines/details.rs.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/timelines/details.rs.html b/templates/timelines/details.rs.html index 916b4f76..b85110a1 100644 --- a/templates/timelines/details.rs.html +++ b/templates/timelines/details.rs.html @@ -8,21 +8,21 @@ @(ctx: BaseContext, tl: Timeline, articles: Vec, all_tl: Vec, page: i32, n_pages: i32) @:base(ctx, tl.name.clone(), {}, {}, { -
-

@i18n_timeline_name(ctx.1, &tl.name)

-
+
+

@i18n_timeline_name(ctx.1, &tl.name)

+
@tabs(&vec![(format!("{}", uri!(instance::index)), i18n!(ctx.1, "Latest articles"), false)] .into_iter().chain(all_tl .into_iter() .map(|t| { - let url = format!("{}", uri!(timelines::details: id = t.id, page = _)); + let url = format!("{}", uri!(timelines::details: id = t.id, page = _)); (url, i18n_timeline_name(ctx.1, &t.name), t.id == tl.id) }) ).collect::>() ) - @if !articles.is_empty() { + @if !articles.is_empty() {
@for article in articles { @:post_card(ctx, article) From 39de96714170ec67c72296cef961fe1cebc3ecde Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 5 May 2022 19:03:33 +0900 Subject: [PATCH 09/11] Show first timeline at home --- src/routes/instance.rs | 39 ++++++++++++++------------- src/routes/mod.rs | 6 +++++ templates/instance/index.rs.html | 46 ++++++++++++++++---------------- 3 files changed, 49 insertions(+), 42 deletions(-) mode change 100755 => 100644 src/routes/mod.rs diff --git a/src/routes/instance.rs b/src/routes/instance.rs index cedaa900..526bde31 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -28,25 +28,26 @@ use plume_models::{ #[get("/")] pub fn index(conn: DbConn, rockets: PlumeRocket) -> Result { - let inst = Instance::get_local()?; - let timelines = Timeline::list_all_for_user(&conn, rockets.user.clone().map(|u| u.id))? - .into_iter() - .filter_map(|t| { - if let Ok(latest) = t.get_latest(&conn, 12) { - Some((t, latest)) - } else { - None - } - }) - .collect(); - - Ok(render!(instance::index( - &(&conn, &rockets).to_context(), - inst, - User::count_local(&conn)?, - Post::count_local(&conn)?, - timelines - ))) + let all_tl = Timeline::list_all_for_user(&conn, rockets.user.clone().map(|u| u.id))?; + if all_tl.is_empty() { + Err(Error::NotFound.into()) + } else { + let inst = Instance::get_local()?; + let page = Page::default(); + let tl = &all_tl[0]; + let posts = tl.get_page(&conn, page.limits())?; + let total_posts = tl.count_posts(&conn)?; + Ok(render!(instance::index( + &(&conn, &rockets).to_context(), + inst, + User::count_local(&conn)?, + Post::count_local(&conn)?, + tl.id, + posts, + all_tl, + Page::total(total_posts as i32) + ))) + } } #[get("/admin")] diff --git a/src/routes/mod.rs b/src/routes/mod.rs old mode 100755 new mode 100644 index b239abec..5ea53c96 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -59,6 +59,12 @@ impl From> for RespondOrRedirect { #[derive(Shrinkwrap, Copy, Clone, UriDisplayQuery)] pub struct Page(i32); +impl From for Page { + fn from(page: i32) -> Self { + Self(page) + } +} + impl<'v> FromFormValue<'v> for Page { type Error = &'v RawStr; fn from_form_value(form_value: &'v RawStr) -> Result { diff --git a/templates/instance/index.rs.html b/templates/instance/index.rs.html index 0361318e..4e25401a 100644 --- a/templates/instance/index.rs.html +++ b/templates/instance/index.rs.html @@ -4,37 +4,37 @@ @use crate::templates::{base, partials::*}; @use crate::template_utils::*; @use crate::routes::*; +@use rocket::uri; -@(ctx: BaseContext, instance: Instance, n_users: i64, n_articles: i64, all_tl: Vec<(Timeline, Vec)>) +@(ctx: BaseContext, instance: Instance, n_users: i64, n_articles: i64, tl_id: i32, articles: Vec, all_tl: Vec, n_pages: i32) @:base(ctx, instance.name.clone(), {}, {}, { -

@i18n!(ctx.1, "Welcome to {}"; instance.name.as_str())

+
+

@i18n!(ctx.1, "Welcome to {}"; instance.name.as_str())

+
- @tabs(&vec![(format!("{}", uri!(instance::index)), i18n!(ctx.1, "Latest articles"), true)] - .into_iter().chain(all_tl.clone() + @tabs(&all_tl .into_iter() - .map(|(tl, _)| { - let url = format!("{}", uri!(timelines::details: id = tl.id, page = _)); - (url, i18n_timeline_name(ctx.1, &tl.name), false) + .map(|t| { + let url = format!("{}", uri!(timelines::details: id = t.id, page = _)); + (url, i18n_timeline_name(ctx.1, &t.name), t.id == tl_id) }) - ).collect::>() + .collect::>() ) - @for (tl, articles) in all_tl { - @if !articles.is_empty() { -
-

- @i18n_timeline_name(ctx.1, &tl.name) - — - @i18n!(ctx.1, "View all") -

-
- @for article in articles { - @:post_card(ctx, article) - } -
-
- } + @if !articles.is_empty() { +
+ @for article in articles { + @:post_card(ctx, article) + } +
+ } else { +

@i18n!(ctx.1, "Nothing to see here yet.")

+ } + @if n_pages > 1 { + } @:instance_description(ctx, instance, n_users, n_articles) From ccf7ff2bc9590c65b88bd02f39d9b35c1bce4483 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 5 May 2022 19:05:54 +0900 Subject: [PATCH 10/11] Remove Latest articles from timeline tabs --- templates/timelines/details.rs.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/templates/timelines/details.rs.html b/templates/timelines/details.rs.html index b85110a1..d745a4ba 100644 --- a/templates/timelines/details.rs.html +++ b/templates/timelines/details.rs.html @@ -12,14 +12,13 @@

@i18n_timeline_name(ctx.1, &tl.name)

- @tabs(&vec![(format!("{}", uri!(instance::index)), i18n!(ctx.1, "Latest articles"), false)] - .into_iter().chain(all_tl + @tabs(&all_tl .into_iter() .map(|t| { let url = format!("{}", uri!(timelines::details: id = t.id, page = _)); (url, i18n_timeline_name(ctx.1, &t.name), t.id == tl.id) }) - ).collect::>() + .collect::>() ) @if !articles.is_empty() { From 8948b7acc1861464c4d95d1f46ed009437df74e2 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 5 May 2022 19:11:17 +0900 Subject: [PATCH 11/11] Center timeline tabs --- assets/themes/default/_global.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/themes/default/_global.scss b/assets/themes/default/_global.scss index fe92d062..23f6acec 100644 --- a/assets/themes/default/_global.scss +++ b/assets/themes/default/_global.scss @@ -507,6 +507,7 @@ figure { margin: auto $horizontal-margin 2em; overflow: auto; display: flex; + justify-content: center; a { display: inline-block;