Skip to content
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
8 changes: 7 additions & 1 deletion src/legacy/status_im/data_store/activities.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@
:communityId :community-id
:installationId :installation-id
:membershipStatus :membership-status
:albumMessages :album-messages})
:albumMessages :album-messages
:newsImageUrl :news-image-url
:newsTitle :news-title
:newsDescription :news-description
:newsContent :news-content
:newsLink :news-link
:newsLinkLabel :news-link-label})
(update :last-message #(when % (messages/<-rpc %)))
(update :message #(when % (messages/<-rpc %)))
(update :reply-message #(when % (messages/<-rpc %)))
Expand Down
20 changes: 19 additions & 1 deletion src/status_im/contexts/settings/privacy_and_security/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
(let [customization-color (rf/sub [:profile/customization-color])

preview-privacy? (rf/sub [:profile/preview-privacy?])
news-feed-enabled? (rf/sub [:profile/news-feed-enabled?])
see-profile-pictures-from (rf/sub [:profile/pictures-visibility])
show-profile-pictures-to (rf/sub [:multiaccount/profile-pictures-show-to])

Expand All @@ -38,6 +39,14 @@
(not preview-privacy?)]))
[preview-privacy?])

toggle-news-feed
(rn/use-callback (fn []
(rf/dispatch [:profile.settings/profile-update :news-feed-enabled?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sharing for awareness: it's not the first time I see an opportunity to make settings_saveSetting support multiple settings at once so that we can do one atomic update.

(not news-feed-enabled?)])
(rf/dispatch [:profile.settings/profile-update :news-rss-enabled?
(not news-feed-enabled?)]))
[news-feed-enabled?])

open-see-profile-pictures-from-options
(rn/use-callback (fn []
(rf/dispatch
Expand Down Expand Up @@ -89,6 +98,15 @@
:blur? true
:action :arrow
:action-props {:on-change #(rf/dispatch [:open-modal
:screen/settings.share-usage-data])}}]
:screen/settings.share-usage-data])}}
{:title (i18n/label :t/status-news-rss)
:description :text
:description-props {:text (i18n/label :t/rss-privacy-warning)}
:blur? true
:action :selector
:action-props {:on-change toggle-news-feed
:checked? news-feed-enabled?
:id :news-feed
:customization-color customization-color}}]
:blur? true
:list-type :settings}]]))
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
(ns status-im.contexts.shell.activity-center.notification.news.view
(:require [clojure.string :as string]
[promesa.core :as promesa]
[quo.core :as quo]
[react-native.core :as rn]
[react-native.gesture :as gesture]
[status-im.contexts.shell.activity-center.notification.common.view :as common]
[utils.datetime :as datetime]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn auto-resized-image
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use custom hooks more often, even if they will be used only once, since a hook is just a function anyway. The following is untested code. This allows us to decouple state management & effects from hiccup.

Note: untested code.
Note 2: I'm passing the url as a dependency to use-effect

(defn- use-auto-image-height
  [url]
  (let [[height set-height] (rn/use-state nil)
        window-width        (- (:width (rn/get-window)) 40)]
    (rn/use-effect
     (fn []
       (-> (rn/image-get-size url)
           (promesa/then (fn [[w h]]
                           (let [scale      (/ window-width w)
                                 new-height (* h scale)]
                             (set-height new-height))))))
     [url])
    {:height height
     :width  window-width}))

(defn auto-resized-image
  [url]
  (let [{:keys [height width]} (use-auto-image-height url)]
    (if height
      [rn/image
       {:resize-mode :contain
        :style       {:width         width
                      :height        height
                      :align-self    :center
                      :border-radius 12}
        :source      url}]
      [rn/view {:style {:height 200 :align-items :center :justify-content :center}}
       [rn/activity-indicator]])))

[url]
(let [[height set-height] (rn/use-state nil)
window-width (- (:width (rn/get-window)) 40)]
(rn/use-effect #(-> (rn/image-get-size url)
(promesa/then (fn [[w h]]
(let [scale (/ window-width w)
new-height (* h scale)]
(set-height new-height))))))
(if height
[rn/image
{:resize-mode :contain
:style {:width window-width
:height height
:align-self :center
:border-radius 12}
:source url}]
[rn/view {:style {:height 200 :align-items :center :justify-content :center}}
[rn/activity-indicator]])))

(defn sheet
[{:keys [news-image-url news-title news-content news-link news-link-label]} timestamp]
(let [customization-color (rf/sub [:profile/customization-color])]
[:<>
[quo/drawer-top {:title news-title :description timestamp}]
[rn/scroll-view {:style {:flex 1}}
(when (not (string/blank? news-image-url))
[auto-resized-image news-image-url])
[quo/text
{:style {:padding-horizontal 20
:padding-vertical 8}}
news-content]]
(when (and (not (string/blank? news-link)) (not (string/blank? news-link-label)))
[quo/bottom-actions
{:button-one-label news-link-label
:button-one-props {:customization-color customization-color
:icon-right :i/external
:on-press (fn []
(rf/dispatch [:browser.ui/open-url news-link])
(rf/dispatch [:hide-bottom-sheet]))}}])]))

