narrow_term: Refactor a NeverNegatedNarrowTerm.

Previously `NarrowTerm` is only used in our event-handling paths and to
a lesser extent in the `detect_narrowed_window` in `view/home.py`. Both
of which haven't yet support or handle the `negated` term.

Since we're planning to parse a narrow URL into narrow terms (like in
`hash_util.ts`) in the web app, we're going to need a `NarrowTerm`
dataclass with all three flags.

This commit adds the `negated` term to `NarrowTerm` and adds a
`NeverNegatedNarrowTerm` which is a subclass of `NarrowTerm` that always
has the `negated` flag as `False`, so functionally it is the same as the
current `NarrowTerm`.
This commit is contained in:
PieterCK
2025-01-20 20:16:50 +07:00
committed by Tim Abbott
parent 71e412ec00
commit c861bdd494
6 changed files with 58 additions and 31 deletions

View File

@@ -14,7 +14,7 @@ from zerver.lib.i18n import (
get_language_list,
get_language_translation_data,
)
from zerver.lib.narrow_helpers import NarrowTerm
from zerver.lib.narrow_helpers import NeverNegatedNarrowTerm
from zerver.lib.realm_description import get_realm_rendered_description
from zerver.lib.request import RequestNotes
from zerver.models import Message, Realm, Stream, UserProfile
@@ -121,7 +121,7 @@ def build_page_params_for_home_page_load(
user_profile: UserProfile | None,
realm: Realm,
insecure_desktop_app: bool,
narrow: list[NarrowTerm],
narrow: list[NeverNegatedNarrowTerm],
narrow_stream: Stream | None,
narrow_topic_name: str | None,
) -> tuple[int, dict[str, object]]: