Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit db73e64

Browse files
authored
Merge pull request #2998 from matrix-org/jryans/clamp-reaction-senders
Limit reaction sender tooltip to 6 people
2 parents 1368a5e + 1bc9bad commit db73e64

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

src/components/views/elements/MemberEventListSummary.js

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2016 OpenMarket Ltd
3+
Copyright 2019 The Matrix.org Foundation C.I.C.
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -13,11 +14,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1314
See the License for the specific language governing permissions and
1415
limitations under the License.
1516
*/
17+
1618
import React from 'react';
1719
import PropTypes from 'prop-types';
1820
import sdk from '../../../index';
19-
const MemberAvatar = require('../avatars/MemberAvatar.js');
21+
import MemberAvatar from '../avatars/MemberAvatar';
2022
import { _t } from '../../../languageHandler';
23+
import { formatCommaSeparatedList } from '../../../utils/FormattingUtils';
2124

2225
module.exports = React.createClass({
2326
displayName: 'MemberEventListSummary',
@@ -105,7 +108,7 @@ module.exports = React.createClass({
105108
);
106109
});
107110

108-
const desc = this._renderCommaSeparatedList(descs);
111+
const desc = formatCommaSeparatedList(descs);
109112

110113
return _t('%(nameList)s %(transitionList)s', { nameList: nameList, transitionList: desc });
111114
});
@@ -132,7 +135,7 @@ module.exports = React.createClass({
132135
* included before "and [n] others".
133136
*/
134137
_renderNameList: function(users) {
135-
return this._renderCommaSeparatedList(users, this.props.summaryLength);
138+
return formatCommaSeparatedList(users, this.props.summaryLength);
136139
},
137140

138141
/**
@@ -283,35 +286,6 @@ module.exports = React.createClass({
283286
return res;
284287
},
285288

286-
/**
287-
* Constructs a written English string representing `items`, with an optional limit on
288-
* the number of items included in the result. If specified and if the length of
289-
*`items` is greater than the limit, the string "and n others" will be appended onto
290-
* the result.
291-
* If `items` is empty, returns the empty string. If there is only one item, return
292-
* it.
293-
* @param {string[]} items the items to construct a string from.
294-
* @param {number?} itemLimit the number by which to limit the list.
295-
* @returns {string} a string constructed by joining `items` with a comma between each
296-
* item, but with the last item appended as " and [lastItem]".
297-
*/
298-
_renderCommaSeparatedList(items, itemLimit) {
299-
const remaining = itemLimit === undefined ? 0 : Math.max(
300-
items.length - itemLimit, 0,
301-
);
302-
if (items.length === 0) {
303-
return "";
304-
} else if (items.length === 1) {
305-
return items[0];
306-
} else if (remaining > 0) {
307-
items = items.slice(0, itemLimit);
308-
return _t("%(items)s and %(count)s others", { items: items.join(', '), count: remaining } );
309-
} else {
310-
const lastItem = items.pop();
311-
return _t("%(items)s and %(lastItem)s", { items: items.join(', '), lastItem: lastItem });
312-
}
313-
},
314-
315289
_renderAvatars: function(roomMembers) {
316290
const avatars = roomMembers.slice(0, this.props.avatarsMaxLength).map((m) => {
317291
return (

src/components/views/messages/ReactionsRowButtonTooltip.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import MatrixClientPeg from '../../../MatrixClientPeg';
2121
import sdk from '../../../index';
2222
import { unicodeToShort } from '../../../HtmlUtils';
2323
import { _t } from '../../../languageHandler';
24+
import { formatCommaSeparatedList } from '../../../utils/FormattingUtils';
2425

2526
export default class ReactionsRowButtonTooltip extends React.PureComponent {
2627
static propTypes = {
@@ -54,7 +55,7 @@ export default class ReactionsRowButtonTooltip extends React.PureComponent {
5455
{
5556
reactors: () => {
5657
return <div className="mx_ReactionsRowButtonTooltip_senders">
57-
{senders.join(", ")}
58+
{formatCommaSeparatedList(senders, 6)}
5859
</div>;
5960
},
6061
reactedWith: (sub) => {

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@
253253
"This homeserver has exceeded one of its resource limits.": "This homeserver has exceeded one of its resource limits.",
254254
"Please <a>contact your service administrator</a> to continue using the service.": "Please <a>contact your service administrator</a> to continue using the service.",
255255
"Unable to connect to Homeserver. Retrying...": "Unable to connect to Homeserver. Retrying...",
256+
"%(items)s and %(count)s others|other": "%(items)s and %(count)s others",
257+
"%(items)s and %(count)s others|one": "%(items)s and one other",
258+
"%(items)s and %(lastItem)s": "%(items)s and %(lastItem)s",
256259
"Your browser does not support the required cryptography extensions": "Your browser does not support the required cryptography extensions",
257260
"Not a valid Riot keyfile": "Not a valid Riot keyfile",
258261
"Authentication check failed: incorrect password?": "Authentication check failed: incorrect password?",
@@ -1046,9 +1049,6 @@
10461049
"%(severalUsers)schanged their avatar %(count)s times|one": "%(severalUsers)schanged their avatar",
10471050
"%(oneUser)schanged their avatar %(count)s times|other": "%(oneUser)schanged their avatar %(count)s times",
10481051
"%(oneUser)schanged their avatar %(count)s times|one": "%(oneUser)schanged their avatar",
1049-
"%(items)s and %(count)s others|other": "%(items)s and %(count)s others",
1050-
"%(items)s and %(count)s others|one": "%(items)s and one other",
1051-
"%(items)s and %(lastItem)s": "%(items)s and %(lastItem)s",
10521052
"collapse": "collapse",
10531053
"expand": "expand",
10541054
"Power level": "Power level",

src/utils/FormattingUtils.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2016 OpenMarket Ltd
3+
Copyright 2019 The Matrix.org Foundation C.I.C.
34
45
Licensed under the Apache License, Version 2.0 (the "License");
56
you may not use this file except in compliance with the License.
@@ -14,6 +15,8 @@ See the License for the specific language governing permissions and
1415
limitations under the License.
1516
*/
1617

18+
import { _t } from '../languageHandler';
19+
1720
/**
1821
* formats numbers to fit into ~3 characters, suitable for badge counts
1922
* e.g: 999, 9.9K, 99K, 0.9M, 9.9M, 99M, 0.9B, 9.9B
@@ -63,3 +66,31 @@ export function getUserNameColorClass(userId) {
6366
const colorNumber = (hashCode(userId) % 8) + 1;
6467
return `mx_Username_color${colorNumber}`;
6568
}
69+
70+
/**
71+
* Constructs a written English string representing `items`, with an optional
72+
* limit on the number of items included in the result. If specified and if the
73+
* length of `items` is greater than the limit, the string "and n others" will
74+
* be appended onto the result. If `items` is empty, returns the empty string.
75+
* If there is only one item, return it.
76+
* @param {string[]} items the items to construct a string from.
77+
* @param {number?} itemLimit the number by which to limit the list.
78+
* @returns {string} a string constructed by joining `items` with a comma
79+
* between each item, but with the last item appended as " and [lastItem]".
80+
*/
81+
export function formatCommaSeparatedList(items, itemLimit) {
82+
const remaining = itemLimit === undefined ? 0 : Math.max(
83+
items.length - itemLimit, 0,
84+
);
85+
if (items.length === 0) {
86+
return "";
87+
} else if (items.length === 1) {
88+
return items[0];
89+
} else if (remaining > 0) {
90+
items = items.slice(0, itemLimit);
91+
return _t("%(items)s and %(count)s others", { items: items.join(', '), count: remaining } );
92+
} else {
93+
const lastItem = items.pop();
94+
return _t("%(items)s and %(lastItem)s", { items: items.join(', '), lastItem: lastItem });
95+
}
96+
}

0 commit comments

Comments
 (0)