Skip to content

Commit

Permalink
tidy: use :type instead of :kind, remove unneeded schema registration…
Browse files Browse the repository at this point in the history
…s, use :multi for schema definition
  • Loading branch information
seanstrom committed Mar 22, 2024
1 parent 64fb6cc commit 1362a09
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 49 deletions.
28 changes: 13 additions & 15 deletions src/schema/quo.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@
[:override-ring? [:maybe :boolean]]])

(def ^:private ?image-uri-config
[:or
[:map
[:kind [:enum :contact]]
[:options ?contact-image-uri-options]]
[:map
[:kind [:enum :account]]
[:options ?account-image-uri-options]]
[:map
[:kind [:enum :initials]]
[:options ?initials-image-uri-options]]])
[:merge
[:map [:type [:enum :account :contact :initials]]]
[:multi {:dispatch :type}
[:account
[:map
[:options ?account-image-uri-options]]]
[:contact
[:map
[:options ?contact-image-uri-options]]]
[:initials
[:map
[:options ?initials-image-uri-options]]]]])

(def ^:private ?profile-picture-source
[:or
Expand All @@ -67,10 +69,6 @@

(defn register-schemas
[]
(registry/register ::profile-picture-options ?profile-picture-options)
(registry/register ::image-uri-config ?image-uri-config)
(registry/register ::profile-picture-source ?profile-picture-source)
(registry/register ::profile-picture-options ?profile-picture-options)
(registry/register ::account-image-uri-options ?account-image-uri-options)
(registry/register ::contact-image-uri-options ?contact-image-uri-options)
(registry/register ::initials-image-uri-options ?initials-image-uri-options))
(registry/register ::profile-picture-options ?profile-picture-options))
4 changes: 2 additions & 2 deletions src/status_im/subs/contact.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
(when ens-name false)}]
(assoc-in acc
[(keyword image-name) :config]
{:kind :contact
{:type :contact
:options options})))
images
(vals images))

images (if (seq images)
images
{:thumbnail
{:config {:kind :initials
{:config {:type :initials
:options {:port port
:ratio pixel-ratio/ratio
:public-key public-key
Expand Down
12 changes: 6 additions & 6 deletions src/status_im/subs/profile.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
(fn [[port font-file] [_ profile-pic]]
{:config
(if profile-pic
{:kind :account
{:type :account
:options {:port port
:ratio pixel-ratio/ratio
:image-name profile-pic
:override-ring? false
:uppercase-ratio (:uppercase-ratio
constants/initials-avatar-font-conf)
:theme (theme/get-theme)}}
{:kind :initials
{:type :initials
:options {:port port
:ratio pixel-ratio/ratio
:theme (theme/get-theme)
Expand All @@ -68,14 +68,14 @@
(when profile
{:config
(if image-name
{:kind :account
{:type :account
:options {:port port
:ratio pixel-ratio/ratio
:image-name image-name
:key-uid target-key-uid
:theme (theme/get-theme)
:override-ring? override-ring?}}
{:kind :initials
{:type :initials
:options {:port port
:ratio pixel-ratio/ratio
:key-uid target-key-uid
Expand Down Expand Up @@ -328,7 +328,7 @@
images-with-uri (mapv (fn [{key-uid :keyUid image-name :type :as image}]
(assoc image
:config
{:kind :account
{:type :account
:options (merge
{:port port
:ratio pixel-ratio/ratio
Expand All @@ -339,7 +339,7 @@
images)
new-images (if (seq images-with-uri)
images-with-uri
[{:config {:kind :initials
[{:config {:type :initials
:options (merge
{:port port
:ratio pixel-ratio/ratio
Expand Down
28 changes: 2 additions & 26 deletions src/utils/image_server.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@
"&ringWidth="
(* ring-width ratio)))

(schema/=> get-account-image-uri
[:=>
[:cat
[:union
:schema.quo/account-image-uri-options
:schema.quo/profile-picture-options]]
[:string]])

(defn get-initials-avatar-uri
"fn to get the avatar uri when account/contact/placeholder has no custom pic set
Expand Down Expand Up @@ -163,14 +155,6 @@
"&ringWidth="
(* ring-width ratio)))

(schema/=> get-initials-avatar-uri
[:=>
[:cat
[:union
:schema.quo/initials-image-uri-options
:schema.quo/profile-picture-options]]
[:string]])

(defn get-contact-image-uri
"check `get-account-image-uri` for color formats
check `get-font-file-ready` for `font-file`
Expand Down Expand Up @@ -207,14 +191,6 @@
"&ringWidth="
(* ring-width ratio)))

(schema/=> get-contact-image-uri
[:=>
[:cat
[:union
:schema.quo/contact-image-uri-options
:schema.quo/profile-picture-options]]
[:string]])

(defn get-qr-image-uri-for-any-url
[{:keys [url port qr-size error-level]}]
(let [qr-url-base64 (js/btoa url)
Expand All @@ -234,9 +210,9 @@
media-server-url))

(defn get-image-uri
[{:keys [kind options]}
[{:keys [type options]}
profile-picture-options]
((case kind
((case type
:account get-account-image-uri
:contact get-contact-image-uri
:initials get-initials-avatar-uri
Expand Down

0 comments on commit 1362a09

Please sign in to comment.