mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 08:20:36 +01:00
refactor deleter code to use unixtimestamp
This commit is contained in:
@@ -146,24 +146,6 @@ topicsController.get = function (req, res, callback) {
|
|||||||
next(null, data.topicData);
|
next(null, data.topicData);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function (topicData, next) {
|
|
||||||
if (!topicData.deleterUid) {
|
|
||||||
return next(null, topicData);
|
|
||||||
}
|
|
||||||
|
|
||||||
user.getUserFields(topicData.deleterUid, ['username', 'userslug'], function(err, deleter) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
topicData.deleter = deleter;
|
|
||||||
topicData.deleter.timestampISO = topicData.deletedTimestampISO
|
|
||||||
delete topicData.deleterUid;
|
|
||||||
delete topicData.deletedTimestampISO;
|
|
||||||
|
|
||||||
next(null, topicData);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
function (topicData, next) {
|
function (topicData, next) {
|
||||||
function findPost(index) {
|
function findPost(index) {
|
||||||
for (var i = 0; i < topicData.posts.length; i += 1) {
|
for (var i = 0; i < topicData.posts.length; i += 1) {
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ var social = require('./social');
|
|||||||
isIgnoring: async.apply(Topics.isIgnoring, [topicData.tid], uid),
|
isIgnoring: async.apply(Topics.isIgnoring, [topicData.tid], uid),
|
||||||
bookmark: async.apply(Topics.getUserBookmark, topicData.tid, uid),
|
bookmark: async.apply(Topics.getUserBookmark, topicData.tid, uid),
|
||||||
postSharing: async.apply(social.getActivePostSharing),
|
postSharing: async.apply(social.getActivePostSharing),
|
||||||
|
deleter: async.apply(getDeleter, topicData),
|
||||||
related: function (next) {
|
related: function (next) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -202,6 +203,8 @@ var social = require('./social');
|
|||||||
topicData.isIgnoring = results.isIgnoring[0];
|
topicData.isIgnoring = results.isIgnoring[0];
|
||||||
topicData.bookmark = results.bookmark;
|
topicData.bookmark = results.bookmark;
|
||||||
topicData.postSharing = results.postSharing;
|
topicData.postSharing = results.postSharing;
|
||||||
|
topicData.deleter = results.deleter;
|
||||||
|
topicData.deletedTimestampISO = utils.toISOString(topicData.deletedTimestamp);
|
||||||
topicData.related = results.related || [];
|
topicData.related = results.related || [];
|
||||||
|
|
||||||
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
|
topicData.unreplied = parseInt(topicData.postcount, 10) === 1;
|
||||||
@@ -258,6 +261,13 @@ var social = require('./social');
|
|||||||
], callback);
|
], callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDeleter(topicData, callback) {
|
||||||
|
if (!topicData.deleterUid) {
|
||||||
|
return setImmediate(callback, null, null);
|
||||||
|
}
|
||||||
|
user.getUserFields(topicData.deleterUid, ['username', 'userslug', 'picture'], callback);
|
||||||
|
}
|
||||||
|
|
||||||
Topics.getMainPost = function (tid, uid, callback) {
|
Topics.getMainPost = function (tid, uid, callback) {
|
||||||
Topics.getMainPosts([tid], uid, function (err, mainPosts) {
|
Topics.getMainPosts([tid], uid, function (err, mainPosts) {
|
||||||
callback(err, Array.isArray(mainPosts) && mainPosts.length ? mainPosts[0] : null);
|
callback(err, Array.isArray(mainPosts) && mainPosts.length ? mainPosts[0] : null);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ module.exports = function (Topics) {
|
|||||||
Topics.setTopicFields(tid, {
|
Topics.setTopicFields(tid, {
|
||||||
deleted: 1,
|
deleted: 1,
|
||||||
deleterUid: uid,
|
deleterUid: uid,
|
||||||
deletedTimestampISO: (new Date()).toISOString()
|
deletedTimestamp: Date.now(),
|
||||||
}, next);
|
}, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
@@ -52,7 +52,7 @@ module.exports = function (Topics) {
|
|||||||
Topics.setTopicField(tid, 'deleted', 0, next);
|
Topics.setTopicField(tid, 'deleted', 0, next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
Topics.deleteTopicFields(tid, ['deleterUid', 'deletedTimestampISO'], next);
|
Topics.deleteTopicFields(tid, ['deleterUid', 'deletedTimestamp'], next);
|
||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
Topics.updateRecent(tid, topicData.lastposttime, next);
|
Topics.updateRecent(tid, topicData.lastposttime, next);
|
||||||
|
|||||||
Reference in New Issue
Block a user