Skip to content

Commit 2b837e2

Browse files
committed
feat(news): hook settings to the backend
Fixes #17811 Hooks the NewsFeedNotification setting and the RSS setting to the backend. The Notification setting has a bit of complexity on the service side, because while the UI setting is a select of 3 options, the status-go settings are actually 2 bool settings. So the service does some logic to set the right setting from those two. The settings are used to disable the polling if one of the settings is disabled. If the setting is on DeliverQuietly, the AC notif is shown, but no notificaiton
1 parent dc11a2b commit 2b837e2

File tree

11 files changed

+170
-13
lines changed

11 files changed

+170
-13
lines changed

src/app/core/notifications/notifications_manager.nim

+9-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ QtObject:
241241
details.notificationType == NotificationType.NewMessageWithGlobalMention or
242242
details.notificationType == NotificationType.NewContactRequest or
243243
details.notificationType == NotificationType.ContactRemoved or
244-
details.notificationType == NotificationType.IdentityVerificationRequest:
244+
details.notificationType == NotificationType.IdentityVerificationRequest or
245+
details.notificationType == NotificationType.NewsFeedMessage:
245246

246247
if notificationWay == VALUE_NOTIF_DELIVER_QUIETLY:
247248
return
@@ -293,6 +294,13 @@ QtObject:
293294
self.notificationCheck(title, message, details, self.settingsService.getNotifSettingContactRequests())
294295
return
295296

