drafts: Update drafts when topics are moved.

We've for years done this for the currently open compose box state,
and it seems very natural to do this for drafts as well.

Fixes #22068.
This commit is contained in:
evykassirer
2022-05-19 11:32:26 -07:00
committed by Tim Abbott
parent 668a215ef9
commit 4c8079c49a
2 changed files with 18 additions and 2 deletions

View File

@@ -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