Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track Push Notification Opt-In Status #14579

Merged
merged 42 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2b5d385
Install react-native-device-info
roryabraham Jan 26, 2023
b6e2b21
Upgrade urbanairship-react-native
roryabraham Jan 26, 2023
4fc6f26
Add mock for react-native-device-info
roryabraham Jan 26, 2023
efc4490
Update urbanairship-react-native mock
roryabraham Jan 26, 2023
599be59
Update CustomNotificationProvider
roryabraham Jan 26, 2023
cce0558
Make PushNotification lib have same exports on web and native
roryabraham Jan 26, 2023
51116a7
Create User actions to opt in and out of push notifications
roryabraham Jan 26, 2023
e158dbd
Fix ternary
roryabraham Jan 26, 2023
6ddd67c
Use only one user action instead of two
roryabraham Jan 26, 2023
735e5a9
Hook up listeners in the PushNotification library to track push notif…
roryabraham Jan 26, 2023
7e0a54a
Fix JS style
roryabraham Jan 26, 2023
fa2fe5e
Fix Onyx.connect callback to handle updated NVP shape
roryabraham Jan 26, 2023
72fea38
Merge branch 'main' into Rory-PushNotificationOptInStatus
roryabraham Jan 26, 2023
8941f11
Fix Onyx.connect to be keyed by deviceID
roryabraham Jan 26, 2023
01048e3
Consolidate Onyx connection into PushNotification lib
roryabraham Jan 26, 2023
6f89dc0
Fix require cycle
roryabraham Jan 26, 2023
29f15e0
Use Google Play-compliant deviceID alternative
roryabraham Jan 26, 2023
973b551
Move Device to its own action
roryabraham Jan 27, 2023
1513b20
Fix require cycle by moving push notification tracking to separate mo…
roryabraham Jan 27, 2023
ac8badf
Fix permission tracker export
roryabraham Jan 27, 2023
3b13de7
Fix require cycle by moving setPushNotificationOptInStatus out of User
roryabraham Jan 27, 2023
6a7c215
Remove awkward newline
roryabraham Jan 27, 2023
6621f1e
Clarify comment
roryabraham Jan 27, 2023
4f2ca7b
Simplify Onyx data to a boolean
roryabraham Jan 27, 2023
77f029d
Fix use of PermissionsTracker
roryabraham Jan 27, 2023
fb853a3
Remove permissionTracker entirely
roryabraham Jan 27, 2023
1470b01
Improve device comment again
roryabraham Jan 27, 2023
1924a4b
Add static deviceID for the desktop app
roryabraham Jan 27, 2023
ae22dee
Separate out Android and web deviceID implementations
roryabraham Jan 27, 2023
7287f42
Improve comment on invoke
roryabraham Jan 27, 2023
4baf080
Improve comment in generateDeviceID/index.android.js
roryabraham Jan 27, 2023
137740d
Fix ReportTest
roryabraham Jan 27, 2023
d9d8999
Rename index.js to index.website.js
roryabraham Jan 27, 2023
412e6c3
Fix expensify-common import
roryabraham Jan 27, 2023
9bc0558
Fix NetworkTest
roryabraham Jan 27, 2023
050f700
Merge branch main into Rory-PushNotificationOptInStatus
roryabraham Feb 3, 2023
0b6b425
Remove super bizzare unnecessary import
roryabraham Feb 3, 2023
ba8728f
Remove context
roryabraham Feb 3, 2023
db124ad
Clarify comments around PUSH_NOTIFICATIONS_ENABLED
roryabraham Feb 3, 2023
8fe9141
Remove server-side assumption from comment
roryabraham Feb 3, 2023
99d799d
Merge branch 'main' into Rory-PushNotificationOptInStatus
roryabraham Feb 9, 2023
5af1d26
Merge branch 'main' into Rory-PushNotificationOptInStatus
roryabraham Feb 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions __mocks__/react-native-device-info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import MockDeviceInfo from 'react-native-device-info/jest/react-native-device-info-mock';

export default MockDeviceInfo;
1 change: 1 addition & 0 deletions __mocks__/urbanairship-react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const UrbanAirship = {
removeAllListeners: jest.fn(),
setBadgeNumber: jest.fn(),
setForegroundPresentationOptions: jest.fn(),
getNotificationStatus: () => Promise.resolve({airshipOptIn: false, systemEnabled: false}),
};

export default UrbanAirship;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import java.util.concurrent.TimeUnit;