297+
# In case of News message
298+
elif details.notificationType == NotificationType.NewsFeedMessage:
299+
let newsSetting = self.settingsService.getNotifSettingStatusNews()
300+
if newsSetting != VALUE_NOTIF_TURN_OFF:
301+
self.notificationCheck(title, message, details, newsSetting)
302+
return
303+
296304
# In case of new message (regardless it's message with mention or not)
297305
elif(details.notificationType == NotificationType.NewMessage or
298306
details.notificationType == NotificationType.NewMessageWithPersonalMention or

src/app_service/service/settings/dto/settings.nim

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const PROFILE_MIGRATION_NEEDED* = "profile-migration-needed"
5555
const KEY_URL_UNFURLING_MODE* = "url-unfurling-mode"
5656
const KEY_AUTO_REFRESH_TOKENS* = "auto-refresh-tokens-enabled"
5757
const KEY_LAST_TOKENS_UPDATE* = "last-tokens-update"
58+
const KEY_NEWS_FEED_ENABLED* = "news-feed-enabled?"
59+
const KEY_NEWS_NOTIFICATIONS_ENABLED* = "news-notifications-enabled?"
60+
const KEY_NEWS_RSS_ENABLED* = "news-rss-enabled?"
5861

5962
# Notifications Settings Values
6063
const VALUE_NOTIF_SEND_ALERTS* = "SendAlerts"
@@ -145,6 +148,9 @@ type
145148
gifRecents*: JsonNode
146149
gifFavorites*: JsonNode
147150
testNetworksEnabled*: bool
151+
newsFeedEnabled*: bool
152+
newsNotificationsEnabled*: bool
153+
newsRSSEnabled*: bool
148154
notificationsAllowNotifications*: bool
149155
notificationsOneToOneChats*: string
150156
notificationsGroupChats*: string
@@ -249,6 +255,10 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
249255
discard jsonObj.getProp(KEY_NODE_CONFIG, result.nodeConfig)
250256
discard jsonObj.getProp(KEY_WAKU_BLOOM_FILTER_MODE, result.wakuBloomFilterMode)
251257

258+
discard jsonObj.getProp(KEY_NEWS_FEED_ENABLED, result.newsFeedEnabled)
259+
discard jsonObj.getProp(KEY_NEWS_NOTIFICATIONS_ENABLED, result.newsNotificationsEnabled)
260+
discard jsonObj.getProp(KEY_NEWS_RSS_ENABLED, result.newsRSSEnabled)
261+
252262
var usernamesArr: JsonNode
253263
if (jsonObj.getProp(KEY_ENS_USERNAMES, usernamesArr)):
254264
if (usernamesArr.kind == JArray):

src/app_service/service/settings/service.nim

+116
Original file line numberDiff line numberDiff line change
@@ -985,3 +985,119 @@ QtObject:
985985
except ValueError:
986986
error "parse lastTokensUpdate: ", lastTokensUpdate
987987
return self.settings.lastTokensUpdate
988+
989+
### News Feed Settings ###
990+
proc notifSettingStatusNewsChanged*(self: Service) {.signal.}
991+
992+
proc toggleNewsFeedEnabled*(self: Service, value: bool): bool =
993+
try:
994+
let response = status_settings.toggleNewsFeedEnabled(value)
995+
if not response.error.isNil:
996+
raise newException(RpcException, response.error.message)
997+
998+
self.settings.newsFeedEnabled = value
999+
self.notifSettingStatusNewsChanged()
1000+
return true
1001+
except Exception as e:
1002+
error "error: ", procName="toggleNewsFeedEnabled", errName = e.name, errDesription = e.msg
1003+
return false
1004+
1005+
proc getNotifSettingStatusNews*(self: Service): string {.slot.} =
1006+
result = VALUE_NOTIF_SEND_ALERTS # Default value
1007+
1008+
var newsFeedEnabled = false
1009+
var newsNotificationsEnabled = false
1010+
1011+
if self.initialized:
1012+
newsFeedEnabled = self.settings.newsFeedEnabled
1013+
newsNotificationsEnabled = self.settings.newsNotificationsEnabled
1014+
else:
1015+
try:
1016+
var response = status_settings.newsFeedEnabled()
1017+
if not response.error.isNil:
1018+
error "error reading news feed enabled setting: ", errDescription = response.error.message
1019+
return
1020+
newsFeedEnabled = response.result.getBool
1021+
1022+
response = status_settings.newsNotificationsEnabled()
1023+
if not response.error.isNil:
1024+
error "error reading news notifications enabled setting: ", errDescription = response.error.message
1025+
return
1026+
newsNotificationsEnabled = response.result.getBool
1027+
except Exception as e:
1028+
let errDesription = e.msg
1029+
error "reading news settings error: ", errDesription
1030+
return
1031+
1032+
# We convert the bools to the right setting
1033+
# Send alerts means the News Feed is enabled + notifications are enabled
1034+
# Deliver quietly means the News Feed is enabled + notifications are disabled
1035+
# Turn off means the News Feed is disabled
1036+
if not newsFeedEnabled:
1037+
return VALUE_NOTIF_TURN_OFF
1038+
if not newsNotificationsEnabled:
1039+
return VALUE_NOTIF_DELIVER_QUIETLY
1040+
return VALUE_NOTIF_SEND_ALERTS
1041+
1042+
proc setNotifSettingStatusNews*(self: Service, value: string) {.slot.} =
1043+
var newsFeedEnabled = false
1044+
var newsNotificationsEnabled = false
1045+
# We need to convert the string value to the right setting to turn off
1046+
case value
1047+
of VALUE_NOTIF_SEND_ALERTS:
1048+
# Send alerts means the News Feed is enabled + notifications are enabled
1049+
newsFeedEnabled = true
1050+
newsNotificationsEnabled = true
1051+
of VALUE_NOTIF_TURN_OFF:
1052+
# Turn off means the News Feed is disabled + notifications are disabled
1053+
newsFeedEnabled = false
1054+
newsNotificationsEnabled = false
1055+
of VALUE_NOTIF_DELIVER_QUIETLY:
1056+
# Deliver quietly means the News Feed is enabled + notifications are disabled
1057+
newsFeedEnabled = true
1058+
newsNotificationsEnabled = false
1059+
else:
1060+
error "error: ", procName="setNotifSettingStatusNews", errDescription = "Unknown value: ", value
1061+
return
1062+
1063+
if not self.saveSetting(KEY_NEWS_NOTIFICATIONS_ENABLED, newsNotificationsEnabled):
1064+
return
1065+
self.settings.newsNotificationsEnabled = newsNotificationsEnabled
1066+
1067+
# toggleNewsFeedEnabled changes the value and calls the signals
1068+
discard self.toggleNewsFeedEnabled(newsFeedEnabled)
1069+
QtProperty[string] notifSettingStatusNews:
1070+
read = getNotifSettingStatusNews
1071+
write = setNotifSettingStatusNews
1072+
notify = notifSettingStatusNewsChanged
1073+
1074+
proc newsRSSEnabledChanged*(self: Service) {.signal.}
1075+
proc getNewsRSSEnabled*(self: Service): bool {.slot.} =
1076+
if self.initialized:
1077+
return self.settings.newsRSSEnabled
1078+
1079+
result = true #default value
1080+
try:
1081+
let response = status_settings.newsRSSEnabled()
1082+
if(not response.error.isNil):
1083+
raise newException(RpcException, response.error.message)
1084+
result = response.result.getBool
1085+
except Exception as e:
1086+
let errDesription = e.msg
1087+
error "reading news RSS setting error: ", errDesription
1088+
1089+
proc setNewsRSSEnabled*(self: Service, value: bool) {.slot.} =
1090+
try:
1091+
let response = status_settings.toggleNewsRSSEnabled(value)
1092+
if not response.error.isNil:
1093+
raise newException(RpcException, response.error.message)
1094+
1095+
self.settings.newsRSSEnabled = value
1096+
self.newsRSSEnabledChanged()
1097+
except Exception as e:
1098+
error "error: ", procName="toggleNewsRSSEnabled", errName = e.name, errDesription = e.msg
1099+
1100+
QtProperty[bool] newsRSSEnabled:
1101+
read = getNewsRSSEnabled
1102+
write = setNewsRSSEnabled
1103+
notify = newsRSSEnabledChanged

src/backend/settings.nim

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
import ./core, ./response_type
2+
import ./core, ./response_type, ../app_service/common/utils
33

44
export response_type
55

@@ -94,4 +94,19 @@ proc mnemonicWasShown*(): RpcResponse[JsonNode] =
9494
return core.callPrivateRPC("settings_mnemonicWasShown")
9595

9696
proc lastTokensUpdate*(): RpcResponse[JsonNode] =
97-
return core.callPrivateRPC("settings_lastTokensUpdate")
97+
return core.callPrivateRPC("settings_lastTokensUpdate")
98+
99+
proc newsFeedEnabled*(): RpcResponse[JsonNode] =
100+
return core.callPrivateRPC("settings_newsFeedEnabled")
101+
102+
proc newsNotificationsEnabled*(): RpcResponse[JsonNode] =
103+
return core.callPrivateRPC("settings_newsNotificationsEnabled")
104+
105+
proc newsRSSEnabled*(): RpcResponse[JsonNode] =
106+
return core.callPrivateRPC("settings_newsRSSEnabled")
107+
108+
proc toggleNewsFeedEnabled*(value: bool): RpcResponse[JsonNode] =
109+
return core.callPrivateRPC("toggleNewsFeedEnabled".prefix, %*[value])
110+
111+
proc toggleNewsRSSEnabled*(value: bool): RpcResponse[JsonNode] =
112+
result = core.callPrivateRPC("toggleNewsRSSEnabled".prefix, %*[ value ])

ui/app/AppLayouts/Profile/ProfileLayout.qml

+3-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,9 @@ StatusSectionLayout {
527527
sectionTitle: settingsEntriesModel.getNameForSubsection(Constants.settingsSubsection.privacyAndSecurity)
528528
contentWidth: d.contentWidth
529529

530-
onIsStatusNewsViaRSSEnabledChanged: root.store.privacyStore.isStatusNewsViaRSSEnabled = isStatusNewsViaRSSEnabled
530+
onSetNewsRSSEnabledRequested: function (isStatusNewsViaRSSEnabled) {
531+
root.store.privacyStore.setNewsRSSEnabled(isStatusNewsViaRSSEnabled)
532+
}
531533
}
532534
}
533535
}

