teaser fixes

if a post is deleted/restored update the teaser to the latest undeleted
pid, if all posts are deleted it will be set to null
This commit is contained in:
Barış Soner Uşaklı
2015-04-16 13:23:21 -04:00
parent edb856ba90
commit e7dd881092
3 changed files with 29 additions and 13 deletions

View File

@@ -101,11 +101,12 @@ module.exports = function(Topics) {
};
Topics.updateTeaser = function(tid, callback) {
db.getSortedSetRevRange('tid:' + tid + ':posts', 0, 0, function(err, pids) {
Topics.getLatestUndeletedPid(tid, function(err, pid) {
if (err) {
return callback(err);
}
var pid = Array.isArray(pids) && pids.length ? pids[0] : null;
pid = pid || null;
Topics.setTopicField(tid, 'teaserPid', pid, callback);
});
};