mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	drafts: Delete a draft if it is cleared from the compose box.
We used to keep the draft, assuming that clearing the composebox was an accident. Now we want to delete the draft, in preparation for auto-restoring drafts when opening the composebox for narrows with drafts associated with them. If a user opens the composebox and sees a draft they don't want anymore, clearing the box is a way we expect them to try to delete it.
This commit is contained in:
		@@ -235,6 +235,20 @@ async function test_save_draft_by_reloading(page: Page): Promise<void> {
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function test_delete_draft_on_clearing_text(page: Page): Promise<void> {
 | 
			
		||||
    console.log("Deleting draft by clearing compose box textarea.");
 | 
			
		||||
    await page.click("#drafts_table .message_row:not(.private-message) .restore-overlay-message");
 | 
			
		||||
    await wait_for_drafts_to_disappear(page);
 | 
			
		||||
    await page.waitForSelector("#send_message_form", {visible: true});
 | 
			
		||||
    await common.fill_form(page, "form#send_message_form", {content: ""});
 | 
			
		||||
    await page.click("#compose_close");
 | 
			
		||||
    await page.waitForSelector("#send_message_form", {hidden: true});
 | 
			
		||||
    await page.click(drafts_button);
 | 
			
		||||
    await wait_for_drafts_to_appear(page);
 | 
			
		||||
    const drafts_count = await get_drafts_count(page);
 | 
			
		||||
    assert.strictEqual(drafts_count, 1, "Draft not deleted.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function drafts_test(page: Page): Promise<void> {
 | 
			
		||||
    await common.log_in(page);
 | 
			
		||||
    await page.click("#left-sidebar-navigation-list .top_left_all_messages");
 | 
			
		||||
@@ -256,6 +270,7 @@ async function drafts_test(page: Page): Promise<void> {
 | 
			
		||||
    await test_restore_private_message_draft_via_draft_overlay(page);
 | 
			
		||||
    await test_delete_draft(page);
 | 
			
		||||
    await test_save_draft_by_reloading(page);
 | 
			
		||||
    await test_delete_draft_on_clearing_text(page);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
common.run_test(drafts_test);
 | 
			
		||||
 
 | 
			
		||||
@@ -377,18 +377,18 @@ type UpdateDraftOptions = {
 | 
			
		||||
export function update_draft(opts: UpdateDraftOptions = {}): string | undefined {
 | 
			
		||||
    const no_notify = opts.no_notify ?? false;
 | 
			
		||||
    const draft = snapshot_message();
 | 
			
		||||
    const draft_id = $("textarea#compose-textarea").data("draft-id");
 | 
			
		||||
 | 
			
		||||
    if (draft === undefined) {
 | 
			
		||||
        // The user cleared the compose box, which means
 | 
			
		||||
        // there is nothing to save here.  Don't obliterate
 | 
			
		||||
        // the existing draft yet--the user may have mistakenly
 | 
			
		||||
        // hit delete after select-all or something.
 | 
			
		||||
        // Just do nothing.
 | 
			
		||||
        // there is nothing to save here but delete the
 | 
			
		||||
        // draft if exists.
 | 
			
		||||
        if (draft_id) {
 | 
			
		||||
            draft_model.deleteDraft(draft_id);
 | 
			
		||||
        }
 | 
			
		||||
        return undefined;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const draft_id = $("textarea#compose-textarea").data("draft-id");
 | 
			
		||||
 | 
			
		||||
    if (draft_id !== undefined) {
 | 
			
		||||
        // We don't save multiple drafts of the same message;
 | 
			
		||||
        // just update the existing draft.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user