From d689d4e1faf28e2f14772516d02227904f4d7b34 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Thu, 1 Jun 2017 13:31:15 +0100 Subject: [PATCH] quick and dirty RoomAvatarEvent --- .../views/messages/RoomAvatarEvent.js | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/components/views/messages/RoomAvatarEvent.js diff --git a/src/components/views/messages/RoomAvatarEvent.js b/src/components/views/messages/RoomAvatarEvent.js new file mode 100644 index 0000000000..9f69473dd6 --- /dev/null +++ b/src/components/views/messages/RoomAvatarEvent.js @@ -0,0 +1,92 @@ +/* +Copyright 2017 Vector Creations Ltd + +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'; + +var React = require('react'); + +var MatrixClientPeg = require("../../../MatrixClientPeg"); +var ContentRepo = require("matrix-js-sdk").ContentRepo; +import { _tJsx } from '../../../languageHandler'; +import sdk from '../../../index'; +import Modal from '../../../Modal'; +import AccessibleButton from '../elements/AccessibleButton'; + +module.exports = React.createClass({ + displayName: 'RoomAvatarEvent', + + propTypes: { + /* the MatrixEvent to show */ + mxEvent: React.PropTypes.object.isRequired, + }, + + onAvatarClick: function(name, e) { + var httpUrl = MatrixClientPeg.get().mxcUrlToHttp(this.props.mxEvent.getContent().url); + var ImageView = sdk.getComponent("elements.ImageView"); + var params = { + src: httpUrl, + name: name, + }; + Modal.createDialog(ImageView, params, "mx_Dialog_lightbox"); + }, + + render: function() { + var ev = this.props.mxEvent; + var senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(); + var BaseAvatar = sdk.getComponent("avatars.BaseAvatar"); + + var room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); + var name = room ? room.name : ''; + + if (!ev.getContent().url || ev.getContent().url.trim().length === 0) { + return ( +
+ { _t('%(senderDisplayName)s removed the room avatar.', {senderDisplayName: senderDisplayName}) } +
+ ); + } + + var url = ContentRepo.getHttpUriForMxc( + MatrixClientPeg.get().getHomeserverUrl(), + ev.getContent().url, + 14 * window.devicePixelRatio, + 14 * window.devicePixelRatio, + 'crop' + ); + + // it sucks that _tJsx doesn't support normal _t substitutions :(( + return ( +
+ { _tJsx('$senderDisplayName changed the room avatar to ', + [ + /\$senderDisplayName/, + //, + ], + [ + (sub) => senderDisplayName, + (sub) => + + + , + ] + ) + } +
+ ); + }, +});