2020-08-17 21:07:16 +01:00
import React from 'react'
2020-08-17 21:59:29 +01:00
import PropTypes from 'prop-types'
2020-08-17 21:39:25 +01:00
import { connect } from 'react-redux'
2020-03-25 03:08:43 +00:00
import { defineMessages , injectIntl } from 'react-intl'
2020-03-14 17:31:29 +00:00
import {
followAccount ,
unfollowAccount ,
unblockAccount ,
unmuteAccount ,
} from '../../actions/accounts'
import {
mentionCompose ,
} from '../../actions/compose'
2020-07-22 04:24:26 +01:00
import {
addShortcut ,
removeShortcut ,
} from '../../actions/shortcuts'
2020-03-14 17:31:29 +00:00
import { initReport } from '../../actions/reports'
import { openModal } from '../../actions/modal'
2020-12-24 18:27:55 +00:00
import {
openPopover ,
closePopover ,
} from '../../actions/popover'
import { POPOVER _SHARE } from '../../constants'
2020-07-22 04:24:26 +01:00
import { unfollowModal , me , isStaff } from '../../initial_state'
2020-03-14 17:31:29 +00:00
import { makeGetAccount } from '../../selectors'
2020-02-28 15:20:47 +00:00
import PopoverLayout from './popover_layout'
2020-03-14 17:31:29 +00:00
import List from '../list'
2020-08-17 21:07:16 +01:00
class ProfileOptionsPopover extends React . PureComponent {
2020-03-14 17:31:29 +00:00
makeMenu ( ) {
2020-07-22 04:24:26 +01:00
const {
account ,
intl ,
isShortcut ,
} = this . props ;
2020-03-14 17:31:29 +00:00
let menu = [ ] ;
2020-03-24 04:39:12 +00:00
if ( ! account ) return menu
if ( account . get ( 'id' ) === me ) return menu
2020-03-14 17:31:29 +00:00
2020-12-24 18:27:55 +00:00
menu . push ( {
hideArrow : true ,
icon : 'share' ,
title : intl . formatMessage ( messages . share , { name : account . get ( 'username' ) } ) ,
onClick : this . handleShare
} ) ;
2020-03-14 17:31:29 +00:00
2020-03-24 04:39:12 +00:00
menu . push ( {
hideArrow : true ,
icon : 'comment' ,
title : intl . formatMessage ( messages . mention , { name : account . get ( 'acct' ) } ) ,
onClick : this . handleOnMention
} ) ;
if ( account . getIn ( [ 'relationship' , 'following' ] ) ) {
const showingReblogs = account . getIn ( [ 'relationship' , 'showing_reblogs' ] )
menu . push ( {
hideArrow : true ,
icon : 'repost' ,
title : intl . formatMessage ( showingReblogs ? messages . hideReposts : messages . showReposts , {
name : account . get ( 'username' )
} ) ,
onClick : this . handleRepostToggle ,
} )
2020-03-14 17:31:29 +00:00
}
2020-03-24 04:39:12 +00:00
const isMuting = account . getIn ( [ 'relationship' , 'muting' ] )
menu . push ( {
hideArrow : true ,
icon : 'audio-mute' ,
title : intl . formatMessage ( isMuting ? messages . unmute : messages . mute , {
name : account . get ( 'username' )
} ) ,
onClick : this . handleMute ,
} )
const isBlocking = account . getIn ( [ 'relationship' , 'blocking' ] )
menu . push ( {
hideArrow : true ,
icon : 'block' ,
title : intl . formatMessage ( isBlocking ? messages . unblock : messages . block , {
name : account . get ( 'username' )
} ) ,
onClick : this . handleBlock
} )
menu . push ( {
hideArrow : true ,
icon : 'report' ,
title : intl . formatMessage ( messages . report , { name : account . get ( 'username' ) } ) ,
onClick : this . handleReport
} )
2020-06-16 04:34:44 +01:00
// menu.push({
// hideArrow: true,
// icon: 'list',
// title: intl.formatMessage(messages.add_to_list),
// onClick: this.handleAddToList
// })
2020-03-24 04:39:12 +00:00
2020-07-22 04:24:26 +01:00
menu . push ( {
hideArrow : true ,
icon : 'star' ,
title : intl . formatMessage ( isShortcut ? messages . remove _from _shortcuts : messages . add _to _shortcuts ) ,
onClick : this . handleToggleShortcuts ,
} )
2020-03-24 04:39:12 +00:00
if ( isStaff ) {
menu . push ( {
hideArrow : true ,
icon : 'circle' ,
title : intl . formatMessage ( messages . admin _account ) ,
2021-02-11 05:23:20 +00:00
href : ` /admin/accounts/ ${ account . get ( 'id' ) } ` ,
openInNewTab : true ,
2020-03-24 04:39:12 +00:00
} )
2020-03-14 17:31:29 +00:00
}
2020-03-24 04:39:12 +00:00
return menu
2020-03-14 17:31:29 +00:00
}
2020-03-24 04:39:12 +00:00
handleShare = ( ) => {
2020-12-24 18:27:55 +00:00
this . props . onShare ( this . props . account )
2020-03-24 04:39:12 +00:00
}
handleFollow = ( ) => {
this . props . onFollow ( this . props . account ) ;
}
handleBlock = ( ) => {
this . props . onBlock ( this . props . account ) ;
}
handleOnMention = ( ) => {
this . props . onMention ( this . props . account ) ;
}
handleReport = ( ) => {
this . props . onReport ( this . props . account ) ;
}
handleRepostToggle = ( ) => {
this . props . onRepostToggle ( this . props . account ) ;
}
handleMute = ( ) => {
this . props . onMute ( this . props . account ) ;
}
handleAddToList = ( ) => {
this . props . onAddToList ( this . props . account ) ;
}
2020-07-22 04:24:26 +01:00
handleToggleShortcuts = ( ) => {
if ( this . props . isShortcut ) {
this . props . onRemoveShortcut ( this . props . account . get ( 'id' ) )
} else {
this . props . onAddShortcut ( this . props . account . get ( 'id' ) )
}
2020-03-24 04:39:12 +00:00
}
2020-02-28 15:20:47 +00:00
2020-07-06 21:13:44 +01:00
handleOnClosePopover = ( ) => {
this . props . onClosePopover ( )
}
2020-02-28 15:20:47 +00:00
render ( ) {
2020-05-13 01:36:54 +01:00
const { isXS } = this . props
2020-03-14 17:31:29 +00:00
const listItems = this . makeMenu ( )
2020-02-28 15:20:47 +00:00
return (
2020-07-06 21:13:44 +01:00
< PopoverLayout
width = { 250 }
isXS = { isXS }
onClose = { this . handleOnClosePopover }
>
2020-03-14 17:31:29 +00:00
< List
scrollKey = 'profile_options'
items = { listItems }
2020-07-25 00:54:44 +01:00
size = { isXS ? 'large' : 'small' }
2020-03-14 17:31:29 +00:00
/ >
2020-02-28 15:20:47 +00:00
< / P o p o v e r L a y o u t >
)
}
2020-08-19 01:22:15 +01:00
}
const messages = defineMessages ( {
blockAndReport : { id : 'confirmations.block.block_and_report' , defaultMessage : 'Block & Report' } ,
unfollow : { id : 'account.unfollow' , defaultMessage : 'Unfollow' } ,
follow : { id : 'account.follow' , defaultMessage : 'Follow' } ,
requested : { id : 'account.requested' , defaultMessage : 'Awaiting approval. Click to cancel follow request' } ,
unblock : { id : 'account.unblock' , defaultMessage : 'Unblock @{name}' } ,
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' } ,
unmute : { id : 'account.unmute' , defaultMessage : 'Unmute @{name}' } ,
block : { id : 'account.block' , defaultMessage : 'Block @{name}' } ,
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' } ,
hideReposts : { id : 'account.hide_reblogs' , defaultMessage : 'Hide reposts from @{name}' } ,
showReposts : { id : 'account.show_reblogs' , defaultMessage : 'Show reposts from @{name}' } ,
preferences : { id : 'navigation_bar.preferences' , defaultMessage : 'Preferences' } ,
blocks : { id : 'navigation_bar.blocks' , defaultMessage : 'Blocked users' } ,
mutes : { id : 'navigation_bar.mutes' , defaultMessage : 'Muted users' } ,
admin _account : { id : 'admin_account' , defaultMessage : 'Open moderation interface' } ,
add _to _list : { id : 'lists.account.add' , defaultMessage : 'Add to list' } ,
add _to _shortcuts : { id : 'account.add_to_shortcuts' , defaultMessage : 'Add to shortcuts' } ,
remove _from _shortcuts : { id : 'account.remove_from_shortcuts' , defaultMessage : 'Remove from shortcuts' } ,
accountBlocked : { id : 'account.blocked' , defaultMessage : 'Blocked' } ,
accountMuted : { id : 'account.muted' , defaultMessage : 'Muted' } ,
} ) ;
const mapStateToProps = ( state , { account } ) => {
const getAccount = makeGetAccount ( )
const accountId = ! ! account ? account . get ( 'id' ) : - 1
const shortcuts = state . getIn ( [ 'shortcuts' , 'items' ] )
const isShortcut = ! ! shortcuts . find ( ( s ) => {
return s . get ( 'shortcut_id' ) == accountId && s . get ( 'shortcut_type' ) === 'account'
} )
return {
isShortcut ,
account : getAccount ( state , accountId ) ,
}
}
2020-12-24 18:27:55 +00:00
const mapDispatchToProps = ( dispatch , { intl , innerRef } ) => ( {
2020-08-19 01:22:15 +01:00
onFollow ( account ) {
if ( account . getIn ( [ 'relationship' , 'following' ] ) || account . getIn ( [ 'relationship' , 'requested' ] ) ) {
if ( unfollowModal ) {
dispatch ( openModal ( 'UNFOLLOW' , {
account ,
} ) )
} else {
dispatch ( unfollowAccount ( account . get ( 'id' ) ) )
}
} else {
dispatch ( followAccount ( account . get ( 'id' ) ) )
}
} ,
onBlock ( account ) {
dispatch ( closePopover ( ) )
if ( account . getIn ( [ 'relationship' , 'blocking' ] ) ) {
dispatch ( unblockAccount ( account . get ( 'id' ) ) ) ;
} else {
dispatch ( openModal ( 'BLOCK_ACCOUNT' , {
accountId : account . get ( 'id' ) ,
} ) ) ;
}
} ,
onMention ( account ) {
dispatch ( closePopover ( ) )
dispatch ( mentionCompose ( account ) ) ;
} ,
onRepostToggle ( account ) {
dispatch ( closePopover ( ) )
if ( account . getIn ( [ 'relationship' , 'showing_reblogs' ] ) ) {
dispatch ( followAccount ( account . get ( 'id' ) , false ) ) ;
} else {
dispatch ( followAccount ( account . get ( 'id' ) , true ) ) ;
}
} ,
onReport ( account ) {
dispatch ( closePopover ( ) )
dispatch ( initReport ( account ) ) ;
} ,
onMute ( account ) {
dispatch ( closePopover ( ) )
if ( account . getIn ( [ 'relationship' , 'muting' ] ) ) {
dispatch ( unmuteAccount ( account . get ( 'id' ) ) ) ;
} else {
dispatch ( openModal ( 'MUTE' , {
accountId : account . get ( 'id' ) ,
} ) )
}
} ,
onAddToList ( account ) {
dispatch ( closePopover ( ) )
dispatch ( openModal ( 'LIST_ADD_USER' , {
accountId : account . get ( 'id' ) ,
} ) ) ;
} ,
onClosePopover : ( ) => dispatch ( closePopover ( ) ) ,
onAddShortcut ( accountId ) {
dispatch ( closePopover ( ) )
dispatch ( addShortcut ( 'account' , accountId ) )
} ,
onRemoveShortcut ( accountId ) {
dispatch ( closePopover ( ) )
dispatch ( removeShortcut ( null , 'account' , accountId ) )
} ,
2020-12-24 18:27:55 +00:00
onShare ( account ) {
dispatch ( openPopover ( POPOVER _SHARE , {
innerRef ,
account ,
position : 'top' ,
} ) )
} ,
2020-08-19 01:22:15 +01:00
} )
ProfileOptionsPopover . defaultProps = {
isXS : PropTypes . bool ,
isShortcut : PropTypes . bool ,
}
export default injectIntl ( connect ( mapStateToProps , mapDispatchToProps ) ( ProfileOptionsPopover ) )