[#11643] Display profile picture only of users I have added to contacts

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2021-01-15 11:56:39 +01:00
parent 5c3133adb6
commit 329182fdbe
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
9 changed files with 84 additions and 25 deletions

View File

@ -57,6 +57,10 @@
(def command-state-transaction-pending 6) (def command-state-transaction-pending 6)
(def command-state-transaction-sent 7) (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 min-password-length 6)
(def max-group-chat-participants 20) (def max-group-chat-participants 20)
(def default-number-of-messages 20) (def default-number-of-messages 20)

View File

@ -4,7 +4,8 @@
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.utils.gfycat.core :as gfycat] [status-im.utils.gfycat.core :as gfycat]
[status-im.utils.identicon :as identicon] [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] (defn public-key->new-contact [public-key]
(let [alias (gfycat/generate-gfy public-key)] (let [alias (gfycat/generate-gfy public-key)]
@ -54,7 +55,7 @@
[members admins contacts {:keys [public-key] :as current-account}] [members admins contacts {:keys [public-key] :as current-account}]
(let [current-contact (some-> (let [current-contact (some->
current-account 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 (clojure.set/rename-keys {:name :alias
:preferred-name :name})) :preferred-name :name}))
all-contacts (cond-> contacts all-contacts (cond-> contacts
@ -130,19 +131,26 @@
:added? (contains? system-tags :contact/added))))) :added? (contains? system-tags :contact/added)))))
(defn enrich-contact (defn enrich-contact
[{:keys [system-tags] :as contact}] ([contact] (enrich-contact contact nil nil))
(-> contact ([{: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) (dissoc :ens-verified-at :ens-verification-retries)
(assoc :pending? (pending? contact) (assoc :pending? (pending? contact)
:blocked? (blocked? contact) :blocked? (blocked? contact)
:active? (active? contact) :active? (active? contact)
:added? (contains? system-tags :contact/added)) :added? added?)
(multiaccounts/contact-with-names))) (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 (defn enrich-contacts
[contacts] [contacts profile-pictures-visibility own-public-key]
(reduce-kv (fn [acc public-key contact] (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)) contacts))

View File

@ -166,6 +166,11 @@
{::switch-theme theme} {::switch-theme theme}
(multiaccounts.update/multiaccount-update :appearance 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] (defn clean-path [path]
(if path (if path
(string/replace-first path #"file://" "") (string/replace-first path #"file://" "")

View File

@ -910,7 +910,7 @@
(re-frame/reg-sub (re-frame/reg-sub
:chats/photo-path :chats/photo-path
:<- [::contacts] :<- [:contacts/contacts]
:<- [:multiaccount] :<- [:multiaccount]
(fn [[contacts multiaccount] [_ id identicon]] (fn [[contacts multiaccount] [_ id identicon]]
(let [contact (or (get contacts id) (let [contact (or (get contacts id)
@ -1801,11 +1801,19 @@
(fn [[chat contacts] [_ query-fn]] (fn [[chat contacts] [_ query-fn]]
(contact.db/query-chat-contacts 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 (re-frame/reg-sub
:contacts/contacts :contacts/contacts
:<- [::contacts] :<- [::contacts]
(fn [contacts] :<- [::profile-pictures-visibility]
(contact.db/enrich-contacts contacts))) :<- [:multiaccount/public-key]
(fn [[contacts profile-pictures-visibility public-key]]
(contact.db/enrich-contacts contacts profile-pictures-visibility public-key)))
(re-frame/reg-sub (re-frame/reg-sub
:contacts/active :contacts/active
@ -2097,7 +2105,7 @@
(re-frame/reg-sub (re-frame/reg-sub
:search/filtered-chats :search/filtered-chats
:<- [:chats/active-chats] :<- [:chats/active-chats]
:<- [::contacts] :<- [:contacts/contacts]
:<- [:search/home-filter] :<- [:search/home-filter]
(fn [[chats contacts search-filter]] (fn [[chats contacts search-filter]]
;; Short-circuit if search-filter is empty ;; Short-circuit if search-filter is empty

View File

@ -6,7 +6,12 @@
[status-im.react-native.resources :as resources] [status-im.react-native.resources :as resources]
[quo.core :as quo] [quo.core :as quo]
[status-im.ui.components.colors :as colors] [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?] (defn button [label icon theme selected?]
[react/touchable-highlight [react/touchable-highlight
@ -19,12 +24,36 @@
(i18n/label label)]]]) (i18n/label label)]]])
(views/defview appearance [] (views/defview appearance []
(views/letsubs [{:keys [appearance]} [:multiaccount]] (views/letsubs [{:keys [appearance profile-pictures-visibility]} [:multiaccount]]
[react/view {:flex 1} [react/view {:flex 1}
[topbar/topbar {:title (i18n/label :t/appearance)}] [topbar/topbar {:title (i18n/label :t/appearance)}]
[quo/list-header (i18n/label :t/preference)] [quo/list-header (i18n/label :t/preference)]
[react/view {:flex-direction :row :flex 1 :padding-horizontal 8 [react/view {:flex-direction :row :padding-horizontal 8
:justify-content :space-between :margin-top 16} :justify-content :space-between :margin-vertical 16}
[button :t/light :theme-light 1 (= 1 appearance)] [button :t/light :theme-light 1 (= 1 appearance)]
[button :t/dark :theme-dark 2 (= 2 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]]]))

View File

@ -83,6 +83,8 @@
:component privacy-and-security/privacy-and-security} :component privacy-and-security/privacy-and-security}
{:name :appearance {:name :appearance
:component appearance/appearance} :component appearance/appearance}
{:name :appearance-profile-pic
:component appearance/profile-pic}
{:name :notifications {:name :notifications
:component notifications-settings/notifications-settings} :component notifications-settings/notifications-settings}
{:name :notifications-servers {:name :notifications-servers

View File

@ -78,6 +78,7 @@
:wallet/visible-tokens {:mainnet #{:SNT}} :wallet/visible-tokens {:mainnet #{:SNT}}
:currency :usd :currency :usd
:appearance 0 :appearance 0
:profile-pictures-visibility 1
:log-level log-level :log-level log-level
:webview-allow-permission-requests? false :webview-allow-permission-requests? false
:link-previews-enabled-sites #{} :link-previews-enabled-sites #{}

View File

@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead", "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.68.4", "version": "v0.68.5",
"commit-sha1": "79716227db0f4b2a2ddcd8763ce48bab5d487d04", "commit-sha1": "b5b1e19c2454ae1174915e6cb2fabaaa0955084c",
"src-sha256": "11bgn2k93838b1z5mk7parwqkzqydfg51c1cphmfrd33flf1pvkj" "src-sha256": "0gm2mlcrh1al197yzl2b57p0xvwjbz2jb5cbiq7a3cn43gvvcqy0"
} }

View File

@ -1399,5 +1399,7 @@
"seed-key-uid-mismatch-desc-2": "To manage keys for this account verify your seed phrase and try again.", "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", "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-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"
} }