2017-06-29 19:51:38 +03:00
|
|
|
/*
|
2021-03-04 05:06:46 +03:00
|
|
|
Copyright 2017, 2021 The Matrix.org Foundation C.I.C.
|
2017-06-29 19:51:38 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2020-07-07 00:42:46 +03:00
|
|
|
import BaseAvatar from './BaseAvatar';
|
2021-03-09 05:45:39 +03:00
|
|
|
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
2021-03-04 05:06:46 +03:00
|
|
|
import {mediaFromMxc} from "../../../customisations/Media";
|
|
|
|
import {ResizeMode} from "../../../customisations/models/ResizeMode";
|
2020-07-07 00:42:46 +03:00
|
|
|
|
|
|
|
export interface IProps {
|
2020-07-07 17:40:05 +03:00
|
|
|
groupId?: string;
|
|
|
|
groupName?: string;
|
|
|
|
groupAvatarUrl?: string;
|
|
|
|
width?: number;
|
|
|
|
height?: number;
|
2021-03-04 05:06:46 +03:00
|
|
|
resizeMethod?: ResizeMode;
|
2020-07-07 17:40:05 +03:00
|
|
|
onClick?: React.MouseEventHandler;
|
2020-07-07 00:42:46 +03:00
|
|
|
}
|
|
|
|
|
2021-03-09 05:45:39 +03:00
|
|
|
@replaceableComponent("views.avatars.GroupAvatar")
|
2020-07-07 00:42:46 +03:00
|
|
|
export default class GroupAvatar extends React.Component<IProps> {
|
|
|
|
public static defaultProps = {
|
|
|
|
width: 36,
|
|
|
|
height: 36,
|
|
|
|
resizeMethod: 'crop',
|
|
|
|
};
|
|
|
|
|
|
|
|
getGroupAvatarUrl() {
|
2021-03-04 05:06:46 +03:00
|
|
|
return mediaFromMxc(this.props.groupAvatarUrl).getThumbnailOfSourceHttp(
|
2017-06-29 19:51:38 +03:00
|
|
|
this.props.width,
|
|
|
|
this.props.height,
|
|
|
|
this.props.resizeMethod,
|
|
|
|
);
|
2020-07-07 00:42:46 +03:00
|
|
|
}
|
2017-06-29 19:51:38 +03:00
|
|
|
|
2020-07-07 00:42:46 +03:00
|
|
|
render() {
|
2017-06-30 18:05:19 +03:00
|
|
|
// extract the props we use from props so we can pass any others through
|
2017-07-07 12:41:59 +03:00
|
|
|
// should consider adding this as a global rule in js-sdk?
|
2020-08-29 03:11:08 +03:00
|
|
|
/* eslint @typescript-eslint/no-unused-vars: ["error", { "ignoreRestSiblings": true }] */
|
2017-11-01 20:12:22 +03:00
|
|
|
const {groupId, groupAvatarUrl, groupName, ...otherProps} = this.props;
|
2017-06-29 19:51:38 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<BaseAvatar
|
2017-11-01 20:12:22 +03:00
|
|
|
name={groupName || this.props.groupId[1]}
|
2017-06-29 19:51:38 +03:00
|
|
|
idName={this.props.groupId}
|
|
|
|
url={this.getGroupAvatarUrl()}
|
2017-06-30 18:05:19 +03:00
|
|
|
{...otherProps}
|
2017-06-29 19:51:38 +03:00
|
|
|
/>
|
|
|
|
);
|
2020-07-07 00:42:46 +03:00
|
|
|
}
|
|
|
|
}
|