diff --git a/template/app/CommentCounts.js b/template/app/CommentCounts.js index 6bd3f92ff086ba2a37f25fb934251c3e84f7ab3a..832abe490740baa73482e153f367c4f8a3fdf24c 100644 --- a/template/app/CommentCounts.js +++ b/template/app/CommentCounts.js @@ -4,34 +4,11 @@ Ext.define('Docs.CommentCounts', { /** - * Initialized CommentCounts with the main Comments class instance - * which is used to perform queries. - * @param {Docs.Comments} comments + * Initializes CommentCounts with the list of counts from + * comments_meta request result. + * @param {Object[]} counts Objects with `_id` and `value` fields. */ - constructor: function(comments) { - this.comments = comments; - this.loadCallbacks = []; - }, - - /** - * Fetches all comment counts. - * - * @param {Function} callback Called after done. - * @param {Object} scope - */ - fetch: function(callback, scope) { - this.comments.request("jsonp", { - url: '/comments_meta', - method: 'GET', - success: function(response) { - this.load(response.comments); - callback.call(scope); - }, - scope: this - }); - }, - - load: function(counts) { + constructor: function(counts) { this.counts = {}; Ext.Array.each(counts, function(r) { this.counts[r._id] = r.value; diff --git a/template/app/Comments.js b/template/app/Comments.js index f3c1de11d21a6c699812b6242cf629fdb91b6eab..ef9c78d5560b35e5c3517c54aac20171ef318229 100644 --- a/template/app/Comments.js +++ b/template/app/Comments.js @@ -28,8 +28,10 @@ Ext.define('Docs.Comments', { Docs.Auth.init(function(success) { if (success) { this.enabled = true; - this.counts = new Docs.CommentCounts(this); - this.counts.fetch(callback, scope); + this.fetchCountsAndSubscriptions(function(counts, subscriptions) { + this.counts = new Docs.CommentCounts(counts); + callback.call(scope); + }, this); } else { callback.call(scope); @@ -37,6 +39,18 @@ Ext.define('Docs.Comments', { }, this); }, + // Fetches comment counts and subscriptions. + fetchCountsAndSubscriptions: function(callback, scope) { + this.request("jsonp", { + url: '/comments_meta', + method: 'GET', + success: function(response) { + callback.call(scope, response.comments, response.subscriptions); + }, + scope: this + }); + }, + /** * True when comments system is enabled. * @return {Boolean}