Commit 0db2c7e6 authored by Akinwale Ariwodola's avatar Akinwale Ariwodola
Browse files

basic repost redirect handling

parent f05d357f
......@@ -104,6 +104,8 @@ class FilePage extends React.PureComponent {
stopDownloadConfirmed: false,
streamingMode: false,
viewCountFetched: false,
isRepost: false,
uriPushedToDrawerStack: false,
};
}
......@@ -114,6 +116,22 @@ class FilePage extends React.PureComponent {
// this.didFocusListener = navigation.addListener('didFocus', this.onComponentFocused);
}
checkRepost = () => {
const { claim, isResolvingUri, navigation, pushDrawerStack } = this.props;
const { uri } = this.state;
if (!isResolvingUri) {
if (claim && claim.repost_url) {
// redirect to canonical url
this.setState({ isRepost: true });
navigateToUri(navigation, claim.canonical_url, null, false, claim.permanent_url, false, true);
} else {
this.setState({ uriPushedToDrawerStack: true }, () => {
pushDrawerStack(uri);
});
}
}
};
onComponentFocused = () => {
StatusBar.setHidden(false);
NativeModules.Firebase.setCurrentScreen('File').then(result => {
......@@ -130,6 +148,8 @@ class FilePage extends React.PureComponent {
setPlayerVisible(true, uri);
if (!isResolvingUri && !claim) resolveUri(uri);
this.checkRepost();
this.fetchFileInfo(uri, this.props);
this.fetchCostInfo(uri, this.props);
......@@ -283,6 +303,11 @@ class FilePage extends React.PureComponent {
resolveUri(uri);
}
if (!prevProps.claim && claim) {
this.checkRepost();
return;
}
// Returned to the page. If mediaLoaded, and currentMediaInfo is different, update
if (this.state.mediaLoaded && window.currentMediaInfo && window.currentMediaInfo.uri !== this.state.uri) {
const { metadata } = this.props;
......@@ -973,6 +998,12 @@ class FilePage extends React.PureComponent {
let innerContent = null;
if ((isResolvingUri && !claim) || !claim) {
if (!isResolvingUri && !claim && !this.state.uriPushedToDrawerStack) {
this.setState({ uriPushedToDrawerStack: true }, () => {
pushDrawerStack(uri);
});
}
return (
<View style={filePageStyle.pageContainer}>
<UriBar value={uri} navigation={navigation} />
......@@ -1041,6 +1072,17 @@ class FilePage extends React.PureComponent {
tags = claim.value.tags;
}
if (!isResolvingUri && this.state.isRepost) {
return null;
}
// in case we somehow get here without the uri pushed to the drawer stack
if (!isResolvingUri && !this.state.isRepost && !this.state.uriPushedToDrawerStack) {
this.setState({ uriPushedToDrawerStack: true }, () => {
pushDrawerStack(uri);
});
}
const completed = fileInfo && fileInfo.completed;
const isRewardContent = rewardedContentClaimIds.includes(claim.claim_id);
const description = metadata.description ? metadata.description : null;
......
......@@ -116,7 +116,15 @@ function parseUriVars(vars) {
return uriVars;
}
export function navigateToUri(navigation, uri, additionalParams, isNavigatingBack, fullUri, setPlayerVisible) {
export function navigateToUri(
navigation,
uri,
additionalParams,
isNavigatingBack,
fullUri,
setPlayerVisible,
pushStack = false,
) {
if (!navigation) {
return;
}
......@@ -154,7 +162,7 @@ export function navigateToUri(navigation, uri, additionalParams, isNavigatingBac
}
navigation.navigate({ routeName: 'File', key: uri, params });
if (store && store.dispatch && !isNavigatingBack) {
if (pushStack && store && store.dispatch && !isNavigatingBack) {
store.dispatch(doPushDrawerStack(uri));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment