@@ -26,6 +26,9 @@ import { ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT, ADDON_MESSAGES_MEMBER_INFO
2626import { CoreAlerts } from '@services/overlays/alerts' ;
2727import { Translate } from '@singletons' ;
2828import { CoreSharedModule } from '@/core/shared.module' ;
29+ import { Subscription } from 'rxjs' ;
30+ import { CorePushNotificationsDelegate } from '@features/pushnotifications/services/push-delegate' ;
31+ import { CorePushNotificationsNotificationBasicData } from '@features/pushnotifications/services/pushnotifications' ;
2932
3033/**
3134 * Page that displays contacts and contact requests.
@@ -42,6 +45,7 @@ export default class AddonMessagesContactsPage implements OnInit, OnDestroy {
4245
4346 readonly splitView = viewChild . required ( CoreSplitViewComponent ) ;
4447
48+ protected pushObserver : Subscription ;
4549 selected : 'confirmed' | 'requests' = 'confirmed' ;
4650 requestsBadge = '' ;
4751 selectedUserId ?: number ; // User id of the conversation opened in the split view.
@@ -103,6 +107,19 @@ export default class AddonMessagesContactsPage implements OnInit, OnDestroy {
103107 CoreSites . getCurrentSiteId ( ) ,
104108 ) ;
105109
110+ this . pushObserver = CorePushNotificationsDelegate . on < CorePushNotificationsNotificationBasicData > ( 'receive' )
111+ . subscribe ( ( notification ) => {
112+ if ( notification . name === 'messagecontactrequests' ) {
113+ AddonMessages . refreshContactRequestsCount ( ) ;
114+
115+ if ( this . requestsLoaded ) {
116+ // Contact requests notification, refresh contact requests list.
117+ this . requestsFetchData ( true ) ;
118+ } else {
119+ AddonMessages . invalidateContactRequestsCache ( ) ;
120+ }
121+ }
122+ } ) ;
106123 }
107124
108125 /**
@@ -310,6 +327,7 @@ export default class AddonMessagesContactsPage implements OnInit, OnDestroy {
310327 */
311328 ngOnDestroy ( ) : void {
312329 this . contactRequestsCountObserver ?. off ( ) ;
330+ this . pushObserver ?. unsubscribe ( ) ;
313331 }
314332
315333}
0 commit comments