@@ -16,7 +16,6 @@ import { isEqual } from 'underscore'
1616interface NotificationsLoadState {
1717 dbNotifications : ReadonlyMap < string , DBNotificationObj > | null
1818 updatedNotifications : Map < string , Omit < DBNotificationObj , 'created' | 'modified' > | null >
19- // createdTimestamps: Map<string, number>
2019
2120 removeAllMissing : boolean
2221}
@@ -67,7 +66,7 @@ export class NotificationsModelHelper implements INotificationsModel {
6766 }
6867
6968 async getAllNotifications ( category : string ) : Promise < INotificationWithTarget [ ] > {
70- const notificationsForCategory = this . #getOrCategoryEntry ( category )
69+ const notificationsForCategory = this . #getOrCreateCategoryEntry ( category )
7170
7271 await this . #getAllNotificationsRaw( notificationsForCategory , category )
7372
@@ -99,14 +98,14 @@ export class NotificationsModelHelper implements INotificationsModel {
9998 }
10099
101100 clearNotification ( category : string , notificationId : string ) : void {
102- const notificationsForCategory = this . #getOrCategoryEntry ( category )
101+ const notificationsForCategory = this . #getOrCreateCategoryEntry ( category )
103102
104103 // The notification may or may not be loaded, but this indicates that to the saving that we intend to delete it
105104 notificationsForCategory . updatedNotifications . set ( notificationId , null )
106105 }
107106
108107 setNotification ( category : string , notification : INotificationWithTarget ) : void {
109- const notificationsForCategory = this . #getOrCategoryEntry ( category )
108+ const notificationsForCategory = this . #getOrCreateCategoryEntry ( category )
110109
111110 const fullCategory = this . #getFullCategoryName( category )
112111 notificationsForCategory . updatedNotifications . set ( notification . id , {
@@ -120,7 +119,7 @@ export class NotificationsModelHelper implements INotificationsModel {
120119 }
121120
122121 clearAllNotifications ( category : string ) : void {
123- const notificationsForCategory = this . #getOrCategoryEntry ( category )
122+ const notificationsForCategory = this . #getOrCreateCategoryEntry ( category )
124123
125124 // Tell this store that any documents not in the `updatedNotifications` should be deleted
126125 notificationsForCategory . removeAllMissing = true
@@ -129,7 +128,7 @@ export class NotificationsModelHelper implements INotificationsModel {
129128 notificationsForCategory . updatedNotifications . clear ( )
130129 }
131130
132- #getOrCategoryEntry ( category : string ) : NotificationsLoadState {
131+ #getOrCreateCategoryEntry ( category : string ) : NotificationsLoadState {
133132 let notificationsForCategory = this . #notificationsByCategory. get ( category )
134133 if ( ! notificationsForCategory ) {
135134 notificationsForCategory = {
@@ -199,9 +198,7 @@ export class NotificationsModelHelper implements INotificationsModel {
199198 updates . push ( {
200199 replaceOne : {
201200 filter : {
202- category : this . #getFullCategoryName( category ) ,
203- localId : localId ,
204- 'relatedTo.studioId' : this . #context. studioId ,
201+ _id : updatedNotification . _id ,
205202 } ,
206203 replacement : {
207204 ...updatedNotification ,
@@ -218,9 +215,9 @@ export class NotificationsModelHelper implements INotificationsModel {
218215 updates . push ( {
219216 deleteMany : {
220217 filter : {
218+ 'relatedTo.studioId' : this . #context. studioId ,
221219 category : this . #getFullCategoryName( category ) ,
222220 localId : { $nin : localIdsToKeep } ,
223- 'relatedTo.studioId' : this . #context. studioId ,
224221 } ,
225222 } ,
226223 } )
@@ -229,9 +226,9 @@ export class NotificationsModelHelper implements INotificationsModel {
229226 updates . push ( {
230227 deleteMany : {
231228 filter : {
229+ 'relatedTo.studioId' : this . #context. studioId ,
232230 category : this . #getFullCategoryName( category ) ,
233231 localId : { $in : localIdsToDelete } ,
234- 'relatedTo.studioId' : this . #context. studioId ,
235232 } ,
236233 } ,
237234 } )
0 commit comments