Merge pull request #304 from ZogStriP/minimum-character-count
Quoting another reply won't satisfy the minimum character count (fixes #180)
This commit is contained in:
commit
2106d72d4c
|
@ -9,7 +9,7 @@
|
||||||
**/
|
**/
|
||||||
Discourse.BBCode = {
|
Discourse.BBCode = {
|
||||||
|
|
||||||
QUOTE_REGEXP: /\[quote=([^\]]*)\]([\s\S]*?)\[\/quote\]/im,
|
QUOTE_REGEXP: /\[quote=([^\]]*)\]((?:[^](?!\[quote=[^\]]*\]))*?)\[\/quote\]/im,
|
||||||
|
|
||||||
// Define our replacers
|
// Define our replacers
|
||||||
replacers: {
|
replacers: {
|
||||||
|
|
|
@ -431,7 +431,7 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
_this = this;
|
_this = this;
|
||||||
if (this.get('disableDrafts')) return;
|
if (this.get('disableDrafts')) return;
|
||||||
if (!this.get('reply')) return;
|
if (!this.get('reply')) return;
|
||||||
if (this.get('reply').length < Discourse.SiteSettings.min_post_length) return;
|
if (this.get('replyLength') < Discourse.SiteSettings.min_post_length) return;
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
reply: this.get('reply'),
|
reply: this.get('reply'),
|
||||||
|
@ -453,34 +453,42 @@ Discourse.Composer = Discourse.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
resetDraftStatus: (function() {
|
resetDraftStatus: (function() {
|
||||||
var len, reply;
|
var len = Discourse.SiteSettings.min_post_length,
|
||||||
reply = this.get('reply');
|
replyLength = this.get('replyLength');
|
||||||
len = Discourse.SiteSettings.min_post_length;
|
|
||||||
if (!reply) {
|
if (replyLength === 0) {
|
||||||
return this.set('draftStatus', Em.String.i18n('composer.min_length.at_least', {
|
this.set('draftStatus', Em.String.i18n('composer.min_length.at_least', { n: len }));
|
||||||
n: len
|
} else if (replyLength < len) {
|
||||||
}));
|
this.set('draftStatus', Em.String.i18n('composer.min_length.more', { n: len - replyLength }));
|
||||||
} else if (reply.length < len) {
|
|
||||||
return this.set('draftStatus', Em.String.i18n('composer.min_length.more', {
|
|
||||||
n: len - reply.length
|
|
||||||
}));
|
|
||||||
} else {
|
} else {
|
||||||
return this.set('draftStatus', null);
|
this.set('draftStatus', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}).observes('reply', 'title'),
|
}).observes('reply', 'title'),
|
||||||
|
|
||||||
blank: function(prop) {
|
blank: function(prop) {
|
||||||
var p;
|
var p = this.get(prop);
|
||||||
p = this.get(prop);
|
|
||||||
return !(p && p.length > 0);
|
return !(p && p.length > 0);
|
||||||
}
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Computes the length of the reply minus the quote(s).
|
||||||
|
|
||||||
|
@property replyLength
|
||||||
|
**/
|
||||||
|
replyLength: function() {
|
||||||
|
var reply = this.get('reply');
|
||||||
|
if(!reply) reply = "";
|
||||||
|
while (Discourse.BBCode.QUOTE_REGEXP.test(reply)) { reply = reply.replace(Discourse.BBCode.QUOTE_REGEXP, ""); }
|
||||||
|
return reply.trim().length;
|
||||||
|
}.property('reply')
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Discourse.Composer.reopenClass({
|
Discourse.Composer.reopenClass({
|
||||||
|
|
||||||
open: function(opts) {
|
open: function(opts) {
|
||||||
var composer;
|
var composer = Discourse.Composer.create();
|
||||||
composer = Discourse.Composer.create();
|
|
||||||
composer.open(opts);
|
composer.open(opts);
|
||||||
return composer;
|
return composer;
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
describe("Discourse.Composer", function() {
|
||||||
|
|
||||||
|
describe("replyLength", function() {
|
||||||
|
|
||||||
|
it("returns the length of a basic reply", function() {
|
||||||
|
var composer = Discourse.Composer.create({ reply: "basic reply" });
|
||||||
|
expect(composer.get('replyLength')).toBe(11);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("trims whitespaces", function() {
|
||||||
|
var composer = Discourse.Composer.create({ reply: "\nbasic reply\t" });
|
||||||
|
expect(composer.get('replyLength')).toBe(11);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes quotes", function() {
|
||||||
|
var composer = Discourse.Composer.create({ reply: "1[quote=]not counted[/quote]2[quote=]at all[/quote]3" });
|
||||||
|
expect(composer.get('replyLength')).toBe(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles nested quotes correctly", function() {
|
||||||
|
var composer = Discourse.Composer.create({ reply: "1[quote=]not[quote=]counted[/quote]yay[/quote]2" });
|
||||||
|
expect(composer.get('replyLength')).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue