refactor: Extract stream_data.clean_up_description().

We use this in the few places where update_calculated_fields()
could plausibly be dealing with a new rendered description.
This commit is contained in:
Steve Howell
2021-04-04 17:07:25 +00:00
committed by Tim Abbott
parent 99b177dc7d
commit 5624ed2afe
4 changed files with 10 additions and 5 deletions

View File

@@ -631,6 +631,12 @@ export function create_streams(streams) {
}
}
export function clean_up_description(sub) {
if (sub.rendered_description !== undefined) {
sub.rendered_description = sub.rendered_description.replace("<p>", "").replace("</p>", "");
}
}
export function create_sub_from_server_data(attrs) {
if (!attrs.stream_id) {
// fail fast
@@ -680,6 +686,7 @@ export function create_sub_from_server_data(attrs) {
// TODO: Let stream settings code add these fields.
stream_settings_data.update_calculated_fields(sub);
clean_up_description(sub);
stream_info.set(sub.name, sub);
subs_by_stream_id.set(sub.stream_id, sub);

View File

@@ -436,6 +436,7 @@ export function show_settings_for(node) {
const sub = stream_data.get_sub_by_id(stream_id);
stream_settings_data.update_calculated_fields(sub);
stream_data.clean_up_description(sub);
const html = render_subscription_settings({
sub,
settings: stream_settings(sub),

View File

@@ -60,10 +60,6 @@ export function update_calculated_fields(sub) {
sub.preview_url = hash_util.by_stream_uri(sub.stream_id);
sub.is_old_stream = sub.stream_weekly_traffic !== null;
if (sub.rendered_description !== undefined) {
sub.rendered_description = sub.rendered_description.replace("<p>", "").replace("</p>", "");
}
// Apply the defaults for our notification settings for rendering.
for (const setting of settings_config.stream_specific_notification_settings) {
sub[setting + "_display"] = stream_data.receives_notifications(sub.stream_id, setting);

View File

@@ -209,7 +209,8 @@ export function update_stream_name(sub, new_name) {
export function update_stream_description(sub, description, rendered_description) {
sub.description = description;
sub.rendered_description = rendered_description.replace("<p>", "").replace("</p>", "");
sub.rendered_description = rendered_description;
stream_data.clean_up_description(sub);
// Update stream row
const sub_row = row_for_stream_id(sub.stream_id);