Progress on DMs

Progress on DMs
This commit is contained in:
mgabdev
2020-12-19 01:33:33 -05:00
parent 47cd60f851
commit 7ec426e3d8
38 changed files with 447 additions and 197 deletions

View File

@@ -3,12 +3,12 @@ import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { defineMessages, injectIntl } from 'react-intl'
import { closePopover } from '../../actions/popover'
import { changeExpiresAt } from '../../actions/compose'
import { setChatConversationExpiration } from '../../actions/chat_conversations'
import {
EXPIRATION_OPTION_5_MINUTES,
EXPIRATION_OPTION_60_MINUTES,
EXPIRATION_OPTION_1_HOUR,
EXPIRATION_OPTION_6_HOURS,
EXPIRATION_OPTION_24_HOURS,
EXPIRATION_OPTION_1_DAY,
EXPIRATION_OPTION_3_DAYS,
EXPIRATION_OPTION_7_DAYS,
} from '../../constants'
@@ -19,7 +19,7 @@ import Text from '../text'
class ChatConversationExpirationOptionsPopover extends React.PureComponent {
handleOnSetExpiration = (expiresAt) => {
this.props.onChangeExpiresAt(expiresAt)
this.props.onSetChatConversationExpiration(expiresAt)
this.handleOnClosePopover()
}
@@ -29,66 +29,62 @@ class ChatConversationExpirationOptionsPopover extends React.PureComponent {
render() {
const {
chatConversationId,
expiresAtValue,
intl,
isXS,
} = this.props
console.log("expiresAtValue:", expiresAtValue)
if (!chatConversationId) return <div/>
const listItems = [
{
hideArrow: true,
title: 'None',
onClick: () => this.handleOnSetStatusExpiration(null),
onClick: () => this.handleOnSetExpiration(null),
isActive: !expiresAtValue,
},
{
hideArrow: true,
title: intl.formatMessage(messages.minutes, { number: 5 }),
onClick: () => this.handleOnSetStatusExpiration(EXPIRATION_OPTION_5_MINUTES),
onClick: () => this.handleOnSetExpiration(EXPIRATION_OPTION_5_MINUTES),
isActive: expiresAtValue === EXPIRATION_OPTION_5_MINUTES,
},
{
hideArrow: true,
title: intl.formatMessage(messages.minutes, { number: 60 }),
onClick: () => this.handleOnSetStatusExpiration(EXPIRATION_OPTION_60_MINUTES),
isActive: expiresAtValue === EXPIRATION_OPTION_60_MINUTES,
onClick: () => this.handleOnSetExpiration(EXPIRATION_OPTION_1_HOUR),
isActive: expiresAtValue === EXPIRATION_OPTION_1_HOUR,
},
{
hideArrow: true,
title: '6 hours',
title: intl.formatMessage(messages.hours, { number: 6 }),
onClick: () => this.handleOnSetStatusExpiration(EXPIRATION_OPTION_6_HOURS),
onClick: () => this.handleOnSetExpiration(EXPIRATION_OPTION_6_HOURS),
isActive: expiresAtValue === EXPIRATION_OPTION_6_HOURS,
},
{
hideArrow: true,
title: intl.formatMessage(messages.hours, { number: 24 }),
onClick: () => this.handleOnSetStatusExpiration(EXPIRATION_OPTION_24_HOURS),
isActive: expiresAtValue === EXPIRATION_OPTION_24_HOURS,
onClick: () => this.handleOnSetExpiration(EXPIRATION_OPTION_1_DAY),
isActive: expiresAtValue === EXPIRATION_OPTION_1_DAY,
},
{
hideArrow: true,
title: '3 days',
title: intl.formatMessage(messages.days, { number: 3 }),
onClick: () => this.handleOnSetStatusExpiration(EXPIRATION_OPTION_3_DAYS),
onClick: () => this.handleOnSetExpiration(EXPIRATION_OPTION_3_DAYS),
isActive: expiresAtValue === EXPIRATION_OPTION_3_DAYS,
},
{
hideArrow: true,
title: intl.formatMessage(messages.days, { number: 7 }),
onClick: () => this.handleOnSetStatusExpiration(EXPIRATION_OPTION_7_DAYS),
onClick: () => this.handleOnSetExpiration(EXPIRATION_OPTION_7_DAYS),
isActive: expiresAtValue === EXPIRATION_OPTION_7_DAYS,
},
]
if (expiresAtValue) {
listItems.unshift({
hideArrow: true,
title: 'Remove expiration',
onClick: () => this.handleOnSetStatusExpiration(null),
},)
}
return (
<PopoverLayout
width={210}
@@ -113,24 +109,24 @@ const messages = defineMessages({
days: { id: 'intervals.full.days', defaultMessage: '{number, plural, one {# day} other {# days}}' },
})
const mapStateToProps = (state) => ({
expiresAtValue: state.getIn(['compose', 'expires_at']),
const mapStateToProps = (state, { chatConversationId }) => ({
expiresAtValue: state.getIn(['chat_conversations', chatConversationId, 'chat_message_expiration_policy']),
})
const mapDispatchToProps = (dispatch) => ({
onChangeExpiresAt(expiresAt) {
dispatch(changeExpiresAt(expiresAt))
},
const mapDispatchToProps = (dispatch, { chatConversationId }) => ({
onClosePopover() {
dispatch(closePopover())
},
onSetChatConversationExpiration(expiration) {
dispatch(setChatConversationExpiration(chatConversationId, expiration))
},
})
ChatConversationExpirationOptionsPopover.defaultProps = {
expiresAtValue: PropTypes.string.isRequired,
intl: PropTypes.object.isRequired,
isXS: PropTypes.bool,
onChangeExpiresAt: PropTypes.func.isRequired,
onSetChatConversationExpiration: PropTypes.func.isRequired,
}
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ChatConversationExpirationOptionsPopover))

View File

@@ -6,6 +6,10 @@ import { connect } from 'react-redux'
import { closePopover } from '../../actions/popover'
import { openModal } from '../../actions/modal'
import { hideChatConversation } from '../../actions/chat_conversations'
import {
muteChatConversation,
unmuteChatConversation,
} from '../../actions/chat_conversation_accounts'
import { purgeChatMessages } from '../../actions/chat_messages'
import { MODAL_PRO_UPGRADE } from '../../constants'
import { me } from '../../initial_state'
@@ -21,8 +25,12 @@ class ChatConversationOptionsPopover extends ImmutablePureComponent {
this.handleOnClosePopover()
}
handleOnUnmute = () => {
this.props.onUnute()
handleOnMute = () => {
if (this.props.isMuted) {
this.props.onUnmute()
} else {
this.props.onMute()
}
this.handleOnClosePopover()
}
@@ -30,7 +38,7 @@ class ChatConversationOptionsPopover extends ImmutablePureComponent {
if (!this.props.isPro) {
this.props.openProUpgradeModal()
} else {
this.props.onPurge(this.props.chatConversationId)
this.props.onPurge()
}
this.handleOnClosePopover()
@@ -44,6 +52,7 @@ class ChatConversationOptionsPopover extends ImmutablePureComponent {
const {
intl,
isXS,
isMuted,
} = this.props
const items = [
@@ -55,9 +64,9 @@ class ChatConversationOptionsPopover extends ImmutablePureComponent {
},
{
hideArrow: true,
title: 'Mute Conversation',
subtitle: "Don't get notified of new messages",
onClick: () => this.handleOnHide(),
title: isMuted ? 'Unmute Conversation' : 'Mute Conversation',
subtitle: isMuted ? null : "Don't get notified of new messages",
onClick: () => this.handleOnMute(),
},
{},
{
@@ -86,23 +95,28 @@ class ChatConversationOptionsPopover extends ImmutablePureComponent {
const mapStateToProps = (state, { chatConversationId }) => ({
isPro: state.getIn(['accounts', me, 'is_pro']),
chatConversation: makeGetChatConversation()(state, { id: chatConversationId }),
isMuted: state.getIn(['chat_conversations', chatConversationId, 'is_muted']),
})
const mapDispatchToProps = (dispatch) => ({
const mapDispatchToProps = (dispatch, { chatConversationId }) => ({
openProUpgradeModal() {
dispatch(openModal(MODAL_PRO_UPGRADE))
},
onSetCommentSortingSetting(type) {
dispatch(closePopover())
},
onPurge(chatConversationId) {
onPurge() {
dispatch(purgeChatMessages(chatConversationId))
},
onHide(chatConversationId) {
onHide() {
dispatch(hideChatConversation(chatConversationId))
},
onClosePopover: () => dispatch(closePopover()),
onMute() {
dispatch(muteChatConversation(chatConversationId))
},
onUnmute() {
dispatch(unmuteChatConversation(chatConversationId))
},
onClosePopover() {
dispatch(closePopover())
},
})
ChatConversationOptionsPopover.propTypes = {

View File

@@ -4,11 +4,11 @@ import { connect } from 'react-redux'
import { closePopover } from '../../actions/popover'
import { deleteChatMessage } from '../../actions/chat_messages'
import {
fetchMessengerBlockingRelationships,
blockChatMessenger,
unblockChatMessenger,
reportChatMessage,
// reportChatMessage,
} from '../../actions/chat_conversation_accounts'
import { fetchRelationships } from '../../actions/accounts'
import { makeGetChatMessage } from '../../selectors'
import { me } from '../../initial_state'
import PopoverLayout from './popover_layout'
@@ -20,7 +20,7 @@ class ChatMessageOptionsPopover extends React.PureComponent {
componentDidMount() {
if (!this.props.isMine) {
this.props.onFetchRelationships(this.props.fromAccountId)
this.props.onFetchMessengerBlockingRelationships(this.props.fromAccountId)
}
}
@@ -33,7 +33,7 @@ class ChatMessageOptionsPopover extends React.PureComponent {
}
handleOnBlock = () => {
if (this.props.isBlocked) {
if (this.props.isChatBlocked) {
this.props.onUnblock(this.props.fromAccountId)
} else {
this.props.onBlock(this.props.fromAccountId)
@@ -48,7 +48,7 @@ class ChatMessageOptionsPopover extends React.PureComponent {
const {
isXS,
isMine,
isBlocked,
isChatBlocked,
} = this.props
const items = isMine ? [
@@ -66,8 +66,8 @@ class ChatMessageOptionsPopover extends React.PureComponent {
{},
{
hideArrow: true,
title: isBlocked ? 'Unblock Messenger' : 'Block Messenger',
subtitle: isBlocked ? '' : 'The messenger will not be able to message you.',
title: isChatBlocked ? 'Unblock Messenger' : 'Block Messenger',
subtitle: isChatBlocked ? null : 'The messenger will not be able to message you.',
onClick: () => this.handleOnBlock(),
},
]
@@ -90,7 +90,7 @@ const mapStateToProps = (state, { chatMessageId }) => {
return {
fromAccountId,
isMine: fromAccountId === me,
isBlocked: state.getIn(['relationships', fromAccountId, 'chat_blocked_by'], false),
isChatBlocked: state.getIn(['relationships', fromAccountId, 'chat_blocking'], false),
}
}
@@ -101,15 +101,19 @@ const mapDispatchToProps = (dispatch) => ({
},
onBlock(accountId) {
dispatch(blockChatMessenger(accountId))
dispatch(closePopover())
},
onUnblock(accountId) {
dispatch(unblockChatMessenger(accountId))
dispatch(closePopover())
},
onReportChatMessage(chatMessageId) {
dispatch(reportChatMessage(chatMessageId))
// : todo :
// dispatch(reportChatMessage(chatMessageId))
dispatch(closePopover())
},
onFetchRelationships(accountId) {
// dispatch(fetchRelationships(accountId))
onFetchMessengerBlockingRelationships(accountId) {
dispatch(fetchMessengerBlockingRelationships(accountId))
},
onClosePopover() {
dispatch(closePopover())
@@ -120,8 +124,9 @@ ChatMessageOptionsPopover.propTypes = {
isXS: PropTypes.bool,
isMine: PropTypes.bool,
chatMessageId: PropTypes.string.isRequired,
isBlocked: PropTypes.bool.isRequired,
isChatBlocked: PropTypes.bool.isRequired,
onDeleteChatMessage: PropTypes.func.isRequired,
onIsChatMessengerBlocked: PropTypes.func.isRequired,
}
export default connect(mapStateToProps, mapDispatchToProps)(ChatMessageOptionsPopover)

View File

@@ -6,9 +6,9 @@ import { closePopover } from '../../actions/popover'
import { changeExpiresAt } from '../../actions/compose'
import {
EXPIRATION_OPTION_5_MINUTES,
EXPIRATION_OPTION_60_MINUTES,
EXPIRATION_OPTION_1_HOUR,
EXPIRATION_OPTION_6_HOURS,
EXPIRATION_OPTION_24_HOURS,
EXPIRATION_OPTION_1_DAY,
EXPIRATION_OPTION_3_DAYS,
EXPIRATION_OPTION_7_DAYS,
} from '../../constants'
@@ -50,8 +50,8 @@ class StatusExpirationOptionsPopover extends React.PureComponent {
{
hideArrow: true,
title: intl.formatMessage(messages.minutes, { number: 60 }),
onClick: () => this.handleOnSetStatusExpiration(EXPIRATION_OPTION_60_MINUTES),
isActive: expiresAtValue === EXPIRATION_OPTION_60_MINUTES,
onClick: () => this.handleOnSetStatusExpiration(EXPIRATION_OPTION_1_HOUR),
isActive: expiresAtValue === EXPIRATION_OPTION_1_HOUR,
},
{
hideArrow: true,
@@ -63,8 +63,8 @@ class StatusExpirationOptionsPopover extends React.PureComponent {
{
hideArrow: true,
title: intl.formatMessage(messages.hours, { number: 24 }),
onClick: () => this.handleOnSetStatusExpiration(EXPIRATION_OPTION_24_HOURS),
isActive: expiresAtValue === EXPIRATION_OPTION_24_HOURS,
onClick: () => this.handleOnSetStatusExpiration(EXPIRATION_OPTION_1_DAY),
isActive: expiresAtValue === EXPIRATION_OPTION_1_DAY,
},
{
hideArrow: true,