@@ -14,18 +14,18 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- import React , { useContext , useRef , useState } from 'react' ;
18
- import { EventType } from 'matrix-js-sdk/src/@types/event' ;
19
17
import classNames from 'classnames' ;
18
+ import { EventType } from 'matrix-js-sdk/src/@types/event' ;
19
+ import React , { useContext , useRef , useState , MouseEvent } from 'react' ;
20
20
21
- import AccessibleButton from "./AccessibleButton" ;
22
- import Spinner from "./Spinner" ;
21
+ import Analytics from "../../../Analytics" ;
23
22
import MatrixClientContext from "../../../contexts/MatrixClientContext" ;
23
+ import RoomContext from "../../../contexts/RoomContext" ;
24
24
import { useTimeout } from "../../../hooks/useTimeout" ;
25
- import Analytics from "../../../Analytics" ;
26
25
import { TranslatedString } from '../../../languageHandler' ;
27
- import RoomContext from "../../../contexts/RoomContext" ;
28
26
import { chromeFileInputFix } from "../../../utils/BrowserWorkarounds" ;
27
+ import AccessibleButton from "./AccessibleButton" ;
28
+ import Spinner from "./Spinner" ;
29
29
30
30
export const AVATAR_SIZE = 52 ;
31
31
@@ -34,9 +34,13 @@ interface IProps {
34
34
noAvatarLabel ?: TranslatedString ;
35
35
hasAvatarLabel ?: TranslatedString ;
36
36
setAvatarUrl ( url : string ) : Promise < unknown > ;
37
+ isUserAvatar ?: boolean ;
38
+ onClick ?( ev : MouseEvent < HTMLInputElement > ) : void ;
37
39
}
38
40
39
- const MiniAvatarUploader : React . FC < IProps > = ( { hasAvatar, hasAvatarLabel, noAvatarLabel, setAvatarUrl, children } ) => {
41
+ const MiniAvatarUploader : React . FC < IProps > = ( {
42
+ hasAvatar, hasAvatarLabel, noAvatarLabel, setAvatarUrl, isUserAvatar, children, onClick,
43
+ } ) => {
40
44
const cli = useContext ( MatrixClientContext ) ;
41
45
const [ busy , setBusy ] = useState ( false ) ;
42
46
const [ hover , setHover ] = useState ( false ) ;
@@ -54,7 +58,7 @@ const MiniAvatarUploader: React.FC<IProps> = ({ hasAvatar, hasAvatarLabel, noAva
54
58
const label = ( hasAvatar || busy ) ? hasAvatarLabel : noAvatarLabel ;
55
59
56
60
const { room } = useContext ( RoomContext ) ;
57
- const canSetAvatar = room ?. currentState . maySendStateEvent ( EventType . RoomAvatar , cli . getUserId ( ) ) ;
61
+ const canSetAvatar = isUserAvatar || room ?. currentState ? .maySendStateEvent ( EventType . RoomAvatar , cli . getUserId ( ) ) ;
58
62
if ( ! canSetAvatar ) return < React . Fragment > { children } </ React . Fragment > ;
59
63
60
64
const visible = ! ! label && ( hover || show ) ;
@@ -63,7 +67,10 @@ const MiniAvatarUploader: React.FC<IProps> = ({ hasAvatar, hasAvatarLabel, noAva
63
67
type = "file"
64
68
ref = { uploadRef }
65
69
className = "mx_MiniAvatarUploader_input"
66
- onClick = { chromeFileInputFix }
70
+ onClick = { ( ev ) => {
71
+ chromeFileInputFix ( ev ) ;
72
+ onClick ?.( ev ) ;
73
+ } }
67
74
onChange = { async ( ev ) => {
68
75
if ( ! ev . target . files ?. length ) return ;
69
76
setBusy ( true ) ;
0 commit comments