From 329182fdbe0c2d18b6b9c026c43094dd9581bd99 Mon Sep 17 00:00:00 2001 From: andrey Date: Fri, 15 Jan 2021 11:56:39 +0100 Subject: [PATCH] [#11643] Display profile picture only of users I have added to contacts Signed-off-by: andrey --- src/status_im/constants.cljs | 4 ++ src/status_im/contact/db.cljs | 32 +++++++++------ src/status_im/multiaccounts/core.cljs | 5 +++ src/status_im/subs.cljs | 16 ++++++-- .../ui/screens/appearance/views.cljs | 39 ++++++++++++++++--- .../ui/screens/routing/profile_stack.cljs | 2 + src/status_im/utils/config.cljs | 1 + status-go-version.json | 6 +-- translations/en.json | 4 +- 9 files changed, 84 insertions(+), 25 deletions(-) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 1887e88247..03d1a5ec66 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -57,6 +57,10 @@ (def command-state-transaction-pending 6) (def command-state-transaction-sent 7) +(def profile-pictures-visibility-contacts-only 1) +(def profile-pictures-visibility-everyone 2) +(def profile-pictures-visibility-none 3) + (def min-password-length 6) (def max-group-chat-participants 20) (def default-number-of-messages 20) diff --git a/src/status_im/contact/db.cljs b/src/status_im/contact/db.cljs index 28a886e68c..4e7f86db24 100644 --- a/src/status_im/contact/db.cljs +++ b/src/status_im/contact/db.cljs @@ -4,7 +4,8 @@ [status-im.ethereum.core :as ethereum] [status-im.utils.gfycat.core :as gfycat] [status-im.utils.identicon :as identicon] - [status-im.multiaccounts.core :as multiaccounts])) + [status-im.multiaccounts.core :as multiaccounts] + [status-im.constants :as constants])) (defn public-key->new-contact [public-key] (let [alias (gfycat/generate-gfy public-key)] @@ -54,7 +55,7 @@ [members admins contacts {:keys [public-key] :as current-account}] (let [current-contact (some-> current-account - (select-keys [:name :preferred-name :public-key :identicon]) + (select-keys [:name :preferred-name :public-key :identicon :images]) (clojure.set/rename-keys {:name :alias :preferred-name :name})) all-contacts (cond-> contacts @@ -130,19 +131,26 @@ :added? (contains? system-tags :contact/added))))) (defn enrich-contact - [{:keys [system-tags] :as contact}] - (-> contact - (dissoc :ens-verified-at :ens-verification-retries) - (assoc :pending? (pending? contact) - :blocked? (blocked? contact) - :active? (active? contact) - :added? (contains? system-tags :contact/added)) - (multiaccounts/contact-with-names))) + ([contact] (enrich-contact contact nil nil)) + ([{:keys [system-tags public-key] :as contact} setting own-public-key] + (let [added? (contains? system-tags :contact/added)] + (cond-> (-> contact + (dissoc :ens-verified-at :ens-verification-retries) + (assoc :pending? (pending? contact) + :blocked? (blocked? contact) + :active? (active? contact) + :added? added?) + (multiaccounts/contact-with-names)) + (and setting (not= public-key own-public-key) + (or (= setting constants/profile-pictures-visibility-none) + (and (= setting constants/profile-pictures-visibility-contacts-only) + (not added?)))) + (dissoc :images))))) (defn enrich-contacts - [contacts] + [contacts profile-pictures-visibility own-public-key] (reduce-kv (fn [acc public-key contact] - (assoc acc public-key (enrich-contact contact))) + (assoc acc public-key (enrich-contact contact profile-pictures-visibility own-public-key))) {} contacts)) diff --git a/src/status_im/multiaccounts/core.cljs b/src/status_im/multiaccounts/core.cljs index 72a0001fa2..6b1ceffdac 100644 --- a/src/status_im/multiaccounts/core.cljs +++ b/src/status_im/multiaccounts/core.cljs @@ -166,6 +166,11 @@ {::switch-theme theme} (multiaccounts.update/multiaccount-update :appearance theme {}))) +(fx/defn switch-appearance-profile + {:events [:multiaccounts.ui/appearance-profile-switched]} + [cofx id] + (multiaccounts.update/multiaccount-update cofx :profile-pictures-visibility id {})) + (defn clean-path [path] (if path (string/replace-first path #"file://" "") diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 092ffd6f3f..23604c8a7f 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -910,7 +910,7 @@ (re-frame/reg-sub :chats/photo-path - :<- [::contacts] + :<- [:contacts/contacts] :<- [:multiaccount] (fn [[contacts multiaccount] [_ id identicon]] (let [contact (or (get contacts id) @@ -1801,11 +1801,19 @@ (fn [[chat contacts] [_ query-fn]] (contact.db/query-chat-contacts chat contacts query-fn))) +(re-frame/reg-sub + ::profile-pictures-visibility + :<- [:multiaccount] + (fn [multiaccount] + (get multiaccount :profile-pictures-visibility))) + (re-frame/reg-sub :contacts/contacts :<- [::contacts] - (fn [contacts] - (contact.db/enrich-contacts contacts))) + :<- [::profile-pictures-visibility] + :<- [:multiaccount/public-key] + (fn [[contacts profile-pictures-visibility public-key]] + (contact.db/enrich-contacts contacts profile-pictures-visibility public-key))) (re-frame/reg-sub :contacts/active @@ -2097,7 +2105,7 @@ (re-frame/reg-sub :search/filtered-chats :<- [:chats/active-chats] - :<- [::contacts] + :<- [:contacts/contacts] :<- [:search/home-filter] (fn [[chats contacts search-filter]] ;; Short-circuit if search-filter is empty diff --git a/src/status_im/ui/screens/appearance/views.cljs b/src/status_im/ui/screens/appearance/views.cljs index 9f57f15ef4..46f44e9892 100644 --- a/src/status_im/ui/screens/appearance/views.cljs +++ b/src/status_im/ui/screens/appearance/views.cljs @@ -6,7 +6,12 @@ [status-im.react-native.resources :as resources] [quo.core :as quo] [status-im.ui.components.colors :as colors] - [status-im.i18n :as i18n])) + [status-im.i18n :as i18n] + [status-im.constants :as constants])) + +(def titles {constants/profile-pictures-visibility-contacts-only (i18n/label :t/recent-recipients) + constants/profile-pictures-visibility-everyone (i18n/label :t/everyone) + constants/profile-pictures-visibility-none (i18n/label :t/none)}) (defn button [label icon theme selected?] [react/touchable-highlight @@ -19,12 +24,36 @@ (i18n/label label)]]]) (views/defview appearance [] - (views/letsubs [{:keys [appearance]} [:multiaccount]] + (views/letsubs [{:keys [appearance profile-pictures-visibility]} [:multiaccount]] [react/view {:flex 1} [topbar/topbar {:title (i18n/label :t/appearance)}] [quo/list-header (i18n/label :t/preference)] - [react/view {:flex-direction :row :flex 1 :padding-horizontal 8 - :justify-content :space-between :margin-top 16} + [react/view {:flex-direction :row :padding-horizontal 8 + :justify-content :space-between :margin-vertical 16} [button :t/light :theme-light 1 (= 1 appearance)] [button :t/dark :theme-dark 2 (= 2 appearance)] - [button :t/system :theme-system 0 (= 0 appearance)]]])) + [button :t/system :theme-system 0 (= 0 appearance)]] + [quo/list-header (i18n/label :t/chat)] + [quo/list-item + {:title (i18n/label :t/show-profile-pictures) + :accessibility-label :show-profile-pictures + :accessory :text + :accessory-text (get titles profile-pictures-visibility) + :on-press #(re-frame/dispatch [:navigate-to :appearance-profile-pic]) + :chevron true}]])) + +(defn radio-item [id value] + [quo/list-item + {:active (= value id) + :accessory :radio + :title (get titles id) + :on-press #(re-frame/dispatch [:multiaccounts.ui/appearance-profile-switched id])}]) + +(views/defview profile-pic [] + (views/letsubs [{:keys [profile-pictures-visibility]} [:multiaccount]] + [react/view {:flex 1} + [topbar/topbar {:title (i18n/label :t/show-profile-pictures)}] + [react/view {:margin-top 8} + [radio-item constants/profile-pictures-visibility-everyone profile-pictures-visibility] + [radio-item constants/profile-pictures-visibility-contacts-only profile-pictures-visibility] + [radio-item constants/profile-pictures-visibility-none profile-pictures-visibility]]])) \ No newline at end of file diff --git a/src/status_im/ui/screens/routing/profile_stack.cljs b/src/status_im/ui/screens/routing/profile_stack.cljs index d709db35cf..a117dad33b 100644 --- a/src/status_im/ui/screens/routing/profile_stack.cljs +++ b/src/status_im/ui/screens/routing/profile_stack.cljs @@ -83,6 +83,8 @@ :component privacy-and-security/privacy-and-security} {:name :appearance :component appearance/appearance} + {:name :appearance-profile-pic + :component appearance/profile-pic} {:name :notifications :component notifications-settings/notifications-settings} {:name :notifications-servers diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index afc84b8571..7c22ed1a0f 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -78,6 +78,7 @@ :wallet/visible-tokens {:mainnet #{:SNT}} :currency :usd :appearance 0 + :profile-pictures-visibility 1 :log-level log-level :webview-allow-permission-requests? false :link-previews-enabled-sites #{} diff --git a/status-go-version.json b/status-go-version.json index ce496965bf..3aa5cc56c3 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -2,7 +2,7 @@ "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh ' instead", "owner": "status-im", "repo": "status-go", - "version": "v0.68.4", - "commit-sha1": "79716227db0f4b2a2ddcd8763ce48bab5d487d04", - "src-sha256": "11bgn2k93838b1z5mk7parwqkzqydfg51c1cphmfrd33flf1pvkj" + "version": "v0.68.5", + "commit-sha1": "b5b1e19c2454ae1174915e6cb2fabaaa0955084c", + "src-sha256": "0gm2mlcrh1al197yzl2b57p0xvwjbz2jb5cbiq7a3cn43gvvcqy0" } diff --git a/translations/en.json b/translations/en.json index 349a2edc73..8619e62022 100644 --- a/translations/en.json +++ b/translations/en.json @@ -1399,5 +1399,7 @@ "seed-key-uid-mismatch-desc-2": "To manage keys for this account verify your seed phrase and try again.", "recover-with-seed-phrase": "Recover with seed phrase", "transfer-ma-unknown-error-desc-1": "It looks like your multiaccount was not deleted. Database may have been reset", - "transfer-ma-unknown-error-desc-2": "Please check your account list and try again. If the account is not listed go to Access existing keys to recover with seed phrase" + "transfer-ma-unknown-error-desc-2": "Please check your account list and try again. If the account is not listed go to Access existing keys to recover with seed phrase", + "everyone": "Everyone", + "show-profile-pictures": "Show profile pictures of" }