2017-06-01 15:31:15 +03:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
2019-08-08 22:21:53 +03:00
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
2019-12-20 03:45:24 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2017-06-01 15:31:15 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-06-01 16:42:44 +03:00
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-12-21 00:13:46 +03:00
|
|
|
import {MatrixClientPeg} from '../../../MatrixClientPeg';
|
2017-11-13 22:19:33 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../../index';
|
2017-06-01 15:31:15 +03:00
|
|
|
import Modal from '../../../Modal';
|
|
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
export default class RoomAvatarEvent extends React.Component {
|
|
|
|
static propTypes = {
|
2017-06-01 15:31:15 +03:00
|
|
|
/* the MatrixEvent to show */
|
2017-12-26 04:03:18 +03:00
|
|
|
mxEvent: PropTypes.object.isRequired,
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-06-01 15:31:15 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
onAvatarClick = () => {
|
2019-08-08 22:07:38 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const ev = this.props.mxEvent;
|
|
|
|
const httpUrl = cli.mxcUrlToHttp(ev.getContent().url);
|
|
|
|
|
|
|
|
const room = cli.getRoom(this.props.mxEvent.getRoomId());
|
|
|
|
const text = _t('%(senderDisplayName)s changed the avatar for %(roomName)s', {
|
|
|
|
senderDisplayName: ev.sender && ev.sender.name ? ev.sender.name : ev.getSender(),
|
|
|
|
roomName: room ? room.name : '',
|
|
|
|
});
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const ImageView = sdk.getComponent("elements.ImageView");
|
|
|
|
const params = {
|
2017-06-01 15:31:15 +03:00
|
|
|
src: httpUrl,
|
2019-08-08 22:07:38 +03:00
|
|
|
name: text,
|
2017-06-01 15:31:15 +03:00
|
|
|
};
|
|
|
|
Modal.createDialog(ImageView, params, "mx_Dialog_lightbox");
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-06-01 15:31:15 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
render() {
|
2017-10-11 19:56:17 +03:00
|
|
|
const ev = this.props.mxEvent;
|
|
|
|
const senderDisplayName = ev.sender && ev.sender.name ? ev.sender.name : ev.getSender();
|
2019-08-08 22:21:53 +03:00
|
|
|
const RoomAvatar = sdk.getComponent("avatars.RoomAvatar");
|
2017-06-01 15:31:15 +03:00
|
|
|
|
|
|
|
if (!ev.getContent().url || ev.getContent().url.trim().length === 0) {
|
|
|
|
return (
|
|
|
|
<div className="mx_TextualEvent">
|
2019-08-08 22:07:38 +03:00
|
|
|
{ _t('%(senderDisplayName)s removed the room avatar.', {senderDisplayName}) }
|
2017-06-01 15:31:15 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-08 22:21:53 +03:00
|
|
|
const room = MatrixClientPeg.get().getRoom(ev.getRoomId());
|
2019-08-09 13:31:04 +03:00
|
|
|
// Provide all arguments to RoomAvatar via oobData because the avatar is historic
|
2019-08-08 22:21:53 +03:00
|
|
|
const oobData = {
|
|
|
|
avatarUrl: ev.getContent().url,
|
2019-08-09 13:31:04 +03:00
|
|
|
name: room ? room.name : "",
|
2019-08-08 22:21:53 +03:00
|
|
|
};
|
2017-06-01 15:31:15 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="mx_RoomAvatarEvent">
|
2017-11-13 22:19:33 +03:00
|
|
|
{ _t('%(senderDisplayName)s changed the room avatar to <img/>',
|
|
|
|
{ senderDisplayName: senderDisplayName },
|
|
|
|
{
|
|
|
|
'img': () =>
|
|
|
|
<AccessibleButton key="avatar" className="mx_RoomAvatarEvent_avatar"
|
2019-08-08 22:07:38 +03:00
|
|
|
onClick={this.onAvatarClick}>
|
2019-08-09 13:31:04 +03:00
|
|
|
<RoomAvatar width={14} height={14} oobData={oobData} />
|
2017-11-13 22:19:33 +03:00
|
|
|
</AccessibleButton>,
|
|
|
|
})
|
2017-06-01 15:31:15 +03:00
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
|
|
|
}
|