simplify visibility states using the new visstates

because of #606, we now have a relatively decent way of representing
how post/comment state is in the database. we'll use this in our code
which is used to determine what is shown in the UI
This commit is contained in:
justcool393 2023-07-12 13:22:34 -05:00 committed by Ben Rog-Wilhelm
parent 099d15b59b
commit db1f578f26
6 changed files with 137 additions and 119 deletions

View file

@ -1,16 +1,16 @@
import math
from typing import TYPE_CHECKING, Literal, Optional
from urllib.parse import parse_qs, urlencode, urlparse
from flask import g
import math
from sqlalchemy import *
from sqlalchemy.orm import relationship
from files.classes.base import CreatedBase
from files.classes.visstate import StateMod, StateReport
from files.classes.visstate import StateMod, StateReport, VisibilityState
from files.helpers.config.const import *
from files.helpers.config.environment import SCORE_HIDING_TIME_HOURS, SITE_FULL
from files.helpers.content import (ModerationState, body_displayed,
from files.helpers.content import (body_displayed,
execute_shadowbanned_fake_votes)
from files.helpers.lazy import lazy
from files.helpers.math import clamp
@ -420,22 +420,23 @@ class Comment(CreatedBase):
@lazy
def show_descendants(self, v:"User | None") -> bool:
if self.moderation_state.is_visible_to(v, getattr(self, 'is_blocking', False)):
if self.visibility_state.is_visible_to(v, getattr(self, 'is_blocking', False)):
return True
return bool(self.descendant_count)
@lazy
def visibility_state(self, v:"User | None") -> tuple[bool, str]:
def visibility_and_message(self, v:"User | None") -> tuple[bool, str]:
'''
Returns a tuple of whether this content is visible and a publicly
visible message to accompany it. The visibility state machine is
a slight mess but... this should at least unify the state checks.
'''
return self.moderation_state.visibility_state(v, getattr(self, 'is_blocking', False))
return self.visibility_state.visibility_and_message(
v, getattr(self, 'is_blocking', False))
@property
def moderation_state(self) -> ModerationState:
return ModerationState.from_submittable(self)
def visibility_state(self) -> VisibilityState:
return VisibilityState.from_submittable(self)
def volunteer_janitor_is_unknown(self):
return self.volunteer_janitor_badness > 0.4 and self.volunteer_janitor_badness < 0.6