Skip to content
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

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

Merged
merged 1 commit into from
Jan 18, 2021
Merged
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
4 changes: 4 additions & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 20 additions & 12 deletions src/status_im/contact/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down
5 changes: 5 additions & 0 deletions src/status_im/multiaccounts/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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://" "")
Expand Down
16 changes: 12 additions & 4 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
39 changes: 34 additions & 5 deletions src/status_im/ui/screens/appearance/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]]]))
2 changes: 2 additions & 0 deletions src/status_im/ui/screens/routing/profile_stack.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/status_im/utils/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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 #{}
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' 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"
}
4 changes: 3 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}