about summary refs log tree commit diff
path: root/src/state/models/root-store.ts
diff options
context:
space:
mode:
authorAnsh <anshnanda10@gmail.com>2023-08-23 16:28:51 -0700
committerGitHub <noreply@github.com>2023-08-23 16:28:51 -0700
commit8ab5eb6583b6ddd4ed03ef2b1a55ef83fa0c0625 (patch)
tree06ab22c1f0faf121f1de89247ccc43bf353408c7 /src/state/models/root-store.ts
parent32b9648931589311667423ce377ee42a1c78a84f (diff)
downloadvoidsky-8ab5eb6583b6ddd4ed03ef2b1a55ef83fa0c0625.tar.zst
[APP-786] Native notifications (#1095)
* move `notifee.ts` to notifications folder

* install expo notifications

* add UIBackgroundMode `remote-notifications` to app.json

* fix notifee import in Debug.tsx

* add `google-services.json`

* add `development-device` class to eas.json

* Add `notifications.ts` for native notification handling

* send push token to server

* update `@atproto/api`

* fix putting notif token to server

* fix how push token is uploaded

* fix lint

* enable debug appview proxy header on all platforms

* setup `notifications.ts` to work with app view notifs

* clean up notification handler

* add comments

* update packages to correct versions

* remove notifee

* clean up code a lil

* rename push token endpoint

* remove unnecessary comments

* fix comments

* Remove old background scheduler

* Fixes to push notifications API use

* Bump @atproto/api@0.6.6

---------

Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src/state/models/root-store.ts')
-rw-r--r--src/state/models/root-store.ts59
1 files changed, 0 insertions, 59 deletions
diff --git a/src/state/models/root-store.ts b/src/state/models/root-store.ts
index 6ced8090a..1d6d3a0d0 100644
--- a/src/state/models/root-store.ts
+++ b/src/state/models/root-store.ts
@@ -6,7 +6,6 @@ import {makeAutoObservable} from 'mobx'
 import {BskyAgent} from '@atproto/api'
 import {createContext, useContext} from 'react'
 import {DeviceEventEmitter, EmitterSubscription} from 'react-native'
-import * as BgScheduler from 'lib/bg-scheduler'
 import {z} from 'zod'
 import {isObj, hasProp} from 'lib/type-guards'
 import {LogModel} from './log'
@@ -16,7 +15,6 @@ import {HandleResolutionsCache} from './cache/handle-resolutions'
 import {ProfilesCache} from './cache/profiles-view'
 import {PostsCache} from './cache/posts'
 import {LinkMetasCache} from './cache/link-metas'
-import {NotificationsFeedItemModel} from './feeds/notifications'
 import {MeModel} from './me'
 import {InvitedUsers} from './invited-users'
 import {PreferencesModel} from './ui/preferences'
@@ -61,7 +59,6 @@ export class RootStoreModel {
       serialize: false,
       hydrate: false,
     })
-    this.initBgFetch()
   }
 
   setAppInfo(info: AppInfo) {
@@ -249,62 +246,6 @@ export class RootStoreModel {
   emitUnreadNotifications(count: number) {
     DeviceEventEmitter.emit('unread-notifications', count)
   }
-
-  // a notification has been queued for push
-  onPushNotification(
-    handler: (notif: NotificationsFeedItemModel) => void,
-  ): EmitterSubscription {
-    return DeviceEventEmitter.addListener('push-notification', handler)
-  }
-  emitPushNotification(notif: NotificationsFeedItemModel) {
-    DeviceEventEmitter.emit('push-notification', notif)
-  }
-
-  // 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
-    BgScheduler.configure(
-      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) {
-      const res = await this.agent.countUnreadNotifications()
-      const hasNewNotifs = this.me.notifications.unreadCount !== res.data.count
-      this.emitUnreadNotifications(res.data.count)
-      this.log.debug(
-        `Background fetch received unread count = ${res.data.count}`,
-      )
-      if (hasNewNotifs) {
-        this.log.debug(
-          'Background fetch detected potentially a new notification',
-        )
-        const mostRecent = await this.me.notifications.getNewMostRecent()
-        if (mostRecent) {
-          this.log.debug('Got the notification, triggering a push')
-          this.emitPushNotification(mostRecent)
-        }
-      }
-    }
-    BgScheduler.finish(taskId)
-  }
-
-  onBgFetchTimeout(taskId: string) {
-    this.log.debug(`Background fetch timed out for task ${taskId}`)
-    BgScheduler.finish(taskId)
-  }
 }
 
 const throwawayInst = new RootStoreModel(