2018-01-09 09:50:55 -05:00
import React , { Fragment } from 'react' ;
2016-10-27 15:59:56 -04:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2017-04-21 14:05:35 -04:00
import PropTypes from 'prop-types' ;
2016-11-20 13:39:18 -05:00
import Avatar from './avatar' ;
import DisplayName from './display_name' ;
2016-12-02 09:05:50 -05:00
import Permalink from './permalink' ;
2016-11-20 13:39:18 -05:00
import IconButton from './icon_button' ;
2016-11-18 09:36:16 -05:00
import { defineMessages , injectIntl } from 'react-intl' ;
2017-05-02 20:04:16 -04:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2017-12-04 02:26:40 -05:00
import { me } from 'flavours/glitch/util/initial_state' ;
2020-10-12 19:01:14 -04:00
import RelativeTimestamp from './relative_timestamp' ;
2016-11-18 09:36:16 -05:00
const messages = defineMessages ( {
2016-12-11 17:13:05 -05:00
follow : { id : 'account.follow' , defaultMessage : 'Follow' } ,
2017-01-16 13:36:32 -05:00
unfollow : { id : 'account.unfollow' , defaultMessage : 'Unfollow' } ,
requested : { id : 'account.requested' , defaultMessage : 'Awaiting approval' } ,
2017-04-27 06:03:28 -04:00
unblock : { id : 'account.unblock' , defaultMessage : 'Unblock @{name}' } ,
2017-05-20 11:31:47 -04:00
unmute : { id : 'account.unmute' , defaultMessage : 'Unmute @{name}' } ,
2017-09-13 23:54:14 -04:00
mute _notifications : { id : 'account.mute_notifications' , defaultMessage : 'You are not currently muting notifications from @{name}. Click to mute notifications' } ,
unmute _notifications : { id : 'account.unmute_notifications' , defaultMessage : 'You are currently muting notifications from @{name}. Click to unmute notifications' } ,
2016-11-18 09:36:16 -05:00
} ) ;
2016-10-27 15:59:56 -04:00
2019-09-09 09:16:08 -04:00
export default @ injectIntl
class Account extends ImmutablePureComponent {
2016-10-27 15:59:56 -04:00
2017-05-12 08:44:10 -04:00
static propTypes = {
account : ImmutablePropTypes . map . isRequired ,
onFollow : PropTypes . func . isRequired ,
onBlock : PropTypes . func . isRequired ,
onMute : PropTypes . func . isRequired ,
2017-12-26 14:25:43 -05:00
onMuteNotifications : PropTypes . func . isRequired ,
2017-05-20 11:31:47 -04:00
intl : PropTypes . object . isRequired ,
2017-08-28 16:23:44 -04:00
hidden : PropTypes . bool ,
2017-12-24 01:16:45 -05:00
small : PropTypes . bool ,
2018-10-22 18:08:39 -04:00
actionIcon : PropTypes . string ,
actionTitle : PropTypes . string ,
onActionClick : PropTypes . func ,
2017-05-12 08:44:10 -04:00
} ;
2017-05-24 11:55:16 -04:00
handleFollow = ( ) => {
2016-10-28 14:05:44 -04:00
this . props . onFollow ( this . props . account ) ;
2017-04-21 14:05:35 -04:00
}
2016-10-28 14:05:44 -04:00
2017-05-24 11:55:16 -04:00
handleBlock = ( ) => {
2017-01-16 13:36:32 -05:00
this . props . onBlock ( this . props . account ) ;
2017-04-21 14:05:35 -04:00
}
2017-01-16 13:36:32 -05:00
2017-05-24 11:55:16 -04:00
handleMute = ( ) => {
2017-04-14 19:23:49 -04:00
this . props . onMute ( this . props . account ) ;
2017-04-21 14:05:35 -04:00
}
2017-04-14 19:23:49 -04:00
2017-11-14 21:56:41 -05:00
handleMuteNotifications = ( ) => {
this . props . onMuteNotifications ( this . props . account , true ) ;
}
handleUnmuteNotifications = ( ) => {
this . props . onMuteNotifications ( this . props . account , false ) ;
}
2018-10-22 18:08:39 -04:00
handleAction = ( ) => {
this . props . onActionClick ( this . props . account ) ;
}
2016-10-27 15:59:56 -04:00
render ( ) {
2017-12-24 01:16:45 -05:00
const {
account ,
hidden ,
intl ,
small ,
2018-10-22 18:08:39 -04:00
onActionClick ,
actionIcon ,
actionTitle ,
2017-12-24 01:16:45 -05:00
} = this . props ;
2016-10-27 15:59:56 -04:00
if ( ! account ) {
return < div / > ;
}
2017-08-28 16:23:44 -04:00
if ( hidden ) {
return (
2019-01-10 14:22:28 -05:00
< Fragment >
2017-08-28 16:23:44 -04:00
{ account . get ( 'display_name' ) }
{ account . get ( 'username' ) }
2019-01-10 14:22:28 -05:00
< / F r a g m e n t >
2017-08-28 16:23:44 -04:00
) ;
}
2017-02-08 19:20:09 -05:00
let buttons ;
2016-10-28 14:05:44 -04:00
2021-04-16 04:06:42 -04:00
if ( onActionClick ) {
if ( actionIcon ) {
buttons = < IconButton icon = { actionIcon } title = { actionTitle } onClick = { this . handleAction } / > ;
}
2018-10-22 18:08:39 -04:00
} else if ( account . get ( 'id' ) !== me && ! small && account . get ( 'relationship' , null ) !== null ) {
2016-11-01 13:03:51 -04:00
const following = account . getIn ( [ 'relationship' , 'following' ] ) ;
2017-01-16 13:36:32 -05:00
const requested = account . getIn ( [ 'relationship' , 'requested' ] ) ;
const blocking = account . getIn ( [ 'relationship' , 'blocking' ] ) ;
2017-04-14 19:23:49 -04:00
const muting = account . getIn ( [ 'relationship' , 'muting' ] ) ;
2017-01-16 13:36:32 -05:00
if ( requested ) {
2017-06-06 07:20:07 -04:00
buttons = < IconButton disabled icon = 'hourglass' title = { intl . formatMessage ( messages . requested ) } / > ;
2017-01-16 13:36:32 -05:00
} else if ( blocking ) {
2019-02-01 10:15:44 -05:00
buttons = < IconButton active icon = 'unlock' title = { intl . formatMessage ( messages . unblock , { name : account . get ( 'username' ) } ) } onClick = { this . handleBlock } / > ;
2017-04-14 19:23:49 -04:00
} else if ( muting ) {
2017-11-14 21:56:41 -05:00
let hidingNotificationsButton ;
2017-12-06 19:23:28 -05:00
if ( account . getIn ( [ 'relationship' , 'muting_notifications' ] ) ) {
2017-11-14 21:56:41 -05:00
hidingNotificationsButton = < IconButton active icon = 'bell' title = { intl . formatMessage ( messages . unmute _notifications , { name : account . get ( 'username' ) } ) } onClick = { this . handleUnmuteNotifications } / > ;
} else {
hidingNotificationsButton = < IconButton active icon = 'bell-slash' title = { intl . formatMessage ( messages . mute _notifications , { name : account . get ( 'username' ) } ) } onClick = { this . handleMuteNotifications } / > ;
}
buttons = (
2018-01-09 09:50:55 -05:00
< Fragment >
2017-11-14 21:56:41 -05:00
< IconButton active icon = 'volume-up' title = { intl . formatMessage ( messages . unmute , { name : account . get ( 'username' ) } ) } onClick = { this . handleMute } / >
{ hidingNotificationsButton }
2018-01-09 09:50:55 -05:00
< / F r a g m e n t >
2017-11-14 21:56:41 -05:00
) ;
2018-03-29 08:46:00 -04:00
} else if ( ! account . get ( 'moved' ) || following ) {
2017-12-06 19:23:28 -05:00
buttons = < IconButton icon = { following ? 'user-times' : 'user-plus' } title = { intl . formatMessage ( following ? messages . unfollow : messages . follow ) } onClick = { this . handleFollow } active = { following } / > ;
2017-01-16 13:36:32 -05:00
}
2016-10-27 15:59:56 -04:00
}
2020-10-12 19:01:14 -04:00
let mute _expires _at ;
if ( account . get ( 'mute_expires_at' ) ) {
mute _expires _at = < div > < RelativeTimestamp timestamp = { account . get ( 'mute_expires_at' ) } futureDate / > < / d i v > ;
}
2017-12-24 01:16:45 -05:00
return small ? (
2018-01-05 23:04:13 -05:00
< Permalink
className = 'account small'
href = { account . get ( 'url' ) }
2021-09-25 23:46:13 -04:00
to = { ` /@ ${ account . get ( 'acct' ) } ` }
2018-01-05 23:04:13 -05:00
>
< div className = 'account__avatar-wrapper' >
< Avatar
account = { account }
size = { 24 }
/ >
< / d i v >
< DisplayName
account = { account }
inline
/ >
< / P e r m a l i n k >
2017-12-24 01:16:45 -05:00
) : (
2017-02-08 19:20:09 -05:00
< div className = 'account' >
2017-04-22 22:26:55 -04:00
< div className = 'account__wrapper' >
2021-09-25 23:46:13 -04:00
< Permalink key = { account . get ( 'id' ) } className = 'account__display-name' title = { account . get ( 'acct' ) } href = { account . get ( 'url' ) } to = { ` /@ ${ account . get ( 'acct' ) } ` } >
2017-08-07 13:44:55 -04:00
< div className = 'account__avatar-wrapper' > < Avatar account = { account } size = { 36 } / > < / d i v >
2020-10-12 19:01:14 -04:00
{ mute _expires _at }
2016-10-28 14:05:44 -04:00
< DisplayName account = { account } / >
2016-12-02 09:05:50 -05:00
< / P e r m a l i n k >
2017-12-24 01:16:45 -05:00
{ buttons ?
< div className = 'account__relationship' >
{ buttons }
< / d i v >
2018-01-18 10:13:07 -05:00
: null }
2016-10-28 14:05:44 -04:00
< / d i v >
2016-10-27 15:59:56 -04:00
< / d i v >
) ;
}
2017-04-21 14:05:35 -04:00
}