diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-01-25 11:31:09 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-25 11:31:09 -0600 |
commit | 5f189319157dfed67b331145cdfd322515022b93 (patch) | |
tree | 1a87f8c7dd46552ba137ff898eb972024e413fdd /src/state/models/notifications-view.ts | |
parent | 079e1dbe180e7a1a5a58cdab90f154157ed07d23 (diff) | |
download | voidsky-5f189319157dfed67b331145cdfd322515022b93.tar.zst |
Push notification & session management cleanup (#92)
* Add some temporary logging to help suss out the session drop issue * Fix to session resumption: copy session tokens during a resumeSession attempt * Factor out notifee display into a lib and add to storybook * Tune the bg notifications fetch to only get what is needed * Fix: run account update inside a mobx action * Remove debugging logs for sessions * Fixes to bg notifications fetch
Diffstat (limited to 'src/state/models/notifications-view.ts')
-rw-r--r-- | src/state/models/notifications-view.ts | 61 |
1 files changed, 20 insertions, 41 deletions
diff --git a/src/state/models/notifications-view.ts b/src/state/models/notifications-view.ts index 34bb57f6e..93b6a398f 100644 --- a/src/state/models/notifications-view.ts +++ b/src/state/models/notifications-view.ts @@ -7,7 +7,6 @@ import { AppBskyFeedVote, AppBskyGraphAssertion, AppBskyGraphFollow, - AppBskyEmbedImages, } from '@atproto/api' import {RootStoreModel} from './root-store' import {PostThreadViewModel} from './post-thread-view' @@ -180,42 +179,6 @@ export class NotificationsViewItemModel { }) } } - - toNotifeeOpts() { - let author = this.author.displayName || this.author.handle - let title: string - let body: string = '' - if (this.isUpvote) { - title = `${author} liked your post` - body = this.additionalPost?.thread?.postRecord?.text || '' - } else if (this.isRepost) { - title = `${author} reposted your post` - body = this.additionalPost?.thread?.postRecord?.text || '' - } else if (this.isReply) { - title = `${author} replied to your post` - body = this.additionalPost?.thread?.postRecord?.text || '' - } else if (this.isFollow) { - title = `${author} followed you` - } else { - return undefined - } - let ios - if ( - AppBskyEmbedImages.isPresented(this.additionalPost?.thread?.post.embed) && - this.additionalPost?.thread?.post.embed.images[0]?.thumb - ) { - ios = { - attachments: [ - {url: this.additionalPost.thread.post.embed.images[0].thumb}, - ], - } - } - return { - title, - body, - ios, - } - } } export class NotificationsViewModel { @@ -234,7 +197,7 @@ export class NotificationsViewModel { // data notifications: NotificationsViewItemModel[] = [] - // this is used to trigger push notifications + // this is used to help trigger push notifications mostRecentNotification: NotificationsViewItemModel | undefined constructor( @@ -246,6 +209,7 @@ export class NotificationsViewModel { { rootStore: false, params: false, + mostRecentNotification: false, _loadPromise: false, _loadMorePromise: false, _updatePromise: false, @@ -333,6 +297,24 @@ export class NotificationsViewModel { } } + async getNewMostRecent(): Promise<NotificationsViewItemModel | undefined> { + let old = this.mostRecentNotification + const res = await this.rootStore.api.app.bsky.notification.list({limit: 1}) + if ( + !res.data.notifications[0] || + old?.uri === res.data.notifications[0].uri + ) { + return + } + this.mostRecentNotification = new NotificationsViewItemModel( + this.rootStore, + 'mostRecent', + res.data.notifications[0], + ) + await this.mostRecentNotification.fetchAdditionalData() + return this.mostRecentNotification + } + // state transitions // = @@ -434,9 +416,6 @@ export class NotificationsViewModel { 'mostRecent', res.data.notifications[0], ) - await this.mostRecentNotification.fetchAdditionalData() - } else { - this.mostRecentNotification = undefined } return this._appendAll(res, true) } |