Skip to content

Commit 19e542c

Browse files
committed
sharing: Make the app not quit after share to zulip concludes.
Previously after content was shared to zulip the app would quit, regardless of the fact that the content was shared successfully or failed to share, now the behaviour is as follows: - If user cancels sharing/sharing fails, user is returned back to the previous view. - If app was started from share intent, user returns to home screen of zulip. - If share is successful user is navigated to chat screen where the content was shared.
1 parent e6bcb0e commit 19e542c

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

src/nav/navActions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export const resetToMainTabs = (): GenericNavigationAction =>
2929
export const navigateToChat = (narrow: Narrow): GenericNavigationAction =>
3030
StackActions.push('chat', { narrow, editMessage: null });
3131

32+
export const replaceWithChat = (narrow: Narrow): GenericNavigationAction =>
33+
StackActions.replace('chat', { narrow });
34+
3235
export const navigateToUsersScreen = (): GenericNavigationAction => StackActions.push('users');
3336

3437
export const navigateToSearch = (): GenericNavigationAction => StackActions.push('search-messages');

src/sharing/ShareToPm.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* @flow strict-local */
22
import React from 'react';
3-
import { View, Image, ScrollView, Modal, BackHandler } from 'react-native';
4-
3+
import { View, Image, ScrollView, Modal } from 'react-native';
54
import type { RouteProp } from '../react-navigation';
65
import type { SharingNavigationProp } from './SharingScreen';
76
import * as NavigationService from '../nav/NavigationService';
@@ -12,9 +11,12 @@ import { connect } from '../react-redux';
1211
import { ZulipButton, Input, Label } from '../common';
1312
import UserItem from '../users/UserItem';
1413
import { getAuth } from '../selectors';
15-
import { navigateBack } from '../nav/navActions';
14+
import { navigateBack, replaceWithChat } from '../nav/navActions';
1615
import ChooseRecipientsScreen from './ChooseRecipientsScreen';
1716
import { handleSend } from './send';
17+
import { pmNarrowFromRecipients } from '../utils/narrow';
18+
import { pmKeyRecipientsFromIds } from '../utils/recipient';
19+
import { getOwnUserId } from '../users/userSelectors';
1820

1921
const styles = createStyleSheet({
2022
wrapper: {
@@ -58,7 +60,7 @@ const styles = createStyleSheet({
5860
type Props = $ReadOnly<{|
5961
navigation: SharingNavigationProp<'share-to-pm'>,
6062
route: RouteProp<'share-to-pm', {| sharedData: SharedData |}>,
61-
63+
ownUserId: UserId,
6264
dispatch: Dispatch,
6365
auth: Auth,
6466
|}>;
@@ -105,13 +107,24 @@ class ShareToPm extends React.Component<Props, State> {
105107
const data = { selectedRecipients, message, sharedData, type: 'pm' };
106108

107109
this.setSending();
108-
await handleSend(data, auth, _);
109-
this.finishShare();
110+
try {
111+
await handleSend(data, auth, _);
112+
this.shareSuccess();
113+
} catch (err) {
114+
this.finishShare();
115+
}
116+
};
117+
118+
shareSuccess = () => {
119+
const { selectedRecipients } = this.state;
120+
const { ownUserId } = this.props;
121+
const recipients = pmKeyRecipientsFromIds(selectedRecipients, ownUserId);
122+
const narrow = pmNarrowFromRecipients(recipients);
123+
NavigationService.dispatch(replaceWithChat(narrow));
110124
};
111125

112126
finishShare = () => {
113127
NavigationService.dispatch(navigateBack());
114-
BackHandler.exitApp();
115128
};
116129

117130
handleMessageChange = message => {
@@ -195,4 +208,5 @@ class ShareToPm extends React.Component<Props, State> {
195208

196209
export default connect(state => ({
197210
auth: getAuth(state),
211+
ownUserId: getOwnUserId(state),
198212
}))(ShareToPm);

src/sharing/ShareToStream.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* @flow strict-local */
22
import React from 'react';
3-
import { View, Image, ScrollView, BackHandler } from 'react-native';
4-
3+
import { View, Image, ScrollView } from 'react-native';
54
import type { SharingNavigationProp } from './SharingScreen';
65
import type { RouteProp } from '../react-navigation';
76
import * as NavigationService from '../nav/NavigationService';
@@ -16,7 +15,7 @@ import TopicAutocomplete from '../autocomplete/TopicAutocomplete';
1615
import AnimatedScaleComponent from '../animation/AnimatedScaleComponent';
1716
import { streamNarrow } from '../utils/narrow';
1817
import { getAuth } from '../selectors';
19-
import { navigateBack } from '../nav/navActions';
18+
import { navigateBack, replaceWithChat } from '../nav/navActions';
2019
import { fetchTopicsForStream } from '../topics/topicActions';
2120
import { handleSend } from './send';
2221

@@ -128,13 +127,22 @@ class ShareToStream extends React.Component<Props, State> {
128127
const data = { stream, topic, message, sharedData, type: 'stream' };
129128

130129
this.setSending();
131-
await handleSend(data, auth, _);
132-
this.finishShare();
130+
try {
131+
await handleSend(data, auth, _);
132+
this.shareSuccess();
133+
} catch (err) {
134+
this.finishShare();
135+
}
136+
};
137+
138+
shareSuccess = () => {
139+
const { stream } = this.state;
140+
const narrow = streamNarrow(stream);
141+
NavigationService.dispatch(replaceWithChat(narrow));
133142
};
134143

135144
finishShare = () => {
136145
NavigationService.dispatch(navigateBack());
137-
BackHandler.exitApp();
138146
};
139147

140148
isSendButtonEnabled = () => {

0 commit comments

Comments
 (0)