Skip to content

Commit

Permalink
Merge pull request #2825 from ecency/nt/hiveuri-notifications
Browse files Browse the repository at this point in the history
add support to process hiveuris from notification data
  • Loading branch information
feruzm authored Feb 4, 2024
2 parents 881dcbc + 354dcc3 commit 8a33ab8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/components/qrModal/qrModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,33 @@ export const QRModal = () => {
const isPinCodeOpen = useAppSelector((state) => state.application.isPinCodeOpen);
const isLoggedIn = useAppSelector((state) => state.application.isLoggedIn);


const [isScannerActive, setIsScannerActive] = useState(true);
const [isProcessing, setIsProcessing] = useState(false);
const sheetModalRef = useRef<ActionSheet>();
const scannerRef = useRef(null);

//TODO: make sure to properly clean uri processing code to process uri from deep links and notifications
const hiveUriToHandle = useAppSelector((state) => state.ui.hiveUriToHandle);
useEffect(() => {
if(hiveUriToHandle){
_handleHiveUri(hiveUriToHandle);
}
}, [hiveUriToHandle])


useEffect(() => {
if (isVisibleQRModal) {
requestCameraPermission();
sheetModalRef?.current?.show();
} else {
sheetModalRef?.current?.hide();
}

}, [isVisibleQRModal]);



const requestCameraPermission = async () => {
if (Platform.OS === 'ios') {
const permissionStatus = await check(PERMISSIONS.IOS.CAMERA);
Expand Down
6 changes: 6 additions & 0 deletions src/redux/actions/uiAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
LOGOUT_DONE,
SHOW_WEBVIEW_MODAL,
HIDE_WEBVIEW_MODAL,
HIVE_URI_TO_HANDLE,
} from '../constants/constants';
import { PostEditorModalData } from '../reducers/uiReducer';

Expand Down Expand Up @@ -118,3 +119,8 @@ export const logout = () => ({
export const logoutDone = () => ({
type: LOGOUT_DONE,
});

export const handleHiveUri = (hiveUri:string) => ({
payload:hiveUri,
type: HIVE_URI_TO_HANDLE
})
1 change: 1 addition & 0 deletions src/redux/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const SET_DEVICE_ORIENTATION = 'SET_DEVICE_ORIENTATION';
export const SET_LOCKED_ORIENTATION = 'SET_LOCKED_ORIENTATION';
export const SHOW_REPLY_MODAL = 'SHOW_REPLY_MODAL';
export const HIDE_REPLY_MODAL = 'HIDE_REPLY_MODAL';
export const HIVE_URI_TO_HANDLE = 'HIVE_URI_TO_HANDLE';

// POSTS
export const SET_FEED_POSTS = 'SET_FEED_POSTS';
Expand Down
8 changes: 8 additions & 0 deletions src/redux/reducers/uiReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
LOGOUT_DONE,
SHOW_WEBVIEW_MODAL,
HIDE_WEBVIEW_MODAL,
HIVE_URI_TO_HANDLE,
} from '../constants/constants';
import { orientations } from '../constants/orientationsConstants';

Expand All @@ -42,6 +43,7 @@ interface UiState {
replyModalVisible: boolean;
replyModalData?: PostEditorModalData | null;
isLogingOut: boolean;
hiveUriToHandle:string;
}

const initialState: UiState = {
Expand All @@ -61,6 +63,7 @@ const initialState: UiState = {
replyModalData: null,
replyModalVisible: false,
isLogingOut: false,
hiveUriToHandle: '',
};

const uiReducer = (state = initialState, action): UiState => {
Expand Down Expand Up @@ -176,6 +179,11 @@ const uiReducer = (state = initialState, action): UiState => {
...state,
isLogingOut: false,
};
case HIVE_URI_TO_HANDLE:
return {
...state,
hiveUriToHandle: action.payload
}
default:
return state;
}
Expand Down
11 changes: 10 additions & 1 deletion src/screens/application/hook/useInitApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import messaging from '@react-native-firebase/messaging';
import BackgroundTimer from 'react-native-background-timer';
import FastImage from 'react-native-fast-image';
import { useAppDispatch, useAppSelector } from '../../../hooks';
import { setDeviceOrientation, setLockedOrientation } from '../../../redux/actions/uiAction';
import { handleHiveUri, setDeviceOrientation, setLockedOrientation } from '../../../redux/actions/uiAction';
import { orientations } from '../../../redux/constants/orientationsConstants';
import isAndroidTablet from '../../../utils/isAndroidTablet';
import darkTheme from '../../../themes/darkTheme';
Expand All @@ -27,6 +27,8 @@ import { markNotifications } from '../../../providers/ecency/ecency';
import { updateUnreadActivityCount } from '../../../redux/actions/accountAction';
import RootNavigation from '../../../navigation/rootNavigation';
import ROUTES from '../../../constants/routeNames';
import { isPoundElement } from 'intl-messageformat-parser';
import * as hiveuri from 'hive-uri';

export const useInitApplication = () => {
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -232,6 +234,12 @@ export const useInitApplication = () => {
key = push.source || 'inactive';
break;

case 'hiveuri':
if(push.hiveUri){
dispatch(handleHiveUri(push.hiveUri))
}
break;

default:
break;
}
Expand Down Expand Up @@ -259,6 +267,7 @@ export const useInitApplication = () => {
});
}
}

}
};
};

0 comments on commit 8a33ab8

Please sign in to comment.