1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 08:27:42 +02:00

Truncate list of replies, pluralize notification text

ref flarum/core#597
This commit is contained in:
Toby Zerner
2015-10-24 13:14:57 +10:30
parent 61d8e8714d
commit 3d7fcaa2b2
2 changed files with 32 additions and 19 deletions

View File

@@ -70,21 +70,24 @@ 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
// Create a list of unique users who have replied. So even if a user has .sort(reply => reply.user() === app.session.user ? -1 : 0)
// replied twice, they will only be in this array once. .filter(reply => {
const used = [];
const repliers = replies.filter(reply => {
const user = reply.user(); const user = reply.user();
const id = user && user.id(); if (users.indexOf(user) === -1) {
if (used.indexOf(id) === -1) { users.push(user);
used.push(id);
return true; return true;
} }
}); });
const names = repliers.sort(a => a === app.session.user ? -1 : 1) 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 names = repliers
.slice(0, overLimit ? limit - 1 : limit)
.map(reply => { .map(reply => {
const user = reply.user(); const user = reply.user();
@@ -98,12 +101,22 @@ export default function addMentionedByList() {
); );
}); });
// 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', items.add('replies',
<div className="Post-mentionedBy" config={config}> <div className="Post-mentionedBy" config={config}>
<span className="Post-mentionedBy-summary"> <span className="Post-mentionedBy-summary">
{icon('reply')} {icon('reply')}
// PLEASE CHECK: Using the syntax from "addLikesList.js" with "repliers[0]" in place of "likes[0]". {app.translator.transChoice('flarum-mentions.forum.post.mentioned_by' + (replies[0] === app.session.user ? '_self' : '') + '_text', names.length, {
{app.translator.transChoice('flarum-mentions.forum.post.mentioned_by' + (repliers[0] === app.session.user ? '_self' : '') + '_text', names.length, {
count: names.length, count: names.length,
users: punctuateSeries(names) users: punctuateSeries(names)
})} })}

View File

@@ -21,11 +21,11 @@ export default class PostMentionedNotification extends Notification {
const auc = notification.additionalUnreadCount(); const auc = notification.additionalUnreadCount();
const user = notification.sender(); const user = notification.sender();
return app.translator.trans('flarum-mentions.forum.notifications.post_mentioned_text', { return app.translator.transChoice('flarum-mentions.forum.notifications.post_mentioned_text', auc + 1, {
user, user,
username: auc ? punctuateSeries([ username: auc ? punctuateSeries([
username(user), username(user),
app.translator.trans('flarum-mentions.forum.notifications.others_text', {count: auc}) app.translator.transChoice('flarum-mentions.forum.notifications.others_text', auc, {count: auc})
]) : undefined ]) : undefined
}); });
} }