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