basic repost redirect handling

This commit is contained in:
Akinwale Ariwodola 2020-02-24 15:55:44 +01:00
parent f05d357fa7
commit 0db2c7e628
2 changed files with 52 additions and 2 deletions

View file

@ -104,6 +104,8 @@ class FilePage extends React.PureComponent {
stopDownloadConfirmed: false, stopDownloadConfirmed: false,
streamingMode: false, streamingMode: false,
viewCountFetched: false, viewCountFetched: false,
isRepost: false,
uriPushedToDrawerStack: false,
}; };
} }
@ -114,6 +116,22 @@ class FilePage extends React.PureComponent {
// this.didFocusListener = navigation.addListener('didFocus', this.onComponentFocused); // 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 = () => { onComponentFocused = () => {
StatusBar.setHidden(false); StatusBar.setHidden(false);
NativeModules.Firebase.setCurrentScreen('File').then(result => { NativeModules.Firebase.setCurrentScreen('File').then(result => {
@ -130,6 +148,8 @@ class FilePage extends React.PureComponent {
setPlayerVisible(true, uri); setPlayerVisible(true, uri);
if (!isResolvingUri && !claim) resolveUri(uri); if (!isResolvingUri && !claim) resolveUri(uri);
this.checkRepost();
this.fetchFileInfo(uri, this.props); this.fetchFileInfo(uri, this.props);
this.fetchCostInfo(uri, this.props); this.fetchCostInfo(uri, this.props);
@ -283,6 +303,11 @@ class FilePage extends React.PureComponent {
resolveUri(uri); resolveUri(uri);
} }
if (!prevProps.claim && claim) {
this.checkRepost();
return;
}
// Returned to the page. If mediaLoaded, and currentMediaInfo is different, update // Returned to the page. If mediaLoaded, and currentMediaInfo is different, update
if (this.state.mediaLoaded && window.currentMediaInfo && window.currentMediaInfo.uri !== this.state.uri) { if (this.state.mediaLoaded && window.currentMediaInfo && window.currentMediaInfo.uri !== this.state.uri) {
const { metadata } = this.props; const { metadata } = this.props;
@ -973,6 +998,12 @@ class FilePage extends React.PureComponent {
let innerContent = null; let innerContent = null;
if ((isResolvingUri && !claim) || !claim) { if ((isResolvingUri && !claim) || !claim) {
if (!isResolvingUri && !claim && !this.state.uriPushedToDrawerStack) {
this.setState({ uriPushedToDrawerStack: true }, () => {
pushDrawerStack(uri);
});
}
return ( return (
<View style={filePageStyle.pageContainer}> <View style={filePageStyle.pageContainer}>
<UriBar value={uri} navigation={navigation} /> <UriBar value={uri} navigation={navigation} />
@ -1041,6 +1072,17 @@ class FilePage extends React.PureComponent {
tags = claim.value.tags; 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 completed = fileInfo && fileInfo.completed;
const isRewardContent = rewardedContentClaimIds.includes(claim.claim_id); const isRewardContent = rewardedContentClaimIds.includes(claim.claim_id);
const description = metadata.description ? metadata.description : null; const description = metadata.description ? metadata.description : null;

View file

@ -116,7 +116,15 @@ function parseUriVars(vars) {
return uriVars; return uriVars;
} }
export function navigateToUri(navigation, uri, additionalParams, isNavigatingBack, fullUri, setPlayerVisible) { export function navigateToUri(
navigation,
uri,
additionalParams,
isNavigatingBack,
fullUri,
setPlayerVisible,
pushStack = false,
) {
if (!navigation) { if (!navigation) {
return; return;
} }
@ -154,7 +162,7 @@ export function navigateToUri(navigation, uri, additionalParams, isNavigatingBac
} }
navigation.navigate({ routeName: 'File', key: uri, params }); navigation.navigate({ routeName: 'File', key: uri, params });
if (store && store.dispatch && !isNavigatingBack) { if (pushStack && store && store.dispatch && !isNavigatingBack) {
store.dispatch(doPushDrawerStack(uri)); store.dispatch(doPushDrawerStack(uri));
} }
} }