diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-01-24 19:32:24 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-24 19:32:24 -0600 |
commit | 869f6c4e0e464b7f5be9ef5676210ae8844bd834 (patch) | |
tree | a9a823723099129bb25c4b57435925b481d54266 /src/state/models/notifications-view.ts | |
parent | 21f5f4de157a73b3c4406461b2a36555b1bff228 (diff) | |
download | voidsky-869f6c4e0e464b7f5be9ef5676210ae8844bd834.tar.zst |
Initial pass at push notifications + some fixes to the session management (#91)
* Fix: test the session during resume to ensure it's valid * Don't delete sessions for now * Add notifee and request notif permissions on first login * Set unread notifications badge on app icon * Trigger a notifee card on new notifications * Experimental: use react-native-background-fetch to check for notifications * Add missing mocks * Fix to resumeSession()
Diffstat (limited to 'src/state/models/notifications-view.ts')
-rw-r--r-- | src/state/models/notifications-view.ts | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/state/models/notifications-view.ts b/src/state/models/notifications-view.ts index 32294ef33..34bb57f6e 100644 --- a/src/state/models/notifications-view.ts +++ b/src/state/models/notifications-view.ts @@ -7,6 +7,7 @@ import { AppBskyFeedVote, AppBskyGraphAssertion, AppBskyGraphFollow, + AppBskyEmbedImages, } from '@atproto/api' import {RootStoreModel} from './root-store' import {PostThreadViewModel} from './post-thread-view' @@ -179,6 +180,42 @@ 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 { @@ -197,6 +234,9 @@ export class NotificationsViewModel { // data notifications: NotificationsViewItemModel[] = [] + // this is used to trigger push notifications + mostRecentNotification: NotificationsViewItemModel | undefined + constructor( public rootStore: RootStoreModel, params: ListNotifications.QueryParams, @@ -388,6 +428,16 @@ export class NotificationsViewModel { } private async _replaceAll(res: ListNotifications.Response) { + if (res.data.notifications[0]) { + this.mostRecentNotification = new NotificationsViewItemModel( + this.rootStore, + 'mostRecent', + res.data.notifications[0], + ) + await this.mostRecentNotification.fetchAdditionalData() + } else { + this.mostRecentNotification = undefined + } return this._appendAll(res, true) } |