mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 07:23:22 +00:00
compose: Restore the last draft when compose box is opened.
Now when the user opens a narrow that has a draft saved for that particular conversation, the draft will automatically be restored in the compose box. This will make it easy to return to a draft after clicking away, and also will make it less confusing when people close the compose box by accident. Note that this only restores the draft when there is a full recipient specified (stream and topic, or at least one PM recipient). Fixes part of #18555. Fixes #11218 and #17396.
This commit is contained in:
@@ -493,6 +493,20 @@ export function filter_drafts_by_compose_box_and_recipient(
|
||||
return _.pick(drafts, narrow_drafts_ids);
|
||||
}
|
||||
|
||||
export function get_last_draft_based_on_compose_state(): LocalStorageDraftWithId | undefined {
|
||||
const current_drafts = draft_model.get();
|
||||
const drafts_map_for_compose_state = filter_drafts_by_compose_box_and_recipient(current_drafts);
|
||||
const drafts_for_compose_state = Object.entries(drafts_map_for_compose_state).map(
|
||||
([draft_id, draft]) => ({
|
||||
...draft,
|
||||
id: draft_id,
|
||||
}),
|
||||
);
|
||||
return drafts_for_compose_state
|
||||
.sort((draft_a, draft_b) => draft_a.updatedAt - draft_b.updatedAt)
|
||||
.pop();
|
||||
}
|
||||
|
||||
export function remove_old_drafts(): void {
|
||||
const old_date = subDays(new Date(), DRAFT_LIFETIME).getTime();
|
||||
const drafts = draft_model.get();
|
||||
|
||||
Reference in New Issue
Block a user