diff --git a/app/components/DeleteHistoryModal.js b/app/components/DeleteHistoryModal.js index 5b7d6f2..03b5ce4 100644 --- a/app/components/DeleteHistoryModal.js +++ b/app/components/DeleteHistoryModal.js @@ -1,224 +1,230 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import autoBind from 'auto-bind'; import { View, Platform } from 'react-native'; import UserIcon from './UserIcon'; import { Chip, Dialog, Portal, Text, Button, Surface, TextInput, Paragraph, RadioButton, Checkbox, Switch } from 'react-native-paper'; import KeyboardAwareDialog from './KeyBoardAwareDialog'; const DialogType = Platform.OS === 'ios' ? KeyboardAwareDialog : Dialog; import styles from '../assets/styles/blink/_DeleteHistoryModal.scss'; class DeleteHistoryModal extends Component { constructor(props) { super(props); autoBind(this); this.state = { displayName: this.props.displayName, show: this.props.show, uri: this.props.uri, + username: this.props.uri && this.props.uri ? this.props.uri.split('@')[0] : null, period: "0", remoteDelete: false, deleteContact: false, confirm: false, hasMessages: this.props.hasMessages, filteredMessageIds: this.props.filteredMessageIds } } UNSAFE_componentWillReceiveProps(nextProps) { this.setState({show: nextProps.show, displayName: nextProps.displayName, + username: nextProps.uri && nextProps.uri ? nextProps.uri.split('@')[0] : null, uri: nextProps.uri, deleteContact: nextProps.deleteContact, confirm: nextProps.confirm, hasMessages: nextProps.hasMessages, filteredMessageIds: nextProps.filteredMessageIds }); } deleteMessages(event) { event.preventDefault(); if (this.state.confirm) { this.setState({confirm: false, remoteDelete: false, deleteContact:false}); this.props.deleteMessages(this.state.uri, this.state.remoteDelete); if (this.state.deleteContact) { this.props.deleteContactFunc(this.state.uri); } this.props.close(); } else { this.setState({confirm: true}); } } toggleDeleteContact() { this.setState({deleteContact: !this.state.deleteContact}); } setPeriod(value) { this.setState({period: value}); } toggleRemoteDelete() { this.setState({remoteDelete: !this.state.remoteDelete}) } render() { let identity = {uri: this.state.uri, displayName: this.state.displayName}; let canDeleteRemote = this.state.uri && this.state.uri.indexOf('@videoconference') === -1; let canDeleteByTime = false; let deleteLabel = this.state.confirm ? 'Confirm': 'Delete'; + let remote_label = (this.state.displayName && this.state.displayName !== this.state.uri) ? this.state.displayName : this.state.username; let what = 'all messages'; if (this.state.filteredMessageIds.length > 0) { - what = 'the selected messages'; + what = this.state.filteredMessageIds.length + ' selected messages'; } if (this.state.hasMessages || !this.state.uri) { return ( { this.state.uri ? : null} {this.state.uri ? 'Delete messages' : 'Wipe device'} { this.state.uri ? - Are you sure you want to delete {what} exchanged with {this.state.displayName || this.state.uri}? + Are you sure you want to delete {what} exchanged with {remote_label}? : Delete all messages from this device. {"\n"}{"\n"} Messages will remain on the server. } { canDeleteByTime ? this.setPeriod(newValue)} value={this.state.period}> Last hour Last day All : null} + {this.state.uri ? {Platform.OS === 'ios' ? this.toggleRemoteDelete()}/> : {this.toggleRemoteDelete()}}/> } - Also delete for {this.state.displayName || this.state.uri} + Also delete for {remote_label} + : null + } {this.state.uri && this.state.filteredMessageIds.length === 0 ? {Platform.OS === 'ios' ? this.toggleDeleteContact()}/> : {this.toggleDeleteContact()}}/> } Delete contact : null} ); } else { return ( { this.state.uri ? : null} Delete contact Are you sure you want to delete all message? ); } } } DeleteHistoryModal.propTypes = { show : PropTypes.bool, close : PropTypes.func.isRequired, uri : PropTypes.string, displayName : PropTypes.string, deleteMessages : PropTypes.func, deleteContactFunc : PropTypes.func, hasMessages : PropTypes.bool, filteredMessageIds : PropTypes.array }; export default DeleteHistoryModal; diff --git a/app/components/DeleteMessageModal.js b/app/components/DeleteMessageModal.js index bd7fc97..5959cf7 100644 --- a/app/components/DeleteMessageModal.js +++ b/app/components/DeleteMessageModal.js @@ -1,113 +1,116 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import autoBind from 'auto-bind'; import { View, Platform } from 'react-native'; import UserIcon from './UserIcon'; import { Chip, Dialog, Portal, Text, Button, Surface, TextInput, Paragraph, RadioButton, Checkbox, Switch } from 'react-native-paper'; import KeyboardAwareDialog from './KeyBoardAwareDialog'; const DialogType = Platform.OS === 'ios' ? KeyboardAwareDialog : Dialog; import styles from '../assets/styles/blink/_DeleteMessageModal.scss'; class DeleteMessageModal extends Component { constructor(props) { super(props); autoBind(this); this.state = { uri: this.props.contact ? this.props.contact.uri : null, + username: this.props.contact && this.props.contact.uri ? this.props.contact.uri.split('@')[0] : null, displayName: this.props.contact ? this.props.contact.name : null, contact: this.props.contact, show: this.props.show, remoteDelete: true, message: this.props.message, confirm: false, } } UNSAFE_componentWillReceiveProps(nextProps) { this.setState({show: nextProps.show, uri: nextProps.contact ? nextProps.contact.uri : null, + username: nextProps.contact && nextProps.contact.uri ? nextProps.contact.uri.split('@')[0] : null, displayName: nextProps.contact ? nextProps.contact.name : null, confirm: nextProps.confirm, contact: nextProps.contact, message: nextProps.message }); } deleteMessage(event) { event.preventDefault(); if (this.state.confirm || true) { let id = this.state.message ? this.state.message._id : 'Unknown'; this.setState({confirm: false, remoteDelete: true}); this.props.deleteMessage(id, this.state.uri, this.state.remoteDelete); this.props.close(); } else { this.setState({confirm: true}); } } toggleRemoteDelete() { this.setState({remoteDelete: !this.state.remoteDelete}) } render() { let identity = {uri: this.state.uri, displayName: this.state.displayName}; let deleteLabel = this.state.confirm || true ? 'Confirm': 'Delete'; + let remote_label = (this.state.displayName && this.state.displayName !== this.state.uri) ? this.state.displayName : this.state.username; return ( {'Delete message'} Are you sure you want to delete this message? {Platform.OS === 'ios' ? this.toggleRemoteDelete()}/> : {this.toggleRemoteDelete()}}/> } - Also delete for {this.state.displayName || this.state.uri} + Also delete for {remote_label} ); } } DeleteMessageModal.propTypes = { show : PropTypes.bool, close : PropTypes.func.isRequired, contact : PropTypes.object, deleteMessage : PropTypes.func, message : PropTypes.object }; export default DeleteMessageModal;