@@ -54,7 +54,7 @@ describe("fixNotificationCountOnDecryption", () => {
54
54
mockClient = getMockClientWithEventEmitter ( {
55
55
...mockClientMethodsUser ( ) ,
56
56
isInitialSyncComplete : jest . fn ( ) . mockReturnValue ( false ) ,
57
- getPushActionsForEvent : jest . fn ( ) . mockReturnValue ( mkPushAction ( true , true ) ) ,
57
+ getPushActionsForEvent : jest . fn ( ( ev ) => event . getPushActions ( ) ?? mkPushAction ( true , true ) ) ,
58
58
getRoom : jest . fn ( ) . mockImplementation ( ( ) => room ) ,
59
59
decryptEventIfNeeded : jest . fn ( ) . mockResolvedValue ( void 0 ) ,
60
60
supportsThreads : jest . fn ( ) . mockReturnValue ( true ) ,
@@ -125,15 +125,15 @@ describe("fixNotificationCountOnDecryption", () => {
125
125
room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Total , 1 ) ;
126
126
room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Highlight , 0 ) ;
127
127
128
- event . getPushActions = jest . fn ( ) . mockReturnValue ( mkPushAction ( false , false ) ) ;
129
- threadEvent . getPushActions = jest . fn ( ) . mockReturnValue ( mkPushAction ( false , false ) ) ;
128
+ event . getPushActions = jest . fn ( ) . mockReturnValue ( mkPushAction ( true , true ) ) ;
129
+ threadEvent . getPushActions = jest . fn ( ) . mockReturnValue ( mkPushAction ( true , true ) ) ;
130
130
} ) ;
131
131
132
132
it ( "changes the room count to highlight on decryption" , ( ) => {
133
133
expect ( room . getUnreadNotificationCount ( NotificationCountType . Total ) ) . toBe ( 2 ) ;
134
134
expect ( room . getUnreadNotificationCount ( NotificationCountType . Highlight ) ) . toBe ( 0 ) ;
135
135
136
- fixNotificationCountOnDecryption ( mockClient , event ) ;
136
+ fixNotificationCountOnDecryption ( mockClient , event , { } ) ;
137
137
138
138
expect ( room . getUnreadNotificationCount ( NotificationCountType . Total ) ) . toBe ( 3 ) ;
139
139
expect ( room . getUnreadNotificationCount ( NotificationCountType . Highlight ) ) . toBe ( 1 ) ;
@@ -143,7 +143,7 @@ describe("fixNotificationCountOnDecryption", () => {
143
143
room . setUnreadNotificationCount ( NotificationCountType . Total , 0 ) ;
144
144
room . setUnreadNotificationCount ( NotificationCountType . Highlight , 0 ) ;
145
145
146
- fixNotificationCountOnDecryption ( mockClient , event ) ;
146
+ fixNotificationCountOnDecryption ( mockClient , event , { } ) ;
147
147
148
148
expect ( room . getRoomUnreadNotificationCount ( NotificationCountType . Total ) ) . toBe ( 1 ) ;
149
149
expect ( room . getRoomUnreadNotificationCount ( NotificationCountType . Highlight ) ) . toBe ( 1 ) ;
@@ -153,7 +153,7 @@ describe("fixNotificationCountOnDecryption", () => {
153
153
expect ( room . getThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Total ) ) . toBe ( 1 ) ;
154
154
expect ( room . getThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Highlight ) ) . toBe ( 0 ) ;
155
155
156
- fixNotificationCountOnDecryption ( mockClient , threadEvent ) ;
156
+ fixNotificationCountOnDecryption ( mockClient , threadEvent , { } ) ;
157
157
158
158
expect ( room . getThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Total ) ) . toBe ( 2 ) ;
159
159
expect ( room . getThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Highlight ) ) . toBe ( 1 ) ;
@@ -163,7 +163,7 @@ describe("fixNotificationCountOnDecryption", () => {
163
163
room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Total , 0 ) ;
164
164
room . setThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Highlight , 0 ) ;
165
165
166
- fixNotificationCountOnDecryption ( mockClient , event ) ;
166
+ fixNotificationCountOnDecryption ( mockClient , event , { } ) ;
167
167
168
168
expect ( room . getThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Total ) ) . toBe ( 0 ) ;
169
169
expect ( room . getThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Highlight ) ) . toBe ( 0 ) ;
@@ -187,7 +187,7 @@ describe("fixNotificationCountOnDecryption", () => {
187
187
event : true ,
188
188
} ) ;
189
189
190
- fixNotificationCountOnDecryption ( mockClient , unknownThreadEvent ) ;
190
+ fixNotificationCountOnDecryption ( mockClient , unknownThreadEvent , { } ) ;
191
191
192
192
expect ( room . getThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Total ) ) . toBe ( 0 ) ;
193
193
expect ( room . getThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Highlight ) ) . toBe ( 0 ) ;
@@ -201,7 +201,7 @@ describe("fixNotificationCountOnDecryption", () => {
201
201
event . getPushActions = jest . fn ( ) . mockReturnValue ( mkPushAction ( true , false ) ) ;
202
202
mockClient . getPushActionsForEvent = jest . fn ( ) . mockReturnValue ( mkPushAction ( false , false ) ) ;
203
203
204
- fixNotificationCountOnDecryption ( mockClient , event ) ;
204
+ fixNotificationCountOnDecryption ( mockClient , event , { } ) ;
205
205
expect ( room . getUnreadNotificationCount ( NotificationCountType . Total ) ) . toBe ( 0 ) ;
206
206
expect ( room . getUnreadNotificationCount ( NotificationCountType . Highlight ) ) . toBe ( 0 ) ;
207
207
} ) ;
@@ -213,7 +213,7 @@ describe("fixNotificationCountOnDecryption", () => {
213
213
threadEvent . getPushActions = jest . fn ( ) . mockReturnValue ( mkPushAction ( true , false ) ) ;
214
214
mockClient . getPushActionsForEvent = jest . fn ( ) . mockReturnValue ( mkPushAction ( false , false ) ) ;
215
215
216
- fixNotificationCountOnDecryption ( mockClient , event ) ;
216
+ fixNotificationCountOnDecryption ( mockClient , event , { } ) ;
217
217
expect ( room . getThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Total ) ) . toBe ( 0 ) ;
218
218
expect ( room . getThreadUnreadNotificationCount ( THREAD_ID , NotificationCountType . Highlight ) ) . toBe ( 0 ) ;
219
219
} ) ;
@@ -231,4 +231,15 @@ describe("fixNotificationCountOnDecryption", () => {
231
231
room . setThreadUnreadNotificationCount ( "$123" , NotificationCountType . Highlight , 5 ) ;
232
232
expect ( cb ) . toHaveBeenLastCalledWith ( { highlight : 5 } , "$123" ) ;
233
233
} ) ;
234
+
235
+ it ( "should not increment notification count where event was already contributing notification" , ( ) => {
236
+ expect ( room . getUnreadNotificationCount ( NotificationCountType . Total ) ) . toBe ( 2 ) ;
237
+ expect ( room . getUnreadNotificationCount ( NotificationCountType . Highlight ) ) . toBe ( 0 ) ;
238
+
239
+ event . getPushActions = jest . fn ( ) . mockReturnValue ( mkPushAction ( true , false ) ) ;
240
+ fixNotificationCountOnDecryption ( mockClient , event , { actions : { notify : true , tweaks : { } } } ) ;
241
+
242
+ expect ( room . getUnreadNotificationCount ( NotificationCountType . Total ) ) . toBe ( 2 ) ;
243
+ expect ( room . getUnreadNotificationCount ( NotificationCountType . Highlight ) ) . toBe ( 0 ) ;
244
+ } ) ;
234
245
} ) ;
0 commit comments