mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 12:05:47 +08:00
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");
|
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")
|
@computed("fancy_title")
|
||||||
fancyTitle(title) {
|
fancyTitle(title) {
|
||||||
let fancyTitle = censor(
|
let fancyTitle = censor(
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
</td>
|
</td>
|
||||||
|
|
||||||
{{#if showPosters}}
|
{{#if showPosters}}
|
||||||
{{raw "list/posters-column" posters=topic.posters}}
|
{{raw "list/posters-column" posters=topic.featuredUsers}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{raw "list/posts-count-column" topic=topic}}
|
{{raw "list/posts-count-column" topic=topic}}
|
||||||
|
@ -24,7 +24,7 @@ class TopicParticipantsSummary
|
|||||||
end
|
end
|
||||||
|
|
||||||
def top_participants
|
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
|
end
|
||||||
|
|
||||||
def user_ids
|
def user_ids
|
||||||
|
@ -17,10 +17,11 @@ describe TopicParticipantsSummary do
|
|||||||
let(:user2) { Fabricate(:user) }
|
let(:user2) { Fabricate(:user) }
|
||||||
let(:user3) { Fabricate(:user) }
|
let(:user3) { Fabricate(:user) }
|
||||||
let(:user4) { Fabricate(:user) }
|
let(:user4) { Fabricate(:user) }
|
||||||
|
let(:user5) { Fabricate(:user) }
|
||||||
|
|
||||||
it "must never contains the user and at most 3 participants" do
|
it "must never contains the user and at most 4 participants" do
|
||||||
topic.allowed_user_ids = [user1.id, user2.id, user3.id, user4.id]
|
topic.allowed_user_ids = [user1.id, user2.id, user3.id, user4.id, user5.id]
|
||||||
expect(summary.map(&:user)).to eq([user1, user2, user3])
|
expect(summary.map(&:user)).to eq([user1, user2, user3, user4])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user