diff --git a/crates/app/src/assets.rs b/crates/app/src/assets.rs index def0aba..80e79ff 100644 --- a/crates/app/src/assets.rs +++ b/crates/app/src/assets.rs @@ -9,6 +9,7 @@ use tera::Context; use tetratto_core::{ config::Config, model::auth::{DefaultTimelineChoice, User}, + PUBSUB_ENABLED, }; use tetratto_l10n::LangFile; use tetratto_shared::hash::salt; @@ -283,6 +284,8 @@ pub(crate) async fn initial_context( ) -> Context { let mut ctx = Context::new(); ctx.insert("config", &config); + ctx.insert("pubsub", &PUBSUB_ENABLED); + ctx.insert("user", &user); ctx.insert("use_user_theme", &true); diff --git a/crates/core/src/database/posts.rs b/crates/core/src/database/posts.rs index d126775..60fdcce 100644 --- a/crates/core/src/database/posts.rs +++ b/crates/core/src/database/posts.rs @@ -202,7 +202,7 @@ impl DataManager { let user = self.get_user_by_id(owner).await?; // check relationship - if user.settings.private_profile { + if user.settings.private_profile && user.id != user_id { if user_id == 0 { continue; } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index b94890d..94f6914 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -4,3 +4,10 @@ pub mod database; pub mod model; pub use database::DataManager; + +/// 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/channels.rs b/crates/core/src/model/channels.rs new file mode 100644 index 0000000..d1c6e34 --- /dev/null +++ b/crates/core/src/model/channels.rs @@ -0,0 +1,78 @@ +use serde::{Serialize, Deserialize}; +use tetratto_shared::{snow::AlmostSnowflake, unix_epoch_timestamp}; + +use super::communities_permissions::CommunityPermission; + +/// A channel is a more "chat-like" feed in communities. +#[derive(Serialize, Deserialize)] +pub struct Channel { + pub id: usize, + pub community: usize, + pub owner: usize, + pub created: usize, + /// The minimum role (as bits) that can read this channel. + pub minimum_role_read: u32, + /// The minimum role (as bits) that can write to this channel. + pub minimum_role_write: u32, + /// The position of this channel in the UI. + /// + /// Top (0) to bottom. + pub order: usize, +} + +impl Channel { + /// Create a new [`Channel`]. + pub fn new(community: usize, owner: usize, order: usize) -> Self { + Self { + id: AlmostSnowflake::new(1234567890) + .to_string() + .parse::() + .unwrap(), + community, + owner, + created: unix_epoch_timestamp() as usize, + minimum_role_read: (CommunityPermission::DEFAULT | CommunityPermission::MEMBER).bits(), + minimum_role_write: (CommunityPermission::DEFAULT | CommunityPermission::MEMBER).bits(), + order, + } + } +} + +#[derive(Serialize, Deserialize)] +pub struct Message { + pub id: usize, + pub channel: usize, + pub owner: usize, + pub created: usize, + pub edited: usize, + pub content: String, + pub context: MessageContext, +} + +impl Message { + pub fn new(channel: usize, owner: usize, content: String) -> Self { + let now = unix_epoch_timestamp() as usize; + + Self { + id: AlmostSnowflake::new(1234567890) + .to_string() + .parse::() + .unwrap(), + channel, + owner, + created: now, + edited: now, + content, + context: MessageContext::default(), + } + } +} + +#[derive(Serialize, Deserialize)] +pub struct MessageContext; + +impl Default for MessageContext { + fn default() -> Self { + Self + } +} diff --git a/crates/core/src/model/communities_permissions.rs b/crates/core/src/model/communities_permissions.rs index 2fbba3f..731d4bf 100644 --- a/crates/core/src/model/communities_permissions.rs +++ b/crates/core/src/model/communities_permissions.rs @@ -18,6 +18,8 @@ bitflags! { const MANAGE_PINS = 1 << 7; const MANAGE_COMMUNITY = 1 << 8; const MANAGE_QUESTIONS = 1 << 9; + const MANAGE_CHANNELS = 1 << 10; + const MANAGE_MESSAGES = 1 << 11; const _ = !0; } diff --git a/crates/core/src/model/mod.rs b/crates/core/src/model/mod.rs index 0d43fba..1de07b6 100644 --- a/crates/core/src/model/mod.rs +++ b/crates/core/src/model/mod.rs @@ -6,6 +6,9 @@ pub mod permissions; pub mod reactions; pub mod requests; +#[cfg(feature = "redis")] +pub mod channels; + use std::fmt::Display; use serde::{Deserialize, Serialize};