Skip to content

Commit

Permalink
Contact notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferossgp committed Jul 24, 2020
1 parent 9e23dbf commit ff8c0f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/status_im/ethereum/json_rpc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
"wakuext_acceptRequestTransaction" {}
"wakuext_registerForPushNotifications" {}
"wakuext_unregisterFromPushNotifications" {}
"wakuext_enablePushNotificationsFromContactsOnly" {}
"wakuext_disablePushNotificationsFromContactsOnly" {}
"status_chats" {}
"wallet_getTransfers" {}
"wallet_getTokensBalances" {}
Expand Down
12 changes: 9 additions & 3 deletions src/status_im/notifications/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@
(fx/merge cofx
(multiaccounts.update/multiaccount-update :notifications-enabled? false {})))

;; TODO: add optimistic update in local state, and then update with status-go state
(fx/defn notification-switch
{:events [::switch]}
[{:keys [db] :as cofx} enabled?]
(fx/merge cofx
;; TODO: use the new key from status-go
(multiaccounts.update/multiaccount-update
:notifications-enabled? (boolean enabled?) {})
(if enabled?
Expand All @@ -72,6 +74,10 @@
(fx/defn notification-non-contacts
{:events [::switch-non-contacts]}
[{:keys [db] :as cofx} enabled?]
(fx/merge cofx
(multiaccounts.update/multiaccount-update
:notifications-non-contact? (boolean enabled?) {})))
(let [method (if-not enabled? ; NOTE: we inverse them as UI shows "non-contacts", while go stores "contacts" flag.
"enablePushNotificationsFromContactsOnly"
"disablePushNotificationsFromContactsOnly")]
(fx/merge cofx
{::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) method)
:params []
:on-success #(log/info "[push-notifications] contacts-notification-success" %)}]})))
4 changes: 2 additions & 2 deletions src/status_im/ui/screens/notifications_settings/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

(defn notifications-settings []
(let [{:keys [notifications-enabled?
notifications-non-contact?]}
push-notifications-from-contacts-only]}
@(re-frame/subscribe [:multiaccount])]
[react/view {:flex 1}
[topbar/topbar {:title :t/notification-settings}]
Expand All @@ -32,7 +32,7 @@
:title (i18n/label :t/notifications-non-contacts)
:accessibility-label :notifications-button
:active (and notifications-enabled?
notifications-non-contact?)
push-notifications-from-contacts-only)
:on-press #(re-frame/dispatch
[::notifications/switch-non-contacts (not notifications-enabled?)])
:accessory :switch}]]]))

0 comments on commit ff8c0f8

Please sign in to comment.