snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
87
zerver/actions/user_topics.py
Normal file
87
zerver/actions/user_topics.py
Normal file
@@ -0,0 +1,87 @@
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from django.db import transaction
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from zerver.lib.timestamp import datetime_to_timestamp
|
||||
from zerver.lib.topic import maybe_rename_general_chat_to_empty_topic
|
||||
from zerver.lib.user_topics import (
|
||||
bulk_set_user_topic_visibility_policy_in_database,
|
||||
get_topic_mutes,
|
||||
)
|
||||
from zerver.models import Stream, UserProfile
|
||||
from zerver.tornado.django_api import send_event_on_commit
|
||||
|
||||
|
||||
@transaction.atomic(savepoint=False)
|
||||
def bulk_do_set_user_topic_visibility_policy(
|
||||
user_profiles: list[UserProfile],
|
||||
stream: Stream,
|
||||
topic_name: str,
|
||||
*,
|
||||
visibility_policy: int,
|
||||
last_updated: datetime | None = None,
|
||||
skip_muted_topics_event: bool = False,
|
||||
) -> None:
|
||||
if last_updated is None:
|
||||
last_updated = timezone_now()
|
||||
|
||||
topic_name = maybe_rename_general_chat_to_empty_topic(topic_name)
|
||||
|
||||
user_profiles_with_changed_user_topic_rows = bulk_set_user_topic_visibility_policy_in_database(
|
||||
user_profiles,
|
||||
stream.id,
|
||||
topic_name,
|
||||
visibility_policy=visibility_policy,
|
||||
recipient_id=stream.recipient_id,
|
||||
last_updated=last_updated,
|
||||
)
|
||||
|
||||
# Users with requests to set the visibility_policy to its current value
|
||||
# or to delete a UserTopic row that doesn't exist shouldn't
|
||||
# send an unnecessary event.
|
||||
if len(user_profiles_with_changed_user_topic_rows) == 0:
|
||||
return
|
||||
|
||||
for user_profile in user_profiles_with_changed_user_topic_rows:
|
||||
# This first muted_topics event is deprecated and will be removed
|
||||
# once clients are migrated to handle the user_topic event type
|
||||
# instead.
|
||||
if not skip_muted_topics_event:
|
||||
muted_topics_event = dict(
|
||||
type="muted_topics", muted_topics=get_topic_mutes(user_profile)
|
||||
)
|
||||
send_event_on_commit(user_profile.realm, muted_topics_event, [user_profile.id])
|
||||
|
||||
user_topic_event: dict[str, Any] = {
|
||||
"type": "user_topic",
|
||||
"stream_id": stream.id,
|
||||
"topic_name": topic_name,
|
||||
"last_updated": datetime_to_timestamp(last_updated),
|
||||
"visibility_policy": visibility_policy,
|
||||
}
|
||||
|
||||
send_event_on_commit(user_profile.realm, user_topic_event, [user_profile.id])
|
||||
|
||||
|
||||
def do_set_user_topic_visibility_policy(
|
||||
user_profile: UserProfile,
|
||||
stream: Stream,
|
||||
topic_name: str,
|
||||
*,
|
||||
visibility_policy: int,
|
||||
last_updated: datetime | None = None,
|
||||
skip_muted_topics_event: bool = False,
|
||||
) -> None:
|
||||
# For conciseness, this function should be used when a single
|
||||
# user_profile is involved. In the case of multiple user profiles,
|
||||
# call 'bulk_do_set_user_topic_visibility_policy' directly.
|
||||
bulk_do_set_user_topic_visibility_policy(
|
||||
[user_profile],
|
||||
stream,
|
||||
topic_name,
|
||||
visibility_policy=visibility_policy,
|
||||
last_updated=last_updated,
|
||||
skip_muted_topics_event=skip_muted_topics_event,
|
||||
)
|
||||
Reference in New Issue
Block a user