(defn view
[{:keys [notification extra-fn]}]
(let [customization-color (rf/sub [:profile/customization-color])
{:keys [news-title
news-description
timestamp
read
id]} notification
timestamp (datetime/timestamp->relative timestamp)
on-press (rn/use-callback
(fn []
(rf/dispatch [:activity-center.notifications/mark-as-read id])
(rf/dispatch [:show-bottom-sheet
{:theme :dark
:content (fn []
[sheet notification timestamp])}])))]
[common/swipeable
{:left-button common/swipe-button-read-or-unread
:left-on-press common/swipe-on-press-toggle-read
:right-button common/swipe-button-delete
:right-on-press common/swipe-on-press-delete
:extra-fn extra-fn}
[gesture/touchable-without-feedback
{:on-press on-press}
[quo/activity-log
{:title news-title
:customization-color customization-color
:icon :i/status-logo-bw
:timestamp timestamp
:unread? (not read)
:context [[quo/text {} news-description]]
:items [{:type :button
:subtype :primary
:key :button-reply
:customization-color customization-color
:label (i18n/label :t/read-more)
:accessibility-label :read-more
:on-press on-press}]}]]]))
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
(def ^:const contact-verification 10)
(def ^:const new-installation-received 23)
(def ^:const new-installation-created 24)
(def ^:const news-feed 29)

(def ^:const all-supported
#{one-to-one-chat
Expand All @@ -24,7 +25,8 @@
community-kicked
contact-verification
new-installation-received
new-installation-created})
new-installation-created
news-feed})

;; TODO: Replace with correct enum values once status-go implements them.
(def ^:const tx 66612)
Expand Down
5 changes: 5 additions & 0 deletions src/status_im/contexts/shell/activity_center/tabs/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
:default-active filter-type
:data [{:id types/no-type
:label (i18n/label :t/all)}
{:id types/news-feed
:label (i18n/label :t/news)
:accessibility-label :tab-news
:notification-dot? (when-not is-mark-all-as-read-undoable?
(contains? types-with-unread types/news-feed))}
{:id types/admin
:label (i18n/label :t/admin)
:accessibility-label :tab-admin
Expand Down
5 changes: 4 additions & 1 deletion src/status_im/contexts/shell/activity_center/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
contact-verification]
[status-im.contexts.shell.activity-center.notification.membership.view :as membership]
[status-im.contexts.shell.activity-center.notification.mentions.view :as mentions]
[status-im.contexts.shell.activity-center.notification.news.view :as news]
[status-im.contexts.shell.activity-center.notification.reply.view :as reply]
[status-im.contexts.shell.activity-center.notification.syncing.view :as syncing]
[status-im.contexts.shell.activity-center.style :as style]
Expand Down Expand Up @@ -55,6 +56,9 @@
(= notification-type types/new-installation-created)
[syncing/installation-created-view props]

(= notification-type types/news-feed)
[news/view props]

(types/membership notification-type)
(condp = notification-type
types/private-group-chat [membership/view props]
Expand All @@ -69,7 +73,6 @@
(defn view
[]
(let [notifications (rf/sub [:activity-center/notifications])

;; We globally control the active swipeable for all notifications
;; because when a swipe left/right gesture initiates, the previously
;; active swiped notification (if any) must be removed & closed with
Expand Down
5 changes: 5 additions & 0 deletions src/status_im/subs/profile.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@
(fn [{:keys [preview-privacy?]}]
(boolean preview-privacy?)))

(re-frame/reg-sub :profile/news-feed-enabled?
:<- [:profile/profile]
(fn [{:keys [news-feed-enabled?]}]
(boolean news-feed-enabled?)))

(defn- replace-multiaccount-image-uri
[profile port font-file avatar-opts theme]
(let [{:keys [key-uid images
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v10.27.0",
"commit-sha1": "f5fe88d8b31a287e66a48fe90ef613c7617279b6",
"src-sha256": "01cn2f9f3sq5dmygh4gqpip5zp9f61383xix7rfwxr2nazbqrka3"
"version": "feat/news-feed-mobile",
"commit-sha1": "6ded349455d121039625961cec23fdbb403fb175",
"src-sha256": "1rvnvmzvq9g4rnc3mvbyk63m8v6zv8bvim586p2l4x02p2ywha29"
}
3 changes: 3 additions & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,7 @@
"new-tab": "New tab",
"new-to-status": "I’m new to Status",
"new-ui": "New UI",
"news": "News",
"next": "Next",
"next-you-will": "Next, you will be asked to confirm the position of certain words in your recovery phrase",
"NFT": "NFT",
Expand Down Expand Up @@ -2315,6 +2316,7 @@
"rpc-usage-info": "RPC usage stats",
"rpc-usage-reset": "Reset",
"rpc-usage-total": "Total",
"rss-privacy-warning": "Fetches news from external sites which may expose your IP",
"sa": "Sa",
"safe-estimate": "Safe estimate",
"sat": "Sat",
Expand Down Expand Up @@ -2591,6 +2593,7 @@
"status-is-open-source": "Status is open-source",
"status-keycard": "Status Keycard",
"status-mobile-descr": "Status tends to use a lot of data when syncing chats. You can choose not to sync when on mobile network",
"status-news-rss": "Receive Status News via RSS",
"status-not-sent-click": "Not confirmed. Click for options",
"status-not-sent-tap": "Not confirmed. Tap for options",
"status-pending": "Pending",
Expand Down