2020-03-27 13:59:38 -07:00
import React from 'react' ;
2022-01-10 14:01:24 -08:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2022-01-10 14:17:52 -08:00
import { connect } from 'react-redux' ;
2022-01-10 14:25:06 -08:00
2022-01-10 14:01:24 -08:00
import { launchChat } from 'soapbox/actions/chats' ;
2022-01-10 14:17:52 -08:00
import { deactivateUserModal , deleteUserModal , deleteStatusModal , toggleStatusSensitivityModal } from 'soapbox/actions/moderation' ;
import { getSoapboxConfig } from 'soapbox/actions/soapbox' ;
2022-01-10 14:25:06 -08:00
2022-01-10 14:17:52 -08:00
import { blockAccount } from '../actions/accounts' ;
import { showAlertForError } from '../actions/alerts' ;
2020-03-27 13:59:38 -07:00
import {
replyCompose ,
mentionCompose ,
directCompose ,
} from '../actions/compose' ;
2022-01-10 14:17:52 -08:00
import {
createRemovedAccount ,
groupRemoveStatus ,
} from '../actions/groups' ;
2020-03-27 13:59:38 -07:00
import {
reblog ,
favourite ,
unreblog ,
unfavourite ,
2020-07-29 14:08:36 -07:00
bookmark ,
unbookmark ,
2020-03-27 13:59:38 -07:00
pin ,
unpin ,
} from '../actions/interactions' ;
2022-01-10 14:17:52 -08:00
import { openModal } from '../actions/modal' ;
import { initMuteModal } from '../actions/mutes' ;
import { initReport } from '../actions/reports' ;
import { getSettings } from '../actions/settings' ;
2020-03-27 13:59:38 -07:00
import {
muteStatus ,
unmuteStatus ,
deleteStatus ,
hideStatus ,
revealStatus ,
} from '../actions/statuses' ;
2022-01-10 14:17:52 -08:00
import Status from '../components/status' ;
import { makeGetStatus } from '../selectors' ;
2020-03-27 13:59:38 -07:00
const messages = defineMessages ( {
deleteConfirm : { id : 'confirmations.delete.confirm' , defaultMessage : 'Delete' } ,
2022-01-06 07:51:34 -08:00
deleteHeading : { id : 'confirmations.delete.heading' , defaultMessage : 'Delete post' } ,
2020-03-27 13:59:38 -07:00
deleteMessage : { id : 'confirmations.delete.message' , defaultMessage : 'Are you sure you want to delete this post?' } ,
redraftConfirm : { id : 'confirmations.redraft.confirm' , defaultMessage : 'Delete & redraft' } ,
redraftMessage : { id : 'confirmations.redraft.message' , defaultMessage : 'Are you sure you want to delete this post and re-draft it? Favorites and reposts will be lost, and replies to the original post will be orphaned.' } ,
blockConfirm : { id : 'confirmations.block.confirm' , defaultMessage : 'Block' } ,
replyConfirm : { id : 'confirmations.reply.confirm' , defaultMessage : 'Reply' } ,
2022-01-03 09:52:22 -08:00
redraftHeading : { id : 'confirmations.redraft.heading' , defaultMessage : 'Delete & redraft' } ,
2020-03-27 13:59:38 -07:00
replyMessage : { id : 'confirmations.reply.message' , defaultMessage : 'Replying now will overwrite the message you are currently composing. Are you sure you want to proceed?' } ,
blockAndReport : { id : 'confirmations.block.block_and_report' , defaultMessage : 'Block & Report' } ,
} ) ;
const makeMapStateToProps = ( ) => {
const getStatus = makeGetStatus ( ) ;
2021-06-30 19:39:27 -07:00
const mapStateToProps = ( state , props ) => {
const soapbox = getSoapboxConfig ( state ) ;
return {
status : getStatus ( state , props ) ,
displayMedia : getSettings ( state ) . get ( 'displayMedia' ) ,
allowedEmoji : soapbox . get ( 'allowedEmoji' ) ,
} ;
} ;
2020-03-27 13:59:38 -07:00
return mapStateToProps ;
} ;
2022-01-03 08:27:31 -08:00
const mapDispatchToProps = ( dispatch , { intl } ) => {
function onModalReblog ( status ) {
2020-03-27 13:59:38 -07:00
if ( status . get ( 'reblogged' ) ) {
dispatch ( unreblog ( status ) ) ;
} else {
dispatch ( reblog ( status ) ) ;
}
2022-01-03 08:27:31 -08:00
}
return {
onReply ( status , router ) {
dispatch ( ( _ , getState ) => {
const state = getState ( ) ;
if ( state . getIn ( [ 'compose' , 'text' ] ) . trim ( ) . length !== 0 ) {
dispatch ( openModal ( 'CONFIRM' , {
message : intl . formatMessage ( messages . replyMessage ) ,
confirm : intl . formatMessage ( messages . replyConfirm ) ,
onConfirm : ( ) => dispatch ( replyCompose ( status , router ) ) ,
} ) ) ;
} else {
dispatch ( replyCompose ( status , router ) ) ;
}
} ) ;
} ,
onModalReblog ,
onReblog ( status , e ) {
dispatch ( ( _ , getState ) => {
const boostModal = getSettings ( getState ( ) ) . get ( 'boostModal' ) ;
if ( e . shiftKey || ! boostModal ) {
2022-01-03 14:30:29 -08:00
onModalReblog ( status ) ;
2022-01-03 08:27:31 -08:00
} else {
dispatch ( openModal ( 'BOOST' , { status , onReblog : onModalReblog } ) ) ;
}
} ) ;
} ,
onFavourite ( status ) {
if ( status . get ( 'favourited' ) ) {
dispatch ( unfavourite ( status ) ) ;
2020-04-21 12:41:13 -07:00
} else {
2022-01-03 08:27:31 -08:00
dispatch ( favourite ( status ) ) ;
2020-04-21 12:41:13 -07:00
}
2022-01-03 08:27:31 -08:00
} ,
2020-03-27 13:59:38 -07:00
2022-01-03 08:27:31 -08:00
onBookmark ( status ) {
if ( status . get ( 'bookmarked' ) ) {
dispatch ( unbookmark ( intl , status ) ) ;
2020-04-21 12:41:13 -07:00
} else {
2022-01-03 08:27:31 -08:00
dispatch ( bookmark ( intl , status ) ) ;
2020-04-21 12:41:13 -07:00
}
2022-01-03 08:27:31 -08:00
} ,
2020-03-27 13:59:38 -07:00
2022-01-03 08:27:31 -08:00
onPin ( status ) {
if ( status . get ( 'pinned' ) ) {
dispatch ( unpin ( status ) ) ;
} else {
dispatch ( pin ( status ) ) ;
}
} ,
onEmbed ( status ) {
dispatch ( openModal ( 'EMBED' , {
url : status . get ( 'url' ) ,
onError : error => dispatch ( showAlertForError ( error ) ) ,
} ) ) ;
} ,
onDelete ( status , history , withRedraft = false ) {
dispatch ( ( _ , getState ) => {
const deleteModal = getSettings ( getState ( ) ) . get ( 'deleteModal' ) ;
if ( ! deleteModal ) {
dispatch ( deleteStatus ( status . get ( 'id' ) , history , withRedraft ) ) ;
} else {
dispatch ( openModal ( 'CONFIRM' , {
2022-01-03 09:52:22 -08:00
icon : withRedraft ? require ( '@tabler/icons/icons/edit.svg' ) : require ( '@tabler/icons/icons/trash.svg' ) ,
2022-01-08 04:13:19 -08:00
heading : intl . formatMessage ( withRedraft ? messages . redraftHeading : messages . deleteHeading ) ,
2022-01-03 08:27:31 -08:00
message : intl . formatMessage ( withRedraft ? messages . redraftMessage : messages . deleteMessage ) ,
confirm : intl . formatMessage ( withRedraft ? messages . redraftConfirm : messages . deleteConfirm ) ,
onConfirm : ( ) => dispatch ( deleteStatus ( status . get ( 'id' ) , history , withRedraft ) ) ,
} ) ) ;
}
} ) ;
} ,
onDirect ( account , router ) {
dispatch ( directCompose ( account , router ) ) ;
} ,
onChat ( account , router ) {
dispatch ( launchChat ( account . get ( 'id' ) , router ) ) ;
} ,
onMention ( account , router ) {
dispatch ( mentionCompose ( account , router ) ) ;
} ,
onOpenMedia ( media , index ) {
dispatch ( openModal ( 'MEDIA' , { media , index } ) ) ;
} ,
onOpenVideo ( media , time ) {
dispatch ( openModal ( 'VIDEO' , { media , time } ) ) ;
} ,
onOpenAudio ( media , time ) {
dispatch ( openModal ( 'AUDIO' , { media , time } ) ) ;
} ,
onBlock ( status ) {
const account = status . get ( 'account' ) ;
dispatch ( openModal ( 'CONFIRM' , {
2022-01-03 09:52:22 -08:00
icon : require ( '@tabler/icons/icons/ban.svg' ) ,
2022-01-10 14:01:24 -08:00
heading : < FormattedMessage id = 'confirmations.block.heading' defaultMessage = 'Block @{name}' values = { { name : account . get ( 'acct' ) } } / > ,
2022-01-03 08:27:31 -08:00
message : < FormattedMessage id = 'confirmations.block.message' defaultMessage = 'Are you sure you want to block {name}?' values = { { name : < strong > @ { account . get ( 'acct' ) } < /strong> }} / > ,
confirm : intl . formatMessage ( messages . blockConfirm ) ,
onConfirm : ( ) => dispatch ( blockAccount ( account . get ( 'id' ) ) ) ,
secondary : intl . formatMessage ( messages . blockAndReport ) ,
onSecondary : ( ) => {
dispatch ( blockAccount ( account . get ( 'id' ) ) ) ;
dispatch ( initReport ( account , status ) ) ;
} ,
} ) ) ;
} ,
onReport ( status ) {
dispatch ( initReport ( status . get ( 'account' ) , status ) ) ;
} ,
onMute ( account ) {
dispatch ( initMuteModal ( account ) ) ;
} ,
onMuteConversation ( status ) {
if ( status . get ( 'muted' ) ) {
dispatch ( unmuteStatus ( status . get ( 'id' ) ) ) ;
} else {
dispatch ( muteStatus ( status . get ( 'id' ) ) ) ;
}
} ,
2020-03-27 13:59:38 -07:00
2022-01-03 08:27:31 -08:00
onToggleHidden ( status ) {
if ( status . get ( 'hidden' ) ) {
dispatch ( revealStatus ( status . get ( 'id' ) ) ) ;
} else {
dispatch ( hideStatus ( status . get ( 'id' ) ) ) ;
}
} ,
2020-03-27 13:59:38 -07:00
2022-01-03 08:27:31 -08:00
onGroupRemoveAccount ( groupId , accountId ) {
dispatch ( createRemovedAccount ( groupId , accountId ) ) ;
} ,
2020-03-27 13:59:38 -07:00
2022-01-03 08:27:31 -08:00
onGroupRemoveStatus ( groupId , statusId ) {
dispatch ( groupRemoveStatus ( groupId , statusId ) ) ;
} ,
2021-01-18 13:27:35 -08:00
2022-01-03 08:27:31 -08:00
onDeactivateUser ( status ) {
dispatch ( deactivateUserModal ( intl , status . getIn ( [ 'account' , 'id' ] ) ) ) ;
} ,
2021-01-18 13:27:35 -08:00
2022-01-03 08:27:31 -08:00
onDeleteUser ( status ) {
dispatch ( deleteUserModal ( intl , status . getIn ( [ 'account' , 'id' ] ) ) ) ;
} ,
2021-01-18 13:57:20 -08:00
2022-01-03 08:27:31 -08:00
onDeleteStatus ( status ) {
dispatch ( deleteStatusModal ( intl , status . get ( 'id' ) ) ) ;
} ,
2021-01-18 18:59:07 -08:00
2022-01-03 08:27:31 -08:00
onToggleStatusSensitivity ( status ) {
dispatch ( toggleStatusSensitivityModal ( intl , status . get ( 'id' ) , status . get ( 'sensitive' ) ) ) ;
} ,
} ;
} ;
2020-03-27 13:59:38 -07:00
2021-10-06 12:39:39 -07:00
export default injectIntl ( connect ( makeMapStateToProps , mapDispatchToProps ) ( Status ) ) ;