2020-03-27 13:59:38 -07:00
'use strict' ;
import React from 'react' ;
2020-04-01 19:20:47 -07:00
import { connect } from 'react-redux' ;
2020-03-27 13:59:38 -07:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import PropTypes from 'prop-types' ;
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2020-08-27 11:32:52 -07:00
import Icon from 'soapbox/components/icon' ;
2020-05-28 15:52:07 -07:00
import Button from 'soapbox/components/button' ;
2020-03-27 13:59:38 -07:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2020-05-28 15:52:07 -07:00
import { isStaff } from 'soapbox/utils/accounts' ;
import { parseVersion } from 'soapbox/utils/features' ;
2020-03-27 13:59:38 -07:00
import classNames from 'classnames' ;
2020-05-28 15:52:07 -07:00
import Avatar from 'soapbox/components/avatar' ;
import { shortNumberFormat } from 'soapbox/utils/numbers' ;
2020-03-27 13:59:38 -07:00
import { NavLink } from 'react-router-dom' ;
2020-05-28 15:52:07 -07:00
import DropdownMenuContainer from 'soapbox/containers/dropdown_menu_container' ;
2020-03-27 13:59:38 -07:00
import ProfileInfoPanel from '../../ui/components/profile_info_panel' ;
import { debounce } from 'lodash' ;
2020-06-10 06:30:33 -07:00
import StillImage from 'soapbox/components/still_image' ;
2020-08-02 19:16:13 -07:00
import ActionButton from 'soapbox/features/ui/components/action_button' ;
2021-03-15 19:50:16 -07:00
import { isVerified } from 'soapbox/utils/accounts' ;
2021-05-01 13:02:27 -07:00
import { openModal } from 'soapbox/actions/modal' ;
import { List as ImmutableList , Map as ImmutableMap } from 'immutable' ;
2020-03-27 13:59:38 -07:00
const messages = defineMessages ( {
edit _profile : { id : 'account.edit_profile' , defaultMessage : 'Edit profile' } ,
linkVerifiedOn : { id : 'account.link_verified_on' , defaultMessage : 'Ownership of this link was checked on {date}' } ,
account _locked : { id : 'account.locked_info' , defaultMessage : 'This account privacy status is set to locked. The owner manually reviews who can follow them.' } ,
mention : { id : 'account.mention' , defaultMessage : 'Mention' } ,
direct : { id : 'account.direct' , defaultMessage : 'Direct message @{name}' } ,
unmute : { id : 'account.unmute' , defaultMessage : 'Unmute @{name}' } ,
block : { id : 'account.block' , defaultMessage : 'Block @{name}' } ,
2020-08-14 15:16:38 -07:00
unblock : { id : 'account.unblock' , defaultMessage : 'Unblock @{name}' } ,
2020-03-27 13:59:38 -07:00
mute : { id : 'account.mute' , defaultMessage : 'Mute @{name}' } ,
report : { id : 'account.report' , defaultMessage : 'Report @{name}' } ,
share : { id : 'account.share' , defaultMessage : 'Share @{name}\'s profile' } ,
media : { id : 'account.media' , defaultMessage : 'Media' } ,
blockDomain : { id : 'account.block_domain' , defaultMessage : 'Hide everything from {domain}' } ,
unblockDomain : { id : 'account.unblock_domain' , defaultMessage : 'Unhide {domain}' } ,
hideReblogs : { id : 'account.hide_reblogs' , defaultMessage : 'Hide reposts from @{name}' } ,
showReblogs : { id : 'account.show_reblogs' , defaultMessage : 'Show reposts from @{name}' } ,
preferences : { id : 'navigation_bar.preferences' , defaultMessage : 'Preferences' } ,
follow _requests : { id : 'navigation_bar.follow_requests' , defaultMessage : 'Follow requests' } ,
blocks : { id : 'navigation_bar.blocks' , defaultMessage : 'Blocked users' } ,
domain _blocks : { id : 'navigation_bar.domain_blocks' , defaultMessage : 'Hidden domains' } ,
mutes : { id : 'navigation_bar.mutes' , defaultMessage : 'Muted users' } ,
endorse : { id : 'account.endorse' , defaultMessage : 'Feature on profile' } ,
unendorse : { id : 'account.unendorse' , defaultMessage : 'Don\'t feature on profile' } ,
admin _account : { id : 'status.admin_account' , defaultMessage : 'Open moderation interface for @{name}' } ,
add _or _remove _from _list : { id : 'account.add_or_remove_from_list' , defaultMessage : 'Add or Remove from lists' } ,
2021-01-18 16:25:36 -08:00
deactivateUser : { id : 'admin.users.actions.deactivate_user' , defaultMessage : 'Deactivate @{name}' } ,
deleteUser : { id : 'admin.users.actions.delete_user' , defaultMessage : 'Delete @{name}' } ,
2021-03-15 19:50:16 -07:00
verifyUser : { id : 'admin.users.actions.verify_user' , defaultMessage : 'Verify @{name}' } ,
unverifyUser : { id : 'admin.users.actions.unverify_user' , defaultMessage : 'Unverify @{name}' } ,
2020-03-27 13:59:38 -07:00
} ) ;
2020-04-01 19:20:47 -07:00
const mapStateToProps = state => {
2020-04-18 13:22:40 -07:00
const me = state . get ( 'me' ) ;
2020-04-01 19:20:47 -07:00
return {
2020-04-18 13:22:40 -07:00
me ,
2020-04-20 14:08:31 -07:00
isStaff : isStaff ( state . getIn ( [ 'accounts' , me ] ) ) ,
2020-06-04 21:12:14 -07:00
version : parseVersion ( state . getIn ( [ 'instance' , 'version' ] ) ) ,
2020-04-01 19:20:47 -07:00
} ;
} ;
export default @ connect ( mapStateToProps )
@ injectIntl
2020-03-27 13:59:38 -07:00
class Header extends ImmutablePureComponent {
static propTypes = {
account : ImmutablePropTypes . map ,
identity _props : ImmutablePropTypes . list ,
intl : PropTypes . object . isRequired ,
username : PropTypes . string ,
2020-04-20 14:08:31 -07:00
isStaff : PropTypes . bool . isRequired ,
2020-05-26 21:56:54 -07:00
version : PropTypes . object ,
2020-03-27 13:59:38 -07:00
} ;
2020-04-20 14:08:31 -07:00
static defaultProps = {
isStaff : false ,
}
2020-03-27 13:59:38 -07:00
state = {
isSmallScreen : ( window . innerWidth <= 895 ) ,
}
isStatusesPageActive = ( match , location ) => {
if ( ! match ) {
return false ;
}
return ! location . pathname . match ( /\/(followers|following|favorites|pins)\/?$/ ) ;
}
2020-06-17 18:42:30 -07:00
componentDidMount ( ) {
2020-03-27 13:59:38 -07:00
window . addEventListener ( 'resize' , this . handleResize , { passive : true } ) ;
}
2020-04-14 14:47:35 -07:00
componentWillUnmount ( ) {
2020-03-27 13:59:38 -07:00
window . removeEventListener ( 'resize' , this . handleResize ) ;
}
handleResize = debounce ( ( ) => {
this . setState ( { isSmallScreen : ( window . innerWidth <= 895 ) } ) ;
} , 5 , {
trailing : true ,
} ) ;
2021-05-01 13:02:27 -07:00
onAvatarClick = ( ) => {
const avatar _url = this . props . account . get ( 'avatar' ) ;
const avatar = ImmutableMap ( {
type : 'image' ,
preview _url : avatar _url ,
url : avatar _url ,
description : '' ,
} ) ;
this . props . dispatch ( openModal ( 'MEDIA' , { media : ImmutableList . of ( avatar ) , index : 0 } ) ) ;
}
handleAvatarClick = ( e ) => {
if ( e . button === 0 && ! ( e . ctrlKey || e . metaKey ) ) {
e . preventDefault ( ) ;
this . onAvatarClick ( ) ;
}
}
2020-03-27 13:59:38 -07:00
makeMenu ( ) {
2020-05-26 05:49:05 -07:00
const { account , intl , me , isStaff , version } = this . props ;
2020-03-27 13:59:38 -07:00
let menu = [ ] ;
if ( ! account || ! me ) {
return [ ] ;
}
if ( 'share' in navigator ) {
menu . push ( { text : intl . formatMessage ( messages . share , { name : account . get ( 'username' ) } ) , action : this . handleShare } ) ;
menu . push ( null ) ;
}
if ( account . get ( 'id' ) === me ) {
2020-04-21 14:20:17 -07:00
menu . push ( { text : intl . formatMessage ( messages . edit _profile ) , to : '/settings/profile' } ) ;
menu . push ( { text : intl . formatMessage ( messages . preferences ) , to : '/settings/preferences' } ) ;
2020-03-27 13:59:38 -07:00
menu . push ( null ) ;
menu . push ( { text : intl . formatMessage ( messages . follow _requests ) , to : '/follow_requests' } ) ;
menu . push ( null ) ;
menu . push ( { text : intl . formatMessage ( messages . mutes ) , to : '/mutes' } ) ;
menu . push ( { text : intl . formatMessage ( messages . blocks ) , to : '/blocks' } ) ;
menu . push ( { text : intl . formatMessage ( messages . domain _blocks ) , to : '/domain_blocks' } ) ;
} else {
menu . push ( { text : intl . formatMessage ( messages . mention , { name : account . get ( 'username' ) } ) , action : this . props . onMention } ) ;
if ( account . getIn ( [ 'relationship' , 'following' ] ) ) {
if ( account . getIn ( [ 'relationship' , 'showing_reblogs' ] ) ) {
menu . push ( { text : intl . formatMessage ( messages . hideReblogs , { name : account . get ( 'username' ) } ) , action : this . props . onReblogToggle } ) ;
} else {
menu . push ( { text : intl . formatMessage ( messages . showReblogs , { name : account . get ( 'username' ) } ) , action : this . props . onReblogToggle } ) ;
}
menu . push ( { text : intl . formatMessage ( messages . add _or _remove _from _list ) , action : this . props . onAddToList } ) ;
2020-08-15 22:23:06 -07:00
// menu.push({ text: intl.formatMessage(account.getIn(['relationship', 'endorsed']) ? messages.unendorse : messages.endorse), action: this.props.onEndorseToggle });
2020-03-27 13:59:38 -07:00
menu . push ( null ) ;
2020-06-04 21:12:14 -07:00
} else if ( version . software === 'Pleroma' ) {
2020-05-26 05:49:05 -07:00
menu . push ( { text : intl . formatMessage ( messages . add _or _remove _from _list ) , action : this . props . onAddToList } ) ;
}
2020-03-27 13:59:38 -07:00
if ( account . getIn ( [ 'relationship' , 'muting' ] ) ) {
menu . push ( { text : intl . formatMessage ( messages . unmute , { name : account . get ( 'username' ) } ) , action : this . props . onMute } ) ;
} else {
menu . push ( { text : intl . formatMessage ( messages . mute , { name : account . get ( 'username' ) } ) , action : this . props . onMute } ) ;
}
if ( account . getIn ( [ 'relationship' , 'blocking' ] ) ) {
menu . push ( { text : intl . formatMessage ( messages . unblock , { name : account . get ( 'username' ) } ) , action : this . props . onBlock } ) ;
} else {
menu . push ( { text : intl . formatMessage ( messages . block , { name : account . get ( 'username' ) } ) , action : this . props . onBlock } ) ;
}
menu . push ( { text : intl . formatMessage ( messages . report , { name : account . get ( 'username' ) } ) , action : this . props . onReport } ) ;
}
if ( account . get ( 'acct' ) !== account . get ( 'username' ) ) {
const domain = account . get ( 'acct' ) . split ( '@' ) [ 1 ] ;
menu . push ( null ) ;
if ( account . getIn ( [ 'relationship' , 'domain_blocking' ] ) ) {
menu . push ( { text : intl . formatMessage ( messages . unblockDomain , { domain } ) , action : this . props . onUnblockDomain } ) ;
} else {
menu . push ( { text : intl . formatMessage ( messages . blockDomain , { domain } ) , action : this . props . onBlockDomain } ) ;
}
}
2021-03-15 19:57:24 -07:00
if ( isStaff ) {
2020-03-27 13:59:38 -07:00
menu . push ( null ) ;
2020-08-07 10:58:59 -07:00
menu . push ( { text : intl . formatMessage ( messages . admin _account , { name : account . get ( 'username' ) } ) , href : ` /pleroma/admin/#/users/ ${ account . get ( 'id' ) } / ` , newTab : true } ) ;
2021-03-15 19:50:16 -07:00
if ( isVerified ( account ) ) {
menu . push ( { text : intl . formatMessage ( messages . unverifyUser , { name : account . get ( 'username' ) } ) , action : this . props . onUnverifyUser } ) ;
} else {
menu . push ( { text : intl . formatMessage ( messages . verifyUser , { name : account . get ( 'username' ) } ) , action : this . props . onVerifyUser } ) ;
}
2021-03-15 19:57:24 -07:00
if ( account . get ( 'id' ) !== me ) {
menu . push ( { text : intl . formatMessage ( messages . deactivateUser , { name : account . get ( 'username' ) } ) , action : this . props . onDeactivateUser } ) ;
menu . push ( { text : intl . formatMessage ( messages . deleteUser , { name : account . get ( 'username' ) } ) , action : this . props . onDeleteUser } ) ;
}
2020-03-27 13:59:38 -07:00
}
return menu ;
}
makeInfo ( ) {
2020-04-14 13:45:38 -07:00
const { account , me } = this . props ;
2020-03-27 13:59:38 -07:00
let info = [ ] ;
if ( ! account || ! me ) return info ;
if ( me !== account . get ( 'id' ) && account . getIn ( [ 'relationship' , 'followed_by' ] ) ) {
info . push ( < span key = 'followed_by' className = 'relationship-tag' > < FormattedMessage id = 'account.follows_you' defaultMessage = 'Follows you' / > < / s p a n > ) ;
} else if ( me !== account . get ( 'id' ) && account . getIn ( [ 'relationship' , 'blocking' ] ) ) {
info . push ( < span key = 'blocked' className = 'relationship-tag' > < FormattedMessage id = 'account.blocked' defaultMessage = 'Blocked' / > < / s p a n > ) ;
}
if ( me !== account . get ( 'id' ) && account . getIn ( [ 'relationship' , 'muting' ] ) ) {
info . push ( < span key = 'muted' className = 'relationship-tag' > < FormattedMessage id = 'account.muted' defaultMessage = 'Muted' / > < / s p a n > ) ;
} else if ( me !== account . get ( 'id' ) && account . getIn ( [ 'relationship' , 'domain_blocking' ] ) ) {
info . push ( < span key = 'domain_blocked' className = 'relationship-tag' > < FormattedMessage id = 'account.domain_blocked' defaultMessage = 'Domain hidden' / > < / s p a n > ) ;
}
return info ;
} ;
2020-04-14 14:47:35 -07:00
render ( ) {
2020-06-10 06:30:33 -07:00
const { account , intl , username , me } = this . props ;
2020-03-27 13:59:38 -07:00
const { isSmallScreen } = this . state ;
if ( ! account ) {
return (
< div className = 'account__header' >
2020-04-14 11:44:40 -07:00
< div className = 'account__header__image account__header__image--none' / >
2020-03-27 13:59:38 -07:00
< div className = 'account__header__bar' >
< div className = 'account__header__extra' >
2020-04-14 11:44:40 -07:00
< div className = 'account__header__avatar' / >
2020-03-27 13:59:38 -07:00
< / d i v >
{
isSmallScreen &&
< div className = 'account-mobile-container account-mobile-container--nonuser' >
< ProfileInfoPanel username = { username } / >
< / d i v >
}
< / d i v >
< / d i v >
) ;
}
2021-06-16 12:20:57 -07:00
const self = account . get ( 'id' ) === me ;
2020-03-27 13:59:38 -07:00
const info = this . makeInfo ( ) ;
const menu = this . makeMenu ( ) ;
2020-06-10 06:30:33 -07:00
const headerMissing = ( account . get ( 'header' ) . indexOf ( '/headers/original/missing.png' ) > - 1 ) ;
2020-03-27 13:59:38 -07:00
const avatarSize = isSmallScreen ? 90 : 200 ;
2021-01-18 11:59:24 -08:00
const deactivated = ! account . getIn ( [ 'pleroma' , 'is_active' ] , true ) ;
2020-03-27 13:59:38 -07:00
return (
2020-08-25 11:47:02 -07:00
< div className = { classNames ( 'account__header' , { inactive : ! ! account . get ( 'moved' ) , deactivated : deactivated } ) } >
2020-08-12 11:02:20 -07:00
< div className = { classNames ( 'account__header__image' , { 'account__header__image--none' : headerMissing || deactivated } ) } >
2020-03-27 13:59:38 -07:00
< div className = 'account__header__info' >
{ info }
< / d i v >
2020-06-10 06:30:33 -07:00
< StillImage src = { account . get ( 'header' ) } alt = '' className = 'parallax' / >
2020-03-27 13:59:38 -07:00
< / d i v >
< div className = 'account__header__bar' >
< div className = 'account__header__extra' >
2021-05-01 13:02:27 -07:00
< a className = 'account__header__avatar' href = { account . get ( 'avatar' ) } onClick = { this . handleAvatarClick } target = '_blank' >
2020-08-25 11:47:02 -07:00
< Avatar account = { account } size = { avatarSize } / >
2021-05-01 13:02:27 -07:00
< / a >
2020-03-27 13:59:38 -07:00
2020-08-25 11:47:02 -07:00
< div className = 'account__header__extra__links' >
< NavLink isActive = { this . isStatusesPageActive } activeClassName = 'active' to = { ` /@ ${ account . get ( 'acct' ) } ` } title = { intl . formatNumber ( account . get ( 'statuses_count' ) ) } >
< span > { shortNumberFormat ( account . get ( 'statuses_count' ) ) } < / s p a n >
< span > < FormattedMessage id = 'account.posts' defaultMessage = 'Posts' / > < / s p a n >
< / N a v L i n k >
2021-06-16 12:20:57 -07:00
{ ( self || ! account . getIn ( [ 'pleroma' , 'hide_follows' ] , false ) ) && < NavLink exact activeClassName = 'active' to = { ` /@ ${ account . get ( 'acct' ) } /following ` } title = { intl . formatNumber ( account . get ( 'following_count' ) ) } >
{ account . getIn ( [ 'pleroma' , 'hide_follows_count' ] , false ) ? < span > • < / s p a n > : < s p a n > { s h o r t N u m b e r F o r m a t ( a c c o u n t . g e t ( ' f o l l o w i n g _ c o u n t ' ) ) } < / s p a n > }
2020-08-25 11:47:02 -07:00
< span > < FormattedMessage id = 'account.follows' defaultMessage = 'Follows' / > < / s p a n >
2021-06-16 12:20:57 -07:00
< / N a v L i n k > }
2020-08-25 11:47:02 -07:00
2021-06-16 12:20:57 -07:00
{ ( self || ! account . getIn ( [ 'pleroma' , 'hide_followers' ] , false ) ) && < NavLink exact activeClassName = 'active' to = { ` /@ ${ account . get ( 'acct' ) } /followers ` } title = { intl . formatNumber ( account . get ( 'followers_count' ) ) } >
{ account . getIn ( [ 'pleroma' , 'hide_followers_count' ] , false ) ? < span > • < / s p a n > : < s p a n > { s h o r t N u m b e r F o r m a t ( a c c o u n t . g e t ( ' f o l l o w e r s _ c o u n t ' ) ) } < / s p a n > }
2020-08-25 11:47:02 -07:00
< span > < FormattedMessage id = 'account.followers' defaultMessage = 'Followers' / > < / s p a n >
2021-06-16 12:20:57 -07:00
< / N a v L i n k > }
2020-08-25 11:47:02 -07:00
{
2021-06-16 12:20:57 -07:00
self &&
2020-08-25 11:47:02 -07:00
< div >
< NavLink
exact activeClassName = 'active' to = { ` /@ ${ account . get ( 'acct' ) } /favorites ` }
>
{ /* : TODO : shortNumberFormat(account.get('favourite_count')) */ }
< span > • < / s p a n >
< span > < FormattedMessage id = 'navigation_bar.favourites' defaultMessage = 'Likes' / > < / s p a n >
< / N a v L i n k >
< NavLink
exact activeClassName = 'active' to = { ` /@ ${ account . get ( 'acct' ) } /pins ` }
>
{ /* : TODO : shortNumberFormat(account.get('pinned_count')) */ }
< span > • < / s p a n >
< span > < FormattedMessage id = 'navigation_bar.pins' defaultMessage = 'Pins' / > < / s p a n >
< / N a v L i n k >
< / d i v >
}
< / d i v >
2020-03-27 13:59:38 -07:00
{
isSmallScreen &&
2020-08-12 11:02:20 -07:00
< div className = { classNames ( 'account-mobile-container' , { 'deactivated' : deactivated } ) } >
2020-03-27 13:59:38 -07:00
< ProfileInfoPanel username = { username } account = { account } / >
< / d i v >
}
2020-08-30 19:15:02 -07:00
< div className = 'account__header__extra__buttons' >
< ActionButton account = { account } / >
{ me && account . get ( 'id' ) !== me && account . getIn ( [ 'pleroma' , 'accepts_chat_messages' ] , false ) === true &&
< Button className = 'button-alternative-2' onClick = { this . props . onChat } >
< Icon id = 'comment' / >
< FormattedMessage id = 'account.message' defaultMessage = 'Message' / >
< / B u t t o n >
}
{ me && < DropdownMenuContainer items = { menu } icon = 'ellipsis-v' size = { 24 } direction = 'right' / > }
< / d i v >
2020-03-27 13:59:38 -07:00
< / d i v >
< / d i v >
< / d i v >
) ;
}
}