Skip to content

Commit 4584dbc

Browse files
authored
Fix notification settings issues and add settings to Site Details (#24134)
* Extract ReaderSubscriptionNotificationSettingsButton * Slightly tweak the spacings in NotificationSiteSubscriptionViewController * Fix an issue with bell status not reloading in the list when changing subscription * Update the logic for determining when to show bell-and-waves * Update release notes * Update the share buttons
1 parent 821c784 commit 4584dbc

File tree

9 files changed

+103
-68
lines changed

9 files changed

+103
-68
lines changed

RELEASE-NOTES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
* [*] Fix Reader: Opening comments is slow [#21887]
2525
* [*] Fix an issue with comments button being disabled when shown from Comments or Notifications [#24120]
2626
* [*] Fix unexpected "unsaved changes" notice when closing an un-edited post containing media in the experimental editor [#24102]
27+
* [*] Add "Notification Settings" bell to the "Site Details" screen [#24134]
28+
* [*] Fix an issue where the "Notifications Settings" bell for site subscriptions was not updated after the changes [#24134]
29+
* [*] Update the logic behind the bell. It now show the "bell with waves" when push notifications are enabled [#24134]
2730

2831
25.7
2932
-----

WordPress/Classes/Models/ReaderSiteTopic.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ import Foundation
4848
return postSubscription?.sendPosts ?? false
4949
}
5050

51+
var canManageNotifications: Bool {
52+
!isExternal
53+
}
54+
5155
/// Creates a new ReaderTagTopic object from a RemoteReaderInterest
5256
convenience init(remoteInfo: RemoteReaderSiteInfo, context: NSManagedObjectContext) {
5357
self.init(context: context)

WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSiteSubscriptionViewController.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ class NotificationSiteSubscriptionViewController: UITableViewController {
132132
// Hide the separators, whenever the table is empty
133133
tableView.tableFooterView = UIView()
134134

135+
tableView.tableHeaderView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 0.0, height: 8))
136+
tableView.sectionHeaderHeight = 12
137+
135138
// Style!
136139
WPStyleGuide.configureColors(view: view, tableView: tableView)
137140
WPStyleGuide.configureAutomaticHeightRows(for: tableView)

WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController+Sharing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extension ReaderStreamViewController {
1515
removeShareButton()
1616
return
1717
}
18-
let button = UIBarButtonItem(title: nil, image: UIImage(systemName: "square.and.arrow.up"), target: self, action: #selector(shareButtonTapped))
18+
let button = UIBarButtonItem(title: nil, image: UIImage(named: "wpl-share"), target: self, action: #selector(shareButtonTapped))
1919
button.tag = NavigationItemTag.share.rawValue
2020
button.accessibilityLabel = SharedStrings.Button.share
2121
addRightBarButtonItem(button)

WordPress/Classes/ViewRelated/Reader/Detail/ReaderDetailViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ private extension ReaderDetailViewController {
11251125
}
11261126

11271127
func shareButtonItem(enabled: Bool = true) -> UIBarButtonItem? {
1128-
let button = barButtonItem(with: .gridicon(.shareiOS), action: #selector(didTapShareButton(_:)))
1128+
let button = barButtonItem(with: UIImage(named: "wpl-share") ?? UIImage(), action: #selector(didTapShareButton(_:)))
11291129
button.accessibilityLabel = SharedStrings.Button.share
11301130
button.isEnabled = enabled
11311131

WordPress/Classes/ViewRelated/Reader/Headers/ReaderSiteHeaderView.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class ReaderSiteHeaderView: ReaderBaseHeaderView, ReaderStreamHeader {
4545
// MARK: - ReaderSiteHeader
4646

4747
private struct ReaderSiteHeader: View {
48-
4948
@ObservedObject var viewModel: ReaderSiteHeaderViewModel
5049

5150
var body: some View {
@@ -74,10 +73,21 @@ private struct ReaderSiteHeader: View {
7473
if viewModel.site?.isExternal == false {
7574
countsDisplay
7675
}
77-
ReaderFollowButton(isFollowing: viewModel.isFollowingSite,
78-
isEnabled: viewModel.isFollowEnabled,
79-
size: .regular) {
80-
viewModel.updateFollowStatus()
76+
HStack {
77+
ReaderFollowButton(isFollowing: viewModel.isFollowingSite,
78+
isEnabled: viewModel.isFollowEnabled,
79+
size: .regular) {
80+
viewModel.updateFollowStatus()
81+
}
82+
if let site = viewModel.site, site.canManageNotifications {
83+
ReaderSubscriptionNotificationSettingsButton(site: site)
84+
.padding(.horizontal, 2)
85+
.padding(.vertical, 8)
86+
.overlay(
87+
RoundedRectangle(cornerRadius: 5)
88+
.stroke(Color(.separator), lineWidth: 1)
89+
)
90+
}
8191
}
8292
}
8393
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
@@ -107,7 +117,6 @@ private struct ReaderSiteHeader: View {
107117
"'%2$@' is a placeholder for the blog subscriber count. " +
108118
"Example: `5,000 posts • 10M subscribers`")
109119
}
110-
111120
}
112121

113122
// MARK: - ReaderSiteHeaderViewModel
@@ -148,5 +157,4 @@ private final class ReaderSiteHeaderViewModel: ObservableObject {
148157
self?.isFollowEnabled = true
149158
}
150159
}
151-
152160
}

WordPress/Classes/ViewRelated/Reader/Subscriptions/ReaderSubscriptionCell.swift

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct ReaderSubscriptionCell: View {
3939
Spacer()
4040

4141
HStack(spacing: 0) {
42-
if let status = ReaderSubscriptionNotificationsStatus(site: site) {
43-
makeButtonNotificationSettings(with: status)
42+
if site.canManageNotifications {
43+
ReaderSubscriptionNotificationSettingsButton(site: site)
4444
}
4545
buttonMore
4646
}
@@ -53,36 +53,6 @@ struct ReaderSubscriptionCell: View {
5353
})
5454
}
5555

56-
private func makeButtonNotificationSettings(with status: ReaderSubscriptionNotificationsStatus) -> some View {
57-
Button {
58-
isShowingSettings = true
59-
} label: {
60-
Group {
61-
switch status {
62-
case .all:
63-
Image(systemName: "bell.and.waves.left.and.right")
64-
.foregroundStyle(AppColor.primary)
65-
case .personalized:
66-
Image(systemName: "bell")
67-
.foregroundStyle(AppColor.primary)
68-
case .none:
69-
Image(systemName: "bell.slash")
70-
.foregroundStyle(.secondary)
71-
.opacity(0.6)
72-
}
73-
}
74-
.font(.subheadline)
75-
.frame(width: 34, alignment: .center)
76-
.contentShape(Rectangle())
77-
}
78-
.buttonStyle(.plain)
79-
.sheet(isPresented: $isShowingSettings) {
80-
ReaderSubscriptionNotificationSettingsView(siteID: site.siteID.intValue)
81-
.presentationDetents([.medium, .large])
82-
.edgesIgnoringSafeArea(.bottom)
83-
}
84-
}
85-
8656
private var buttonMore: some View {
8757
Menu {
8858
ReaderSubscriptionContextMenu(site: site, isShowingSettings: $isShowingSettings)

WordPress/Classes/ViewRelated/Reader/Subscriptions/ReaderSubscriptionHelper.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,30 +98,3 @@ private func makeURL(fromUserInput string: String) -> URL? {
9898
}
9999
return nil
100100
}
101-
102-
enum ReaderSubscriptionNotificationsStatus {
103-
/// Receives both posts and notifications
104-
case all
105-
/// Receives some notifications
106-
case personalized
107-
/// Receives none
108-
case none
109-
110-
init?(site: ReaderSiteTopic) {
111-
guard !site.isExternal else {
112-
return nil
113-
}
114-
let posts = site.postSubscription
115-
let emails = site.emailSubscription
116-
117-
let sendPosts = (posts?.sendPosts ?? false) || (emails?.sendPosts ?? false)
118-
let sendComments = emails?.sendComments ?? false
119-
if sendPosts && sendComments {
120-
self = .all
121-
} else if sendPosts || sendComments {
122-
self = .personalized
123-
} else {
124-
self = .none
125-
}
126-
}
127-
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import SwiftUI
2+
3+
struct ReaderSubscriptionNotificationSettingsButton: View {
4+
@ObservedObject var site: ReaderSiteTopic
5+
6+
@State private var isShowingSettings = false
7+
@State private var status: ReaderSubscriptionNotificationsStatus = .none
8+
9+
var body: some View {
10+
Button {
11+
isShowingSettings = true
12+
} label: {
13+
Group {
14+
switch status {
15+
case .notify:
16+
Image(systemName: "bell.and.waves.left.and.right")
17+
.foregroundStyle(AppColor.primary)
18+
case .personalized:
19+
Image(systemName: "bell")
20+
.foregroundStyle(AppColor.primary)
21+
case .none:
22+
Image(systemName: "bell.slash")
23+
.foregroundStyle(.secondary)
24+
.opacity(0.6)
25+
}
26+
}
27+
.font(.subheadline)
28+
.frame(width: 34, alignment: .center)
29+
.contentShape(Rectangle())
30+
}
31+
.buttonStyle(.plain)
32+
.sheet(isPresented: $isShowingSettings) {
33+
ReaderSubscriptionNotificationSettingsView(siteID: site.siteID.intValue)
34+
.presentationDetents([.medium, .large])
35+
.edgesIgnoringSafeArea(.bottom)
36+
}
37+
.onReceive(site.emailSubscription?.objectWillChange ?? .init()) {
38+
refresh()
39+
}
40+
.onReceive(site.postSubscription?.objectWillChange ?? .init()) {
41+
refresh()
42+
}
43+
.onAppear { refresh() }
44+
}
45+
46+
private func refresh() {
47+
status = ReaderSubscriptionNotificationsStatus(site: site)
48+
}
49+
}
50+
51+
private enum ReaderSubscriptionNotificationsStatus {
52+
/// Receive push notifications.
53+
case notify
54+
/// Receives emails notifications.
55+
case personalized
56+
/// Receives none.
57+
case none
58+
59+
init(site: ReaderSiteTopic) {
60+
let notifications = site.postSubscription
61+
let emails = site.emailSubscription
62+
63+
let sendNotifications = notifications?.sendPosts ?? false
64+
let sendEmails = (emails?.sendPosts ?? false) || (emails?.sendComments ?? false)
65+
66+
if sendNotifications {
67+
self = .notify
68+
} else if sendEmails {
69+
self = .personalized
70+
} else {
71+
self = .none
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)