Skip to content

feat(news): hook settings to the backend #17817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/app/core/notifications/notifications_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ QtObject:
details.notificationType == NotificationType.NewMessageWithGlobalMention or
details.notificationType == NotificationType.NewContactRequest or
details.notificationType == NotificationType.ContactRemoved or
details.notificationType == NotificationType.IdentityVerificationRequest:
details.notificationType == NotificationType.IdentityVerificationRequest or
details.notificationType == NotificationType.NewsFeedMessage:

if notificationWay == VALUE_NOTIF_DELIVER_QUIETLY:
return
Expand Down Expand Up @@ -293,6 +294,13 @@ QtObject:
self.notificationCheck(title, message, details, self.settingsService.getNotifSettingContactRequests())
return

# In case of News message
elif details.notificationType == NotificationType.NewsFeedMessage:
let newsSetting = self.settingsService.getNotifSettingStatusNews()
if newsSetting != VALUE_NOTIF_TURN_OFF:
self.notificationCheck(title, message, details, newsSetting)
return

# In case of new message (regardless it's message with mention or not)
elif(details.notificationType == NotificationType.NewMessage or
details.notificationType == NotificationType.NewMessageWithPersonalMention or
Expand Down
10 changes: 10 additions & 0 deletions src/app_service/service/settings/dto/settings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const PROFILE_MIGRATION_NEEDED* = "profile-migration-needed"
const KEY_URL_UNFURLING_MODE* = "url-unfurling-mode"
const KEY_AUTO_REFRESH_TOKENS* = "auto-refresh-tokens-enabled"
const KEY_LAST_TOKENS_UPDATE* = "last-tokens-update"
const KEY_NEWS_FEED_ENABLED* = "news-feed-enabled?"
const KEY_NEWS_NOTIFICATIONS_ENABLED* = "news-notifications-enabled?"
const KEY_NEWS_RSS_ENABLED* = "news-rss-enabled?"

# Notifications Settings Values
const VALUE_NOTIF_SEND_ALERTS* = "SendAlerts"
Expand Down Expand Up @@ -145,6 +148,9 @@ type
gifRecents*: JsonNode
gifFavorites*: JsonNode
testNetworksEnabled*: bool
newsFeedEnabled*: bool
newsNotificationsEnabled*: bool
newsRSSEnabled*: bool
notificationsAllowNotifications*: bool
notificationsOneToOneChats*: string
notificationsGroupChats*: string
Expand Down Expand Up @@ -249,6 +255,10 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto =
discard jsonObj.getProp(KEY_NODE_CONFIG, result.nodeConfig)
discard jsonObj.getProp(KEY_WAKU_BLOOM_FILTER_MODE, result.wakuBloomFilterMode)

discard jsonObj.getProp(KEY_NEWS_FEED_ENABLED, result.newsFeedEnabled)
discard jsonObj.getProp(KEY_NEWS_NOTIFICATIONS_ENABLED, result.newsNotificationsEnabled)
discard jsonObj.getProp(KEY_NEWS_RSS_ENABLED, result.newsRSSEnabled)

var usernamesArr: JsonNode
if (jsonObj.getProp(KEY_ENS_USERNAMES, usernamesArr)):
if (usernamesArr.kind == JArray):
Expand Down
116 changes: 116 additions & 0 deletions src/app_service/service/settings/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -985,3 +985,119 @@ QtObject:
except ValueError:
error "parse lastTokensUpdate: ", lastTokensUpdate
return self.settings.lastTokensUpdate

### News Feed Settings ###
proc notifSettingStatusNewsChanged*(self: Service) {.signal.}

proc toggleNewsFeedEnabled*(self: Service, value: bool): bool =
try:
let response = status_settings.toggleNewsFeedEnabled(value)
if not response.error.isNil:
raise newException(RpcException, response.error.message)

self.settings.newsFeedEnabled = value
self.notifSettingStatusNewsChanged()
return true
except Exception as e:
error "error: ", procName="toggleNewsFeedEnabled", errName = e.name, errDesription = e.msg
return false

proc getNotifSettingStatusNews*(self: Service): string {.slot.} =
result = VALUE_NOTIF_SEND_ALERTS # Default value

var newsFeedEnabled = false
var newsOSNotificationsEnabled = false

if self.initialized:
newsFeedEnabled = self.settings.newsFeedEnabled
newsOSNotificationsEnabled = self.settings.newsNotificationsEnabled
else:
try:
var response = status_settings.newsFeedEnabled()
if not response.error.isNil:
error "error reading news feed enabled setting: ", errDescription = response.error.message
return
newsFeedEnabled = response.result.getBool

response = status_settings.newsNotificationsEnabled()
if not response.error.isNil:
error "error reading news notifications enabled setting: ", errDescription = response.error.message
return
newsOSNotificationsEnabled = response.result.getBool
except Exception as e:
let errDesription = e.msg
error "reading news settings error: ", errDesription
return

# We convert the bools to the right setting
# Send alerts means the News Feed is enabled + OS notifications are enabled
# Deliver quietly means the News Feed is enabled + OS notifications are disabled (so only AC notifications)
# Turn OFF means the News Feed is disabled (so no notifications at all and no polling)
if not newsFeedEnabled:
return VALUE_NOTIF_TURN_OFF
if not newsOSNotificationsEnabled:
return VALUE_NOTIF_DELIVER_QUIETLY
return VALUE_NOTIF_SEND_ALERTS

proc setNotifSettingStatusNews*(self: Service, value: string) {.slot.} =
var newsFeedEnabled = false
var newsOSNotificationsEnabled = false
# We need to convert the string value to the right setting values
case value
of VALUE_NOTIF_SEND_ALERTS:
# Send alerts means the News Feed is enabled + OS notifications are enabled
newsFeedEnabled = true
newsOSNotificationsEnabled = true
of VALUE_NOTIF_TURN_OFF:
# Turn OFF means the News Feed is disabled + OS notifications are disabled
newsFeedEnabled = false
newsOSNotificationsEnabled = false
of VALUE_NOTIF_DELIVER_QUIETLY:
# Deliver quietly means the News Feed is enabled + OS notifications are disabled
newsFeedEnabled = true
newsOSNotificationsEnabled = false
else:
error "error: ", procName="setNotifSettingStatusNews", errDescription = "Unknown value: ", value
return

if not self.saveSetting(KEY_NEWS_NOTIFICATIONS_ENABLED, newsOSNotificationsEnabled):
return
self.settings.newsNotificationsEnabled = newsOSNotificationsEnabled

# toggleNewsFeedEnabled changes the value and calls the signals
discard self.toggleNewsFeedEnabled(newsFeedEnabled)
QtProperty[string] notifSettingStatusNews:
read = getNotifSettingStatusNews
write = setNotifSettingStatusNews
notify = notifSettingStatusNewsChanged

proc newsRSSEnabledChanged*(self: Service) {.signal.}
proc getNewsRSSEnabled*(self: Service): bool {.slot.} =
if self.initialized:
return self.settings.newsRSSEnabled

result = true #default value
try:
let response = status_settings.newsRSSEnabled()
if(not response.error.isNil):
raise newException(RpcException, response.error.message)
result = response.result.getBool
except Exception as e:
let errDesription = e.msg
error "reading news RSS setting error: ", errDesription

proc setNewsRSSEnabled*(self: Service, value: bool) {.slot.} =
try:
let response = status_settings.toggleNewsRSSEnabled(value)
if not response.error.isNil:
raise newException(RpcException, response.error.message)

self.settings.newsRSSEnabled = value
self.newsRSSEnabledChanged()
except Exception as e:
error "error: ", procName="toggleNewsRSSEnabled", errName = e.name, errDesription = e.msg

QtProperty[bool] newsRSSEnabled:
read = getNewsRSSEnabled
write = setNewsRSSEnabled
notify = newsRSSEnabledChanged
19 changes: 17 additions & 2 deletions src/backend/settings.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
import ./core, ./response_type
import ./core, ./response_type, ../app_service/common/utils

export response_type

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

proc lastTokensUpdate*(): RpcResponse[JsonNode] =
return core.callPrivateRPC("settings_lastTokensUpdate")
return core.callPrivateRPC("settings_lastTokensUpdate")

proc newsFeedEnabled*(): RpcResponse[JsonNode] =
return core.callPrivateRPC("settings_newsFeedEnabled")

proc newsNotificationsEnabled*(): RpcResponse[JsonNode] =
return core.callPrivateRPC("settings_newsNotificationsEnabled")

proc newsRSSEnabled*(): RpcResponse[JsonNode] =
return core.callPrivateRPC("settings_newsRSSEnabled")

proc toggleNewsFeedEnabled*(value: bool): RpcResponse[JsonNode] =
return core.callPrivateRPC("toggleNewsFeedEnabled".prefix, %*[value])

proc toggleNewsRSSEnabled*(value: bool): RpcResponse[JsonNode] =
result = core.callPrivateRPC("toggleNewsRSSEnabled".prefix, %*[ value ])
4 changes: 3 additions & 1 deletion ui/app/AppLayouts/Profile/ProfileLayout.qml
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,9 @@ StatusSectionLayout {
sectionTitle: settingsEntriesModel.getNameForSubsection(Constants.settingsSubsection.privacyAndSecurity)
contentWidth: d.contentWidth

onIsStatusNewsViaRSSEnabledChanged: root.store.privacyStore.isStatusNewsViaRSSEnabled = isStatusNewsViaRSSEnabled
onSetNewsRSSEnabledRequested: function (isStatusNewsViaRSSEnabled) {
root.store.privacyStore.setNewsRSSEnabled(isStatusNewsViaRSSEnabled)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/AppLayouts/Profile/stores/NotificationsStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ QtObject {
id: root

property var notificationsModule
property var notificationsSettings: appSettings /*TODO: Add appSettings.notifSettingStatusNews notifiable property in the backend*/
property var notificationsSettings: appSettings

property var exemptionsModel: notificationsModule.exemptionsModel

Expand Down
6 changes: 4 additions & 2 deletions ui/app/AppLayouts/Profile/stores/PrivacyStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ QtObject {
readonly property string keyUid: userProfile.keyUid

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

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

function changePassword(password, newPassword) {
root.privacyModule.changePassword(password, newPassword)
Expand Down
2 changes: 1 addition & 1 deletion ui/app/AppLayouts/Profile/views/NotificationsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ SettingsContentBase {
visible: !root.privacyStore.isStatusNewsViaRSSEnabled
text: qsTr("Enable RSS")

onClicked: root.privacyStore.isStatusNewsViaRSSEnabled = true
onClicked: root.privacyStore.setNewsRSSEnabled(true)
},
NotificationSelect {
visible: root.privacyStore.isStatusNewsViaRSSEnabled
Expand Down
8 changes: 6 additions & 2 deletions ui/app/AppLayouts/Profile/views/PrivacyAndSecurityView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import StatusQ.Controls 0.1
SettingsContentBase {
id: root

property alias isStatusNewsViaRSSEnabled: statusNewsSwitch.checked
property bool isStatusNewsViaRSSEnabled
required property bool isCentralizedMetricsEnabled

signal setNewsRSSEnabledRequested(bool isStatusNewsViaRSSEnabled)

function refreshSwitch() {
enableMetricsSwitch.checked = Qt.binding(function() { return root.isCentralizedMetricsEnabled })
}
Expand All @@ -30,9 +32,11 @@ SettingsContentBase {
components: [
StatusSwitch {
id: statusNewsSwitch
checked: root.isStatusNewsViaRSSEnabled
onToggled: root.setNewsRSSEnabledRequested(statusNewsSwitch.checked)
}
]
onClicked: statusNewsSwitch.checked = !statusNewsSwitch.checked
onClicked: root.setNewsRSSEnabledRequested(!statusNewsSwitch.checked)
}
StatusListItem {
Layout.preferredWidth: root.contentWidth
Expand Down
4 changes: 2 additions & 2 deletions ui/app/mainui/activitycenter/popups/ActivityCenterPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,8 @@ Popup {
font.pixelSize: Theme.additionalTextSize

onClicked: {
if(isEnableRSSNotificationPanelType) {
root.privacyStore.isStatusNewsViaRSSEnabled = true
if (isEnableRSSNotificationPanelType) {
root.privacyStore.setNewsRSSEnabled(true)
} else {
d.notificationsSettings.notifSettingStatusNews = Constants.settingsSection.notifications.sendAlertsValue
}
Expand Down
5 changes: 3 additions & 2 deletions ui/imports/shared/popups/NewsMessagePopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ StatusDialog {

ColumnLayout {
width: parent.width
spacing: 0

Loader {
id: notificationModelEntryLoader
Expand All @@ -74,12 +75,12 @@ StatusDialog {
color: "transparent"
border.color: root.backgroundColor
border.width: 1
radius: 10
radius: 16
}
}

StatusBaseText {
text: notification.newsContent || notification.newsDescription
text: notification.newsDescription || notification.newsContent
Layout.fillWidth: true
Layout.fillHeight: true
wrapMode: Text.WordWrap
Expand Down