diff --git a/zerver/lib/topic.py b/zerver/lib/topic.py index 5f9867327d..51bc59cc89 100644 --- a/zerver/lib/topic.py +++ b/zerver/lib/topic.py @@ -5,7 +5,7 @@ from django.db.models.query import Q, QuerySet from sqlalchemy.sql import column, func, literal from zerver.lib.request import REQ -from zerver.models import Message, Recipient, Stream, UserMessage, UserProfile +from zerver.models import Message, Stream, UserMessage, UserProfile # Only use these constants for events. ORIG_TOPIC = "orig_subject" @@ -158,7 +158,7 @@ def generate_topic_history_from_db_rows(rows: List[Tuple[str, int]]) -> List[Dic ) return sorted(history, key=lambda x: -x['max_id']) -def get_topic_history_for_public_stream(recipient: Recipient) -> List[Dict[str, Any]]: +def get_topic_history_for_public_stream(recipient_id: int) -> List[Dict[str, Any]]: cursor = connection.cursor() query = ''' SELECT @@ -173,17 +173,17 @@ def get_topic_history_for_public_stream(recipient: Recipient) -> List[Dict[str, ) ORDER BY max("zerver_message".id) DESC ''' - cursor.execute(query, [recipient.id]) + cursor.execute(query, [recipient_id]) rows = cursor.fetchall() cursor.close() return generate_topic_history_from_db_rows(rows) def get_topic_history_for_stream(user_profile: UserProfile, - recipient: Recipient, + recipient_id: int, public_history: bool) -> List[Dict[str, Any]]: if public_history: - return get_topic_history_for_public_stream(recipient) + return get_topic_history_for_public_stream(recipient_id) cursor = connection.cursor() query = ''' @@ -203,7 +203,7 @@ def get_topic_history_for_stream(user_profile: UserProfile, ) ORDER BY max("zerver_message".id) DESC ''' - cursor.execute(query, [user_profile.id, recipient.id]) + cursor.execute(query, [user_profile.id, recipient_id]) rows = cursor.fetchall() cursor.close() diff --git a/zerver/views/archive.py b/zerver/views/archive.py index fe3ed631b9..f4f2ae5eab 100644 --- a/zerver/views/archive.py +++ b/zerver/views/archive.py @@ -85,6 +85,6 @@ def get_web_public_topics_backend(request: HttpRequest, stream_id: int) -> HttpR if not stream.is_web_public: return json_success(dict(topics=[])) - result = get_topic_history_for_public_stream(recipient=stream.recipient) + result = get_topic_history_for_public_stream(recipient_id=stream.recipient_id) return json_success(dict(topics=result)) diff --git a/zerver/views/streams.py b/zerver/views/streams.py index cf65126f76..a8811a54e4 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -666,7 +666,7 @@ def get_topics_backend( if is_web_public_query: realm = get_valid_realm_from_request(request) stream = access_web_public_stream(stream_id, realm) - result = get_topic_history_for_public_stream(recipient=stream.recipient) + result = get_topic_history_for_public_stream(recipient_id=stream.recipient_id) else: assert user_profile is not None @@ -675,7 +675,7 @@ def get_topics_backend( result = get_topic_history_for_stream( user_profile=user_profile, - recipient=recipient, + recipient_id=stream.recipient_id, public_history=stream.is_history_public_to_subscribers(), )