Loading comments/lib/mailer.js +1 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ var config = require("../config"); * Takes care of notifying subscribers about a new comment. * * @constructor * * Creates a new mailer. * @param {Object} cfg Config object: * @param {TableFactory} cfg.db Access to database tables. * @param {Object} cfg.comment The new comment that was posted. Loading comments/lib/request.js +48 −0 Original line number Diff line number Diff line Loading @@ -18,10 +18,16 @@ function Request(req) { } Request.prototype = { /** * Performs the login. */ login: function(user, pass, callback) { this.db.users().login(user, pass, callback); }, /** * Does the recent comments query. */ getRecentComments: function(query, callback) { if (query.hideCurrentUser) { query.hideUser = this.getUserId(); Loading @@ -47,12 +53,18 @@ Request.prototype = { }.bind(this)); }, /** * Provides the comments_meta request data. */ getCommentCountsPerTarget: function(callback) { this.db.comments().countsPerTarget(function(err, counts) { callback(counts); }); }, /** * Retrieves comments for a particular target. */ getComments: function(target, callback) { var targetObj = ApiAdapter.targetFromJson(JSON.parse(target)); Loading @@ -72,12 +84,18 @@ Request.prototype = { } }, /** * Gets one comment by ID. */ getComment: function(comment_id, callback) { this.db.comments().getById(comment_id, function(err, comment) { callback(ApiAdapter.commentToJson(comment)); }); }, /** * Adds new comment. */ addComment: function(target, content, threadUrl, callback) { var comment = { user_id: this.getUserId(), Loading Loading @@ -110,6 +128,9 @@ Request.prototype = { }.bind(this)); }, /** * Deletes or undeletes a comment. */ setDeleted: function(comment_id, deleted, callback) { if (deleted === false) { this.db.comments().showDeleted(true); Loading @@ -125,6 +146,9 @@ Request.prototype = { }); }, /** * Updates contents of a comment. */ updateComment: function(comment_id, content, callback) { var update = { id: comment_id, Loading @@ -139,6 +163,9 @@ Request.prototype = { }.bind(this)); }, /** * Votes comment up or down. */ vote: function(comment_id, vote, callback) { var voteObj = { user_id: this.getUserId(), Loading @@ -152,6 +179,9 @@ Request.prototype = { }); }, /** * Marks comment as read. */ markRead: function(comment_id, callback) { var read = { user_id: this.getUserId(), Loading @@ -163,6 +193,9 @@ Request.prototype = { }); }, /** * Returns all subscriptions for current user. */ getSubscriptions: function(callback) { if (!this.isLoggedIn()) { callback([]); Loading @@ -174,6 +207,9 @@ Request.prototype = { }); }, /** * Subscribes or unsubscribes a user. */ changeSubscription: function(target, subscribe, callback) { var sub = { user_id: this.getUserId(), Loading @@ -188,10 +224,17 @@ Request.prototype = { } }, /** * Retrieves the currently logged in user. */ getUser: function(callback) { callback(this.req.session && this.req.session.user); }, /** * Returns ID of logged in user. * @return {Number} */ getUserId: function() { return this.req.session.user.id; }, Loading @@ -204,6 +247,11 @@ Request.prototype = { return this.req.session && this.req.session.user; }, /** * Returns true when logged in user is moderator. * @return {Boolean} * @private */ isModerator: function() { return this.req.session.user.moderator; }, Loading Loading
comments/lib/mailer.js +1 −1 Original line number Diff line number Diff line Loading @@ -6,7 +6,7 @@ var config = require("../config"); * Takes care of notifying subscribers about a new comment. * * @constructor * * Creates a new mailer. * @param {Object} cfg Config object: * @param {TableFactory} cfg.db Access to database tables. * @param {Object} cfg.comment The new comment that was posted. Loading
comments/lib/request.js +48 −0 Original line number Diff line number Diff line Loading @@ -18,10 +18,16 @@ function Request(req) { } Request.prototype = { /** * Performs the login. */ login: function(user, pass, callback) { this.db.users().login(user, pass, callback); }, /** * Does the recent comments query. */ getRecentComments: function(query, callback) { if (query.hideCurrentUser) { query.hideUser = this.getUserId(); Loading @@ -47,12 +53,18 @@ Request.prototype = { }.bind(this)); }, /** * Provides the comments_meta request data. */ getCommentCountsPerTarget: function(callback) { this.db.comments().countsPerTarget(function(err, counts) { callback(counts); }); }, /** * Retrieves comments for a particular target. */ getComments: function(target, callback) { var targetObj = ApiAdapter.targetFromJson(JSON.parse(target)); Loading @@ -72,12 +84,18 @@ Request.prototype = { } }, /** * Gets one comment by ID. */ getComment: function(comment_id, callback) { this.db.comments().getById(comment_id, function(err, comment) { callback(ApiAdapter.commentToJson(comment)); }); }, /** * Adds new comment. */ addComment: function(target, content, threadUrl, callback) { var comment = { user_id: this.getUserId(), Loading Loading @@ -110,6 +128,9 @@ Request.prototype = { }.bind(this)); }, /** * Deletes or undeletes a comment. */ setDeleted: function(comment_id, deleted, callback) { if (deleted === false) { this.db.comments().showDeleted(true); Loading @@ -125,6 +146,9 @@ Request.prototype = { }); }, /** * Updates contents of a comment. */ updateComment: function(comment_id, content, callback) { var update = { id: comment_id, Loading @@ -139,6 +163,9 @@ Request.prototype = { }.bind(this)); }, /** * Votes comment up or down. */ vote: function(comment_id, vote, callback) { var voteObj = { user_id: this.getUserId(), Loading @@ -152,6 +179,9 @@ Request.prototype = { }); }, /** * Marks comment as read. */ markRead: function(comment_id, callback) { var read = { user_id: this.getUserId(), Loading @@ -163,6 +193,9 @@ Request.prototype = { }); }, /** * Returns all subscriptions for current user. */ getSubscriptions: function(callback) { if (!this.isLoggedIn()) { callback([]); Loading @@ -174,6 +207,9 @@ Request.prototype = { }); }, /** * Subscribes or unsubscribes a user. */ changeSubscription: function(target, subscribe, callback) { var sub = { user_id: this.getUserId(), Loading @@ -188,10 +224,17 @@ Request.prototype = { } }, /** * Retrieves the currently logged in user. */ getUser: function(callback) { callback(this.req.session && this.req.session.user); }, /** * Returns ID of logged in user. * @return {Number} */ getUserId: function() { return this.req.session.user.id; }, Loading @@ -204,6 +247,11 @@ Request.prototype = { return this.req.session && this.req.session.user; }, /** * Returns true when logged in user is moderator. * @return {Boolean} * @private */ isModerator: function() { return this.req.session.user.moderator; }, Loading