parent
95380175a6
commit
b1d4368154
|
@ -43,8 +43,8 @@
|
|||
(defn sort-contacts
|
||||
[contacts]
|
||||
(sort (fn [c1 c2]
|
||||
(let [name1 (or (:name c1) (:address c1) (:public-key c1))
|
||||
name2 (or (:name c2) (:address c2) (:public-key c2))]
|
||||
(let [name1 (first (:two-names c1))
|
||||
name2 (first (:two-names c2))]
|
||||
(compare (string/lower-case name1)
|
||||
(string/lower-case name2))))
|
||||
(vals contacts)))
|
||||
|
|
|
@ -40,11 +40,8 @@
|
|||
:three-words-name (or alias (gfycat/generate-gfy public-key))}
|
||||
;; Preferred name is our own otherwise we make sure it's verified
|
||||
(or preferred-name (and ens-verified name))
|
||||
(assoc :ens-name (str "@" (or (stateofus/username ens-name) ens-name))))))
|
||||
(assoc :ens-name (or (stateofus/username ens-name) ens-name)))))
|
||||
|
||||
;; NOTE: this does a bit of unnecessary work, we could short-circuit the work
|
||||
;; once the first two are found, i.e don't calculate short key if 2 are already
|
||||
;; available
|
||||
(defn contact-two-names
|
||||
"Returns vector of two names in next order nickname, ens name, display-name, three word name, public key"
|
||||
[{:keys [names
|
||||
|
@ -56,17 +53,17 @@
|
|||
display-name
|
||||
three-words-name]}
|
||||
(or names (contact-names contact))
|
||||
short-public-key (when public-key?
|
||||
(utils/get-shortened-address (or compressed-key
|
||||
public-key)))]
|
||||
(->> [nickname ens-name display-name three-words-name short-public-key]
|
||||
(remove string/blank?)
|
||||
(take 2))))
|
||||
non-empty-names (remove string/blank? [nickname ens-name display-name three-words-name])]
|
||||
(if (> (count non-empty-names) 1)
|
||||
(vec (take 2 non-empty-names))
|
||||
[(first non-empty-names)
|
||||
(when public-key? (utils/get-shortened-address (or compressed-key public-key)))])))
|
||||
|
||||
(defn contact-with-names
|
||||
"Returns contact with :names map "
|
||||
[contact]
|
||||
(assoc contact :names (contact-names contact)))
|
||||
(let [contact' (assoc contact :names (contact-names contact))]
|
||||
(assoc contact' :two-names (contact-two-names contact' true))))
|
||||
|
||||
(defn displayed-name
|
||||
"Use preferred name, name or alias in that order"
|
||||
|
@ -76,7 +73,7 @@
|
|||
;; Preferred name is our own otherwise we make sure it's verified
|
||||
(if (or preferred-name (and ens-verified name))
|
||||
(let [username (stateofus/username ens-name)]
|
||||
(str "@" (or username ens-name)))
|
||||
(or username ens-name))
|
||||
(or alias (gfycat/generate-gfy public-key)))))
|
||||
|
||||
(defn contact-by-identity
|
||||
|
|
|
@ -29,11 +29,11 @@
|
|||
(testing "names is nil"
|
||||
(testing "nickname has precedence"
|
||||
(is
|
||||
(= [nickname formatted-ens]
|
||||
(= [nickname ens-name]
|
||||
(ma/contact-two-names contact public-key))))
|
||||
(testing "ens name is second option"
|
||||
(is
|
||||
(= [formatted-ens display-name]
|
||||
(= [ens-name display-name]
|
||||
(ma/contact-two-names
|
||||
(dissoc contact :nickname)
|
||||
public-key))))
|
||||
|
|
|
@ -76,16 +76,10 @@
|
|||
:contacts/active-sections
|
||||
:<- [:contacts/active]
|
||||
(fn [contacts]
|
||||
(-> (reduce
|
||||
(fn [acc contact]
|
||||
(let [first-char (first (:alias contact))]
|
||||
(if (get acc first-char)
|
||||
(update-in acc [first-char :data] #(conj % contact))
|
||||
(assoc acc first-char {:title first-char :data [contact]}))))
|
||||
{}
|
||||
contacts)
|
||||
sort
|
||||
vals)))
|
||||
(->> contacts
|
||||
(group-by #(string/upper-case (ffirst (:two-names %))))
|
||||
sort
|
||||
(mapv (fn [[title items]] {:title title :data items})))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:contacts/grouped-by-first-letter
|
||||
|
|
|
@ -95,7 +95,8 @@
|
|||
:names {:nickname nil
|
||||
:display-name ""
|
||||
:three-words-name "Fake Slim Shady"
|
||||
:ens-name "@slim.shady"}
|
||||
:ens-name "slim.shady"}
|
||||
:two-names ["slim.shady" "Fake Slim Shady"]
|
||||
:has-added-us true
|
||||
:contact-request-state 1}]}
|
||||
{:title "I"
|
||||
|
@ -124,7 +125,8 @@
|
|||
:names {:nickname nil
|
||||
:display-name ""
|
||||
:three-words-name "Instant noodles"
|
||||
:ens-name "@slim.shady"}
|
||||
:ens-name "slim.shady"}
|
||||
:two-names ["slim.shady" "Instant noodles"]
|
||||
:has-added-us true
|
||||
:contact-request-state 1}]}
|
||||
{:title "R"
|
||||
|
@ -153,7 +155,8 @@
|
|||
:names {:nickname nil
|
||||
:display-name ""
|
||||
:three-words-name "Real Slim Shady"
|
||||
:ens-name "@slim.shady"}
|
||||
:ens-name "slim.shady"}
|
||||
:two-names ["slim.shady" "Real Slim Shady"]
|
||||
:has-added-us true
|
||||
:contact-request-state 1}]}])
|
||||
|
||||
|
|
Loading…
Reference in New Issue