2019-05-17 13:52:03 +03:00
|
|
|
/*
|
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
|
|
|
import sdk from '../../../index';
|
2019-05-19 17:23:43 +03:00
|
|
|
import { unicodeToShortcode } from '../../../HtmlUtils';
|
2019-05-17 13:52:03 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2019-05-20 18:02:10 +03:00
|
|
|
import { formatCommaSeparatedList } from '../../../utils/FormattingUtils';
|
2019-05-17 13:52:03 +03:00
|
|
|
|
|
|
|
export default class ReactionsRowButtonTooltip extends React.PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
// The event we're displaying reactions for
|
|
|
|
mxEvent: PropTypes.object.isRequired,
|
|
|
|
// The reaction content / key / emoji
|
|
|
|
content: PropTypes.string.isRequired,
|
|
|
|
// A Set of Martix reaction events for this key
|
|
|
|
reactionEvents: PropTypes.object.isRequired,
|
|
|
|
visible: PropTypes.bool.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const Tooltip = sdk.getComponent('elements.Tooltip');
|
|
|
|
const { content, reactionEvents, mxEvent, visible } = this.props;
|
|
|
|
|
|
|
|
const room = MatrixClientPeg.get().getRoom(mxEvent.getRoomId());
|
|
|
|
let tooltipLabel;
|
|
|
|
if (room) {
|
|
|
|
const senders = [];
|
|
|
|
for (const reactionEvent of reactionEvents) {
|
|
|
|
const { name } = room.getMember(reactionEvent.getSender());
|
|
|
|
senders.push(name);
|
|
|
|
}
|
2019-05-19 17:23:43 +03:00
|
|
|
const shortName = unicodeToShortcode(content) || content;
|
2019-05-17 13:52:03 +03:00
|
|
|
tooltipLabel = <div>{_t(
|
|
|
|
"<reactors/><reactedWith>reacted with %(shortName)s</reactedWith>",
|
|
|
|
{
|
|
|
|
shortName,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
reactors: () => {
|
|
|
|
return <div className="mx_ReactionsRowButtonTooltip_senders">
|
2019-05-20 18:02:10 +03:00
|
|
|
{formatCommaSeparatedList(senders, 6)}
|
2019-05-17 13:52:03 +03:00
|
|
|
</div>;
|
|
|
|
},
|
|
|
|
reactedWith: (sub) => {
|
|
|
|
return <div className="mx_ReactionsRowButtonTooltip_reactedWith">
|
|
|
|
{sub}
|
|
|
|
</div>;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
)}</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
let tooltip;
|
|
|
|
if (tooltipLabel) {
|
|
|
|
tooltip = <Tooltip
|
2019-05-17 17:04:27 +03:00
|
|
|
tooltipClassName="mx_Tooltip_timeline"
|
2019-05-17 13:52:03 +03:00
|
|
|
visible={visible}
|
|
|
|
label={tooltipLabel}
|
|
|
|
/>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tooltip;
|
|
|
|
}
|
|
|
|
}
|