Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
streams: Use a common func to send stream recently active update event.
Aman Agrawala2a1a7f8d152
diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.pyindex 5580ee78b3a..6eb9f034018 100644--- a/zerver/actions/message_edit.py+++ b/zerver/actions/message_edit.py@@ -53,6 +53,7 @@ from zerver.lib.streams import (access_stream_by_id_for_message,can_access_stream_history,check_stream_access_based_on_can_send_message_group,+ notify_stream_is_recently_active_update,)from zerver.lib.string_validation import check_stream_topicfrom zerver.lib.timestamp import datetime_to_timestamp@@ -86,7 +87,7 @@ from zerver.models import (UserTopic,)from zerver.models.streams import get_stream_by_id_in_realm-from zerver.models.users import active_user_ids, get_system_bot+from zerver.models.users import get_system_botfrom zerver.tornado.django_api import send_event_on_commit@@ -1526,14 +1527,6 @@ def check_update_message(if is_stream_active != new_stream.is_recently_active:new_stream.is_recently_active = is_stream_activenew_stream.save(update_fields=["is_recently_active"])- event = dict(- type="stream",- op="update",- property="is_recently_active",- value=is_stream_active,- stream_id=stream_id,- name=new_stream.name,- )- send_event_on_commit(user_profile.realm, event, active_user_ids(user_profile.realm_id))+ notify_stream_is_recently_active_update(new_stream, is_stream_active)return updated_message_resultdiff --git a/zerver/actions/message_send.py b/zerver/actions/message_send.pyindex 7a3474862c5..14a12d774dc 100644--- a/zerver/actions/message_send.py+++ b/zerver/actions/message_send.py@@ -65,7 +65,12 @@ from zerver.lib.stream_subscription import (num_subscribers_for_stream_id,)from zerver.lib.stream_topic import StreamTopicTarget-from zerver.lib.streams import access_stream_for_send_message, ensure_stream, subscribed_to_stream+from zerver.lib.streams import (+ access_stream_for_send_message,+ ensure_stream,+ notify_stream_is_recently_active_update,+ subscribed_to_stream,+)from zerver.lib.string_validation import check_stream_namefrom zerver.lib.thumbnail import get_user_upload_previews, rewrite_thumbnailed_imagesfrom zerver.lib.timestamp import timestamp_to_datetime@@ -102,12 +107,7 @@ from zerver.models.streams import (get_stream_by_id_for_sending_message,get_stream_by_name_for_sending_message,)-from zerver.models.users import (- active_user_ids,- get_system_bot,- get_user_by_delivery_email,- is_cross_realm_bot_email,-)+from zerver.models.users import get_system_bot, get_user_by_delivery_email, is_cross_realm_bot_emailfrom zerver.tornado.django_api import send_event_on_commit@@ -1179,17 +1179,7 @@ def do_send_messages(if not send_request.stream.is_recently_active:send_request.stream.is_recently_active = Truestream_update_fields.append("is_recently_active")- stream_update_event = dict(- type="stream",- op="update",- property="is_recently_active",- value=True,- stream_id=send_request.stream.id,- name=send_request.stream.name,- )- send_event_on_commit(- send_request.realm, stream_update_event, active_user_ids(send_request.realm.id)- )+ notify_stream_is_recently_active_update(send_request.stream, True)if len(stream_update_fields) > 0:send_request.stream.save(update_fields=stream_update_fields)diff --git a/zerver/lib/streams.py b/zerver/lib/streams.pyindex 822289013ca..ea5685e15d5 100644--- a/zerver/lib/streams.py+++ b/zerver/lib/streams.py@@ -1540,6 +1540,19 @@ def get_subscribed_private_streams_for_user(user_profile: UserProfile) -> QuerySreturn subscribed_private_streams+def notify_stream_is_recently_active_update(stream: Stream, value: bool) -> None:+ event = dict(+ type="stream",+ op="update",+ property="is_recently_active",+ value=value,+ stream_id=stream.id,+ name=stream.name,+ )++ send_event_on_commit(stream.realm, event, active_user_ids(stream.realm_id))++@transaction.atomic(durable=True)def update_stream_active_status_for_realm(realm: Realm, date_days_ago: datetime) -> int:recent_messages_subquery = Message.objects.filter(@@ -1554,15 +1567,7 @@ def update_stream_active_status_for_realm(realm: Realm, date_days_ago: datetime)# Send events to notify the users about the change in the stream's active status.for stream in streams_to_mark_inactive:- event = dict(- type="stream",- op="update",- property="is_recently_active",- value=False,- stream_id=stream.id,- name=stream.name,- )- send_event_on_commit(stream.realm, event, active_user_ids(stream.realm_id))+ notify_stream_is_recently_active_update(stream, False)count = streams_to_mark_inactive.update(is_recently_active=False)return count