Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

streams: Add default_push_notifications field to Stream.

Aadyot142c2accc0cde
diff --git a/api_docs/unmerged.d/ZF-a71492.md b/api_docs/unmerged.d/ZF-a71492.md
new file mode 100644
index 00000000000..837a0c500d2
--- /dev/null
+++ b/api_docs/unmerged.d/ZF-a71492.md
@@ -0,0 +1,9 @@
+* [`POST /register`](/api/register-queue), [`GET /events`](/api/get-events),
+ [`GET /streams`](/api/get-streams),
+ [`GET /streams/{stream_id}`](/api/get-stream-by-id): Added
+ `default_push_notifications` boolean field to channel objects, which
+ indicates whether mobile push notifications will be enabled by default
+ when a user first subscribes to the channel, potentially overriding the
+ user's [default mobile notification
+ setting](/help/channel-notifications#configure-default-notifications-for-all-channels)
+ for channel messages.
diff --git a/zerver/actions/streams.py b/zerver/actions/streams.py
index efc1e7f6aa1..9800dc4993c 100644
--- a/zerver/actions/streams.py
+++ b/zerver/actions/streams.py
@@ -482,6 +482,7 @@ def send_subscription_add_events(
is_web_public=stream_dict["is_web_public"],
message_retention_days=stream_dict["message_retention_days"],
name=stream_dict["name"],
+ default_push_notifications=stream_dict["default_push_notifications"],
rendered_description=stream_dict["rendered_description"],
stream_id=stream_dict["stream_id"],
stream_post_policy=stream_dict["stream_post_policy"],
diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py
index 7e4720eb884..e4971f7e9e3 100644
--- a/zerver/lib/streams.py
+++ b/zerver/lib/streams.py
@@ -85,6 +85,7 @@ class StreamDict(TypedDict, total=False):
"""
name: str
+ default_push_notifications: bool
description: str
invite_only: bool
is_web_public: bool
@@ -369,6 +370,7 @@ def create_stream_if_needed(
realm: Realm,
stream_name: str,
*,
+ default_push_notifications: bool = False,
invite_only: bool = False,
is_web_public: bool = False,
history_public_to_subscribers: bool | None = None,
@@ -428,6 +430,7 @@ def create_stream_if_needed(
is_web_public=is_web_public,
history_public_to_subscribers=history_public_to_subscribers,
message_retention_days=message_retention_days,
+ default_push_notifications=default_push_notifications,
folder=folder,
topics_policy=topics_policy,
**group_setting_values,
@@ -504,6 +507,7 @@ def create_streams_if_needed(
history_public_to_subscribers=stream_dict.get("history_public_to_subscribers"),
stream_description=stream_dict.get("description", ""),
message_retention_days=stream_dict.get("message_retention_days", None),
+ default_push_notifications=stream_dict.get("default_push_notifications", False),
topics_policy=stream_dict.get("topics_policy", None),
can_add_subscribers_group=stream_dict.get("can_add_subscribers_group", None),
can_administer_channel_group=stream_dict.get("can_administer_channel_group", None),
@@ -1880,6 +1884,7 @@ def stream_to_dict(
is_web_public=stream.is_web_public,
message_retention_days=stream.message_retention_days,
name=stream.name,
+ default_push_notifications=stream.default_push_notifications,
rendered_description=stream.rendered_description,
stream_id=stream.id,
stream_post_policy=stream_post_policy,
diff --git a/zerver/lib/subscription_info.py b/zerver/lib/subscription_info.py
index 64cd195f282..08e6f4f29b7 100644
--- a/zerver/lib/subscription_info.py
+++ b/zerver/lib/subscription_info.py
@@ -108,6 +108,7 @@ def get_web_public_subs(
invite_only = stream.invite_only
is_web_public = stream.is_web_public
message_retention_days = stream.message_retention_days
+ default_push_notifications = stream.default_push_notifications
name = stream.name
rendered_description = stream.rendered_description
stream_id = stream.id
@@ -165,6 +166,7 @@ def get_web_public_subs(
name=name,
pin_to_top=pin_to_top,
push_notifications=push_notifications,
+ default_push_notifications=default_push_notifications,
rendered_description=rendered_description,
stream_id=stream_id,
stream_post_policy=stream_post_policy,
@@ -265,6 +267,7 @@ def build_stream_api_dict(
is_web_public=raw_stream_dict["is_web_public"],
message_retention_days=raw_stream_dict["message_retention_days"],
name=raw_stream_dict["name"],
+ default_push_notifications=raw_stream_dict["default_push_notifications"],
rendered_description=raw_stream_dict["rendered_description"],
stream_id=raw_stream_dict["id"],
stream_post_policy=raw_stream_dict["stream_post_policy"],
@@ -303,6 +306,7 @@ def build_stream_dict_for_sub(
invite_only = stream_dict["invite_only"]
is_web_public = stream_dict["is_web_public"]
message_retention_days = stream_dict["message_retention_days"]
+ default_push_notifications = stream_dict["default_push_notifications"]
name = stream_dict["name"]
rendered_description = stream_dict["rendered_description"]
stream_id = stream_dict["stream_id"]
@@ -361,6 +365,7 @@ def build_stream_dict_for_sub(
name=name,
pin_to_top=pin_to_top,
push_notifications=push_notifications,
+ default_push_notifications=default_push_notifications,
rendered_description=rendered_description,
stream_id=stream_id,
stream_post_policy=stream_post_policy,
@@ -387,6 +392,7 @@ def build_stream_dict_for_never_sub(
invite_only = raw_stream_dict["invite_only"]
is_web_public = raw_stream_dict["is_web_public"]
message_retention_days = raw_stream_dict["message_retention_days"]
+ default_push_notifications = raw_stream_dict["default_push_notifications"]
name = raw_stream_dict["name"]
rendered_description = raw_stream_dict["rendered_description"]
stream_id = raw_stream_dict["id"]
@@ -463,6 +469,7 @@ def build_stream_dict_for_never_sub(
is_announcement_only=is_announcement_only,
is_web_public=is_web_public,
message_retention_days=message_retention_days,
+ default_push_notifications=default_push_notifications,
name=name,
rendered_description=rendered_description,
stream_id=stream_id,
diff --git a/zerver/lib/types.py b/zerver/lib/types.py
index 842fe0ec2a8..7bca057545d 100644
--- a/zerver/lib/types.py
+++ b/zerver/lib/types.py
@@ -182,6 +182,7 @@ class RawStreamDict(TypedDict):
creator_id: int | None
date_created: datetime
deactivated: bool
+ default_push_notifications: bool
description: str
first_message_id: int | None
folder_id: int | None
@@ -237,6 +238,7 @@ class SubscriptionStreamDict(TypedDict):
color: str
creator_id: int | None
date_created: int
+ default_push_notifications: bool
description: str
desktop_notifications: bool | None
email_notifications: bool | None
@@ -280,6 +282,7 @@ class NeverSubscribedStreamDict(TypedDict):
can_subscribe_group: int | UserGroupMembersDict
creator_id: int | None
date_created: int
+ default_push_notifications: bool
description: str
first_message_id: int | None
folder_id: int | None
@@ -320,6 +323,7 @@ class DefaultStreamDict(TypedDict):
can_subscribe_group: int | UserGroupMembersDict
creator_id: int | None
date_created: int
+ default_push_notifications: bool
description: str
first_message_id: int | None
folder_id: int | None
diff --git a/zerver/migrations/0806_stream_default_push_notifications.py b/zerver/migrations/0806_stream_default_push_notifications.py
new file mode 100644
index 00000000000..580d4b55c12
--- /dev/null
+++ b/zerver/migrations/0806_stream_default_push_notifications.py
@@ -0,0 +1,15 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("zerver", "0805_fix_deleteduser_email"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="stream",
+ name="default_push_notifications",
+ field=models.BooleanField(default=False, db_default=False),
+ ),
+ ]
diff --git a/zerver/models/streams.py b/zerver/models/streams.py
index 29089057b01..58c5ba04e6a 100644
--- a/zerver/models/streams.py
+++ b/zerver/models/streams.py
@@ -118,6 +118,10 @@ class Stream(models.Model):
}
message_retention_days = models.IntegerField(null=True, default=None)
+ # When True, new subscriptions default to push_notifications=True instead of
+ # inheriting from the user's account-level default.
+ default_push_notifications = models.BooleanField(default=False, db_default=False)
+
# on_delete field for group value settings is set to RESTRICT
# because we don't want to allow deleting a user group in case it
# is referenced by the respective setting. We are not using PROTECT
@@ -267,6 +271,7 @@ class Stream(models.Model):
"creator_id",
"date_created",
"deactivated",
+ "default_push_notifications",
"description",
"first_message_id",
"folder_id",
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 8bdba457164..f7455db38f7 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -1595,6 +1595,7 @@ paths:
"folder_id": 1,
"is_recently_active": true,
"message_retention_days": null,
+ "default_push_notifications": false,
"is_announcement_only": false,
"can_add_subscribers_group": 2,
"can_remove_subscribers_group": 2,
@@ -19168,6 +19169,7 @@ paths:
stream_post_policy: {}
message_retention_days:
nullable: true
+ default_push_notifications: {}
history_public_to_subscribers: {}
topics_policy: {}
first_message_id:
@@ -24223,6 +24225,7 @@ paths:
stream_post_policy: {}
message_retention_days:
nullable: true
+ default_push_notifications: {}
history_public_to_subscribers: {}
topics_policy: {}
first_message_id:
@@ -24280,6 +24283,7 @@ paths:
- is_web_public
- stream_post_policy
- message_retention_days
+ - default_push_notifications
- history_public_to_subscribers
- first_message_id
- folder_id
@@ -24312,6 +24316,7 @@ paths:
"is_default": false,
"is_web_public": false,
"message_retention_days": null,
+ "default_push_notifications": false,
"name": "management",
"rendered_description": "<p>A private channel</p>",
"stream_id": 2,
@@ -24336,6 +24341,7 @@ paths:
"is_default": true,
"is_web_public": false,
"message_retention_days": null,
+ "default_push_notifications": false,
"name": "welcome",
"rendered_description": "<p>A default public channel</p>",
"stream_id": 1,
@@ -24392,6 +24398,7 @@ paths:
"is_archived": false,
"is_web_public": false,
"message_retention_days": null,
+ "default_push_notifications": false,
"name": "Denmark",
"rendered_description": "<p>A Scandinavian country</p>",
"stream_id": 7,
@@ -27417,6 +27424,7 @@ components:
stream_post_policy: {}
message_retention_days:
nullable: true
+ default_push_notifications: {}
history_public_to_subscribers: {}
topics_policy: {}
first_message_id:
@@ -27465,6 +27473,7 @@ components:
- stream_post_policy
- subscriber_count
- message_retention_days
+ - default_push_notifications
- history_public_to_subscribers
- first_message_id
- folder_id
@@ -27582,6 +27591,8 @@ components:
- `-1` encodes retaining messages in this channel forever.
**Changes**: New in Zulip 3.0 (feature level 17).
+ default_push_notifications:
+ $ref: "#/components/schemas/DefaultPushNotifications"
history_public_to_subscribers:
type: boolean
description: |
@@ -28733,6 +28744,8 @@ components:
- `-1` encodes retaining messages in this channel forever.
**Changes**: New in Zulip 3.0 (feature level 17).
+ default_push_notifications:
+ $ref: "#/components/schemas/DefaultPushNotifications"
history_public_to_subscribers:
type: boolean
description: |
@@ -30795,6 +30808,23 @@ components:
- type: string
- type: integer
example: "20"
+ DefaultPushNotifications:
+ type: boolean
+ description: |
+ Whether mobile push notifications will be enabled by default when a
+ user first subscribes to this channel, potentially overriding the
+ user's [default mobile notification
+ setting](/help/channel-notifications#configure-default-notifications-for-all-channels)
+ for channel messages.
+
+ Because this default is applied only the first time a user
+ subscribes, unsubscribing and resubscribing a user does not reset
+ their preference to this channel default.
+
+ Only organization administrators can set or modify this value.
+
+ **Changes**: New in Zulip 13.0 (feature level ZF-a71492).
+ example: true
TopicsPolicy:
type: string
enum: