2020-01-29 16:53:33 -05:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2019-07-02 03:10:25 -04:00
import {
replyCompose ,
mentionCompose ,
2019-07-30 21:27:49 +03:00
quoteCompose ,
2019-07-02 03:10:25 -04:00
} from '../actions/compose' ;
import {
2020-03-14 13:31:29 -04:00
repost ,
2020-03-04 17:26:01 -05:00
favorite ,
2020-03-14 13:31:29 -04:00
unrepost ,
2020-03-04 17:26:01 -05:00
unfavorite ,
2019-07-02 03:10:25 -04:00
pin ,
unpin ,
} from '../actions/interactions' ;
import { blockAccount } from '../actions/accounts' ;
import {
muteStatus ,
unmuteStatus ,
deleteStatus ,
2019-08-17 14:09:15 +03:00
editStatus ,
2019-07-02 03:10:25 -04:00
hideStatus ,
revealStatus ,
} from '../actions/statuses' ;
import { initMuteModal } from '../actions/mutes' ;
import { initReport } from '../actions/reports' ;
import { openModal } from '../actions/modal' ;
import { boostModal , deleteModal } from '../initial_state' ;
2020-03-14 13:31:29 -04:00
// import { showAlertForError } from '../actions/alerts';
2020-04-07 21:06:59 -04:00
import {
2019-07-17 01:42:26 +03:00
createRemovedAccount ,
2020-04-07 21:06:59 -04:00
groupRemoveStatus ,
2019-07-17 01:42:26 +03:00
} from '../actions/groups' ;
2020-01-29 16:53:33 -05:00
import { makeGetStatus } from '../selectors' ;
import Status from '../components/status' ;
2019-07-02 03:10:25 -04:00
const messages = defineMessages ( {
deleteConfirm : { id : 'confirmations.delete.confirm' , defaultMessage : 'Delete' } ,
deleteMessage : { id : 'confirmations.delete.message' , defaultMessage : 'Are you sure you want to delete this status?' } ,
replyConfirm : { id : 'confirmations.reply.confirm' , defaultMessage : 'Reply' } ,
replyMessage : { id : 'confirmations.reply.message' , defaultMessage : 'Replying now will overwrite the message you are currently composing. Are you sure you want to proceed?' } ,
2019-07-30 21:27:49 +03:00
quoteConfirm : { id : 'confirmations.quote.confirm' , defaultMessage : 'Quote' } ,
quoteMessage : { id : 'confirmations.quote.message' , defaultMessage : 'Quoting now will overwrite the message you are currently composing. Are you sure you want to proceed?' } ,
2019-07-02 03:10:25 -04:00
blockAndReport : { id : 'confirmations.block.block_and_report' , defaultMessage : 'Block & Report' } ,
} ) ;
const makeMapStateToProps = ( ) => {
const getStatus = makeGetStatus ( ) ;
const mapStateToProps = ( state , props ) => ( {
status : getStatus ( state , props ) ,
2020-02-13 19:40:04 -05:00
replies : state . getIn ( [ 'contexts' , 'replies' , props . id ] ) ,
2019-07-02 03:10:25 -04:00
} ) ;
return mapStateToProps ;
} ;
const mapDispatchToProps = ( dispatch , { intl } ) => ( {
onReply ( status , router ) {
dispatch ( ( _ , getState ) => {
2020-04-07 21:06:59 -04:00
const state = getState ( ) ;
2019-07-02 03:10:25 -04:00
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 ) ) ;
}
} ) ;
} ,
2019-07-30 21:27:49 +03:00
onQuote ( status , router ) {
dispatch ( ( _ , getState ) => {
2020-04-07 21:06:59 -04:00
const state = getState ( ) ;
2019-07-30 21:27:49 +03:00
if ( state . getIn ( [ 'compose' , 'text' ] ) . trim ( ) . length !== 0 ) {
dispatch ( openModal ( 'CONFIRM' , {
message : intl . formatMessage ( messages . quoteMessage ) ,
confirm : intl . formatMessage ( messages . quoteConfirm ) ,
onConfirm : ( ) => dispatch ( quoteCompose ( status , router ) ) ,
} ) ) ;
} else {
dispatch ( quoteCompose ( status , router ) ) ;
}
} ) ;
} ,
2020-03-04 17:26:01 -05:00
onModalRepost ( status ) {
2019-07-02 03:10:25 -04:00
if ( status . get ( 'reblogged' ) ) {
2020-03-04 17:26:01 -05:00
dispatch ( unrepost ( status ) ) ;
2019-07-02 03:10:25 -04:00
} else {
2020-03-04 17:26:01 -05:00
dispatch ( repost ( status ) ) ;
2019-07-02 03:10:25 -04:00
}
} ,
2020-03-04 17:26:01 -05:00
onRepost ( status , e ) {
2019-07-02 03:10:25 -04:00
if ( e . shiftKey || ! boostModal ) {
2020-03-04 17:26:01 -05:00
this . onModalRepost ( status ) ;
2019-07-02 03:10:25 -04:00
} else {
2020-03-04 17:26:01 -05:00
dispatch ( openModal ( 'BOOST' , { status , onRepost : this . onModalRepost } ) ) ;
2019-07-02 03:10:25 -04:00
}
} ,
2019-09-17 18:23:51 +03:00
onShowRevisions ( status ) {
dispatch ( openModal ( 'STATUS_REVISION' , { status } ) ) ;
} ,
2020-03-04 17:26:01 -05:00
onFavorite ( status ) {
2020-04-07 21:06:59 -04:00
console . log ( 'onFavorite...' , status )
2019-07-02 03:10:25 -04:00
if ( status . get ( 'favourited' ) ) {
2020-04-07 21:06:59 -04:00
console . log ( 'unfav...' )
2020-03-04 17:26:01 -05:00
dispatch ( unfavorite ( status ) ) ;
2019-07-02 03:10:25 -04:00
} else {
2020-04-07 21:06:59 -04:00
console . log ( 'fav...' )
2020-03-04 17:26:01 -05:00
dispatch ( favorite ( status ) ) ;
2019-07-02 03:10:25 -04:00
}
} ,
onPin ( status ) {
if ( status . get ( 'pinned' ) ) {
dispatch ( unpin ( status ) ) ;
} else {
dispatch ( pin ( status ) ) ;
}
} ,
onEmbed ( status ) {
2020-03-14 13:31:29 -04:00
// dispatch(openModal('EMBED', {
// url: status.get('url'),
// onError: error => dispatch(showAlertForError(error)),
// }));
2019-07-02 03:10:25 -04:00
} ,
2019-08-23 03:58:25 +03:00
onDelete ( status , history ) {
2019-07-02 03:10:25 -04:00
if ( ! deleteModal ) {
2019-08-23 03:58:25 +03:00
dispatch ( deleteStatus ( status . get ( 'id' ) , history ) ) ;
2019-07-02 03:10:25 -04:00
} else {
dispatch ( openModal ( 'CONFIRM' , {
2019-08-23 03:58:25 +03:00
message : intl . formatMessage ( messages . deleteMessage ) ,
confirm : intl . formatMessage ( messages . deleteConfirm ) ,
onConfirm : ( ) => dispatch ( deleteStatus ( status . get ( 'id' ) , history ) ) ,
2019-07-02 03:10:25 -04:00
} ) ) ;
}
} ,
2019-08-17 14:09:15 +03:00
onEdit ( status ) {
dispatch ( editStatus ( status ) ) ;
} ,
2019-07-02 03:10:25 -04:00
onMention ( account , router ) {
dispatch ( mentionCompose ( account , router ) ) ;
} ,
onOpenMedia ( media , index ) {
dispatch ( openModal ( 'MEDIA' , { media , index } ) ) ;
} ,
onOpenVideo ( media , time ) {
dispatch ( openModal ( 'VIDEO' , { media , time } ) ) ;
} ,
onBlock ( status ) {
2020-03-24 00:39:12 -04:00
const account = status . get ( 'account' )
dispatch ( openModal ( 'BLOCK_ACCOUNT' , {
accountId : account . get ( 'id' ) ,
} ) )
2019-07-02 03:10:25 -04:00
} ,
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' ) ) ) ;
}
} ,
onToggleHidden ( status ) {
if ( status . get ( 'hidden' ) ) {
dispatch ( revealStatus ( status . get ( 'id' ) ) ) ;
} else {
dispatch ( hideStatus ( status . get ( 'id' ) ) ) ;
}
} ,
2019-07-17 01:25:23 +03:00
onGroupRemoveAccount ( groupId , accountId ) {
dispatch ( createRemovedAccount ( groupId , accountId ) ) ;
} ,
2019-07-17 01:42:26 +03:00
onGroupRemoveStatus ( groupId , statusId ) {
dispatch ( groupRemoveStatus ( groupId , statusId ) ) ;
} ,
2019-09-18 19:48:37 -04:00
onOpenProUpgradeModal ( ) {
dispatch ( openModal ( 'PRO_UPGRADE' ) ) ;
} ,
2019-07-02 03:10:25 -04:00
} ) ;
export default injectIntl ( connect ( makeMapStateToProps , mapDispatchToProps ) ( Status ) ) ;