mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
nested reply improvements
on new post increase count and add nested reply if replies are expanded on post purge reduce count and remove nested reply
This commit is contained in:
@@ -166,15 +166,16 @@ define('forum/topic/events', [
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onPostPurged(pid) {
|
function onPostPurged(postData) {
|
||||||
components.get('post', 'pid', pid).fadeOut(500, function () {
|
components.get('post', 'pid', postData.pid).fadeOut(500, function () {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
ajaxify.data.postcount --;
|
|
||||||
postTools.updatePostCount(ajaxify.data.postcount);
|
|
||||||
posts.showBottomPostBar();
|
posts.showBottomPostBar();
|
||||||
});
|
});
|
||||||
|
ajaxify.data.postcount --;
|
||||||
postTools.updatePostCount();
|
postTools.updatePostCount(ajaxify.data.postcount);
|
||||||
|
require(['forum/topic/replies'], function (replies) {
|
||||||
|
replies.onPostPurged(postData);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function togglePostDeleteState(data) {
|
function togglePostDeleteState(data) {
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ define('forum/topic/posts', [
|
|||||||
} else {
|
} else {
|
||||||
onNewPostInfiniteScroll(data);
|
onNewPostInfiniteScroll(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require(['forum/topic/replies'], function (replies) {
|
||||||
|
replies.onNewPost(data);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Posts.modifyPostsByPrivileges = function (posts) {
|
Posts.modifyPostsByPrivileges = function (posts) {
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts'],
|
|||||||
var tplData = {
|
var tplData = {
|
||||||
posts: data,
|
posts: data,
|
||||||
privileges: ajaxify.data.privileges,
|
privileges: ajaxify.data.privileges,
|
||||||
|
'downvote:disabled': ajaxify.data['downvote:disabled'],
|
||||||
|
'reputation:disabled': ajaxify.data['reputation:disabled'],
|
||||||
loggedIn: !!app.user.uid,
|
loggedIn: !!app.user.uid,
|
||||||
hideReplies: true
|
hideReplies: true
|
||||||
};
|
};
|
||||||
@@ -60,5 +62,34 @@ define('forum/topic/replies', ['navigator', 'components', 'forum/topic/posts'],
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Replies.onNewPost = function (data) {
|
||||||
|
var post = data.posts[0];
|
||||||
|
if (!post) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
incrementCount(post, 1);
|
||||||
|
data.hideReplies = true;
|
||||||
|
app.parseAndTranslate('topic', 'posts', data, function (html) {
|
||||||
|
var replies = $('[component="post"][data-pid="' + post.toPid + '"] [component="post/replies"]').first();
|
||||||
|
if (replies.length) {
|
||||||
|
replies.append(html);
|
||||||
|
posts.processPage(html);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Replies.onPostPurged = function (post) {
|
||||||
|
incrementCount(post, -1);
|
||||||
|
};
|
||||||
|
|
||||||
|
function incrementCount(post, inc) {
|
||||||
|
var replyCount = $('[component="post"][data-pid="' + post.toPid + '"]').find('[component="post/reply-count"]').first();
|
||||||
|
var countEl = replyCount.find('[component="post/reply-count/text"]');
|
||||||
|
var count = Math.max(0, parseInt(countEl.attr('data-replies'), 10) + inc);
|
||||||
|
countEl.attr('data-replies', count);
|
||||||
|
replyCount.toggleClass('hidden', !count);
|
||||||
|
countEl.translateText('[[topic:replies_to_this_post, ' + count + ']]');
|
||||||
|
}
|
||||||
|
|
||||||
return Replies;
|
return Replies;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var winston = require('winston');
|
|
||||||
var validator = require('validator');
|
var validator = require('validator');
|
||||||
|
|
||||||
var posts = require('../../posts');
|
var posts = require('../../posts');
|
||||||
@@ -137,28 +136,29 @@ module.exports = function (SocketPosts) {
|
|||||||
|
|
||||||
SocketPosts.purge = function (socket, data, callback) {
|
SocketPosts.purge = function (socket, data, callback) {
|
||||||
function purgePost() {
|
function purgePost() {
|
||||||
posts.tools.purge(socket.uid, data.pid, function (err) {
|
var postData;
|
||||||
if (err) {
|
async.waterfall([
|
||||||
return callback(err);
|
function (next) {
|
||||||
}
|
posts.getPostField(data.pid, 'toPid', next);
|
||||||
|
},
|
||||||
websockets.in('topic_' + data.tid).emit('event:post_purged', data.pid);
|
function (toPid, next) {
|
||||||
|
postData = {pid: data.pid, toPid: toPid};
|
||||||
topics.getTopicField(data.tid, 'title', function (err, title) {
|
posts.tools.purge(socket.uid, data.pid, next);
|
||||||
if (err) {
|
},
|
||||||
return winston.error(err);
|
function (next) {
|
||||||
}
|
websockets.in('topic_' + data.tid).emit('event:post_purged', postData);
|
||||||
|
topics.getTopicField(data.tid, 'title', next);
|
||||||
|
},
|
||||||
|
function (title, next) {
|
||||||
events.log({
|
events.log({
|
||||||
type: 'post-purge',
|
type: 'post-purge',
|
||||||
uid: socket.uid,
|
uid: socket.uid,
|
||||||
pid: data.pid,
|
pid: data.pid,
|
||||||
ip: socket.ip,
|
ip: socket.ip,
|
||||||
title: validator.escape(String(title))
|
title: validator.escape(String(title))
|
||||||
});
|
}, next);
|
||||||
});
|
}
|
||||||
|
], callback);
|
||||||
callback();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data || !parseInt(data.pid, 10)) {
|
if (!data || !parseInt(data.pid, 10)) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ var db = require('./mocks/databasemock');
|
|||||||
var topics = require('../src/topics');
|
var topics = require('../src/topics');
|
||||||
var posts = require('../src/posts');
|
var posts = require('../src/posts');
|
||||||
var categories = require('../src/categories');
|
var categories = require('../src/categories');
|
||||||
|
var privileges = require('../src/privileges');
|
||||||
var user = require('../src/user');
|
var user = require('../src/user');
|
||||||
|
|
||||||
describe('Post\'s', function () {
|
describe('Post\'s', function () {
|
||||||
@@ -135,6 +136,7 @@ describe('Post\'s', function () {
|
|||||||
|
|
||||||
describe('delete/restore/purge', function () {
|
describe('delete/restore/purge', function () {
|
||||||
var pid;
|
var pid;
|
||||||
|
var socketPosts = require('../src/socket.io/posts');
|
||||||
before(function (done) {
|
before(function (done) {
|
||||||
topics.reply({
|
topics.reply({
|
||||||
uid: voterUid,
|
uid: voterUid,
|
||||||
@@ -144,14 +146,13 @@ describe('Post\'s', function () {
|
|||||||
}, function (err, data) {
|
}, function (err, data) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
pid = data.pid;
|
pid = data.pid;
|
||||||
done();
|
privileges.categories.give(['purge'], cid, 'registered-users', done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete a post', function (done) {
|
it('should delete a post', function (done) {
|
||||||
posts.delete(pid, voterUid, function (err, postData) {
|
socketPosts.delete({uid: voterUid}, {pid: pid, tid: topicData.tid}, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert(postData);
|
|
||||||
posts.getPostField(pid, 'deleted', function (err, isDeleted) {
|
posts.getPostField(pid, 'deleted', function (err, isDeleted) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(parseInt(isDeleted, 10), 1);
|
assert.equal(parseInt(isDeleted, 10), 1);
|
||||||
@@ -161,9 +162,8 @@ describe('Post\'s', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should restore a post', function (done) {
|
it('should restore a post', function (done) {
|
||||||
posts.restore(pid, voterUid, function (err, postData) {
|
socketPosts.restore({uid: voterUid}, {pid: pid, tid: topicData.tid}, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert(postData);
|
|
||||||
posts.getPostField(pid, 'deleted', function (err, isDeleted) {
|
posts.getPostField(pid, 'deleted', function (err, isDeleted) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(parseInt(isDeleted, 10), 0);
|
assert.equal(parseInt(isDeleted, 10), 0);
|
||||||
@@ -173,9 +173,8 @@ describe('Post\'s', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should purge a post', function (done) {
|
it('should purge a post', function (done) {
|
||||||
posts.purge(pid, voterUid, function (err) {
|
socketPosts.purge({uid: voterUid}, {pid: pid}, function (err) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(arguments.length, 1);
|
|
||||||
posts.exists('post:' + pid, function (err, exists) {
|
posts.exists('post:' + pid, function (err, exists) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.equal(exists, false);
|
assert.equal(exists, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user