Commit 8ab6924a authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Mark moderator comments automatically as read.

parent f75d4015
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -256,11 +256,27 @@ app.post('/auth/:sdk/:version/comments', util.requireLoggedInUser, function(req,
        url: req.body.url
    });

    comment.save(function(err, response) {
        res.json({ success: true, id: response._id, action: req.body.action });
    var afterSave = function() {
        res.json({ success: true, id: comment._id, action: req.body.action });

        util.sendEmailUpdates(comment);
    };

    comment.save(function(err) {
        if (util.isModerator(req.session.user)) {
            // When moderator posts comment, mark it automatically as read.
            var meta = new Meta({
                userId: req.session.user.userid,
                commentId: comment._id,
                metaType: 'read'
            });
            meta.save(afterSave);
        }
        else {
            afterSave();
        }
    });

});

/**
+8 −2
Original line number Diff line number Diff line
@@ -171,15 +171,21 @@ exports.findCommentMeta = function(req, res, next) {
    }
};

// True if the user is moderator
/**
 * True if the user is moderator
 */
function isModerator(user) {
    return _.include(user.membergroupids, 7);
}
exports.isModerator = isModerator;

// True if the user is author of the comment
/**
 * True if the user is author of the comment
 */
function isAuthor(user, comment) {
    return user.username === comment.author;
}
exports.isAuthor = isAuthor;

/**
 * Ensures that user is allowed to modify/delete the comment,