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 frontend to set/update message_retention_days of a stream.

sahil839d9b722844415
diff --git a/frontend_tests/node_tests/stream_data.js b/frontend_tests/node_tests/stream_data.js
index 981c3f0a9a2..9d52b6b6ef1 100644
--- a/frontend_tests/node_tests/stream_data.js
+++ b/frontend_tests/node_tests/stream_data.js
@@ -474,6 +474,7 @@ run_test('stream_settings', () => {
invite_only: true,
history_public_to_subscribers: true,
stream_post_policy: stream_data.stream_post_policy_values.admins.code,
+ message_retention_days: 10,
};
stream_data.clear_subscriptions();
stream_data.add_sub(cinnamon);
@@ -496,6 +497,7 @@ run_test('stream_settings', () => {
assert.equal(sub_rows[0].history_public_to_subscribers, true);
assert.equal(sub_rows[0].stream_post_policy ===
stream_data.stream_post_policy_values.admins.code, true);
+ assert.equal(sub_rows[0].message_retention_days, 10);
const sub = stream_data.get_sub('a');
stream_data.update_stream_privacy(sub, {
@@ -503,11 +505,13 @@ run_test('stream_settings', () => {
history_public_to_subscribers: false,
});
stream_data.update_stream_post_policy(sub, 1);
+ stream_data.update_message_retention_setting(sub, -1);
stream_data.update_calculated_fields(sub);
assert.equal(sub.invite_only, false);
assert.equal(sub.history_public_to_subscribers, false);
assert.equal(sub.stream_post_policy,
stream_data.stream_post_policy_values.everyone.code);
+ assert.equal(sub.message_retention_days, -1);
// For guest user only retrieve subscribed streams
sub_rows = stream_data.get_updated_unsorted_subs();
diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.js
index 007b8489d9b..490f7ee9ae1 100644
--- a/frontend_tests/node_tests/stream_events.js
+++ b/frontend_tests/node_tests/stream_events.js
@@ -156,6 +156,17 @@ run_test('update_property', () => {
assert.equal(args.val, stream_data.stream_post_policy_values.admins.code);
});
});
+
+ // 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);
+ stream_events.update_property(1, 'message_retention_days', 20);
+ const args = stub.get_args('sub', 'val');
+ assert.equal(args.sub.stream_id, 1);
+ assert.equal(args.val, 20);
+ });
+ });
});
run_test('marked_subscribed', () => {
diff --git a/static/js/stream_create.js b/static/js/stream_create.js
index 6631d65d461..2fe05ecca73 100644
--- a/static/js/stream_create.js
+++ b/static/js/stream_create.js
@@ -169,6 +169,13 @@ function create_stream() {
data.stream_post_policy = JSON.stringify(stream_post_policy);
+ let message_retention_selection = $('#stream_creation_form select[name=stream_message_retention_setting]').val();
+ if (message_retention_selection === "retain_for_period") {
+ message_retention_selection = parseInt($('#stream_creation_form input[name=stream-message-retention-days]').val(), 10);
+ }
+
+ data.message_retention_days = JSON.stringify(message_retention_selection);
+
const announce = stream_data.realm_has_notifications_stream() &&
$('#announce-new-stream input').prop('checked');
data.announce = JSON.stringify(announce);
@@ -266,6 +273,8 @@ exports.show_new_stream_modal = function () {
// Make the options default to the same each time:
// public, "announce stream" on.
$('#make-invite-only input:radio[value=public]').prop('checked', true);
+ $("#stream_creation_form .stream-message-retention-days-input").hide();
+ $("#stream_creation_form select[name=stream_message_retention_setting]").val("realm_default");
if (stream_data.realm_has_notifications_stream()) {
$('#announce-new-stream').show();
diff --git a/static/js/stream_data.js b/static/js/stream_data.js
index a652aae4837..b2292a5be40 100644
--- a/static/js/stream_data.js
+++ b/static/js/stream_data.js
@@ -427,6 +427,10 @@ exports.update_stream_privacy = function (sub, values) {
sub.history_public_to_subscribers = values.history_public_to_subscribers;
};
+exports.update_message_retention_setting = function (sub, message_retention_days) {
+ sub.message_retention_days = message_retention_days;
+};
+
exports.receives_notifications = function (stream_name, notification_name) {
const sub = exports.get_sub(stream_name);
if (sub === undefined) {
diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js
index 3835ce303fc..7bfd713993a 100644
--- a/static/js/stream_edit.js
+++ b/static/js/stream_edit.js
@@ -63,6 +63,34 @@ exports.get_users_from_subscribers = function (subscribers) {
});
};
+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) {
+ return i18n.t("(forever)");
+ }
+ return i18n.t("(__message_retention_days__ days)", {message_retention_days: realm_message_retention_days});
+};
+
+function change_stream_message_retention_days_block_display_property(value) {
+ if (value === "retain_for_period") {
+ $('.stream-message-retention-days-input').show();
+ } else {
+ $('.stream-message-retention-days-input').hide();
+ }
+}
+
+function set_stream_message_retention_setting_dropdown(stream) {
+ let value = "retain_for_period";
+ if (stream.message_retention_days === null) {
+ value = "realm_default";
+ } else if (stream.message_retention_days === -1) {
+ value = "forever";
+ }
+
+ $(".stream_message_retention_setting").val(value);
+ change_stream_message_retention_days_block_display_property(value);
+}
+
function clear_edit_panel() {
$(".display-type #add_new_stream_title").hide();
$(".display-type #stream_settings_title, .right .settings").show();
@@ -380,6 +408,7 @@ function change_stream_privacy(e) {
const privacy_setting = $('#stream_privacy_modal input[name=privacy]:checked').val();
const stream_post_policy = parseInt($('#stream_privacy_modal input[name=stream-post-policy]:checked').val(), 10);
+ let message_retention_days = $('#stream_privacy_modal select[name=stream_message_retention_setting]').val();
let invite_only;
let history_public_to_subscribers;
@@ -395,6 +424,10 @@ function change_stream_privacy(e) {
history_public_to_subscribers = true;
}
+ if (message_retention_days === 'retain_for_period') {
+ message_retention_days = parseInt($('#stream_privacy_modal input[name=stream-message-retention-days]').val(), 10);
+ }
+
$(".stream_change_property_info").hide();
const data = {
stream_name: sub.name,
@@ -402,6 +435,7 @@ function change_stream_privacy(e) {
is_private: JSON.stringify(invite_only),
stream_post_policy: JSON.stringify(stream_post_policy),
history_public_to_subscribers: JSON.stringify(history_public_to_subscribers),
+ message_retention_days: JSON.stringify(message_retention_days),
};
channel.patch({
@@ -523,10 +557,17 @@ exports.initialize = function () {
is_private_with_public_history: stream.invite_only &&
stream.history_public_to_subscribers,
is_admin: page_params.is_admin,
+ zulip_plan_is_not_limited: page_params.zulip_plan_is_not_limited,
+ stream_message_retention_days: stream.message_retention_days,
+ realm_message_retention_setting:
+ exports.get_display_text_for_realm_message_retention_setting(),
+ upgrade_text_for_wide_organization_logo:
+ page_params.upgrade_text_for_wide_organization_logo,
};
const change_privacy_modal = render_subscription_stream_privacy_modal(template_data);
$("#stream_privacy_modal").remove();
$("#subscriptions_table").append(change_privacy_modal);
+ set_stream_message_retention_setting_dropdown(stream);
overlays.open_modal('#stream_privacy_modal');
e.preventDefault();
e.stopPropagation();
@@ -687,6 +728,11 @@ exports.initialize = function () {
exports.open_edit_panel_for_row(this);
}
});
+
+ $("#subscriptions_table").on("change", ".stream_message_retention_setting", function (e) {
+ const dropdown_value = e.target.value;
+ change_stream_message_retention_days_block_display_property(dropdown_value);
+ });
};
window.stream_edit = exports;
diff --git a/static/js/stream_events.js b/static/js/stream_events.js
index f35aba93df1..9245dbad353 100644
--- a/static/js/stream_events.js
+++ b/static/js/stream_events.js
@@ -55,6 +55,9 @@ exports.update_property = function (stream_id, property, value, other_values) {
case 'stream_post_policy':
subs.update_stream_post_policy(sub, value);
break;
+ case 'message_retention_days':
+ stream_data.update_message_retention_setting(sub, value);
+ break;
default:
blueslip.warn("Unexpected subscription property type", {property: property,
value: value});
diff --git a/static/js/subs.js b/static/js/subs.js
index 2466b0261d7..bdb91c912f3 100644
--- a/static/js/subs.js
+++ b/static/js/subs.js
@@ -586,6 +586,11 @@ exports.setup_page = function (callback) {
is_admin: page_params.is_admin,
stream_post_policy_values: stream_data.stream_post_policy_values,
stream_post_policy: stream_data.stream_post_policy_values.everyone.code,
+ zulip_plan_is_not_limited: page_params.zulip_plan_is_not_limited,
+ realm_message_retention_setting:
+ stream_edit.get_display_text_for_realm_message_retention_setting,
+ upgrade_text_for_wide_organization_logo:
+ page_params.upgrade_text_for_wide_organization_logo,
};
const rendered = render_subscription_table_body(template_data);
diff --git a/static/styles/subscriptions.scss b/static/styles/subscriptions.scss
index 6bc927aa77f..fbacff2f7d7 100644
--- a/static/styles/subscriptions.scss
+++ b/static/styles/subscriptions.scss
@@ -1061,6 +1061,20 @@ ul.grey-box {
margin-right: 5px;
}
}
+
+ input[type=text] {
+ width: 5ch;
+ text-align: right;
+ }
+
+ label.dropdown-title {
+ display: block;
+ }
+
+ select {
+ width: auto;
+ margin-bottom: 0px;
+ }
}
}
diff --git a/static/templates/stream_types.hbs b/static/templates/stream_types.hbs
index 0ab2d26b03f..5e0736481f3 100644
--- a/static/templates/stream_types.hbs
+++ b/static/templates/stream_types.hbs
@@ -31,4 +31,33 @@
</label>
</li>
{{/each}}
+ {{#if is_admin}}
+ <h4>{{t "Message retention for stream" }}</h4>
+
+ {{> settings/upgrade_tip_widget}}
+
+ <li>
+ <div class="input-group inline-block">
+ <label for="stream_message_retention_setting" class="dropdown-title">{{t "Message retention period" }}</label>
+ <select name="stream_message_retention_setting"
+ class="stream_message_retention_setting" class="prop-element"
+ {{#unless zulip_plan_is_not_limited}}disabled{{/unless}}>
+ <option value="realm_default">{{t 'Use organization level settings '}}{{realm_message_retention_setting}} </option>
+ <option value="forever">{{t 'Retain forever' }}</option>
+ <option value="retain_for_period">{{t 'Retain for N days after posting' }}</option>
+ </select>
+
+ <div class="dependent-inline-block stream-message-retention-days-input">
+ <label class="inline-block">
+ {{t 'N' }}:
+ </label>
+ <input type="text" autocomplete="off"
+ name="stream-message-retention-days"
+ class="stream-message-retention-days"
+ value="{{ stream_message_retention_days }}"
+ {{#unless zulip_plan_is_not_limited}}disabled{{/unless}}/>
+ </div>
+ </div>
+ </li>
+ {{/if}}
</ul>