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: Show message retention policy details in subscription_type text.

sahil839821e25ffb01b
diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.js
index 490f7ee9ae1..2bfa37c2bd3 100644
--- a/frontend_tests/node_tests/stream_events.js
+++ b/frontend_tests/node_tests/stream_events.js
@@ -160,7 +160,7 @@ run_test('update_property', () => {
// Test stream message_retention_days change event
with_overrides(function (override) {
global.with_stub(function (stub) {
- override('stream_data.update_message_retention_setting', stub.f);
+ override('subs.update_message_retention_setting', stub.f);
stream_events.update_property(1, 'message_retention_days', 20);
const args = stub.get_args('sub', 'val');
assert.equal(args.sub.stream_id, 1);
diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js
index 7bfd713993a..fd0c3527f7b 100644
--- a/static/js/stream_edit.js
+++ b/static/js/stream_edit.js
@@ -63,6 +63,30 @@ exports.get_users_from_subscribers = function (subscribers) {
});
};
+exports.get_retention_policy_text_for_subscription_type = function (sub) {
+ let message_retention_days = sub.message_retention_days;
+ // If both this stream and the organization-level policy are to retain forever,
+ // there's no need to comment on retention policies when describing the stream.
+ if ((page_params.realm_message_retention_days === -1 ||
+ page_params.realm_message_retention_days === null)
+ && (sub.message_retention_days === null || sub.message_retention_days === -1)) {
+ return;
+ }
+
+ // Forever for this stream, overriding the organization default
+ if (sub.message_retention_days === -1) {
+ return i18n.t("Messages in this stream will be retained forever.");
+ }
+
+ // If we are deleting messages, even if it's the organization
+ // default, it's worth commenting on the policy.
+ if (message_retention_days === null) {
+ message_retention_days = page_params.realm_message_retention_days;
+ }
+
+ return i18n.t("Messages in this stream will be automatically deleted after __retention_days__ days.", {retention_days: message_retention_days});
+};
+
exports.get_display_text_for_realm_message_retention_setting = function () {
const realm_message_retention_days = page_params.realm_message_retention_days;
if (realm_message_retention_days === -1 || realm_message_retention_days === null) {
@@ -315,6 +339,7 @@ exports.show_settings_for = function (node) {
sub: sub,
settings: exports.stream_settings(sub),
stream_post_policy_values: stream_data.stream_post_policy_values,
+ message_retention_text: exports.get_retention_policy_text_for_subscription_type(sub),
});
ui.get_content_element($('.subscriptions .right .settings')).html(html);
diff --git a/static/js/stream_events.js b/static/js/stream_events.js
index 9245dbad353..e055b7ce223 100644
--- a/static/js/stream_events.js
+++ b/static/js/stream_events.js
@@ -56,7 +56,7 @@ exports.update_property = function (stream_id, property, value, other_values) {
subs.update_stream_post_policy(sub, value);
break;
case 'message_retention_days':
- stream_data.update_message_retention_setting(sub, value);
+ subs.update_message_retention_setting(sub, value);
break;
default:
blueslip.warn("Unexpected subscription property type", {property: property,
diff --git a/static/js/stream_ui_updates.js b/static/js/stream_ui_updates.js
index 72e8755837c..0eb86dabe17 100644
--- a/static/js/stream_ui_updates.js
+++ b/static/js/stream_ui_updates.js
@@ -146,6 +146,7 @@ exports.update_stream_subscription_type_text = function (sub) {
const template_data = {
...sub,
stream_post_policy_values: stream_data.stream_post_policy_values,
+ message_retention_text: stream_edit.get_retention_policy_text_for_subscription_type(sub),
};
const html = render_subscription_type(template_data);
if (stream_edit.is_sub_settings_active(sub)) {
diff --git a/static/js/subs.js b/static/js/subs.js
index bdb91c912f3..93bbea320c5 100644
--- a/static/js/subs.js
+++ b/static/js/subs.js
@@ -192,6 +192,11 @@ exports.update_stream_post_policy = function (sub, new_value) {
stream_ui_updates.update_stream_subscription_type_text(sub);
};
+exports.update_message_retention_setting = function (sub, new_value) {
+ stream_data.update_message_retention_setting(sub, new_value);
+ stream_ui_updates.update_stream_subscription_type_text(sub);
+};
+
exports.set_color = function (stream_id, color) {
const sub = stream_data.get_sub_by_id(stream_id);
stream_edit.set_stream_property(sub, 'color', color);
diff --git a/static/templates/subscription_settings.hbs b/static/templates/subscription_settings.hbs
index 4979c7ba996..38a3616f0d2 100644
--- a/static/templates/subscription_settings.hbs
+++ b/static/templates/subscription_settings.hbs
@@ -35,7 +35,8 @@
<div class="subscription-type">
<div class="subscription-type-text">
{{> subscription_type
- stream_post_policy_values=../stream_post_policy_values}}
+ stream_post_policy_values=../stream_post_policy_values
+ message_retention_text=../message_retention_text}}
</div>
<a class="change-stream-privacy" {{#unless can_change_stream_permissions}}style="display: none;"{{/unless}}>[{{t "Change" }}]</a>
</div>
diff --git a/static/templates/subscription_type.hbs b/static/templates/subscription_type.hbs
index a453813a7b2..63b906f9739 100644
--- a/static/templates/subscription_type.hbs
+++ b/static/templates/subscription_type.hbs
@@ -15,3 +15,4 @@
{{else}}
{{t 'All stream members can post.'}}
{{/if}}
+{{message_retention_text}}