added toPid to posts

v1.18.x
Baris Soner Usakli 11 years ago
parent 81555671da
commit d6d9776cde

@ -405,13 +405,14 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
} }
var username = '', var username = '',
post = $(this).parents('li[data-pid]'); post = $(this).parents('li[data-pid]'),
pid = $(this).parents('.post-row').attr('data-pid');
if (post.length) { if (post.length) {
username = '@' + post.attr('data-username').replace(/\s/g, '-') + ' '; username = '@' + post.attr('data-username').replace(/\s/g, '-') + ' ';
} }
if (thread_state.locked !== '1') { if (thread_state.locked !== '1') {
composer.newReply(tid, topic_name, selectionText.length > 0 ? selectionText + '\n\n' + username : '' + username); composer.newReply(tid, pid, topic_name, selectionText.length > 0 ? selectionText + '\n\n' + username : '' + username);
} }
}); });
@ -436,7 +437,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
if($('.composer').length) { if($('.composer').length) {
composer.addQuote(tid, pid, topic_name, username, quoted); composer.addQuote(tid, pid, topic_name, username, quoted);
}else { }else {
composer.newReply(tid, topic_name, username + ' said:\n' + quoted); composer.newReply(tid, pid, topic_name, username + ' said:\n' + quoted);
} }
}); });
} }

@ -294,22 +294,22 @@ define(['taskbar'], function(taskbar) {
var prevText = bodyEl.val(); var prevText = bodyEl.val();
if(tid !== composer.posts[uuid].tid) { if(tid !== composer.posts[uuid].tid) {
text = username + ' said in ['+title+'](/topic/'+tid+'#'+pid+'):\n'+text; text = username + ' said in ['+title+'](/topic/'+tid+'#'+pid+'):\n'+text;
}else { } else {
text = username + ' said:\n' + text; text = username + ' said:\n' + text;
} }
composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + text; composer.posts[uuid].body = (prevText.length ? prevText + '\n\n' : '') + text;
bodyEl.val(composer.posts[uuid].body); bodyEl.val(composer.posts[uuid].body);
}else{ } else {
composer.newReply(tid,title,username + ' said:\n' + text); composer.newReply(tid, pid, title, username + ' said:\n' + text);
} }
} }
}; };
composer.newReply = function(tid, title, text) { composer.newReply = function(tid, pid, title, text) {
if(allowed()) { if(allowed()) {
push({ push({
tid: tid, tid: tid,
toPid: pid,
title: title, title: title,
body: text, body: text,
modified: false, modified: false,
@ -737,7 +737,8 @@ define(['taskbar'], function(taskbar) {
} else if (parseInt(postData.tid, 10) > 0) { } else if (parseInt(postData.tid, 10) > 0) {
socket.emit('posts.reply', { socket.emit('posts.reply', {
topic_id: postData.tid, topic_id: postData.tid,
content: bodyEl.val() content: bodyEl.val(),
toPid: postData.toPid
}, done); }, done);
} else if (parseInt(postData.pid, 10) > 0) { } else if (parseInt(postData.pid, 10) > 0) {
socket.emit('posts.edit', { socket.emit('posts.edit', {

@ -20,7 +20,12 @@ var db = require('./database'),
(function(Posts) { (function(Posts) {
var customUserInfo = {}; var customUserInfo = {};
Posts.create = function(uid, tid, content, callback) { Posts.create = function(data, callback) {
var uid = data.uid,
tid = data.tid,
content = data.content,
toPid = data.toPid;
if (uid === null) { if (uid === null) {
return callback(new Error('invalid-user'), null); return callback(new Error('invalid-user'), null);
} }
@ -56,6 +61,10 @@ var db = require('./database'),
'deleted': 0 'deleted': 0
}; };
if (toPid) {
postData['toPid'] = toPid;
}
db.setObject('post:' + pid, postData, function(err) { db.setObject('post:' + pid, postData, function(err) {
if(err) { if(err) {
return next(err); return next(err);

@ -14,6 +14,7 @@ var async = require('async'),
SocketPosts = {}; SocketPosts = {};
SocketPosts.reply = function(socket, data, callback) { SocketPosts.reply = function(socket, data, callback) {
if (!socket.uid && !parseInt(meta.config.allowGuestPosting, 10)) { if (!socket.uid && !parseInt(meta.config.allowGuestPosting, 10)) {
socket.emit('event:alert', { socket.emit('event:alert', {
title: 'Reply Unsuccessful', title: 'Reply Unsuccessful',
@ -28,7 +29,9 @@ SocketPosts.reply = function(socket, data, callback) {
return callback(new Error('invalid data')); return callback(new Error('invalid data'));
} }
topics.reply(data.topic_id, socket.uid, data.content, function(err, postData) { data.uid = socket.uid;
topics.reply(data, function(err, postData) {
if(err) { if(err) {
if (err.message === 'content-too-short') { if (err.message === 'content-too-short') {
module.parent.exports.emitContentTooShortAlert(socket); module.parent.exports.emitContentTooShortAlert(socket);

@ -121,7 +121,7 @@ var async = require('async'),
Topics.create({uid: uid, title: title, cid: cid, thumb: thumb}, next); Topics.create({uid: uid, title: title, cid: cid, thumb: thumb}, next);
}, },
function(tid, next) { function(tid, next) {
Topics.reply(tid, uid, content, next); Topics.reply({uid:uid, tid:tid, content:content}, next);
}, },
function(postData, next) { function(postData, next) {
threadTools.toggleFollow(postData.tid, uid); threadTools.toggleFollow(postData.tid, uid);
@ -143,9 +143,13 @@ var async = require('async'),
], callback); ], callback);
}; };
Topics.reply = function(tid, uid, content, callback) { Topics.reply = function(data, callback) {
var privileges; var tid = data.topic_id,
var postData; uid = data.uid,
toPid = data.toPid,
content = data.content,
privileges,
postData;
async.waterfall([ async.waterfall([
function(next) { function(next) {
@ -170,7 +174,7 @@ var async = require('async'),
return next(new Error('content-too-short')); return next(new Error('content-too-short'));
} }
posts.create(uid, tid, content, next); posts.create({uid:uid, tid:tid, content:content, toPid:toPid}, next);
}, },
function(data, next) { function(data, next) {
postData = data; postData = data;

Loading…
Cancel
Save