2020-06-06 09:21:21 +00:00
|
|
|
import ShareExtension, { SharedData } from './ShareExtension';
|
2020-11-07 15:59:37 +00:00
|
|
|
import shim from '@joplin/lib/shim';
|
2020-06-06 09:21:21 +00:00
|
|
|
|
2021-01-22 17:41:11 +00:00
|
|
|
import Note from '@joplin/lib/models/Note';
|
|
|
|
import checkPermissions from './checkPermissions.js';
|
2020-06-04 17:40:44 +00:00
|
|
|
const { ToastAndroid } = require('react-native');
|
|
|
|
const { PermissionsAndroid } = require('react-native');
|
2021-04-24 08:22:11 +00:00
|
|
|
const { Platform } = require('react-native');
|
2020-06-04 17:40:44 +00:00
|
|
|
|
2023-06-30 09:30:29 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
2020-06-04 17:40:44 +00:00
|
|
|
export default async (sharedData: SharedData, folderId: string, dispatch: Function) => {
|
|
|
|
|
|
|
|
if (!!sharedData.resources && sharedData.resources.length > 0) {
|
2021-04-24 08:22:11 +00:00
|
|
|
// No need to check permissions for iOS, the files are already in the shared container
|
|
|
|
if (Platform.OS === 'android') {
|
|
|
|
const response = await checkPermissions(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
|
|
|
|
|
2023-07-25 15:45:21 +00:00
|
|
|
// Note that if the permission is NEVER_ASK_AGAIN, it might still
|
|
|
|
// work because of the way Android permissions work after Android
|
|
|
|
// 10. So it means in that case we give it a try anyway.
|
|
|
|
// https://stackoverflow.com/a/73630987/561309
|
|
|
|
if (response === PermissionsAndroid.RESULTS.DENIED) {
|
2021-04-24 08:22:11 +00:00
|
|
|
ToastAndroid.show('Cannot receive shared data - permission denied', ToastAndroid.SHORT);
|
|
|
|
ShareExtension.close();
|
|
|
|
return;
|
|
|
|
}
|
2020-06-04 17:40:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is a bit hacky, but the surest way to go to
|
|
|
|
// the needed note. We go back one screen in case there's
|
|
|
|
// already a note open - if we don't do this, the dispatch
|
|
|
|
// below will do nothing (because routeName wouldn't change)
|
|
|
|
// Then we wait a bit for the state to be set correctly, and
|
|
|
|
// finally we go to the new note.
|
2020-12-30 10:54:00 +00:00
|
|
|
dispatch({ type: 'NAV_BACK' });
|
2020-06-04 17:40:44 +00:00
|
|
|
|
2020-12-30 10:54:00 +00:00
|
|
|
dispatch({ type: 'SIDE_MENU_CLOSE' });
|
2020-06-04 17:40:44 +00:00
|
|
|
|
|
|
|
const newNote = await Note.save({
|
|
|
|
parent_id: folderId,
|
|
|
|
}, { provisional: true });
|
|
|
|
|
2020-10-09 17:35:46 +00:00
|
|
|
shim.setTimeout(() => {
|
2020-06-04 17:40:44 +00:00
|
|
|
dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: 'Note',
|
|
|
|
noteId: newNote.id,
|
|
|
|
sharedData: sharedData,
|
|
|
|
});
|
2023-02-19 19:06:17 +00:00
|
|
|
|
|
|
|
ShareExtension.close();
|
2020-06-04 17:40:44 +00:00
|
|
|
}, 5);
|
|
|
|
};
|