diff options
author | João Ferreiro <ferreiro@pinkroom.dev> | 2022-11-29 10:29:19 +0000 |
---|---|---|
committer | João Ferreiro <ferreiro@pinkroom.dev> | 2022-11-29 10:29:19 +0000 |
commit | 77ea3bfd0a28f76651ed425cf733abcf01ecaa24 (patch) | |
tree | 53f6806d2ca00366f6f3298e378aa6a59ca17e83 /src/state/models/me.ts | |
parent | 3ce113f1076bbeeffc20888b3a28b2680ada8ab5 (diff) | |
parent | 88c868dd808d204fc29deb162609de984745b951 (diff) | |
download | voidsky-77ea3bfd0a28f76651ed425cf733abcf01ecaa24.tar.zst |
Merge branch 'main' into upload-image
Diffstat (limited to 'src/state/models/me.ts')
-rw-r--r-- | src/state/models/me.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/state/models/me.ts b/src/state/models/me.ts index 78c6d2e76..e3405b80d 100644 --- a/src/state/models/me.ts +++ b/src/state/models/me.ts @@ -1,6 +1,7 @@ import {makeAutoObservable, runInAction} from 'mobx' import {RootStoreModel} from './root-store' import {MembershipsViewModel} from './memberships-view' +import {NotificationsViewModel} from './notifications-view' export class MeModel { did?: string @@ -9,9 +10,11 @@ export class MeModel { description?: string notificationCount: number = 0 memberships?: MembershipsViewModel + notifications: NotificationsViewModel constructor(public rootStore: RootStoreModel) { makeAutoObservable(this, {rootStore: false}, {autoBind: true}) + this.notifications = new NotificationsViewModel(this.rootStore, {}) } clear() { @@ -43,7 +46,12 @@ export class MeModel { this.memberships = new MembershipsViewModel(this.rootStore, { actor: this.did, }) - await this.memberships?.setup() + await this.memberships?.setup().catch(e => { + console.error('Failed to setup memberships model', e) + }) + await this.notifications.setup().catch(e => { + console.error('Failed to setup notifications model', e) + }) } else { this.clear() } @@ -56,7 +64,12 @@ export class MeModel { async fetchStateUpdate() { const res = await this.rootStore.api.app.bsky.notification.getCount() runInAction(() => { + const newNotifications = this.notificationCount !== res.data.count this.notificationCount = res.data.count + if (newNotifications) { + // trigger pre-emptive fetch on new notifications + this.notifications.refresh() + } }) } |