Browse Source

On home page, only include subgroups if subscribed

Previously, subgroups were always included in topic queries. This meant
that, for example, it was impossible to subscribe to ~tildes without
always also having ~tildes.official topics in your home page as well.

This change makes it so that the home page now only includes topics from
groups that the user is actually subscribed to. When visiting a group
individually it still includes the subgroups.

As part of deploying this, I'll want to automatically add subscriptions
for users that were subscribed to ~tildes but not ~tildes.official so
they don't see a behavior change (and that's the only current subgroup).
merge-requests/82/merge
Deimos 5 years ago
parent
commit
0bf09010d1
  1. 11
      tildes/tildes/models/topic/topic_query.py
  2. 6
      tildes/tildes/views/topic.py

11
tildes/tildes/models/topic/topic_query.py

@ -137,14 +137,19 @@ class TopicQuery(PaginatedQuery):
return self
def inside_groups(self, groups: Sequence[Group]) -> "TopicQuery":
def inside_groups(
self, groups: Sequence[Group], include_subgroups: bool = True
) -> "TopicQuery":
"""Restrict the topics to inside specific groups (generative)."""
if include_subgroups:
query_paths = [group.path for group in groups]
subgroup_subquery = self.request.db_session.query(Group.group_id).filter(
group_ids = self.request.db_session.query(Group.group_id).filter(
Group.path.descendant_of(query_paths)
)
else:
group_ids = [group.group_id for group in groups]
return self.filter(Topic.group_id.in_(subgroup_subquery)) # type: ignore
return self.filter(Topic.group_id.in_(group_ids)) # type: ignore
def inside_time_period(self, period: SimpleHoursPeriod) -> "TopicQuery":
"""Restrict the topics to inside a time period (generative)."""

6
tildes/tildes/views/topic.py

@ -146,7 +146,9 @@ def get_group_topics(
) -> dict:
"""Get a listing of topics in the group."""
# pylint: disable=too-many-arguments, too-many-branches, too-many-locals
if request.matched_route.name == "home":
is_home_page = request.matched_route.name == "home"
if is_home_page:
# on the home page, include topics from the user's subscribed groups
# (or all groups, if logged-out)
if request.user:
@ -171,7 +173,7 @@ def get_group_topics(
query = (
request.query(Topic)
.join_all_relationships()
.inside_groups(groups)
.inside_groups(groups, include_subgroups=not is_home_page)
.apply_sort_option(order)
)

Loading…
Cancel
Save