ui/app/AppLayouts/Profile/stores/NotificationsStore.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ QtObject {
55
id: root
66

77
property var notificationsModule
8-
property var notificationsSettings: appSettings /*TODO: Add appSettings.notifSettingStatusNews notifiable property in the backend*/
8+
property var notificationsSettings: appSettings
99

1010
property var exemptionsModel: notificationsModule.exemptionsModel
1111

ui/app/AppLayouts/Profile/stores/PrivacyStore.qml

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ QtObject {
1111
readonly property string keyUid: userProfile.keyUid
1212

1313
// The following properties wrap Privacy and Security View related properties:
14-
property bool isStatusNewsViaRSSEnabled: true /*TODO: Connect it to the backend corresponding property*/
14+
property bool isStatusNewsViaRSSEnabled: appSettings.newsRSSEnabled
1515

16-
onIsStatusNewsViaRSSEnabledChanged: console.warn("TODO: Connect it to the backend corresponding setting: " + isStatusNewsViaRSSEnabled)
16+
function setNewsRSSEnabled(isStatusNewsViaRSSEnabled) {
17+
appSettings.newsRSSEnabled = isStatusNewsViaRSSEnabled
18+
}
1719

1820
function changePassword(password, newPassword) {
1921
root.privacyModule.changePassword(password, newPassword)

ui/app/AppLayouts/Profile/views/NotificationsView.qml

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ SettingsContentBase {
311311
visible: !root.privacyStore.isStatusNewsViaRSSEnabled
312312
text: qsTr("Enable RSS")
313313

314-
onClicked: root.privacyStore.isStatusNewsViaRSSEnabled = true
314+
onClicked: root.privacyStore.setNewsRSSEnabled(true)
315315
},
316316
NotificationSelect {
317317
visible: root.privacyStore.isStatusNewsViaRSSEnabled

ui/app/AppLayouts/Profile/views/PrivacyAndSecurityView.qml

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import StatusQ.Controls 0.1
1010
SettingsContentBase {
1111
id: root
1212

13-
property alias isStatusNewsViaRSSEnabled: statusNewsSwitch.checked
13+
property bool isStatusNewsViaRSSEnabled
1414
required property bool isCentralizedMetricsEnabled
1515

16+
signal setNewsRSSEnabledRequested(bool isStatusNewsViaRSSEnabled)
17+
1618
function refreshSwitch() {
1719
enableMetricsSwitch.checked = Qt.binding(function() { return root.isCentralizedMetricsEnabled })
1820
}
@@ -30,9 +32,11 @@ SettingsContentBase {
3032
components: [
3133
StatusSwitch {
3234
id: statusNewsSwitch
35+
checked: root.isStatusNewsViaRSSEnabled
36+
onToggled: root.setNewsRSSEnabledRequested(statusNewsSwitch.checked)
3337
}
3438
]
35-
onClicked: statusNewsSwitch.checked = !statusNewsSwitch.checked
39+
onClicked: root.setNewsRSSEnabledRequested(!statusNewsSwitch.checked)
3640
}
3741
StatusListItem {
3842
Layout.preferredWidth: root.contentWidth

ui/app/mainui/activitycenter/popups/ActivityCenterPopup.qml

+2-2
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,8 @@ Popup {
595595
font.pixelSize: Theme.additionalTextSize
596596

597597
onClicked: {
598-
if(isEnableRSSNotificationPanelType) {
599-
root.privacyStore.isStatusNewsViaRSSEnabled = true
598+
if (isEnableRSSNotificationPanelType) {
599+
root.privacyStore.setNewsRSSEnabled(true)
600600
} else {
601601
d.notificationsSettings.notifSettingStatusNews = Constants.settingsSection.notifications.sendAlertsValue
602602
}

vendor/status-go

Submodule status-go updated 113 files

0 commit comments

Comments
 (0)