mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 17:07:07 +00:00
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:
@@ -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);
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user