diff --git a/extensions/mentions/js/forum/src/addMentionedByList.js b/extensions/mentions/js/forum/src/addMentionedByList.js index e56cc478b..058d52db0 100644 --- a/extensions/mentions/js/forum/src/addMentionedByList.js +++ b/extensions/mentions/js/forum/src/addMentionedByList.js @@ -70,40 +70,53 @@ export default function addMentionedByList() { }); }; -// NEEDS TO BE FIXED: The next two blocks of code. See https://github.com/flarum/core/issues/597 for details. + const users = []; + const repliers = replies + .sort(reply => reply.user() === app.session.user ? -1 : 0) + .filter(reply => { + const user = reply.user(); + if (users.indexOf(user) === -1) { + users.push(user); + return true; + } + }); + + const limit = 4; + const overLimit = repliers.length > limit; // Create a list of unique users who have replied. So even if a user has // replied twice, they will only be in this array once. - const used = []; - const repliers = replies.filter(reply => { - const user = reply.user(); - const id = user && user.id(); - if (used.indexOf(id) === -1) { - used.push(id); - return true; - } - }); - - const names = repliers.sort(a => a === app.session.user ? -1 : 1) + const names = repliers + .slice(0, overLimit ? limit - 1 : limit) .map(reply => { const user = reply.user(); return ( + config={m.route} + onclick={hidePreview} + data-number={reply.number()}> {app.session.user === user ? app.translator.trans('flarum-mentions.forum.post.you_text') : username(user)} ); }); + // If there are more users that we've run out of room to display, add a "x + // others" name to the end of the list. Clicking on it will display a modal + // with a full list of names. + if (overLimit) { + const count = repliers.length - names.length; + + names.push( + app.translator.transChoice('flarum-mentions.forum.post.others_text', count, {count}) + ); + } + items.add('replies',