public class CustomNotificationProvider extends ReactNotificationProvider {

// Resize icons to 100 dp x 100 dp
private static final int MAX_ICON_SIZE_DPS = 100;

Expand Down
9 changes: 5 additions & 4 deletions desktop/ELECTRON_EVENTS.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
const ELECTRON_EVENTS = {
BLUR: 'blur',
FOCUS: 'focus',
LOCALE_UPDATED: 'locale-updated',
REQUEST_DEVICE_ID: 'requestDeviceID',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This REQUEST_DEVICE_ID is the new one, I just alphabetized this object.

REQUEST_FOCUS_APP: 'requestFocusApp',
REQUEST_UPDATE_BADGE_COUNT: 'requestUpdateBadgeCount',
REQUEST_VISIBILITY: 'requestVisibility',
REQUEST_FOCUS_APP: 'requestFocusApp',
SHOW_KEYBOARD_SHORTCUTS_MODAL: 'show-keyboard-shortcuts-modal',
START_UPDATE: 'start-update',
UPDATE_DOWNLOADED: 'update-downloaded',
FOCUS: 'focus',
BLUR: 'blur',
LOCALE_UPDATED: 'locale-updated',
};

module.exports = ELECTRON_EVENTS;
16 changes: 16 additions & 0 deletions desktop/contextBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
const ELECTRON_EVENTS = require('./ELECTRON_EVENTS');

const WHITELIST_CHANNELS_RENDERER_TO_MAIN = [
ELECTRON_EVENTS.REQUEST_DEVICE_ID,
ELECTRON_EVENTS.REQUEST_FOCUS_APP,
ELECTRON_EVENTS.REQUEST_UPDATE_BADGE_COUNT,
ELECTRON_EVENTS.REQUEST_VISIBILITY,
Expand Down Expand Up @@ -59,6 +60,21 @@ contextBridge.exposeInMainWorld('electron', {
return ipcRenderer.sendSync(channel, data);
},

/**
* Execute a function in the main process and return a promise that resolves with its response.
*
* @param {String} channel
* @param {*} args
* @returns {Promise}
*/
invoke: (channel, ...args) => {
if (!_.contains(WHITELIST_CHANNELS_RENDERER_TO_MAIN, channel)) {
throw new Error(getErrorMessage(channel));
}

return ipcRenderer.invoke(channel, ...args);
},

/**
* Set up a listener for events emitted from the main process and sent to the renderer process.
*
Expand Down
3 changes: 3 additions & 0 deletions desktop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const serve = require('electron-serve');
const contextMenu = require('electron-context-menu');
const {autoUpdater} = require('electron-updater');
const log = require('electron-log');
const {machineId} = require('node-machine-id');
const ELECTRON_EVENTS = require('./ELECTRON_EVENTS');
const checkForUpdates = require('../src/libs/checkForUpdates');
const CONFIG = require('../src/CONFIG').default;
Expand Down Expand Up @@ -282,6 +283,8 @@ const mainWindow = (() => {
titleBarStyle: 'hidden',
});

ipcMain.handle(ELECTRON_EVENTS.REQUEST_DEVICE_ID, () => machineId());

/*
* The default origin of our Electron app is app://- instead of https://new.expensify.com or https://staging.new.expensify.com
* This causes CORS errors because the referer and origin headers are wrong and the API responds with an Access-Control-Allow-Origin that doesn't match app://-
Expand Down
13 changes: 12 additions & 1 deletion desktop/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"electron-context-menu": "^2.3.0",
"electron-log": "^4.4.7",
"electron-serve": "^1.0.0",
"electron-updater": "^4.3.4"
"electron-updater": "^4.3.4",
"node-machine-id": "^1.1.12"
},
"author": "Expensify, Inc.",
"license": "MIT",
Expand Down
36 changes: 21 additions & 15 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
PODS:
- Airship (16.8.0):
- Airship/Automation (= 16.8.0)
- Airship/Basement (= 16.8.0)
- Airship/Core (= 16.8.0)
- Airship/ExtendedActions (= 16.8.0)
- Airship/MessageCenter (= 16.8.0)
- Airship/Automation (16.8.0):
- Airship (16.10.7):
- Airship/Automation (= 16.10.7)
- Airship/Basement (= 16.10.7)
- Airship/Core (= 16.10.7)
- Airship/ExtendedActions (= 16.10.7)
- Airship/MessageCenter (= 16.10.7)
- Airship/Automation (16.10.7):
- Airship/Core
- Airship/Basement (16.8.0)
- Airship/Core (16.8.0):
- Airship/Basement (16.10.7)
- Airship/Core (16.10.7):
- Airship/Basement
- Airship/ExtendedActions (16.8.0):
- Airship/ExtendedActions (16.10.7):
- Airship/Core
- Airship/MessageCenter (16.8.0):
- Airship/MessageCenter (16.10.7):
- Airship/Core
- boost (1.76.0)
- CocoaAsyncSocket (7.6.5)
Expand Down Expand Up @@ -575,6 +575,8 @@ PODS:
- React-Core
- RNDateTimePicker (3.5.2):
- React-Core
- RNDeviceInfo (10.3.0):
- React-Core
- RNFastImage (8.6.3):
- React-Core
- SDWebImage (~> 5.11.1)
Expand Down Expand Up @@ -639,8 +641,8 @@ PODS:
- libwebp (~> 1.0)
- SDWebImage/Core (~> 5.10)
- SocketRocket (0.6.0)
- urbanairship-react-native (14.4.1):
- Airship (= 16.8.0)
- urbanairship-react-native (14.6.1):
- Airship (= 16.10.7)
- React-Core
- Yoga (1.14.0)
- YogaKit (1.18.1):
Expand Down Expand Up @@ -730,6 +732,7 @@ DEPENDENCIES:
- "RNCClipboard (from `../node_modules/@react-native-community/clipboard`)"
- "RNCPicker (from `../node_modules/@react-native-picker/picker`)"
- "RNDateTimePicker (from `../node_modules/@react-native-community/datetimepicker`)"
- RNDeviceInfo (from `../node_modules/react-native-device-info`)
- RNFastImage (from `../node_modules/react-native-fast-image`)
- "RNFBAnalytics (from `../node_modules/@react-native-firebase/analytics`)"
- "RNFBApp (from `../node_modules/@react-native-firebase/app`)"
Expand Down Expand Up @@ -901,6 +904,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-picker/picker"
RNDateTimePicker:
:path: "../node_modules/@react-native-community/datetimepicker"
RNDeviceInfo:
:path: "../node_modules/react-native-device-info"
RNFastImage:
:path: "../node_modules/react-native-fast-image"
RNFBAnalytics:
Expand Down Expand Up @@ -929,7 +934,7 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/yoga"

SPEC CHECKSUMS:
Airship: 4657c3d5118441240e04674d9445cbd6e363c956
Airship: fbff646723323c58e3871cd30488612ca373f597
boost: a7c83b31436843459a1961bfd74b96033dc77234
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
Expand Down Expand Up @@ -1019,6 +1024,7 @@ SPEC CHECKSUMS:
RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495
RNCPicker: 0b65be85fe7954fbb2062ef079e3d1cde252d888
RNDateTimePicker: 7658208086d86d09e1627b5c34ba0cf237c60140
RNDeviceInfo: 4701f0bf2a06b34654745053db0ce4cb0c53ada7
RNFastImage: 5c9c9fed9c076e521b3f509fe79e790418a544e8
RNFBAnalytics: f76bfa164ac235b00505deb9fc1776634056898c
RNFBApp: 729c0666395b1953198dc4a1ec6deb8fbe1c302e
Expand All @@ -1033,7 +1039,7 @@ SPEC CHECKSUMS:
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
urbanairship-react-native: 7e2e9a84c541b1d04798e51f7f390a2d5806eac0
urbanairship-react-native: fe4d169332546a0efd348a009aa490dc36ff815e
Yoga: f77f6497bccebdcbc8efb03dbf83eadfdec6d104
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down
29 changes: 22 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"react-native-blob-util": "^0.16.2",
"react-native-collapsible": "^1.6.0",
"react-native-config": "^1.4.5",
"react-native-device-info": "^10.3.0",
"react-native-document-picker": "^8.0.0",
"react-native-fast-image": "^8.6.3",
"react-native-gesture-handler": "2.9.0",
Expand Down Expand Up @@ -119,7 +120,7 @@
"semver": "^7.3.8",
"shim-keyboard-event-key": "^1.0.3",
"underscore": "^1.13.1",
"urbanairship-react-native": "^14.3.1"
"urbanairship-react-native": "^14.6.1"
},
"devDependencies": {
"@actions/core": "1.10.0",
Expand Down
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ const CONST = {
KYC_MIGRATION: 'expensify_migration_2020_04_28_RunKycVerifications',
PREFERRED_EMOJI_SKIN_TONE: 'expensify_preferredEmojiSkinTone',
FREQUENTLY_USED_EMOJIS: 'expensify_frequentlyUsedEmojis',
PUSH_NOTIFICATIONS_ENABLED: 'pushNotificationsEnabled',
},
DEFAULT_TIME_ZONE: {automatic: true, selected: 'America/Los_Angeles'},
DEFAULT_ACCOUNT_DATA: {errors: null, success: '', isLoading: false},
Expand Down
6 changes: 6 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export default {
// which tab is the leader, and which ones are the followers
ACTIVE_CLIENTS: 'activeClients',

// A unique ID for the device
DEVICE_ID: 'deviceID',

// Boolean flag set whenever the sidebar has loaded
IS_SIDEBAR_LOADED: 'isSidebarLoaded',

Expand Down Expand Up @@ -79,6 +82,9 @@ export default {
// Contains the users's block expiration (if they have one)
NVP_BLOCKED_FROM_CONCIERGE: 'private_blockedFromConcierge',

// Does this user have push notifications enabled for this device?
PUSH_NOTIFICATIONS_ENABLED: 'pushNotificationsEnabled',

// Plaid data (access tokens, bank accounts ...)
PLAID_DATA: 'plaidData',

Expand Down
Loading