Skip to content

Commit 34b5eda

Browse files
committed
fix: reversed the implementation of the reviews notification badge count in the hub menu due to an issue described in a comment.
1 parent 64e6b9b commit 34b5eda

File tree

2 files changed

+8
-34
lines changed

2 files changed

+8
-34
lines changed

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenu.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ struct HubMenu: View {
3030

3131
LazyVGrid(columns: gridItemLayout, spacing: Constants.itemSpacing) {
3232
ForEach(viewModel.menuElements, id: \.self) { menu in
33-
let badgeCount = menu == .reviews ? viewModel.reviewsNotificationBadgeCount : 0
34-
HubMenuElement(image: menu.icon, imageColor: menu.iconColor, text: menu.title, badge: badgeCount, onTapGesture: {
33+
// Currently the badge is always zero, because we are not handling push notifications count
34+
// correctly due to the first behavior described here p91TBi-66O:
35+
// AppDelegate’s `application(_:didReceiveRemoteNotification:fetchCompletionHandler:)`
36+
// can be called twice for the same push notification when receiving it
37+
// and tapping on it to open the app. This means that some push notifications are incrementing the badge number by 2, and some by 1.
38+
HubMenuElement(image: menu.icon, imageColor: menu.iconColor, text: menu.title, badge: 0, onTapGesture: {
3539
switch menu {
3640
case .woocommerceAdmin:
3741
ServiceLocator.analytics.track(.hubMenuOptionTapped, withProperties: [Constants.option: "admin_menu"])

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenuViewModel.swift

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ final class HubMenuViewModel: ObservableObject {
4343

4444
@Published var showingReviewDetail = false
4545

46-
@Published var reviewsNotificationBadgeCount = 0
47-
4846
private var productReviewFromNoteParcel: ProductReviewFromNoteParcel?
4947

5048
private var storePickerCoordinator: StorePickerCoordinator?
@@ -59,8 +57,6 @@ final class HubMenuViewModel: ObservableObject {
5957
menuElements.append(.coupons)
6058
}
6159
observeSiteForUIUpdates()
62-
startListeningToReviewsBadgeUpdates()
63-
loadReviewsNotificationCountAndUpdateBadge()
6460
}
6561

6662
/// Present the `StorePickerViewController` using the `StorePickerCoordinator`, passing the navigation controller from the entry point.
@@ -87,38 +83,12 @@ final class HubMenuViewModel: ObservableObject {
8783
}
8884

8985
private func observeSiteForUIUpdates() {
90-
ServiceLocator.stores.site.sink { [weak self] site in
91-
self?.loadReviewsNotificationCountAndUpdateBadge()
86+
ServiceLocator.stores.site.sink { site in
87+
// This will be useful in the future for updating some info of the screen depending on the store site info
9288
}.store(in: &cancellables)
9389
}
9490
}
9591

96-
// MARK: - Hub Menu Badges Updates
97-
//
98-
private extension HubMenuViewModel {
99-
100-
/// Setup: KVO Hooks.
101-
///
102-
func startListeningToReviewsBadgeUpdates() {
103-
NotificationCenter.default.addObserver(self,
104-
selector: #selector(loadReviewsNotificationCountAndUpdateBadge),
105-
name: .reviewsBadgeReloadRequired,
106-
object: nil)
107-
}
108-
109-
@objc func loadReviewsNotificationCountAndUpdateBadge() {
110-
let stores: StoresManager = ServiceLocator.stores
111-
guard let siteID = stores.sessionManager.defaultStoreID else {
112-
return
113-
}
114-
115-
let action = NotificationCountAction.load(siteID: siteID, type: .kind(.comment)) { [weak self] count in
116-
self?.reviewsNotificationBadgeCount = count
117-
}
118-
stores.dispatch(action)
119-
}
120-
}
121-
12292
extension HubMenuViewModel {
12393
enum Menu: CaseIterable {
12494
case woocommerceAdmin

0 commit comments

Comments
 (0)