Skip to content

Commit

Permalink
Handle post deleted while image preview is open (mattermost#1071)
Browse files Browse the repository at this point in the history
* Handle post deleted while image preview is open

* Review feedback
  • Loading branch information
csduarte authored and hmhealey committed Oct 30, 2017
1 parent 9e0831e commit 898d02c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
47 changes: 41 additions & 6 deletions app/screens/image_preview/image_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {
Alert,
Animated,
InteractionManager,
PanResponder,
Expand All @@ -17,6 +18,7 @@ import {
} from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';
import LinearGradient from 'react-native-linear-gradient';
import {intlShape} from 'react-intl';

import EventEmitter from 'mattermost-redux/utils/event_emitter';

Expand Down Expand Up @@ -53,6 +55,10 @@ export default class ImagePreview extends PureComponent {
theme: PropTypes.object.isRequired
};

static contextTypes = {
intl: intlShape
}

constructor(props) {
super(props);

Expand All @@ -63,6 +69,7 @@ export default class ImagePreview extends PureComponent {
this.state = {
currentFile,
drag: new Animated.ValueXY(),
files: props.files,
footerOpacity: new Animated.Value(1),
pagingEnabled: true,
showFileInfo: true,
Expand Down Expand Up @@ -98,6 +105,10 @@ export default class ImagePreview extends PureComponent {
this.scrollView.scrollTo({x: (this.state.currentFile * nextProps.deviceWidth), animated: false});
});
}

if (!nextProps.files.length) {
this.showDeletedFilesAlert();
}
}

componentWillUnmount() {
Expand Down Expand Up @@ -197,6 +208,28 @@ export default class ImagePreview extends PureComponent {
}
};

showDeletedFilesAlert = () => {
const {intl} = this.context;

Alert.alert(
intl.formatMessage({
id: 'mobile.image_preview.deleted_post_title',
defaultMessage: 'Post Deleted'
}),
intl.formatMessage({
id: 'mobile.image_preview.deleted_post_message',
defaultMessage: "This post and it's files have been deleted. The previewer will now be closed."
}),
[{
text: intl.formatMessage({
id: 'mobile.server_upgrade.button',
defaultMessage: 'OK'
}),
onPress: this.close
}]
);
}

showDownloadOptions = () => {
if (Platform.OS === 'android') {
if (this.state.showDownloader) {
Expand All @@ -213,7 +246,7 @@ export default class ImagePreview extends PureComponent {
this.setHeaderAndFileInfoVisible(false);

const options = {
title: this.props.files[this.state.currentFile].name,
title: this.state.files[this.state.currentFile].name,
items: [{
action: this.showDownloader,
text: {
Expand Down Expand Up @@ -257,7 +290,9 @@ export default class ImagePreview extends PureComponent {
};

renderDownloadButton = () => {
const {canDownloadFiles, files} = this.props;
const {canDownloadFiles} = this.props;
const {files} = this.state;

const file = files[this.state.currentFile];

let icon;
Expand Down Expand Up @@ -325,7 +360,7 @@ export default class ImagePreview extends PureComponent {
onScroll={this.handleScroll}
scrollEventThrottle={2}
>
{this.props.files.map((file, index) => {
{this.state.files.map((file, index) => {
let component;
if (file.has_preview_image || file.mime_type === 'image/gif') {
component = (
Expand Down Expand Up @@ -387,7 +422,7 @@ export default class ImagePreview extends PureComponent {
/>
</TouchableOpacity>
<Text style={style.title}>
{`${this.state.currentFile + 1}/${this.props.files.length}`}
{`${this.state.currentFile + 1}/${this.state.files.length}`}
</Text>
{this.renderDownloadButton()}
</View>
Expand All @@ -400,14 +435,14 @@ export default class ImagePreview extends PureComponent {
pointerEvents='none'
>
<Text style={style.filename}>
{this.props.files[this.state.currentFile].name}
{this.state.files[this.state.currentFile].name}
</Text>
</LinearGradient>
</AnimatedView>
</AnimatedView>
<Downloader
show={this.state.showDownloader}
file={this.props.files[this.state.currentFile]}
file={this.state.files[this.state.currentFile]}
deviceHeight={this.props.deviceHeight}
deviceWidth={this.props.deviceWidth}
onDownloadCancel={this.hideDownloader}
Expand Down
2 changes: 2 additions & 0 deletions assets/base/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,8 @@
"mobile.file_upload.more": "More",
"mobile.file_upload.video": "Video Library",
"mobile.help.title": "Help",
"mobile.image_preview.deleted_post_title": "Post Deleted",
"mobile.image_preview.deleted_post_message": "This post and it's files have been deleted. The previewer will now be closed.",
"mobile.image_preview.save": "Save Image",
"mobile.intro_messages.DM": "This is the start of your direct message history with {teammate}. Direct messages and files shared here are not shown to people outside this area.",
"mobile.intro_messages.default_message": "This is the first channel teammates see when they sign up - use it for posting updates everyone needs to know.",
Expand Down

0 comments on commit 898d02c

Please sign in to comment.