FIX: save draft when either title or reply is present (#11243)

Here's how draft saving process works currently:

- if only title is present (no reply) the draft is saved
- if only reply is present (no title) the draft is saved
- if both title and reply are present, and reply length is less than
`min_post_length` and the title length is less than
`min_topic_title_length`, then the draft is saved
- if both title and reply are present, and reply length is less than
`min_post_length`, then the draft is not saved

The current draft saving conditions are complex to understand and is
causing confusion as seen here: https://meta.discourse.org/t/draft-is-not-being-saved-when-creating-a-new-pm/149990/6?u=techapj

This commit updates the process to always save the draft if either title
or reply exists.
This commit is contained in:
Arpit Jalan 2020-11-16 16:43:50 +05:30 committed by GitHub
parent 9c04d318bd
commit 0853208d67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 9 deletions

View File

@ -1127,26 +1127,22 @@ const Composer = RestModel.extend({
if (this.canEditTitle) {
// Save title and/or post body
if (!this.title && !this.reply) {
if (isEmpty(this.title) && isEmpty(this.reply)) {
return Promise.resolve();
}
if (
this.title &&
this.titleLengthValid &&
this.reply &&
this.replyLength < this.siteSettings.min_post_length
) {
// Do not save when both title and reply's length are too small
if (!this.titleLengthValid && this.replyLength < this.minimumPostLength) {
return Promise.resolve();
}
} else {
// Do not save when there is no reply
if (!this.reply) {
if (isEmpty(this.reply)) {
return Promise.resolve();
}
// Do not save when the reply's length is too small
if (this.replyLength < this.siteSettings.min_post_length) {
if (this.replyLength < this.minimumPostLength) {
return Promise.resolve();
}
}