Skip to content

Commit

Permalink
FEATURE: Add recipient avatars in PM topic list even if they not yet …
Browse files Browse the repository at this point in the history
…replied
  • Loading branch information
vinothkannans committed Jan 25, 2019
1 parent f461a99 commit 2d6aa2a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
34 changes: 34 additions & 0 deletions app/assets/javascripts/discourse/models/topic.js.es6
Expand Up @@ -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(
Expand Down
Expand Up @@ -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}}
Expand Down
2 changes: 1 addition & 1 deletion app/models/topic_participants_summary.rb
Expand Up @@ -24,7 +24,7 @@ def is_latest_poster?(user)
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
Expand Down
7 changes: 4 additions & 3 deletions spec/models/topic_participants_summary_spec.rb
Expand Up @@ -17,10 +17,11 @@
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
Expand Down

1 comment on commit 2d6aa2a

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

https://meta.discourse.org/t/show-recipient-name-in-personal-message-list/107116/7

Please sign in to comment.