FEATURE: Add recipient avatars in PM topic list even if they not yet replied
This commit is contained in:
parent
f461a9971f
commit
2d6aa2aea2
|
@ -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(
|
||||
|
|
|
@ -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}}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue