fix: user community membership checks for timelines
This commit is contained in:
parent
0272985b81
commit
50f4592de2
4 changed files with 67 additions and 17 deletions
|
@ -1,12 +1,10 @@
|
|||
(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 %}
|
||||
{%- endif %}
|
||||
{% endfor %}")
|
||||
(datalist
|
||||
("ui_ident" "list_posts_{{ page }}")
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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<usize, UserStack> = HashMap::new();
|
||||
let mut replying_posts: HashMap<usize, Post> = HashMap::new();
|
||||
let mut memberships: HashMap<usize, CommunityMembership> = 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(),
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue