Experimental: use react-native-background-fetch to check for notifications
This commit is contained in:
@@ -340,6 +340,8 @@ PODS:
|
||||
- React-perflogger (= 0.71.0)
|
||||
- rn-fetch-blob (0.12.0):
|
||||
- React-Core
|
||||
- RNBackgroundFetch (4.1.8):
|
||||
- React-Core
|
||||
- RNCAsyncStorage (1.17.11):
|
||||
- React-Core
|
||||
- RNCClipboard (1.11.1):
|
||||
@@ -453,6 +455,7 @@ DEPENDENCIES:
|
||||
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
|
||||
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
|
||||
- rn-fetch-blob (from `../node_modules/rn-fetch-blob`)
|
||||
- RNBackgroundFetch (from `../node_modules/react-native-background-fetch`)
|
||||
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
|
||||
- "RNCClipboard (from `../node_modules/@react-native-clipboard/clipboard`)"
|
||||
- RNFS (from `../node_modules/react-native-fs`)
|
||||
@@ -562,6 +565,8 @@ EXTERNAL SOURCES:
|
||||
:path: "../node_modules/react-native/ReactCommon"
|
||||
rn-fetch-blob:
|
||||
:path: "../node_modules/rn-fetch-blob"
|
||||
RNBackgroundFetch:
|
||||
:path: "../node_modules/react-native-background-fetch"
|
||||
RNCAsyncStorage:
|
||||
:path: "../node_modules/@react-native-async-storage/async-storage"
|
||||
RNCClipboard:
|
||||
@@ -637,6 +642,7 @@ SPEC CHECKSUMS:
|
||||
React-runtimeexecutor: ac80782d9d76ba2b0f709f4de0c427fe33c352dc
|
||||
ReactCommon: 20e38a9be5fe1341b5e422220877cc94034776ba
|
||||
rn-fetch-blob: f065bb7ab7fb48dd002629f8bdcb0336602d3cba
|
||||
RNBackgroundFetch: 8e16176ff415daac743a6eb57afc8e9e14dbe623
|
||||
RNCAsyncStorage: 8616bd5a58af409453ea4e1b246521bb76578d60
|
||||
RNCClipboard: 2834e1c4af68697089cdd455ee4a4cdd198fa7dd
|
||||
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
"react-dom": "17.0.2",
|
||||
"react-native": "0.71.0",
|
||||
"react-native-appstate-hook": "^1.0.6",
|
||||
"react-native-background-fetch": "^4.1.8",
|
||||
"react-native-fs": "^2.20.0",
|
||||
"react-native-gesture-handler": "^2.5.0",
|
||||
"react-native-haptic-feedback": "^1.14.0",
|
||||
|
||||
@@ -6,6 +6,7 @@ import {makeAutoObservable} from 'mobx'
|
||||
import {sessionClient as AtpApi, SessionServiceClient} from '@atproto/api'
|
||||
import {createContext, useContext} from 'react'
|
||||
import {DeviceEventEmitter, EmitterSubscription} from 'react-native'
|
||||
import BackgroundFetch from 'react-native-background-fetch'
|
||||
import {isObj, hasProp} from '../lib/type-guards'
|
||||
import {LogModel} from './log'
|
||||
import {SessionModel} from './session'
|
||||
@@ -34,6 +35,7 @@ export class RootStoreModel {
|
||||
serialize: false,
|
||||
hydrate: false,
|
||||
})
|
||||
this.initBgFetch()
|
||||
}
|
||||
|
||||
async resolveName(didOrHandle: string) {
|
||||
@@ -109,9 +111,41 @@ export class RootStoreModel {
|
||||
}
|
||||
|
||||
emitPostDeleted(uri: string) {
|
||||
console.log('emit')
|
||||
DeviceEventEmitter.emit('post-deleted', uri)
|
||||
}
|
||||
|
||||
// background fetch
|
||||
// =
|
||||
// - we use this to poll for unread notifications, which is not "ideal" behavior but
|
||||
// gives us a solution for push-notifications that work against any pds
|
||||
|
||||
initBgFetch() {
|
||||
// NOTE
|
||||
// background fetch runs every 15 minutes *at most* and will get slowed down
|
||||
// based on some heuristics run by iOS, meaning it is not a reliable form of delivery
|
||||
// -prf
|
||||
BackgroundFetch.configure(
|
||||
{minimumFetchInterval: 15},
|
||||
this.onBgFetch.bind(this),
|
||||
this.onBgFetchTimeout.bind(this),
|
||||
).then(status => {
|
||||
this.log.debug(`Background fetch initiated, status: ${status}`)
|
||||
})
|
||||
}
|
||||
|
||||
async onBgFetch(taskId: string) {
|
||||
this.log.debug(`Background fetch fired for task ${taskId}`)
|
||||
if (this.session.hasSession) {
|
||||
// grab notifications
|
||||
await this.me.fetchNotifications()
|
||||
}
|
||||
BackgroundFetch.finish(taskId)
|
||||
}
|
||||
|
||||
onBgFetchTimeout(taskId: string) {
|
||||
this.log.debug(`Background fetch timed out for task ${taskId}`)
|
||||
BackgroundFetch.finish(taskId)
|
||||
}
|
||||
}
|
||||
|
||||
const throwawayInst = new RootStoreModel(AtpApi.service('http://localhost')) // this will be replaced by the loader, we just need to supply a value at init
|
||||
|
||||
@@ -11169,6 +11169,11 @@ react-native-appstate-hook@^1.0.6:
|
||||
resolved "https://registry.yarnpkg.com/react-native-appstate-hook/-/react-native-appstate-hook-1.0.6.tgz#cbc16e7b89cfaea034cabd999f00e99053cabd06"
|
||||
integrity sha512-0hPVyf5yLxCSVrrNEuGqN1ZnSSj3Ye2gZex0NtcK/AHYwMc0rXWFNZjBKOoZSouspqu3hXBbQ6NOUSTzrME1AQ==
|
||||
|
||||
react-native-background-fetch@^4.1.8:
|
||||
version "4.1.8"
|
||||
resolved "https://registry.yarnpkg.com/react-native-background-fetch/-/react-native-background-fetch-4.1.8.tgz#a21858e5d876de8d9d15a37f40714b244f73713c"
|
||||
integrity sha512-/qe86laa0n4AbD6mrLL8SCGR+K5693URX95e02/bTJh3UkdS3+sU1Jyc/XTlz4MQwlquI929/lm5EZh8AOUqzQ==
|
||||
|
||||
react-native-codegen@^0.71.3:
|
||||
version "0.71.3"
|
||||
resolved "https://registry.yarnpkg.com/react-native-codegen/-/react-native-codegen-0.71.3.tgz#75fbc591819050791319ebdb9fe341ee4df5c288"
|
||||
|
||||
Reference in New Issue
Block a user