diff --git a/static/js/drafts.js b/static/js/drafts.js index bb25d0e653..3cfcdb251b 100644 --- a/static/js/drafts.js +++ b/static/js/drafts.js @@ -74,7 +74,7 @@ export const draft_model = (function () { return id; }; - exports.editDraft = function (id, draft) { + exports.editDraft = function (id, draft, update_timestamp = true) { const drafts = get(); let changed = false; @@ -84,7 +84,9 @@ export const draft_model = (function () { if (drafts[id]) { changed = !check_if_equal(drafts[id], draft); - draft.updatedAt = getTimestamp(); + if (update_timestamp) { + draft.updatedAt = getTimestamp(); + } drafts[id] = draft; save(drafts); } @@ -118,6 +120,17 @@ export function confirm_delete_all_drafts() { }); } +export function rename_topic(stream_id, old_topic, new_topic) { + const current_drafts = draft_model.get(); + for (const draft_id of Object.keys(current_drafts)) { + const draft = current_drafts[draft_id]; + if (util.same_stream_and_topic(draft, {stream_id, topic: old_topic})) { + draft.topic = new_topic; + draft_model.editDraft(draft_id, draft, false); + } + } +} + export function snapshot_message() { if (!compose_state.composing() || compose_state.message_content().length <= 2) { // If you aren't in the middle of composing the body of a diff --git a/static/js/message_events.js b/static/js/message_events.js index 548a0a91b1..86922c3116 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -7,6 +7,7 @@ import * as compose_fade from "./compose_fade"; import * as compose_state from "./compose_state"; import * as compose_validate from "./compose_validate"; import * as condense from "./condense"; +import * as drafts from "./drafts"; import * as huddle_data from "./huddle_data"; import * as message_edit from "./message_edit"; import * as message_edit_history from "./message_edit_history"; @@ -259,6 +260,8 @@ export function update_messages(events) { compose_fade.set_focused_recipient("stream"); } + drafts.rename_topic(event.stream_id, orig_topic, new_topic); + for (const msg of event_messages) { if (page_params.realm_allow_edit_history) { /* Simulate the format of server-generated edit