mirror of
https://github.com/status-im/status-react.git
synced 2025-02-26 09:35:36 +00:00
Use image server for all kind of images and integrate identity rings
4cc53630...8c35fffd
This commit is contained in:
parent
00a503bf84
commit
bac2bb8b8e
@ -70,6 +70,7 @@
|
||||
"mailserver.available" (mailserver/handle-mailserver-available cofx (.-id event-js))
|
||||
"mailserver.not.working" (mailserver/handle-mailserver-not-working cofx)
|
||||
"discovery.summary" (summary cofx (js->clj event-js :keywordize-keys true))
|
||||
"mediaserver.started" {:db (assoc db :mediaserver/port (.-port event-js))}
|
||||
"wakuv2.peerstats" (wakuv2-peer-stats cofx (js->clj event-js :keywordize-keys true))
|
||||
"messages.new" (transport.message/sanitize-messages-and-process-response cofx event-js true)
|
||||
"wallet" (ethereum.subscriptions/new-wallet-event cofx (js->clj event-js :keywordize-keys true))
|
||||
|
@ -41,7 +41,8 @@
|
||||
[status-im.utils.money :as money]
|
||||
[status-im.utils.security :as security]
|
||||
[status-im.wallet.db :as wallet.db]
|
||||
[status-im.wallet.utils :as wallet.utils]))
|
||||
[status-im.wallet.utils :as wallet.utils]
|
||||
[status-im.utils.image-server :as image-server]))
|
||||
|
||||
;; TOP LEVEL ===========================================================================================================
|
||||
|
||||
@ -267,6 +268,9 @@
|
||||
(reg-root-key-sub :wallet-connect/session-managed :wallet-connect/session-managed)
|
||||
(reg-root-key-sub :contact-requests/pending :contact-requests/pending)
|
||||
|
||||
; media-server
|
||||
(reg-root-key-sub :mediaserver/port :mediaserver/port)
|
||||
|
||||
; Testing
|
||||
|
||||
(reg-root-key-sub :messenger/started? :messenger/started?)
|
||||
@ -1303,15 +1307,27 @@
|
||||
(re-frame/reg-sub
|
||||
:chats/photo-path
|
||||
:<- [:contacts/contacts]
|
||||
:<- [:profile/multiaccount]
|
||||
:<- [:mediaserver/port]
|
||||
(fn [[contacts multiaccount port] [_ id]]
|
||||
(let [contact (or (get contacts id)
|
||||
(when (= id (:public-key multiaccount))
|
||||
multiaccount))]
|
||||
(if (nil? contact)
|
||||
(image-server/get-identicons-uri port id)
|
||||
(multiaccounts/displayed-photo contact)))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:contacts/name-and-photo
|
||||
:<- [:contacts/contacts]
|
||||
:<- [:multiaccount]
|
||||
(fn [[contacts multiaccount] [_ id identicon]]
|
||||
(fn [[contacts multiaccount] [_ id]]
|
||||
(let [contact (or (get contacts id)
|
||||
(when (= id (:public-key multiaccount))
|
||||
multiaccount)
|
||||
(if (not (string/blank? identicon))
|
||||
{:identicon identicon}
|
||||
(contact.db/public-key->new-contact id)))]
|
||||
(multiaccounts/displayed-photo contact))))
|
||||
(contact.db/public-key->new-contact id))]
|
||||
{:name (multiaccounts/displayed-name contact)
|
||||
:photo (multiaccounts/displayed-photo contact)})))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:chats/unread-messages-number
|
||||
@ -2320,13 +2336,34 @@
|
||||
(fn [multiaccount]
|
||||
(get multiaccount :profile-pictures-visibility)))
|
||||
|
||||
(defn- replace-contact-image-uri [contact port identity]
|
||||
(let [identicon (image-server/get-identicons-uri port identity)
|
||||
contact-images (:images contact)
|
||||
contact-images (reduce (fn [acc image] (let [image-name (:type image)
|
||||
; We pass the clock so that we reload the image if the image is updated
|
||||
clock (:clock image)
|
||||
uri (image-server/get-contact-image-uri port identity image-name clock)]
|
||||
(assoc-in acc [(keyword image-name) :uri] uri)))
|
||||
contact-images
|
||||
(vals contact-images))]
|
||||
(assoc contact :identicon identicon :images contact-images)))
|
||||
|
||||
(defn- reduce-contacts-image-uri [contacts port]
|
||||
(reduce-kv (fn [acc public-key contact]
|
||||
(let [contact (replace-contact-image-uri contact port public-key)]
|
||||
(assoc acc public-key contact)))
|
||||
{}
|
||||
contacts))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:contacts/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)))
|
||||
:<- [:mediaserver/port]
|
||||
(fn [[contacts profile-pictures-visibility public-key port]]
|
||||
(let [contacts (contact.db/enrich-contacts contacts profile-pictures-visibility public-key)]
|
||||
(reduce-contacts-image-uri contacts port))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:contacts/active
|
||||
@ -2386,15 +2423,21 @@
|
||||
(string/lower-case search-filter))
|
||||
contacts)))))
|
||||
|
||||
(defn- enrich-contact [_ identity ens-name port]
|
||||
(let [contact (contact.db/enrich-contact
|
||||
(contact.db/public-key-and-ens-name->new-contact identity ens-name))]
|
||||
(replace-contact-image-uri contact port identity)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:contacts/current-contact
|
||||
:<- [:contacts/contacts]
|
||||
:<- [:contacts/current-contact-identity]
|
||||
:<- [:contacts/current-contact-ens-name]
|
||||
(fn [[contacts identity ens-name]]
|
||||
(or (get contacts identity)
|
||||
(contact.db/enrich-contact
|
||||
(contact.db/public-key-and-ens-name->new-contact identity ens-name)))))
|
||||
:<- [:mediaserver/port]
|
||||
(fn [[contacts identity ens-name port]]
|
||||
(let [contact (get contacts identity)]
|
||||
(cond-> contact
|
||||
(nil? contact) (enrich-contact identity ens-name port)))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:contacts/contact-by-identity
|
||||
@ -3005,6 +3048,27 @@
|
||||
(fn [multiaccount]
|
||||
(pos? (count (get multiaccount :images)))))
|
||||
|
||||
(defn- replace-multiaccount-image-uri [multiaccount port]
|
||||
(let [public-key (:public-key multiaccount)
|
||||
identicon (image-server/get-identicons-uri port public-key)
|
||||
multiaccount (assoc multiaccount :identicon identicon)
|
||||
images (:images multiaccount)
|
||||
images (reduce (fn [acc current]
|
||||
(let [key-uid (:keyUid current)
|
||||
image-name (:type current)
|
||||
uri (image-server/get-account-image-uri port public-key image-name key-uid)]
|
||||
(conj acc (assoc current :uri uri))))
|
||||
[]
|
||||
images)]
|
||||
(assoc multiaccount :images images)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:profile/multiaccount
|
||||
:<- [:multiaccount]
|
||||
:<- [:mediaserver/port]
|
||||
(fn [[multiaccount port]]
|
||||
(replace-multiaccount-image-uri multiaccount port)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:mobile-network/syncing-allowed?
|
||||
:<- [:network/type]
|
||||
|
@ -4,20 +4,17 @@
|
||||
[status-im.ui.screens.chat.styles.photos :as style]
|
||||
[status-im.profile.db :as profile.db]
|
||||
[status-im.multiaccounts.core :as multiaccounts]
|
||||
[status-im.utils.image :as utils.image]
|
||||
[quo.design-system.colors :as colors]
|
||||
[status-im.ui.components.fast-image :as fast-image]))
|
||||
|
||||
(def memo-photo-rend
|
||||
(memoize
|
||||
(fn [photo-path size accessibility-label _]
|
||||
(let [identicon? (when photo-path (profile.db/base64-png? photo-path))]
|
||||
[react/view {:style (style/photo-container size)}
|
||||
[fast-image/fast-image {:source (utils.image/source photo-path)
|
||||
:style (style/photo size)
|
||||
:accessibility-label (or accessibility-label :chat-icon)}]
|
||||
(when identicon?
|
||||
[react/view {:style (style/photo-border size)}])]))))
|
||||
[react/view {:style (style/photo-container size)}
|
||||
[fast-image/fast-image {:source {:uri photo-path}
|
||||
:style (style/photo size)
|
||||
:accessibility-label (or accessibility-label :chat-icon)}]
|
||||
[react/view {:style (style/photo-border size)}]])))
|
||||
|
||||
;; "(colors/dark?)" is passed to memoized function to avoid previous themes cache
|
||||
(defn photo [photo-path {:keys [size accessibility-label]}]
|
||||
|
@ -179,7 +179,7 @@
|
||||
(defn my-profile []
|
||||
(fn []
|
||||
(let [{:keys [public-key ens-verified preferred-name]
|
||||
:as account} @(re-frame/subscribe [:multiaccount])
|
||||
:as account} @(re-frame/subscribe [:profile/multiaccount])
|
||||
on-share #(re-frame/dispatch [:show-popover
|
||||
{:view :share-chat-key
|
||||
:address public-key
|
||||
|
31
src/status_im/utils/image_server.cljs
Normal file
31
src/status_im/utils/image_server.cljs
Normal file
@ -0,0 +1,31 @@
|
||||
(ns status-im.utils.image-server
|
||||
(:require [quo.design-system.colors :as colors]
|
||||
[status-im.utils.config :as config]))
|
||||
|
||||
(def ^:const image-server-uri-prefix "https://localhost:")
|
||||
(def ^:const identicons-action "/messages/identicons")
|
||||
(def ^:const account-images-action "/accountImages")
|
||||
(def ^:const contact-images-action "/contactImages")
|
||||
|
||||
(defn current-theme []
|
||||
(case @colors/theme-type
|
||||
:light 1
|
||||
:dark 2))
|
||||
|
||||
(defn- timestamp []
|
||||
(.getTime (js/Date.)))
|
||||
|
||||
(defn get-identicons-uri [port public-key]
|
||||
(let [base (str image-server-uri-prefix port identicons-action "?publicKey=" public-key "&theme=" (current-theme) "&clock=" (timestamp))]
|
||||
(cond-> base
|
||||
@config/new-ui-enabled? (str "&addRing=1"))))
|
||||
|
||||
(defn get-account-image-uri [port public-key image-name key-uid]
|
||||
(let [base (str image-server-uri-prefix port account-images-action "?publicKey=" public-key "&keyUid=" key-uid "&imageName=" image-name "&theme=" (current-theme) "&clock=" (timestamp))]
|
||||
(cond-> base
|
||||
@config/new-ui-enabled? (str "&addRing=1"))))
|
||||
|
||||
(defn get-contact-image-uri [port public-key image-name clock]
|
||||
(let [base (str image-server-uri-prefix port contact-images-action "?publicKey=" public-key "&imageName=" image-name "&theme=" (current-theme) "&clock=" clock)]
|
||||
(cond-> base
|
||||
@config/new-ui-enabled? (str "&addRing=1"))))
|
Loading…
x
Reference in New Issue
Block a user