Extract filter_by_exact_message_topic().

This commit is contained in:
Steve Howell 2018-11-01 14:48:14 +00:00 committed by Tim Abbott
parent 56ecd227ff
commit dc8f893494
2 changed files with 19 additions and 3 deletions

View File

@ -55,6 +55,9 @@ from zerver.lib.stream_subscription import (
num_subscribers_for_stream_id,
)
from zerver.lib.stream_topic import StreamTopicTarget
from zerver.lib.topic import (
filter_by_exact_message_topic,
)
from zerver.lib.topic_mutes import (
get_topic_mutes,
add_topic_mute,
@ -1784,15 +1787,19 @@ def already_sent_mirrored_message_id(message: Message) -> Optional[int]:
else:
time_window = datetime.timedelta(seconds=0)
messages = Message.objects.filter(
query = Message.objects.filter(
sender=message.sender,
recipient=message.recipient,
content=message.content,
subject=message.subject,
sending_client=message.sending_client,
pub_date__gte=message.pub_date - time_window,
pub_date__lte=message.pub_date + time_window)
messages = filter_by_exact_message_topic(
query=query,
message=message,
)
if messages.exists():
return messages[0].id
return None

View File

@ -1,9 +1,18 @@
from django.db import connection
from django.db.models.query import QuerySet
from zerver.models import UserProfile, Recipient
from zerver.models import (
Message,
Recipient,
UserProfile,
)
from typing import Any, Dict, List, Tuple
def filter_by_exact_message_topic(query: QuerySet, message: Message) -> QuerySet:
topic_name = message.topic_name()
return query.filter(subject=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]]