From 8c50a08066940edbf759801cf3caa683a822d5cd Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Tue, 10 Nov 2020 20:27:14 +0530 Subject: [PATCH] stream_edit: Live update UI when a stream becomes web public. --- frontend_tests/node_tests/stream_events.js | 2 ++ static/js/server_events_dispatch.js | 1 + static/js/stream_data.js | 1 + static/js/stream_edit.js | 15 ++++++++++++++- static/js/stream_events.js | 1 + static/js/stream_list.js | 1 + 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.js index fc86036e75..2db9835ad1 100644 --- a/frontend_tests/node_tests/stream_events.js +++ b/frontend_tests/node_tests/stream_events.js @@ -205,6 +205,7 @@ test("update_property", ({override}) => { override(stream_settings_ui, "update_stream_privacy", stub.f); stream_events.update_property(stream_id, "invite_only", true, { history_public_to_subscribers: true, + is_web_public: false, }); assert.equal(stub.num_calls, 1); const args = stub.get_args("sub", "val"); @@ -212,6 +213,7 @@ test("update_property", ({override}) => { assert.deepEqual(args.val, { invite_only: true, history_public_to_subscribers: true, + is_web_public: false, }); } diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index f54dddced9..3a07577a1d 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -448,6 +448,7 @@ export function dispatch_normal_event(event) { stream_events.update_property(event.stream_id, event.property, event.value, { rendered_description: event.rendered_description, history_public_to_subscribers: event.history_public_to_subscribers, + is_web_public: event.is_web_public, }); settings_streams.update_default_streams_table(); break; diff --git a/static/js/stream_data.js b/static/js/stream_data.js index 843a5672ef..3947667711 100644 --- a/static/js/stream_data.js +++ b/static/js/stream_data.js @@ -454,6 +454,7 @@ export function update_stream_post_policy(sub, stream_post_policy) { export function update_stream_privacy(sub, values) { sub.invite_only = values.invite_only; sub.history_public_to_subscribers = values.history_public_to_subscribers; + sub.is_web_public = values.is_web_public; } export function update_message_retention_setting(sub, message_retention_days) { diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js index 34f8cb7fb3..abac02bdc2 100644 --- a/static/js/stream_edit.js +++ b/static/js/stream_edit.js @@ -664,32 +664,45 @@ function change_stream_privacy(e) { let invite_only; let history_public_to_subscribers; + let is_web_public; switch (privacy_setting) { case stream_data.stream_privacy_policy_values.public.code: { invite_only = false; history_public_to_subscribers = true; + is_web_public = false; break; } case stream_data.stream_privacy_policy_values.private.code: { invite_only = true; history_public_to_subscribers = false; + is_web_public = false; + + break; + } + case stream_data.stream_privacy_policy_values.web_public.code: { + invite_only = false; + history_public_to_subscribers = true; + is_web_public = true; break; } default: { invite_only = true; history_public_to_subscribers = true; + is_web_public = false; } } if ( sub.invite_only !== invite_only || - sub.history_public_to_subscribers !== history_public_to_subscribers + sub.history_public_to_subscribers !== history_public_to_subscribers || + sub.is_web_public !== is_web_public ) { data.is_private = JSON.stringify(invite_only); data.history_public_to_subscribers = JSON.stringify(history_public_to_subscribers); + data.is_web_public = JSON.stringify(is_web_public); } let message_retention_days = $( diff --git a/static/js/stream_events.js b/static/js/stream_events.js index b92ddbedf9..7dca8e8a3a 100644 --- a/static/js/stream_events.js +++ b/static/js/stream_events.js @@ -82,6 +82,7 @@ export function update_property(stream_id, property, value, other_values) { stream_settings_ui.update_stream_privacy(sub, { invite_only: value, history_public_to_subscribers: other_values.history_public_to_subscribers, + is_web_public: other_values.is_web_public, }); break; case "stream_post_policy": diff --git a/static/js/stream_list.js b/static/js/stream_list.js index 825521cc98..f9c4f9002f 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -311,6 +311,7 @@ export function redraw_stream_privacy(sub) { const args = { invite_only: sub.invite_only, + is_web_public: sub.is_web_public, dark_background, };