mirror of
https://github.com/balzack/databag.git
synced 2025-02-11 19:19:16 +00:00
passing device token to server
This commit is contained in:
parent
438507ed67
commit
73b6338ff5
@ -1,27 +1,10 @@
|
||||
import 'react-native-gesture-handler';
|
||||
import { registerRootComponent } from 'expo';
|
||||
|
||||
import App from './App';
|
||||
|
||||
import messaging from '@react-native-firebase/messaging';
|
||||
|
||||
|
||||
fetch(`https://balzack.coredb.org/account/flag/DEXPO`, { method: 'POST' } ).then(() => { console.log("FETCHED") });
|
||||
|
||||
console.log("REGISTER");
|
||||
messaging().registerDeviceForRemoteMessages().then(() => {
|
||||
console.log("TOKEN!");
|
||||
fetch(`https://balzack.coredb.org/account/flag/REGISTERED`, { method: 'POST' } );
|
||||
messaging().getToken().then(token => {
|
||||
fetch(`https://balzack.coredb.org/account/flag/TOKEN?topic=${token}`, { method: 'POST' } );
|
||||
})
|
||||
});
|
||||
|
||||
messaging().setBackgroundMessageHandler(async remoteMessage => {
|
||||
fetch(`https://balzack.coredb.org/account/flag/BACKGROUND?topic=${JSON.stringify(remoteMessage)}`, { method: 'POST' } );
|
||||
console.log('Message handled in the background!', remoteMessage);
|
||||
});fetch(`https://balzack.coredb.org/account/flag/DEXPO`, { method: 'POST' } );
|
||||
|
||||
messaging().registerDeviceForRemoteMessages();
|
||||
messaging().setBackgroundMessageHandler(async remoteMessage => {});
|
||||
|
||||
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
|
||||
// It also ensures that whether you load the app in Expo Go or in a native build,
|
||||
|
@ -293,6 +293,7 @@
|
||||
"${BUILT_PRODUCTS_DIR}/RCT-Folly/folly.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/RCTTypeSafety/RCTTypeSafety.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/RNCClipboard/RNCClipboard.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/RNDeviceInfo/RNDeviceInfo.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/RNGestureHandler/RNGestureHandler.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/RNImageCropPicker/RNImageCropPicker.framework",
|
||||
"${BUILT_PRODUCTS_DIR}/RNReanimated/RNReanimated.framework",
|
||||
@ -340,6 +341,7 @@
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/folly.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RCTTypeSafety.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNCClipboard.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNDeviceInfo.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNGestureHandler.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNImageCropPicker.framework",
|
||||
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/RNReanimated.framework",
|
||||
|
@ -410,6 +410,8 @@ PODS:
|
||||
- ReactCommon/turbomodule/core (= 0.69.5)
|
||||
- RNCClipboard (1.11.1):
|
||||
- React-Core
|
||||
- RNDeviceInfo (10.3.0):
|
||||
- React-Core
|
||||
- RNFBApp (16.4.3):
|
||||
- Firebase/CoreOnly (= 10.1.0)
|
||||
- React-Core
|
||||
@ -511,6 +513,7 @@ DEPENDENCIES:
|
||||
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
|
||||
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
|
||||
- "RNCClipboard (from `../node_modules/@react-native-clipboard/clipboard`)"
|
||||
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
|
||||
- "RNFBApp (from `../node_modules/@react-native-firebase/app`)"
|
||||
- "RNFBMessaging (from `../node_modules/@react-native-firebase/messaging`)"
|
||||
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
|
||||
@ -626,6 +629,8 @@ EXTERNAL SOURCES:
|
||||
:path: "../node_modules/react-native/ReactCommon"
|
||||
RNCClipboard:
|
||||
:path: "../node_modules/@react-native-clipboard/clipboard"
|
||||
RNDeviceInfo:
|
||||
:path: "../node_modules/react-native-device-info"
|
||||
RNFBApp:
|
||||
:path: "../node_modules/@react-native-firebase/app"
|
||||
RNFBMessaging:
|
||||
@ -700,6 +705,7 @@ SPEC CHECKSUMS:
|
||||
React-runtimeexecutor: c778439c3c430a5719d027d3c67423b390a221fe
|
||||
ReactCommon: ab1003b81be740fecd82509c370a45b1a7dda0c1
|
||||
RNCClipboard: 2834e1c4af68697089cdd455ee4a4cdd198fa7dd
|
||||
RNDeviceInfo: 4701f0bf2a06b34654745053db0ce4cb0c53ada7
|
||||
RNFBApp: e2157f61e4769b53641df8948c534580630cb50a
|
||||
RNFBMessaging: 00da9a5a7136caa61a7b75d87e1dd83864251136
|
||||
RNGestureHandler: 7673697e7c0e9391adefae4faa087442bc04af33
|
||||
|
@ -28,6 +28,7 @@
|
||||
"react-dom": "18.0.0",
|
||||
"react-native": "0.69.5",
|
||||
"react-native-base64": "^0.2.1",
|
||||
"react-native-device-info": "^10.3.0",
|
||||
"react-native-document-picker": "^8.1.1",
|
||||
"react-native-gesture-handler": "^2.7.0",
|
||||
"react-native-image-crop-picker": "^0.38.0",
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
|
||||
export async function setAccountAccess(server, token) {
|
||||
export async function setAccountAccess(server, token, notifications) {
|
||||
let app = { Name: "indicom", Description: "decentralized communication" }
|
||||
let access = await fetchWithTimeout(`https://${server}/account/access?token=${token}`, { method: 'PUT', body: JSON.stringify(app) })
|
||||
let types = encodeURIComponent(JSON.stringify(notifications));
|
||||
let access = await fetchWithTimeout(`https://${server}/account/access?token=${token}&appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}¬ifications=${types}`, { method: 'PUT', body: JSON.stringify(app) })
|
||||
checkResponse(access)
|
||||
return await access.json()
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { checkResponse, fetchWithTimeout } from './fetchUtil';
|
||||
import base64 from 'react-native-base64'
|
||||
|
||||
export async function setLogin(username, server, password) {
|
||||
export async function setLogin(username, server, password, appName, appVersion, platform, deviceToken, notifications) {
|
||||
let headers = new Headers()
|
||||
headers.append('Authorization', 'Basic ' + base64.encode(username + ":" + password));
|
||||
let types = encodeURIComponent(JSON.stringify(notifications));
|
||||
let app = { Name: "topics", Description: "decentralized communication" }
|
||||
let login = await fetchWithTimeout(`https://${server}/account/apps`, { method: 'POST', body: JSON.stringify(app), headers: headers })
|
||||
let login = await fetchWithTimeout(`https://${server}/account/apps?appName=${appName}&appVersion=${appVersion}&platform=${platform}&deviceToken=${deviceToken}¬ifications=${types}`, { method: 'POST', body: JSON.stringify(app), headers: headers })
|
||||
checkResponse(login)
|
||||
return await login.json()
|
||||
}
|
||||
|
@ -10,12 +10,15 @@ import { AccountContext } from 'context/AccountContext';
|
||||
import { ProfileContext } from 'context/ProfileContext';
|
||||
import { CardContext } from 'context/CardContext';
|
||||
import { ChannelContext } from 'context/ChannelContext';
|
||||
import { getVersion, getApplicationName, getDeviceId } from 'react-native-device-info';
|
||||
import messaging from '@react-native-firebase/messaging';
|
||||
|
||||
export function useAppContext() {
|
||||
const [state, setState] = useState({
|
||||
session: null,
|
||||
loginTimestamp: null,
|
||||
disconnected: null,
|
||||
deviceToken: null,
|
||||
});
|
||||
const store = useContext(StoreContext);
|
||||
const account = useContext(AccountContext);
|
||||
@ -31,6 +34,10 @@ export function useAppContext() {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
messaging().getToken().then(token => {
|
||||
updateState({ deviceToken: token });
|
||||
})
|
||||
|
||||
init();
|
||||
}, []);
|
||||
|
||||
@ -68,18 +75,18 @@ export function useAppContext() {
|
||||
username: getUsername,
|
||||
create: async (server, username, password, token) => {
|
||||
await addAccount(server, username, password, token);
|
||||
const access = await setLogin(username, server, password)
|
||||
const access = await setLogin(username, server, password, getApplicatioName(), getVersion(), getDeviceId(), state.deviceToken, ['contact', 'channel'])
|
||||
await store.actions.setSession({ ...access, server});
|
||||
await setSession({ ...access, server });
|
||||
},
|
||||
access: async (server, token) => {
|
||||
const access = await setAccountAccess(server, token);
|
||||
const access = await setAccountAccess(server, token, getApplicationName(), getVersion(), getDeviceId(), state.deviceToken, ['contact', 'channel']);
|
||||
await store.actions.setSession({ ...access, server});
|
||||
await setSession({ ...access, server });
|
||||
},
|
||||
login: async (username, password) => {
|
||||
const acc = username.split('@');
|
||||
const access = await setLogin(acc[0], acc[1], password)
|
||||
const access = await setLogin(acc[0], acc[1], password, getApplicationName(), getVersion(), getDeviceId(), state.deviceToken, ['contact', 'channel'])
|
||||
await store.actions.setSession({ ...access, server: acc[1]});
|
||||
await setSession({ ...access, server: acc[1] });
|
||||
},
|
||||
|
@ -5706,6 +5706,11 @@ react-native-codegen@^0.69.2:
|
||||
jscodeshift "^0.13.1"
|
||||
nullthrows "^1.1.1"
|
||||
|
||||
react-native-device-info@^10.3.0:
|
||||
version "10.3.0"
|
||||
resolved "https://registry.yarnpkg.com/react-native-device-info/-/react-native-device-info-10.3.0.tgz#6bab64d84d3415dd00cc446c73ec5e2e61fddbe7"
|
||||
integrity sha512-/ziZN1sA1REbJTv5mQZ4tXggcTvSbct+u5kCaze8BmN//lbxcTvWsU6NQd4IihLt89VkbX+14IGc9sVApSxd/w==
|
||||
|
||||
react-native-document-picker@^8.1.1:
|
||||
version "8.1.1"
|
||||
resolved "https://registry.npmjs.org/react-native-document-picker/-/react-native-document-picker-8.1.1.tgz"
|
||||
|
Loading…
Reference in New Issue
Block a user