Skip to content

Commit f5e628b

Browse files
authored
Merge pull request #4708 from alfonso-salces/MOBILE-4332
MOBILE-4332 messages: Update contact request on push received
2 parents 5061546 + db243a5 commit f5e628b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/addons/messages/pages/contacts/contacts.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import { ADDON_MESSAGES_CONTACT_REQUESTS_COUNT_EVENT, ADDON_MESSAGES_MEMBER_INFO
2626
import { CoreAlerts } from '@services/overlays/alerts';
2727
import { Translate } from '@singletons';
2828
import { 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

Comments
 (0)