message_edit: Fix unmute of topic when topic name is edited.

Previously, when a topic was edited (including being resolved), it
would become unmuted for any users who had muted it, which was
annoying.

While it's not possible to determine the user's intent completely,
this is clearly incorrect behavior in the `change_all` case, such as
resolving a topic.

The comments discuss some scenarios where we might want to enhance
this further, but this is the best we can do without large increases
in complexity.

Fixes #15210.

Co-authored-by: akshatdalton <akshat.dak@students.iiit.ac.in>
This commit is contained in:
Tim Abbott
2022-03-17 17:19:16 -07:00
committed by Tim Abbott
parent 26d97ce7e3
commit e45cebd636
3 changed files with 170 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
import datetime
from typing import Any, Callable, Dict, List, Optional, Tuple
from django.db.models.query import QuerySet
from django.utils.timezone import now as timezone_now
from sqlalchemy.sql import ClauseElement, and_, column, not_, or_
from sqlalchemy.types import Integer
@@ -152,3 +153,13 @@ def build_topic_mute_checker(user_profile: UserProfile) -> Callable[[int, str],
return (recipient_id, topic.lower()) in tups
return is_muted
def get_users_muting_topic(stream_id: int, topic_name: str) -> QuerySet[UserProfile]:
return UserProfile.objects.select_related("realm").filter(
id__in=UserTopic.objects.filter(
stream_id=stream_id,
visibility_policy=UserTopic.MUTED,
topic_name__iexact=topic_name,
).values("user_profile_id")
)