mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 06:55:46 +01:00
Composer: simplify code with early returns
This commit is contained in:
@@ -415,65 +415,76 @@ define(['taskbar'], function(taskbar) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
composer.newTopic = function(cid) {
|
composer.newTopic = function(cid) {
|
||||||
if(allowed()) {
|
if(!allowed()) {
|
||||||
push({
|
return;
|
||||||
cid: cid,
|
|
||||||
title: '',
|
|
||||||
body: '',
|
|
||||||
modified: false,
|
|
||||||
isMain: true
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
push({
|
||||||
|
cid: cid,
|
||||||
|
title: '',
|
||||||
|
body: '',
|
||||||
|
modified: false,
|
||||||
|
isMain: true
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
composer.addQuote = function(tid, pid, title, username, text){
|
composer.addQuote = function(tid, pid, title, username, text){
|
||||||
if (allowed()) {
|
if (!allowed()) {
|
||||||
var uuid = composer.active;
|
return;
|
||||||
if(uuid !== undefined){
|
|
||||||
var bodyEl = $('#cmp-uuid-'+uuid).find('textarea');
|
|
||||||
var prevText = bodyEl.val();
|
|
||||||
if(tid !== composer.posts[uuid].tid) {
|
|
||||||
text = username + ' said in ['+title+'](/topic/'+tid+'#'+pid+'):\n'+text;
|
|
||||||
} else {
|
|
||||||
text = username + ' said:\n' + text;
|
|
||||||
}
|
|
||||||
composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + text;
|
|
||||||
bodyEl.val(composer.posts[uuid].body);
|
|
||||||
} else {
|
|
||||||
composer.newReply(tid, pid, title, username + ' said:\n' + text);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var uuid = composer.active;
|
||||||
|
|
||||||
|
if(uuid === undefined){
|
||||||
|
composer.newReply(tid, pid, title, username + ' said:\n' + text);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var bodyEl = $('#cmp-uuid-'+uuid).find('textarea');
|
||||||
|
var prevText = bodyEl.val();
|
||||||
|
if(tid !== composer.posts[uuid].tid) {
|
||||||
|
text = username + ' said in ['+title+'](/topic/'+tid+'#'+pid+'):\n'+text;
|
||||||
|
} else {
|
||||||
|
text = username + ' said:\n' + text;
|
||||||
|
}
|
||||||
|
composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + text;
|
||||||
|
bodyEl.val(composer.posts[uuid].body);
|
||||||
};
|
};
|
||||||
|
|
||||||
composer.newReply = function(tid, pid, title, text) {
|
composer.newReply = function(tid, pid, title, text) {
|
||||||
if(allowed()) {
|
if(!allowed()) {
|
||||||
push({
|
return;
|
||||||
tid: tid,
|
|
||||||
toPid: pid,
|
|
||||||
title: title,
|
|
||||||
body: text,
|
|
||||||
modified: false,
|
|
||||||
isMain: false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
push({
|
||||||
|
tid: tid,
|
||||||
|
toPid: pid,
|
||||||
|
title: title,
|
||||||
|
body: text,
|
||||||
|
modified: false,
|
||||||
|
isMain: false
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
composer.editPost = function(pid) {
|
composer.editPost = function(pid) {
|
||||||
if(allowed()) {
|
if(!allowed()) {
|
||||||
socket.emit('modules.composer.push', pid, function(err, threadData) {
|
return;
|
||||||
if(err) {
|
|
||||||
return app.alertError(err.message);
|
|
||||||
}
|
|
||||||
push({
|
|
||||||
pid: pid,
|
|
||||||
title: threadData.title,
|
|
||||||
body: threadData.body,
|
|
||||||
modified: false,
|
|
||||||
isMain: !threadData.index,
|
|
||||||
topic_thumb: threadData.topic_thumb
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
socket.emit('modules.composer.push', pid, function(err, threadData) {
|
||||||
|
if(err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
push({
|
||||||
|
pid: pid,
|
||||||
|
title: threadData.title,
|
||||||
|
body: threadData.body,
|
||||||
|
modified: false,
|
||||||
|
isMain: !threadData.index,
|
||||||
|
topic_thumb: threadData.topic_thumb
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
composer.load = function(post_uuid) {
|
composer.load = function(post_uuid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user