diff --git a/app/assets/javascripts/discourse/controllers/user-card.js.es6 b/app/assets/javascripts/discourse/controllers/user-card.js.es6 index 21c96e646..60922c4c1 100644 --- a/app/assets/javascripts/discourse/controllers/user-card.js.es6 +++ b/app/assets/javascripts/discourse/controllers/user-card.js.es6 @@ -5,14 +5,16 @@ export default ObjectController.extend({ visible: false, user: null, username: null, - participant: null, avatar: null, userLoading: null, cardTarget: null, post: null, + // If inside a topic + topicPostCount: null, + postStream: Em.computed.alias('controllers.topic.postStream'), - enoughPostsForFiltering: Em.computed.gte('participant.post_count', 2), + enoughPostsForFiltering: Em.computed.gte('topicPostCount', 2), viewingTopic: Em.computed.match('controllers.application.currentPath', /^topic\./), viewingAdmin: Em.computed.match('controllers.application.currentPath', /^admin\./), showFilter: Em.computed.and('viewingTopic', 'postStream.hasNoFilters', 'enoughPostsForFiltering'), @@ -28,14 +30,14 @@ export default ObjectController.extend({ }.property('user.badge_count', 'user.featured_user_badges.@each'), hasCardBadgeImage: function() { - var img = this.get('user.card_badge.image'); + const img = this.get('user.card_badge.image'); return img && img.indexOf('fa-') !== 0; }.property('user.card_badge.image'), - show: function(username, postId, target) { + show(username, postId, target) { // XSS protection (should be encapsulated) username = username.toString().replace(/[^A-Za-z0-9_]/g, ""); - var url = "/users/" + username; + const url = "/users/" + username; // Don't show on mobile if (Discourse.Mobile.mobileView) { @@ -43,7 +45,7 @@ export default ObjectController.extend({ return; } - var currentUsername = this.get('username'), + const currentUsername = this.get('username'), wasVisible = this.get('visible'), post = this.get('viewingTopic') && postId ? this.get('controllers.topic.postStream').findLoadedPost(postId) : null; @@ -60,20 +62,21 @@ export default ObjectController.extend({ return; } - this.set('participant', null); - - // Retrieve their participants info - var participants = this.get('controllers.topic.details.participants'); - if (participants) { - this.set('participant', participants.findBy('username', username)); - } + this.set('topicPostCount', null); this.setProperties({ user: null, userLoading: username, cardTarget: target }); - var self = this; - return Discourse.User.findByUsername(username, { stats: false }).then(function(user) { + const args = { stats: false }; + args.include_post_count_for = this.get('controllers.topic.id'); + + const self = this; + return Discourse.User.findByUsername(username, args).then(function(user) { + + if (user.topic_post_count) { + self.set('topicPostCount', user.topic_post_count[args.include_post_count_for]); + } user = Discourse.User.create(user); - self.setProperties({ user: user, avatar: user, visible: true}); + self.setProperties({ user, avatar: user, visible: true}); self.appEvents.trigger('usercard:shown'); }).catch(function(error) { self.close(); @@ -83,19 +86,19 @@ export default ObjectController.extend({ }); }, - close: function() { + close() { this.setProperties({ visible: false, cardTarget: null }); }, actions: { - togglePosts: function(user) { - var postStream = this.get('controllers.topic.postStream'); + togglePosts(user) { + const postStream = this.get('controllers.topic.postStream'); postStream.toggleParticipant(user.get('username')); this.close(); }, - cancelFilter: function() { - var postStream = this.get('postStream'); + cancelFilter() { + const postStream = this.get('postStream'); postStream.cancelFilter(); postStream.refresh(); this.close(); diff --git a/app/assets/javascripts/discourse/models/user.js.es6 b/app/assets/javascripts/discourse/models/user.js.es6 index dc5df8c22..b458c1188 100644 --- a/app/assets/javascripts/discourse/models/user.js.es6 +++ b/app/assets/javascripts/discourse/models/user.js.es6 @@ -427,14 +427,9 @@ const User = Discourse.Model.extend({ User.reopenClass(Discourse.Singleton, { - /** - Find a `Discourse.User` for a given username. - - @method findByUsername - @returns {Promise} a promise that resolves to a `Discourse.User` - **/ + // Find a `Discourse.User` for a given username. findByUsername: function(username, options) { - var user = Discourse.User.create({username: username}); + const user = Discourse.User.create({username: username}); return user.findDetails(options); }, diff --git a/app/assets/javascripts/discourse/templates/user-card.hbs b/app/assets/javascripts/discourse/templates/user-card.hbs index 1db3b3f32..588da54eb 100644 --- a/app/assets/javascripts/discourse/templates/user-card.hbs +++ b/app/assets/javascripts/discourse/templates/user-card.hbs @@ -28,7 +28,7 @@ {{/if}} {{#if showFilter}} -