diff --git a/crates/app/src/public/html/timelines/swiss_army.lisp b/crates/app/src/public/html/timelines/swiss_army.lisp index 23243ce..535dbe9 100644 --- a/crates/app/src/public/html/timelines/swiss_army.lisp +++ b/crates/app/src/public/html/timelines/swiss_army.lisp @@ -1,11 +1,9 @@ (text "{%- import \"components.html\" as components -%} {%- import \"macros.html\" as macros -%}") (text "{% for post in list %} - {% if post[2].read_access == \"Everybody\" -%} - {% if post[0].context.repost and post[0].context.repost.reposting -%} - {{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }} - {% else %} - {{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2], poll=post[5]) }} - {%- endif %} + {% if post[0].context.repost and post[0].context.repost.reposting -%} + {{ components::repost(repost=post[3], post=post[0], owner=post[1], secondary=true, community=post[2], show_community=true) }} + {% else %} + {{ components::post(post=post[0], owner=post[1], question=post[4], secondary=true, community=post[2], poll=post[5]) }} {%- endif %} {% endfor %}") (datalist diff --git a/crates/app/src/public/js/me.js b/crates/app/src/public/js/me.js index 36ff6b1..e346a6b 100644 --- a/crates/app/src/public/js/me.js +++ b/crates/app/src/public/js/me.js @@ -425,6 +425,7 @@ self.define("notifications_stream", ({ _, streams }) => { const element = document.getElementById("notifications_span"); + let current = Number.parseInt(element.innerText || "0"); streams.subscribe("notifs"); streams.event("notifs", "message", (data) => { @@ -435,13 +436,12 @@ const inner_data = JSON.parse(data.data); if (data.method.Packet.Crud === "Create") { - const current = Number.parseInt(element.innerText || "0"); - if (current <= 0) { element.classList.remove("hidden"); } - element.innerText = current + 1; + current += 1; + element.innerText = current; // check if we're already connected const connected = @@ -477,16 +477,19 @@ console.info("notification created"); } } else if (data.method.Packet.Crud === "Delete") { - const current = Number.parseInt(element.innerText || "0"); - if (current - 1 <= 0) { element.classList.add("hidden"); } - element.innerText = current - 1; + current -= 1; + element.innerText = current; } else { console.warn("correct packet type but with wrong data"); } + + if (element.innerText !== current) { + element.innerText = current; + } }); }); diff --git a/crates/core/src/database/posts.rs b/crates/core/src/database/posts.rs index c1f1dca..011e653 100644 --- a/crates/core/src/database/posts.rs +++ b/crates/core/src/database/posts.rs @@ -1,8 +1,7 @@ use std::collections::HashMap; -use oiseau::cache::Cache; use crate::config::StringBan; use crate::model::auth::Notification; -use crate::model::communities::{Poll, Question}; +use crate::model::communities::{CommunityMembership, CommunityReadAccess, Poll, Question}; use crate::model::communities_permissions::CommunityPermission; use crate::model::moderation::AuditLogEntry; use crate::model::stacks::{StackMode, StackSort, UserStack}; @@ -16,7 +15,7 @@ use tetratto_shared::unix_epoch_timestamp; use crate::{auto_method, DataManager}; use oiseau::{PostgresRow, cache::redis::Commands}; -use oiseau::{execute, get, query_row, query_rows, params}; +use oiseau::{execute, get, query_row, query_rows, params, cache::Cache}; pub type FullPost = ( Post, @@ -479,6 +478,7 @@ impl DataManager { let mut seen_user_follow_statuses: HashMap<(usize, usize), bool> = HashMap::new(); let mut seen_stacks: HashMap = HashMap::new(); let mut replying_posts: HashMap = HashMap::new(); + let mut memberships: HashMap = HashMap::new(); for post in posts { if post.is_deleted { @@ -493,6 +493,30 @@ impl DataManager { continue; } + // check membership + if community.read_access == CommunityReadAccess::Joined { + if let Some(user) = user { + if let Some(membership) = memberships.get(&community.id) { + if !membership.role.check(CommunityPermission::MEMBER) { + continue; + } + } else { + if let Ok(membership) = self + .get_membership_by_owner_community_no_void(user.id, community.id) + .await + { + if !membership.role.check(CommunityPermission::MEMBER) { + continue; + } + } else { + continue; + } + } + } else { + continue; + } + } + // stack let (can_view, stack) = self .get_post_stack( @@ -537,6 +561,32 @@ impl DataManager { continue; } + // check membership + let community = self.get_community_by_id(community).await?; + if community.read_access == CommunityReadAccess::Joined { + if let Some(user) = user { + if let Some(membership) = memberships.get(&community.id) { + if !membership.role.check(CommunityPermission::MEMBER) { + continue; + } + } else { + if let Ok(membership) = self + .get_membership_by_owner_community_no_void(user.id, community.id) + .await + { + memberships.insert(owner, membership.clone()); + if !membership.role.check(CommunityPermission::MEMBER) { + continue; + } + } else { + continue; + } + } + } else { + continue; + } + } + // check relationship if ua.settings.private_profile && ua.id != user_id { if user_id == 0 { @@ -587,7 +637,6 @@ impl DataManager { } // ... - let community = self.get_community_by_id(community).await?; seen_before.insert((owner, community.id), (ua.clone(), community.clone())); out.push(( post.clone(), diff --git a/crates/core/src/model/communities.rs b/crates/core/src/model/communities.rs index 7b1957f..e2c4261 100644 --- a/crates/core/src/model/communities.rs +++ b/crates/core/src/model/communities.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use tetratto_shared::{snow::Snowflake, unix_epoch_timestamp}; use super::communities_permissions::CommunityPermission; -#[derive(Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Community { pub id: usize, pub created: usize,