mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
streams: Use a common func to send stream recently active update event.
This helps us to apply fix for sending event update for private stream to only its subscribers.
This commit is contained in:
@@ -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_topic
|
||||
from 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_bot
|
||||
from 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_active
|
||||
new_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_result
|
||||
|
@@ -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_name
|
||||
from zerver.lib.thumbnail import get_user_upload_previews, rewrite_thumbnailed_images
|
||||
from 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_email
|
||||
from 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 = True
|
||||
stream_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)
|
||||
|
@@ -1540,6 +1540,19 @@ def get_subscribed_private_streams_for_user(user_profile: UserProfile) -> QueryS
|
||||
return 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
|
||||
|
Reference in New Issue
Block a user