From 755f22a7fa77452b414ba7c6aa0ff90e4313af01 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 14 Sep 2017 17:39:18 +0100 Subject: [PATCH] shelving. Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/TextForEvent.js | 19 ++- .../views/messages/RoomAliasesEvent.js | 161 ++++++++++++++++++ src/components/views/rooms/EventTile.js | 2 +- src/i18n/strings/en_EN.json | 7 +- 4 files changed, 184 insertions(+), 5 deletions(-) create mode 100644 src/components/views/messages/RoomAliasesEvent.js diff --git a/src/TextForEvent.js b/src/TextForEvent.js index c8d0a0a0f7..d39ebd6c0a 100644 --- a/src/TextForEvent.js +++ b/src/TextForEvent.js @@ -149,19 +149,32 @@ function textForRoomAliasesEvent(ev) { if (addedAliases.length && !removedAliases.length) { return _t('%(senderName)s added %(addedAddresses)s as addresses for this room.', { senderName: senderName, + count: addedAliases.length, addedAddresses: addedAliases.join(', '), }); } else if (!addedAliases.length && removedAliases.length) { - return _t('%(senderName)s removed %(addresses)s as addresses for this room.', { + return _t('%(senderName)s removed %(removedAddresses)s as addresses for this room.', { senderName: senderName, + count: removedAliases.length, removedAddresses: removedAliases.join(', '), }); } else { - return _t('%(senderName)s added %(addedAddresses)s and removed %(removedAddresses)s as addresses for this room.', { + const args = { senderName: senderName, addedAddresses: addedAliases.join(', '), removedAddresses: removedAliases.join(', '), - }); + }; + /* eslint-disable max-len */ + if (addedAliases.length === 1 && removedAliases.length === 1) { + return _t('%(senderName)s added %(addedAddresses)s and removed %(removedAddresses)s as addresses for this room.|one,one', args); + } else if (addedAliases.length !== 1 && removedAliases.length === 1) { + return _t('%(senderName)s added %(addedAddresses)s and removed %(removedAddresses)s as addresses for this room.|other,one', args); + } else if (addedAliases.length === 1 && removedAliases.length !== 1) { + return _t('%(senderName)s added %(addedAddresses)s and removed %(removedAddresses)s as addresses for this room.|one,other', args); + } else { + return _t('%(senderName)s added %(addedAddresses)s and removed %(removedAddresses)s as addresses for this room.|other,other', args); + } + /* eslint-enable max-len */ } } diff --git a/src/components/views/messages/RoomAliasesEvent.js b/src/components/views/messages/RoomAliasesEvent.js new file mode 100644 index 0000000000..7d9b2e6795 --- /dev/null +++ b/src/components/views/messages/RoomAliasesEvent.js @@ -0,0 +1,161 @@ +/* +Michael Telatynski <7t3chguy@gmail.com> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +'use strict'; + +import React from 'react'; +import PropTypes from 'prop-types'; +import { _t } from '../../../languageHandler'; + +export class GenericEventListSummary extends React.Component { + static propTypes = { + // An summary to display when collapsed + summary: PropTypes.string.isRequired, + // whether to show summary whilst children are expanded + alwaysShowSummary: PropTypes.bool, + // An array of EventTiles to render when expanded + children: PropTypes.array.isRequired, + // Called when the GELS expansion is toggled + onToggle: PropTypes.func, + // how many children should cause GELS to act + threshold: PropTypes.number.isRequired, + }; + + static defaultProps = { + threshold: 1, + }; + + constructor(props, context) { + super(props, context); + this._toggleSummary = this._toggleSummary.bind(this); + } + + state = { + expanded: false, + }; + + _toggleSummary() { + this.setState({expanded: !this.state.expanded}); + this.props.onToggle(); + } + + render() { + const fewEvents = this.props.children.length < this.props.threshold; + const expanded = this.state.expanded || fewEvents; + const showSummary = !expanded || this.props.alwaysShowSummary; + + let expandedEvents = null; + if (expanded) { + expandedEvents = this.props.children; + } + + if (fewEvents) { + return