From 7252861785a604e85a9970e698126367cd0ab55c Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Thu, 1 Nov 2018 17:06:55 +0000 Subject: [PATCH] Extract filter_by_topic_name_via_message. --- zerver/lib/actions.py | 6 +++++- zerver/lib/topic.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 23fdc360d9..ffe976d54a 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -57,6 +57,7 @@ from zerver.lib.stream_subscription import ( from zerver.lib.stream_topic import StreamTopicTarget from zerver.lib.topic import ( filter_by_exact_message_topic, + filter_by_topic_name_via_message, ) from zerver.lib.topic_mutes import ( get_topic_mutes, @@ -3652,7 +3653,10 @@ def do_mark_stream_messages_as_read(user_profile: UserProfile, msgs = msgs.filter(message__recipient=recipient) if topic_name: - msgs = msgs.filter(message__subject__iexact=topic_name) + msgs = filter_by_topic_name_via_message( + query=msgs, + topic_name=topic_name, + ) msgs = msgs.extra( where=[UserMessage.where_unread()] diff --git a/zerver/lib/topic.py b/zerver/lib/topic.py index e05d794d7d..539777e6a1 100644 --- a/zerver/lib/topic.py +++ b/zerver/lib/topic.py @@ -13,6 +13,9 @@ def filter_by_exact_message_topic(query: QuerySet, message: Message) -> QuerySet topic_name = message.topic_name() return query.filter(subject=topic_name) +def filter_by_topic_name_via_message(query: QuerySet, topic_name: str) -> QuerySet: + return query.filter(message__subject__iexact=topic_name) + def generate_topic_history_from_db_rows(rows: List[Tuple[str, int]]) -> List[Dict[str, Any]]: canonical_topic_names = {} # type: Dict[str, Tuple[int, str]]