diff --git a/Cargo.lock b/Cargo.lock index 1126bca..fd8c94a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -787,18 +787,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" -[[package]] -name = "fallible-iterator" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" - -[[package]] -name = "fallible-streaming-iterator" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" - [[package]] name = "fastrand" version = "1.9.0" @@ -839,12 +827,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - [[package]] name = "foreign-types" version = "0.3.2" @@ -1112,18 +1094,6 @@ name = "hashbrown" version = "0.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" -dependencies = [ - "foldhash", -] - -[[package]] -name = "hashlink" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" -dependencies = [ - "hashbrown", -] [[package]] name = "heck" @@ -1697,16 +1667,6 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" -[[package]] -name = "libsqlite3-sys" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91632f3b4fb6bd1d72aa3d78f41ffecfcf2b1a6648d8c241dbe7dbfaf4875e15" -dependencies = [ - "pkg-config", - "vcpkg", -] - [[package]] name = "libwebp-sys" version = "0.9.6" @@ -2033,7 +1993,6 @@ checksum = "99b097052e28781d560587373845626a85460969a55d180fc418aecd58f6fef3" dependencies = [ "bb8-postgres", "redis", - "rusqlite", "serde", "tokio-postgres", ] @@ -2290,7 +2249,7 @@ dependencies = [ "base64 0.22.1", "byteorder", "bytes", - "fallible-iterator 0.2.0", + "fallible-iterator", "hmac", "md-5", "memchr", @@ -2306,7 +2265,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613283563cd90e1dfc3518d548caee47e0e725455ed619881f5cf21f36de4b48" dependencies = [ "bytes", - "fallible-iterator 0.2.0", + "fallible-iterator", "postgres-protocol", ] @@ -2725,20 +2684,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rusqlite" -version = "0.36.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3de23c3319433716cf134eed225fe9986bc24f63bed9be9f20c329029e672dc7" -dependencies = [ - "bitflags 2.9.1", - "fallible-iterator 0.3.0", - "fallible-streaming-iterator", - "hashlink", - "libsqlite3-sys", - "smallvec", -] - [[package]] name = "rustc-demangle" version = "0.1.24" @@ -3527,7 +3472,7 @@ dependencies = [ "async-trait", "byteorder", "bytes", - "fallible-iterator 0.2.0", + "fallible-iterator", "futures-channel", "futures-util", "log", diff --git a/README.md b/README.md index 77155e8..87e0a38 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ Make sure you have AT LEAST rustc version 1.89.0-nightly. Everything Tetratto needs will be built into the main binary. You can build Tetratto with the following command: ```bash -cargo build -r --no-default-features --features=redis,sqlite +cargo build ``` -You can replace `sqlite` in the above command with `postgres`, if you'd like. Redis (or a Redis fork) is required for features such as chats and (realtime) notifications! +Tetratto **requires** a PostgreSQL server, as well as a Redis (or Redis fork) instance. You can then take the binary and place it somewhere else (highly recommended; the binary will create a fair number of files!). You can do this to move it to a directory just called "tetratto" in the parent directory: diff --git a/crates/app/Cargo.toml b/crates/app/Cargo.toml index a575e9d..333bff5 100644 --- a/crates/app/Cargo.toml +++ b/crates/app/Cargo.toml @@ -3,12 +3,6 @@ name = "tetratto" version = "7.0.0" edition = "2024" -[features] -postgres = ["tetratto-core/postgres"] -sqlite = ["tetratto-core/sqlite"] -redis = ["tetratto-core/redis"] -default = ["sqlite", "redis"] - [dependencies] pathbufd = "0.1.4" serde = { version = "1.0.219", features = ["derive"] } @@ -21,9 +15,7 @@ tokio = { version = "1.45.1", features = ["macros", "rt-multi-thread"] } axum-extra = { version = "0.10.1", features = ["cookie", "multipart"] } ammonia = "4.1.0" tetratto-shared = { path = "../shared" } -tetratto-core = { path = "../core", features = [ - "redis", -], default-features = false } +tetratto-core = { path = "../core" } tetratto-l10n = { path = "../l10n" } image = "0.25.6" diff --git a/crates/app/src/assets.rs b/crates/app/src/assets.rs index 877161c..03e8db3 100644 --- a/crates/app/src/assets.rs +++ b/crates/app/src/assets.rs @@ -17,7 +17,6 @@ use tetratto_core::{ auth::{DefaultTimelineChoice, User}, permissions::FinePermission, }, - PUBSUB_ENABLED, }; use tetratto_l10n::LangFile; use tetratto_shared::hash::salt; @@ -468,7 +467,7 @@ pub(crate) async fn initial_context( ) -> Context { let mut ctx = Context::new(); ctx.insert("config", &config); - ctx.insert("pubsub", &PUBSUB_ENABLED); + ctx.insert("pubsub", &true); ctx.insert("user", &user); ctx.insert("use_user_theme", &true); diff --git a/crates/app/src/public/html/macros.lisp b/crates/app/src/public/html/macros.lisp index f544f5e..80ed3ba 100644 --- a/crates/app/src/public/html/macros.lisp +++ b/crates/app/src/public/html/macros.lisp @@ -144,7 +144,9 @@ (text "{{ macros::timelines_nav_options(selected=selected) }}") ; secondary nav desktop only - (text "{{ macros::timelines_secondary_nav(posts=posts, questions=questions, selected=secondary_selected) }}")) + (text "{% if posts and questions -%}") + (text "{{ macros::timelines_secondary_nav(posts=posts, questions=questions, selected=secondary_selected) }}") + (text "{%- endif %}")) (text "{%- endmacro %}") (text "{% macro timelines_nav_options(selected=\"\") -%}") diff --git a/crates/app/src/public/html/stacks/feed.lisp b/crates/app/src/public/html/stacks/feed.lisp index 6107546..a723066 100644 --- a/crates/app/src/public/html/stacks/feed.lisp +++ b/crates/app/src/public/html/stacks/feed.lisp @@ -12,7 +12,9 @@ ("class" "card small flex items-center justify-between gap-2") (div ("class" "flex items-center gap-2") - (text "{{ icon \"list\" }}") + (a + ("href" "/api/v1/auth/user/find/{{ stack.owner }}") + (text "{{ components::avatar(username=stack.owner, selector_type=\"id\") }}")) (span (text "{{ stack.name }}"))) (text "{% if user and user.id == stack.owner -%}") diff --git a/crates/app/src/routes/api/v1/auth/profile.rs b/crates/app/src/routes/api/v1/auth/profile.rs index c98a665..05eefb4 100644 --- a/crates/app/src/routes/api/v1/auth/profile.rs +++ b/crates/app/src/routes/api/v1/auth/profile.rs @@ -28,8 +28,6 @@ use tetratto_core::{ }, DataManager, }; - -#[cfg(feature = "redis")] use tetratto_core::cache::redis::Commands; use tetratto_shared::{ hash::{self, random_id}, @@ -534,7 +532,6 @@ pub async fn has_totp_enabled_request( } /// Handle a subscription to the websocket. -#[cfg(feature = "redis")] pub async fn subscription_handler( jar: CookieJar, ws: WebSocketUpgrade, @@ -557,7 +554,6 @@ pub async fn subscription_handler( })) } -#[cfg(feature = "redis")] pub async fn handle_socket(socket: WebSocket, db: DataManager, user_id: String, stream_id: String) { let (mut sink, mut stream) = socket.split(); let socket_id = tetratto_shared::hash::salt(); diff --git a/crates/app/src/routes/api/v1/mod.rs b/crates/app/src/routes/api/v1/mod.rs index 4b81eb5..5c54aa9 100644 --- a/crates/app/src/routes/api/v1/mod.rs +++ b/crates/app/src/routes/api/v1/mod.rs @@ -1,5 +1,6 @@ pub mod apps; pub mod auth; +pub mod channels; pub mod communities; pub mod notifications; pub mod reactions; @@ -9,9 +10,6 @@ pub mod stacks; pub mod uploads; pub mod util; -#[cfg(feature = "redis")] -pub mod channels; - use axum::{ routing::{any, delete, get, post, put}, Router, diff --git a/crates/app/src/routes/pages/mod.rs b/crates/app/src/routes/pages/mod.rs index 3a67aa7..556b468 100644 --- a/crates/app/src/routes/pages/mod.rs +++ b/crates/app/src/routes/pages/mod.rs @@ -1,4 +1,5 @@ pub mod auth; +pub mod chats; pub mod communities; pub mod developer; pub mod forge; @@ -7,9 +8,6 @@ pub mod mod_panel; pub mod profile; pub mod stacks; -#[cfg(feature = "redis")] -pub mod chats; - use axum::{ routing::{get, post}, Router, diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 01e09c0..87988b0 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -3,12 +3,6 @@ name = "tetratto-core" version = "7.0.0" edition = "2024" -[features] -postgres = ["oiseau/postgres"] -sqlite = ["oiseau/sqlite"] -redis = ["oiseau/redis"] -default = ["sqlite", "redis"] - [dependencies] pathbufd = "0.1.4" serde = { version = "1.0.219", features = ["derive"] } @@ -25,4 +19,4 @@ base16ct = { version = "0.2.0", features = ["alloc"] } base64 = "0.22.1" emojis = "0.6.4" regex = "1.11.1" -oiseau = { version = "0.1.2", default-features = false } +oiseau = { version = "0.1.2", default-features = false, features = ["postgres", "redis"] } diff --git a/crates/core/src/database/apps.rs b/crates/core/src/database/apps.rs index 9e5e56d..9faf6d4 100644 --- a/crates/core/src/database/apps.rs +++ b/crates/core/src/database/apps.rs @@ -8,20 +8,13 @@ use crate::model::{ }; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, query_rows, params}; impl DataManager { /// Get a [`ThirdPartyApp`] from an SQL row. - pub(crate) fn get_app_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> ThirdPartyApp { + pub(crate) fn get_app_from_row(x: &PostgresRow) -> ThirdPartyApp { ThirdPartyApp { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/audit_log.rs b/crates/core/src/database/audit_log.rs index f6f46de..d0c3147 100644 --- a/crates/core/src/database/audit_log.rs +++ b/crates/core/src/database/audit_log.rs @@ -2,20 +2,13 @@ use oiseau::cache::Cache; use crate::model::{Error, Result, auth::User, moderation::AuditLogEntry, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, query_rows, params}; impl DataManager { /// Get an [`AuditLogEntry`] from an SQL row. - pub(crate) fn get_audit_log_entry_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> AuditLogEntry { + pub(crate) fn get_audit_log_entry_from_row(x: &PostgresRow) -> AuditLogEntry { AuditLogEntry { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/auth.rs b/crates/core/src/database/auth.rs index 39626f3..ba07543 100644 --- a/crates/core/src/database/auth.rs +++ b/crates/core/src/database/auth.rs @@ -16,20 +16,13 @@ use tetratto_shared::{ }; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, query_row, params}; impl DataManager { /// Get a [`User`] from an SQL row. - pub(crate) fn get_user_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> User { + pub(crate) fn get_user_from_row(x: &PostgresRow) -> User { User { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/channels.rs b/crates/core/src/database/channels.rs index d258fc6..ed28323 100644 --- a/crates/core/src/database/channels.rs +++ b/crates/core/src/database/channels.rs @@ -6,20 +6,11 @@ use crate::model::{ }; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; - -use oiseau::{execute, get, query_row, query_rows, params}; +use oiseau::{PostgresRow, execute, get, query_row, query_rows, params}; impl DataManager { /// Get a [`Channel`] from an SQL row. - pub(crate) fn get_channel_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> Channel { + pub(crate) fn get_channel_from_row(x: &PostgresRow) -> Channel { Channel { id: get!(x->0(i64)) as usize, community: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/communities.rs b/crates/core/src/database/communities.rs index 52362f5..2642f37 100644 --- a/crates/core/src/database/communities.rs +++ b/crates/core/src/database/communities.rs @@ -14,20 +14,11 @@ use pathbufd::PathBufD; use std::fs::{exists, remove_file}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; - -use oiseau::{execute, get, query_row, query_rows, params}; +use oiseau::{PostgresRow, execute, get, query_row, query_rows, params}; impl DataManager { /// Get a [`Community`] from an SQL row. - pub(crate) fn get_community_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> Community { + pub(crate) fn get_community_from_row(x: &PostgresRow) -> Community { Community { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, @@ -139,15 +130,10 @@ impl DataManager { Err(e) => return Err(Error::DatabaseConnection(e.to_string())), }; - #[cfg(feature = "sqlite")] - let empty = []; - #[cfg(feature = "postgres")] - let empty = &[]; - let res = query_rows!( &conn, "SELECT * FROM communities WHERE NOT context LIKE '%\"is_nsfw\":true%' ORDER BY member_count DESC LIMIT 12", - empty, + params![], |x| { Self::get_community_from_row(x) } ); diff --git a/crates/core/src/database/drafts.rs b/crates/core/src/database/drafts.rs index 53a7abc..a573bcc 100644 --- a/crates/core/src/database/drafts.rs +++ b/crates/core/src/database/drafts.rs @@ -3,20 +3,13 @@ use crate::model::moderation::AuditLogEntry; use crate::model::{Error, Result, auth::User, communities::PostDraft, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, query_rows, params}; impl DataManager { /// Get a [`PostDraft`] from an SQL row. - pub(crate) fn get_draft_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> PostDraft { + pub(crate) fn get_draft_from_row(x: &PostgresRow) -> PostDraft { PostDraft { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/drivers/mod.rs b/crates/core/src/database/drivers/mod.rs index 57d4cb7..60e7435 100644 --- a/crates/core/src/database/drivers/mod.rs +++ b/crates/core/src/database/drivers/mod.rs @@ -2,13 +2,7 @@ pub mod common; use std::collections::HashMap; use tetratto_l10n::{read_langs, LangFile}; - -#[cfg(feature = "sqlite")] -use oiseau::sqlite::{DataManager as OiseauManager, Result}; - -#[cfg(feature = "postgres")] use oiseau::postgres::{DataManager as OiseauManager, Result}; - use crate::config::Config; #[derive(Clone)] diff --git a/crates/core/src/database/drivers/sql/create_posts.sql b/crates/core/src/database/drivers/sql/create_posts.sql index 58c3eea..b200901 100644 --- a/crates/core/src/database/drivers/sql/create_posts.sql +++ b/crates/core/src/database/drivers/sql/create_posts.sql @@ -17,5 +17,6 @@ CREATE TABLE IF NOT EXISTS posts ( tsvector_content tsvector GENERATED ALWAYS AS (to_tsvector ('english', coalesce(content, ''))) STORED, poll_id BIGINT NOT NULL, title TEXT NOT NULL, - is_open INT NOT NULL DEFAULT 1 + is_open INT NOT NULL DEFAULT 1, + circle BIGINT NOT NULL ) diff --git a/crates/core/src/database/emojis.rs b/crates/core/src/database/emojis.rs index 0349d01..c61fed6 100644 --- a/crates/core/src/database/emojis.rs +++ b/crates/core/src/database/emojis.rs @@ -7,20 +7,11 @@ use crate::model::{ }; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; - -use oiseau::{execute, get, query_row, query_rows, params}; +use oiseau::{PostgresRow, execute, get, query_row, query_rows, params}; impl DataManager { /// Get a [`CustomEmoji`] from an SQL row. - pub(crate) fn get_emoji_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> CustomEmoji { + pub(crate) fn get_emoji_from_row(x: &PostgresRow) -> CustomEmoji { CustomEmoji { id: get!(x->0(i64)) as usize, owner: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/ipbans.rs b/crates/core/src/database/ipbans.rs index 4c9e09d..550570d 100644 --- a/crates/core/src/database/ipbans.rs +++ b/crates/core/src/database/ipbans.rs @@ -4,20 +4,11 @@ use crate::model::moderation::AuditLogEntry; use crate::model::{Error, Result, auth::IpBan, auth::User, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; - -use oiseau::{execute, get, query_row, query_rows, params}; +use oiseau::{PostgresRow, execute, get, query_row, query_rows, params}; impl DataManager { /// Get a [`IpBan`] from an SQL row. - pub(crate) fn get_ipban_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> IpBan { + pub(crate) fn get_ipban_from_row(x: &PostgresRow) -> IpBan { IpBan { ip: get!(x->0(String)), created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/ipblocks.rs b/crates/core/src/database/ipblocks.rs index 8c2a8f2..f94ed51 100644 --- a/crates/core/src/database/ipblocks.rs +++ b/crates/core/src/database/ipblocks.rs @@ -2,20 +2,13 @@ use oiseau::cache::Cache; use crate::model::{Error, Result, auth::User, auth::IpBlock, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, query_row, params}; impl DataManager { /// Get an [`IpBlock`] from an SQL row. - pub(crate) fn get_ipblock_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> IpBlock { + pub(crate) fn get_ipblock_from_row(x: &PostgresRow) -> IpBlock { IpBlock { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/memberships.rs b/crates/core/src/database/memberships.rs index 76fbe2b..4ae7094 100644 --- a/crates/core/src/database/memberships.rs +++ b/crates/core/src/database/memberships.rs @@ -10,20 +10,11 @@ use crate::model::{ }; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; - -use oiseau::{execute, get, query_row, query_rows, params}; +use oiseau::{PostgresRow, execute, get, query_row, query_rows, params}; impl DataManager { /// Get a [`CommunityMembership`] from an SQL row. - pub(crate) fn get_membership_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> CommunityMembership { + pub(crate) fn get_membership_from_row(x: &PostgresRow) -> CommunityMembership { CommunityMembership { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/messages.rs b/crates/core/src/database/messages.rs index 17ec914..f5c7024 100644 --- a/crates/core/src/database/messages.rs +++ b/crates/core/src/database/messages.rs @@ -11,14 +11,7 @@ use serde::Serialize; use tetratto_shared::unix_epoch_timestamp; use crate::{auto_method, DataManager}; -#[cfg(feature = "redis")] -use oiseau::cache::redis::Commands; - -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; +use oiseau::{PostgresRow, cache::redis::Commands}; use oiseau::{execute, get, query_rows, params}; @@ -29,10 +22,7 @@ struct DeleteMessageEvent { impl DataManager { /// Get a [`Message`] from an SQL row. - pub(crate) fn get_message_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> Message { + pub(crate) fn get_message_from_row(x: &PostgresRow) -> Message { Message { id: get!(x->0(i64)) as usize, channel: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/mod.rs b/crates/core/src/database/mod.rs index 458897f..b26afbf 100644 --- a/crates/core/src/database/mod.rs +++ b/crates/core/src/database/mod.rs @@ -1,6 +1,7 @@ mod apps; mod audit_log; mod auth; +mod channels; mod common; mod communities; pub mod connections; @@ -10,6 +11,7 @@ mod emojis; mod ipbans; mod ipblocks; mod memberships; +mod messages; mod notifications; mod polls; mod pollvotes; @@ -25,9 +27,4 @@ mod user_warnings; mod userblocks; mod userfollows; -#[cfg(feature = "redis")] -mod channels; -#[cfg(feature = "redis")] -mod messages; - pub use drivers::DataManager; diff --git a/crates/core/src/database/notifications.rs b/crates/core/src/database/notifications.rs index 60659db..620434b 100644 --- a/crates/core/src/database/notifications.rs +++ b/crates/core/src/database/notifications.rs @@ -3,23 +3,13 @@ use crate::model::socket::{CrudMessageType, PacketType, SocketMessage, SocketMet use crate::model::{Error, Result, auth::Notification, auth::User, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "redis")] -use oiseau::cache::redis::Commands; - -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; +use oiseau::{PostgresRow, cache::redis::Commands}; use oiseau::{execute, get, query_rows, params}; impl DataManager { /// Get a [`Notification`] from an SQL row. - pub(crate) fn get_notification_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> Notification { + pub(crate) fn get_notification_from_row(x: &PostgresRow) -> Notification { Notification { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/polls.rs b/crates/core/src/database/polls.rs index c683199..72046a4 100644 --- a/crates/core/src/database/polls.rs +++ b/crates/core/src/database/polls.rs @@ -4,20 +4,13 @@ use crate::model::moderation::AuditLogEntry; use crate::model::{Error, Result, auth::User, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, query_rows, params}; impl DataManager { /// Get a [`Poll`] from an SQL row. - pub(crate) fn get_poll_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> Poll { + pub(crate) fn get_poll_from_row(x: &PostgresRow) -> Poll { Poll { id: get!(x->0(i64)) as usize, owner: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/pollvotes.rs b/crates/core/src/database/pollvotes.rs index f354b32..58d8d5f 100644 --- a/crates/core/src/database/pollvotes.rs +++ b/crates/core/src/database/pollvotes.rs @@ -5,20 +5,13 @@ use crate::model::moderation::AuditLogEntry; use crate::model::{Error, Result, auth::User, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, query_row, params}; impl DataManager { /// Get a [`PollVote`] from an SQL row. - pub(crate) fn get_pollvote_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> PollVote { + pub(crate) fn get_pollvote_from_row(x: &PostgresRow) -> PollVote { PollVote { id: get!(x->0(i64)) as usize, owner: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/posts.rs b/crates/core/src/database/posts.rs index 7e06d67..1853e98 100644 --- a/crates/core/src/database/posts.rs +++ b/crates/core/src/database/posts.rs @@ -15,15 +15,7 @@ use crate::model::{ use tetratto_shared::unix_epoch_timestamp; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; - -#[cfg(feature = "redis")] -use oiseau::cache::redis::Commands; - +use oiseau::{PostgresRow, cache::redis::Commands}; use oiseau::{execute, get, query_row, query_rows, params}; pub type FullPost = ( @@ -101,10 +93,7 @@ macro_rules! private_post_replying { impl DataManager { /// Get a [`Post`] from an SQL row. - pub(crate) fn get_post_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> Post { + pub(crate) fn get_post_from_row(x: &PostgresRow) -> Post { Post { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, @@ -125,6 +114,7 @@ impl DataManager { poll_id: get!(x->13(i64)) as usize, title: get!(x->14(String)), is_open: get!(x->15(i32)) as i8 == 1, + circle: get!(x->16(i64)) as usize, } } @@ -1620,7 +1610,7 @@ impl DataManager { let res = execute!( &conn, - "INSERT INTO posts VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, DEFAULT, $13, $14, $15)", + "INSERT INTO posts VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, DEFAULT, $13, $14, $15, $16)", params![ &(data.id as i64), &(data.created as i64), @@ -1641,6 +1631,7 @@ impl DataManager { &(data.poll_id as i64), &data.title, &{ if data.is_open { 1 } else { 0 } }, + &(data.circle as i64), ] ); diff --git a/crates/core/src/database/questions.rs b/crates/core/src/database/questions.rs index f76efc6..d88fb44 100644 --- a/crates/core/src/database/questions.rs +++ b/crates/core/src/database/questions.rs @@ -11,20 +11,13 @@ use crate::model::{ }; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, query_rows, params}; impl DataManager { /// Get a [`Question`] from an SQL row. - pub(crate) fn get_question_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> Question { + pub(crate) fn get_question_from_row(x: &PostgresRow) -> Question { Question { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/reactions.rs b/crates/core/src/database/reactions.rs index 4dce267..72ef2bc 100644 --- a/crates/core/src/database/reactions.rs +++ b/crates/core/src/database/reactions.rs @@ -7,20 +7,11 @@ use crate::model::{ }; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; - -use oiseau::{execute, get, query_row, query_rows, params}; +use oiseau::{PostgresRow, execute, get, query_row, query_rows, params}; impl DataManager { /// Get a [`Reaction`] from an SQL row. - pub(crate) fn get_reaction_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> Reaction { + pub(crate) fn get_reaction_from_row(x: &PostgresRow) -> Reaction { Reaction { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/reports.rs b/crates/core/src/database/reports.rs index d2cd474..f29fdc8 100644 --- a/crates/core/src/database/reports.rs +++ b/crates/core/src/database/reports.rs @@ -3,20 +3,13 @@ use crate::model::moderation::AuditLogEntry; use crate::model::{Error, Result, auth::User, moderation::Report, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, query_rows, params}; impl DataManager { /// Get a [`Report`] from an SQL row. - pub(crate) fn get_report_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> Report { + pub(crate) fn get_report_from_row(x: &PostgresRow) -> Report { Report { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/requests.rs b/crates/core/src/database/requests.rs index c8d2383..5a82062 100644 --- a/crates/core/src/database/requests.rs +++ b/crates/core/src/database/requests.rs @@ -3,20 +3,11 @@ use crate::model::requests::ActionType; use crate::model::{Error, Result, requests::ActionRequest, auth::User, permissions::FinePermission}; use crate::DataManager; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; - -use oiseau::{execute, get, query_row, query_rows, params}; +use oiseau::{PostgresRow, execute, get, query_row, query_rows, params}; impl DataManager { /// Get an [`ActionRequest`] from an SQL row. - pub(crate) fn get_request_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> ActionRequest { + pub(crate) fn get_request_from_row(x: &PostgresRow) -> ActionRequest { ActionRequest { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/stackblocks.rs b/crates/core/src/database/stackblocks.rs index 8d2d633..4e3c779 100644 --- a/crates/core/src/database/stackblocks.rs +++ b/crates/core/src/database/stackblocks.rs @@ -3,20 +3,13 @@ use crate::model::stacks::StackPrivacy; use crate::model::{Error, Result, auth::User, stacks::StackBlock, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, params, query_row, query_rows}; impl DataManager { /// Get a [`StackBlock`] from an SQL row. - pub(crate) fn get_stackblock_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> StackBlock { + pub(crate) fn get_stackblock_from_row(x: &PostgresRow) -> StackBlock { StackBlock { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/stacks.rs b/crates/core/src/database/stacks.rs index e0789c7..5c92a37 100644 --- a/crates/core/src/database/stacks.rs +++ b/crates/core/src/database/stacks.rs @@ -8,20 +8,13 @@ use crate::model::{ }; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, query_rows, params}; impl DataManager { /// Get a [`UserStack`] from an SQL row. - pub(crate) fn get_stack_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> UserStack { + pub(crate) fn get_stack_from_row(x: &PostgresRow) -> UserStack { UserStack { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/uploads.rs b/crates/core/src/database/uploads.rs index 49778de..e3b2cb5 100644 --- a/crates/core/src/database/uploads.rs +++ b/crates/core/src/database/uploads.rs @@ -4,20 +4,13 @@ use crate::model::permissions::FinePermission; use crate::model::{Error, Result, uploads::MediaUpload}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] use oiseau::PostgresRow; use oiseau::{execute, get, query_rows, params}; impl DataManager { /// Get a [`MediaUpload`] from an SQL row. - pub(crate) fn get_upload_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> MediaUpload { + pub(crate) fn get_upload_from_row(x: &PostgresRow) -> MediaUpload { MediaUpload { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/user_warnings.rs b/crates/core/src/database/user_warnings.rs index 4aebfca..79af849 100644 --- a/crates/core/src/database/user_warnings.rs +++ b/crates/core/src/database/user_warnings.rs @@ -4,20 +4,11 @@ use crate::model::moderation::AuditLogEntry; use crate::model::{Error, Result, auth::User, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; - -use oiseau::{execute, get, query_row, query_rows, params}; +use oiseau::{PostgresRow, execute, get, query_row, query_rows, params}; impl DataManager { /// Get a [`UserWarning`] from an SQL row. - pub(crate) fn get_user_warning_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> UserWarning { + pub(crate) fn get_user_warning_from_row(x: &PostgresRow) -> UserWarning { UserWarning { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/userblocks.rs b/crates/core/src/database/userblocks.rs index f54b97e..ac95cab 100644 --- a/crates/core/src/database/userblocks.rs +++ b/crates/core/src/database/userblocks.rs @@ -2,20 +2,11 @@ use oiseau::cache::Cache; use crate::model::{Error, Result, auth::User, auth::UserBlock, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; - -use oiseau::{execute, get, query_row, query_rows, params}; +use oiseau::{PostgresRow, execute, get, query_row, query_rows, params}; impl DataManager { /// Get a [`UserBlock`] from an SQL row. - pub(crate) fn get_userblock_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> UserBlock { + pub(crate) fn get_userblock_from_row(x: &PostgresRow) -> UserBlock { UserBlock { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/database/userfollows.rs b/crates/core/src/database/userfollows.rs index 4a4889b..09504c0 100644 --- a/crates/core/src/database/userfollows.rs +++ b/crates/core/src/database/userfollows.rs @@ -4,20 +4,11 @@ use crate::model::requests::{ActionRequest, ActionType}; use crate::model::{Error, Result, auth::User, auth::UserFollow, permissions::FinePermission}; use crate::{auto_method, DataManager}; -#[cfg(feature = "sqlite")] -use oiseau::SqliteRow; - -#[cfg(feature = "postgres")] -use oiseau::PostgresRow; - -use oiseau::{execute, get, query_row, query_rows, params}; +use oiseau::{PostgresRow, execute, get, query_row, query_rows, params}; impl DataManager { /// Get a [`UserFollow`] from an SQL row. - pub(crate) fn get_userfollow_from_row( - #[cfg(feature = "sqlite")] x: &SqliteRow<'_>, - #[cfg(feature = "postgres")] x: &PostgresRow, - ) -> UserFollow { + pub(crate) fn get_userfollow_from_row(x: &PostgresRow) -> UserFollow { UserFollow { id: get!(x->0(i64)) as usize, created: get!(x->1(i64)) as usize, diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 8e1e9b7..aa61770 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -4,10 +4,3 @@ pub mod model; pub use database::DataManager; pub use oiseau::cache; - -/// Tells us if pubsub capabilities are provided (via Redis). -/// -/// If we have access to pubsub, community channels/messages will be available. -/// -/// This is mostly used a flag for the UI. -pub const PUBSUB_ENABLED: bool = cfg!(feature = "redis"); diff --git a/crates/core/src/model/communities.rs b/crates/core/src/model/communities.rs index ed0d5b9..c4419c1 100644 --- a/crates/core/src/model/communities.rs +++ b/crates/core/src/model/communities.rs @@ -260,6 +260,10 @@ pub struct Post { pub title: String, /// If the post is "open". Posts can act as tickets in a forge community. pub is_open: bool, + /// The ID of the circle this post belongs to. 0 means no circle is connected. + /// + /// If circle is not 0, community should be 0 (and vice versa). + pub circle: usize, } impl Post { @@ -287,6 +291,7 @@ impl Post { poll_id, title: String::new(), is_open: true, + circle: 0, } } diff --git a/crates/core/src/model/mod.rs b/crates/core/src/model/mod.rs index 1693fa3..8beb286 100644 --- a/crates/core/src/model/mod.rs +++ b/crates/core/src/model/mod.rs @@ -1,6 +1,7 @@ pub mod addr; pub mod apps; pub mod auth; +pub mod channels; pub mod communities; pub mod communities_permissions; pub mod moderation; @@ -8,15 +9,10 @@ pub mod oauth; pub mod permissions; pub mod reactions; pub mod requests; +pub mod socket; pub mod stacks; pub mod uploads; -#[cfg(feature = "redis")] -pub mod channels; - -#[cfg(feature = "redis")] -pub mod socket; - use std::fmt::Display; use serde::{Deserialize, Serialize}; diff --git a/sql_changes/posts_circle.sql b/sql_changes/posts_circle.sql new file mode 100644 index 0000000..ad4d620 --- /dev/null +++ b/sql_changes/posts_circle.sql @@ -0,0 +1,2 @@ +ALTER TABLE posts +ADD COLUMN circle BIGINT NOT NULL DEFAULT 0;