2023-05-24 00:15:17 +09:00
import { defineMessages , injectIntl } from 'react-intl' ;
2018-10-08 06:44:58 +09:00
import { connect } from 'react-redux' ;
2023-05-24 00:15:17 +09:00
2019-09-22 03:01:16 +09:00
import { replyCompose } from 'mastodon/actions/compose' ;
2023-05-24 00:15:17 +09:00
import { markConversationRead , deleteConversation } from 'mastodon/actions/conversations' ;
2019-09-22 03:01:16 +09:00
import { openModal } from 'mastodon/actions/modal' ;
import { muteStatus , unmuteStatus , hideStatus , revealStatus } from 'mastodon/actions/statuses' ;
2023-05-24 00:15:17 +09:00
import { makeGetStatus } from 'mastodon/selectors' ;
import Conversation from '../components/conversation' ;
2018-10-08 06:44:58 +09:00
2019-09-22 03:01:16 +09:00
const messages = defineMessages ( {
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?' } ,
} ) ;
const mapStateToProps = ( ) => {
const getStatus = makeGetStatus ( ) ;
return ( state , { conversationId } ) => {
const conversation = state . getIn ( [ 'conversations' , 'items' ] ) . find ( x => x . get ( 'id' ) === conversationId ) ;
const lastStatusId = conversation . get ( 'last_status' , null ) ;
2018-10-08 06:44:58 +09:00
2019-09-22 03:01:16 +09:00
return {
accounts : conversation . get ( 'accounts' ) . map ( accountId => state . getIn ( [ 'accounts' , accountId ] , null ) ) ,
unread : conversation . get ( 'unread' ) ,
lastStatus : lastStatusId && getStatus ( state , { id : lastStatusId } ) ,
} ;
2018-10-08 06:44:58 +09:00
} ;
} ;
2019-09-22 03:01:16 +09:00
const mapDispatchToProps = ( dispatch , { intl , conversationId } ) => ( {
markRead ( ) {
dispatch ( markConversationRead ( conversationId ) ) ;
} ,
reply ( status , router ) {
dispatch ( ( _ , getState ) => {
let state = getState ( ) ;
if ( state . getIn ( [ 'compose' , 'text' ] ) . trim ( ) . length !== 0 ) {
2023-05-25 22:42:37 +09:00
dispatch ( openModal ( {
modalType : 'CONFIRM' ,
modalProps : {
message : intl . formatMessage ( messages . replyMessage ) ,
confirm : intl . formatMessage ( messages . replyConfirm ) ,
onConfirm : ( ) => dispatch ( replyCompose ( status , router ) ) ,
} ,
2019-09-22 03:01:16 +09:00
} ) ) ;
} else {
dispatch ( replyCompose ( status , router ) ) ;
}
} ) ;
} ,
delete ( ) {
dispatch ( deleteConversation ( conversationId ) ) ;
} ,
onMute ( 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' ) ) ) ;
}
} ,
2018-10-19 08:47:29 +09:00
} ) ;
2019-09-22 03:01:16 +09:00
export default injectIntl ( connect ( mapStateToProps , mapDispatchToProps ) ( Conversation ) ) ;