@@ -228,6 +228,32 @@ function MatrixClient(opts) {
228
228
this . _serverSupportsLazyLoading = null ;
229
229
230
230
this . _cachedCapabilities = null ; // { capabilities: {}, lastUpdated: timestamp }
231
+
232
+ // The SDK doesn't really provide a clean way for events to recalculate the push
233
+ // actions for themselves, so we have to kinda help them out when they are encrypted.
234
+ // We do this so that push rules are correctly executed on events in their decrypted
235
+ // state, such as highlights when the user's name is mentioned.
236
+ this . on ( "Event.decrypted" , ( event ) => {
237
+ const oldActions = event . getPushActions ( ) ;
238
+ const actions = this . _pushProcessor . actionsForEvent ( event ) ;
239
+ event . setPushActions ( actions ) ; // Might as well while we're here
240
+
241
+ // Ensure the unread counts are kept up to date if the event is encrypted
242
+ const oldHighlight = oldActions && oldActions . tweaks
243
+ ? ! ! oldActions . tweaks . highlight : false ;
244
+ const newHighlight = actions && actions . tweaks
245
+ ? ! ! actions . tweaks . highlight : false ;
246
+ if ( oldHighlight !== newHighlight ) {
247
+ const room = this . getRoom ( event . getRoomId ( ) ) ;
248
+ // TODO: Handle mentions received while the client is offline
249
+ // See also https://github.com/vector-im/riot-web/issues/9069
250
+ if ( room && ! room . hasUserReadEvent ( this . getUserId ( ) , event . getId ( ) ) ) {
251
+ const current = room . getUnreadNotificationCount ( "highlight" ) ;
252
+ const newCount = newHighlight ? current + 1 : current - 1 ;
253
+ room . setUnreadNotificationCount ( "highlight" , newCount ) ;
254
+ }
255
+ }
256
+ } ) ;
231
257
}
232
258
utils . inherits ( MatrixClient , EventEmitter ) ;
233
259
utils . extend ( MatrixClient . prototype , MatrixBaseApis . prototype ) ;
0 commit comments