Loading comments/app.js +7 −0 Original line number Diff line number Diff line Loading @@ -161,6 +161,13 @@ app.post('/auth/:sdk/:version/comments/:commentId/undo_delete', validator.isLogg }); }); // Marks a comment 'read' app.post('/auth/:sdk/:version/comments/:commentId/read', validator.isLoggedIn, function(req, res) { new Request(req).markRead(req.params.commentId, function() { res.send({ success: true }); }); }); // Returns all subscriptions for logged in user app.get('/auth/:sdk/:version/subscriptions', function(req, res) { new Request(req).getSubscriptions(function(subs) { Loading comments/comments.js +21 −0 Original line number Diff line number Diff line Loading @@ -320,6 +320,27 @@ Comments.prototype = { }.bind(this)); }, /** * Marks comment as read. * * @param {Object} read * @param {Number} read.user_id The user who's marking it. * @param {Number} read.comment_id The comment he's marking. * @param {Function} callback * @param {Error} callback.err */ markRead: function(read, callback) { read.created_at = new Date(); this.db.insert("readings", read, function(err) { if (err && err.code === "ER_DUP_ENTRY") { callback(); } else { callback(err); } }); }, // Helper that converts all `vote_dir` and `read` fields into // appropriate type. For some reason the vote_dir field is a // string by default, but we don't want that. The `read` field is Loading comments/comments.spec.js +21 −0 Original line number Diff line number Diff line Loading @@ -309,4 +309,25 @@ describe("Comments", function() { }); }); it("#markRead marks comment as read", function(done) { comments.markRead({comment_id: 7, user_id: 1}, function(err) { if (err) throw err; comments.showReadBy(1); comments.getById(7, function(err, com) { expect(com.read).toEqual(true); done(); }); }); }); it("#markRead on already read comment keeps the comment as read", function(done) { comments.markRead({comment_id: 7, user_id: 1}, function(err) { if (err) throw err; comments.showReadBy(1); comments.getById(7, function(err, com) { expect(com.read).toEqual(true); done(); }); }); }); }); comments/request.js +11 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,17 @@ Request.prototype = { }); }, markRead: function(comment_id, callback) { var read = { user_id: this.getUserId(), comment_id: comment_id }; this.db.comments().markRead(read, function(err) { callback(); }); }, getSubscriptions: function(callback) { if (!this.isLoggedIn()) { callback([]); Loading Loading
comments/app.js +7 −0 Original line number Diff line number Diff line Loading @@ -161,6 +161,13 @@ app.post('/auth/:sdk/:version/comments/:commentId/undo_delete', validator.isLogg }); }); // Marks a comment 'read' app.post('/auth/:sdk/:version/comments/:commentId/read', validator.isLoggedIn, function(req, res) { new Request(req).markRead(req.params.commentId, function() { res.send({ success: true }); }); }); // Returns all subscriptions for logged in user app.get('/auth/:sdk/:version/subscriptions', function(req, res) { new Request(req).getSubscriptions(function(subs) { Loading
comments/comments.js +21 −0 Original line number Diff line number Diff line Loading @@ -320,6 +320,27 @@ Comments.prototype = { }.bind(this)); }, /** * Marks comment as read. * * @param {Object} read * @param {Number} read.user_id The user who's marking it. * @param {Number} read.comment_id The comment he's marking. * @param {Function} callback * @param {Error} callback.err */ markRead: function(read, callback) { read.created_at = new Date(); this.db.insert("readings", read, function(err) { if (err && err.code === "ER_DUP_ENTRY") { callback(); } else { callback(err); } }); }, // Helper that converts all `vote_dir` and `read` fields into // appropriate type. For some reason the vote_dir field is a // string by default, but we don't want that. The `read` field is Loading
comments/comments.spec.js +21 −0 Original line number Diff line number Diff line Loading @@ -309,4 +309,25 @@ describe("Comments", function() { }); }); it("#markRead marks comment as read", function(done) { comments.markRead({comment_id: 7, user_id: 1}, function(err) { if (err) throw err; comments.showReadBy(1); comments.getById(7, function(err, com) { expect(com.read).toEqual(true); done(); }); }); }); it("#markRead on already read comment keeps the comment as read", function(done) { comments.markRead({comment_id: 7, user_id: 1}, function(err) { if (err) throw err; comments.showReadBy(1); comments.getById(7, function(err, com) { expect(com.read).toEqual(true); done(); }); }); }); });
comments/request.js +11 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,17 @@ Request.prototype = { }); }, markRead: function(comment_id, callback) { var read = { user_id: this.getUserId(), comment_id: comment_id }; this.db.comments().markRead(read, function(err) { callback(); }); }, getSubscriptions: function(callback) { if (!this.isLoggedIn()) { callback([]); Loading