|
| 1 | +/* |
| 2 | +Copyright 2017 Vector Creations Ltd |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import React from 'react'; |
| 18 | +import MatrixClientPeg from '../../../MatrixClientPeg'; |
| 19 | +import { ContentRepo } from 'matrix-js-sdk'; |
| 20 | +import { _t, _tJsx } from '../../../languageHandler'; |
| 21 | +import sdk from '../../../index'; |
| 22 | +import Modal from '../../../Modal'; |
| 23 | +import AccessibleButton from '../elements/AccessibleButton'; |
| 24 | + |
| 25 | +module.exports = React.createClass({ |
| 26 | + displayName: 'RoomAvatarEvent', |
| 27 | + |
| 28 | + propTypes: { |
| 29 | + /* the MatrixEvent to show */ |
| 30 | + mxEvent: React.PropTypes.object.isRequired, |
| 31 | + }, |
| 32 | + |
| 33 | + onAvatarClick: function(name) { |
| 34 | + var httpUrl = MatrixClientPeg.get().mxcUrlToHttp(this.props.mxEvent.getContent().url); |
| 35 | + var ImageView = sdk.getComponent("elements.ImageView"); |
| 36 | + var params = { |
| 37 | + src: httpUrl, |
| 38 | + name: name, |
| 39 | + }; |
| 40 | + Modal.createDialog(ImageView, params, "mx_Dialog_lightbox"); |
| 41 | + }, |
| 42 | + |
| 43 | + render: function() { |
| 44 | + var ev = this.props.mxEvent; |
| 45 | + var senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); |
| 46 | + var BaseAvatar = sdk.getComponent("avatars.BaseAvatar"); |
| 47 | + |
| 48 | + var room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); |
| 49 | + var name = _t('%(senderDisplayName)s changed the avatar for %(roomName)s', { |
| 50 | + senderDisplayName: senderDisplayName, |
| 51 | + roomName: room ? room.name : '', |
| 52 | + }); |
| 53 | + |
| 54 | + if (!ev.getContent().url || ev.getContent().url.trim().length === 0) { |
| 55 | + return ( |
| 56 | + <div className="mx_TextualEvent"> |
| 57 | + { _t('%(senderDisplayName)s removed the room avatar.', {senderDisplayName: senderDisplayName}) } |
| 58 | + </div> |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + var url = ContentRepo.getHttpUriForMxc( |
| 63 | + MatrixClientPeg.get().getHomeserverUrl(), |
| 64 | + ev.getContent().url, |
| 65 | + 14 * window.devicePixelRatio, |
| 66 | + 14 * window.devicePixelRatio, |
| 67 | + 'crop' |
| 68 | + ); |
| 69 | + |
| 70 | + // it sucks that _tJsx doesn't support normal _t substitutions :(( |
| 71 | + return ( |
| 72 | + <div className="mx_RoomAvatarEvent"> |
| 73 | + { _tJsx('$senderDisplayName changed the room avatar to <img/>', |
| 74 | + [ |
| 75 | + /\$senderDisplayName/, |
| 76 | + /<img\/>/, |
| 77 | + ], |
| 78 | + [ |
| 79 | + (sub) => senderDisplayName, |
| 80 | + (sub) => |
| 81 | + <AccessibleButton key="avatar" className="mx_RoomAvatarEvent_avatar" |
| 82 | + onClick={ this.onAvatarClick.bind(this, name) }> |
| 83 | + <BaseAvatar width={14} height={14} url={ url } |
| 84 | + name={ name } /> |
| 85 | + </AccessibleButton>, |
| 86 | + ] |
| 87 | + ) |
| 88 | + } |
| 89 | + </div> |
| 90 | + ); |
| 91 | + }, |
| 92 | +}); |
0 commit comments