FEATURE: Add recipient avatars in PM topic list even if they not yet replied

FEATURE: Add recipient avatars in PM topic list even if they not yet replied

diff --git a/app/assets/javascripts/discourse/models/topic.js.es6 b/app/assets/javascripts/discourse/models/topic.js.es6
index 18e1ede..af6cc42 100644
--- a/app/assets/javascripts/discourse/models/topic.js.es6
+++ b/app/assets/javascripts/discourse/models/topic.js.es6
@@ -59,6 +59,40 @@ const Topic = RestModel.extend({
     return user || this.get("creator");
   },
 
+  @computed("posters.[]", "participants.[]")
+  featuredUsers(posters, participants) {
+    let users = posters;
+    const maxUserCount = 5;
+    const posterCount = users.length;
+
+    if (
+      this.get("isPrivateMessage") &&
+      participants &&
+      posterCount < maxUserCount
+    ) {
+      let pushOffset = 0;
+      if (posterCount > 1) {
+        const lastUser = users[posterCount - 1];
+        if (lastUser.extras && lastUser.extras.includes("latest")) {
+          pushOffset = 1;
+        }
+      }
+
+      const poster_ids = _.pluck(posters, "user_id");
+      participants.some(p => {
+        if (!poster_ids.includes(p.user_id)) {
+          users.splice(users.length - pushOffset, 0, p);
+          if (users.length === maxUserCount) {
+            return true;
+          }
+        }
+        return false;
+      });
+    }
+
+    return users;
+  },
+
   @computed("fancy_title")
   fancyTitle(title) {
     let fancyTitle = censor(
diff --git a/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs b/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs
index 5b45e1b..ab0e1e3 100644
--- a/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs
+++ b/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs
@@ -39,7 +39,7 @@
 </td>
 
 {{#if showPosters}}
-  {{raw "list/posters-column" posters=topic.posters}}
+  {{raw "list/posters-column" posters=topic.featuredUsers}}
 {{/if}}
 
 {{raw "list/posts-count-column" topic=topic}}
diff --git a/app/models/topic_participants_summary.rb b/app/models/topic_participants_summary.rb
index 424e203..d461eb3 100644
--- a/app/models/topic_participants_summary.rb
+++ b/app/models/topic_participants_summary.rb
@@ -24,7 +24,7 @@ class TopicParticipantsSummary
   end
 
   def top_participants
-    user_ids.map { |id| avatar_lookup[id] }.compact.uniq.take(3)
+    user_ids.map { |id| avatar_lookup[id] }.compact.uniq.take(4)
   end
 
   def user_ids
diff --git a/spec/models/topic_participants_summary_spec.rb b/spec/models/topic_participants_summary_spec.rb
index 29e2edb..830b3e4 100644
--- a/spec/models/topic_participants_summary_spec.rb
+++ b/spec/models/topic_participants_summary_spec.rb
@@ -17,10 +17,11 @@ describe TopicParticipantsSummary do
     let(:user2) { Fabricate(:user) }
     let(:user3) { Fabricate(:user) }
     let(:user4) { Fabricate(:user) }
+    let(:user5) { Fabricate(:user) }
 
-    it "must never contains the user and at most 3 participants" do
-      topic.allowed_user_ids = [user1.id, user2.id, user3.id, user4.id]
-      expect(summary.map(&:user)).to eq([user1, user2, user3])
+    it "must never contains the user and at most 4 participants" do
+      topic.allowed_user_ids = [user1.id, user2.id, user3.id, user4.id, user5.id]
+      expect(summary.map(&:user)).to eq([user1, user2, user3, user4])
     end
 
   end

GitHub sha: 2d6aa2ae

This commit has been mentioned on Discourse Meta. There might be relevant details there: