From eab8dd5ca21b851da7fa508b978a0fb1ffa79647 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Tue, 21 Jun 2016 15:23:19 +0300 Subject: [PATCH] added identicons for default profile pictures --- .re-natal | 3 ++- package.json | 1 + src/status_im/contacts/views/new_contact.cljs | 3 ++- src/status_im/models/contacts.cljs | 5 +++-- src/status_im/utils/identicon.cljs | 9 +++++++++ 5 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 src/status_im/utils/identicon.cljs diff --git a/.re-natal b/.re-natal index 4fecaf5ca5..a547f09695 100644 --- a/.re-natal +++ b/.re-natal @@ -18,7 +18,8 @@ "react-native-linear-gradient", "react-native-android-sms-listener", "react-native-camera", - "react-native-qrcode" + "react-native-qrcode", + "identicon.js" ], "imageDirs": [ "images" diff --git a/package.json b/package.json index b26cf32faf..dae27c270e 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ }, "dependencies": { "awesome-phonenumber": "^1.0.13", + "identicon.js": "github:status-im/identicon.js", "react": "^0.14.5", "react-native": "^0.24.1", "react-native-action-button": "^1.1.4", diff --git a/src/status_im/contacts/views/new_contact.cljs b/src/status_im/contacts/views/new_contact.cljs index 469ed6b914..8a6132f19d 100644 --- a/src/status_im/contacts/views/new_contact.cljs +++ b/src/status_im/contacts/views/new_contact.cljs @@ -7,6 +7,7 @@ image linear-gradient touchable-highlight]] + [status-im.utils.identicon :refer [identicon]] [status-im.components.toolbar :refer [toolbar]] [status-im.components.drawer.view :refer [drawer-view open-drawer]] [status-im.components.styles :refer [color-purple @@ -71,7 +72,7 @@ :custom-content toolbar-title :action {:image {:source {:uri :icon_add} :style icon-search} - :handler #(dispatch [:add-new-contact new-contact])}}] + :handler #(dispatch [:add-new-contact (merge new-contact {:photo-path (identicon whisper-identity 40)})])}}] [view st/form-container [contact-whisper-id-input whisper-identity] [contact-name-input name] diff --git a/src/status_im/models/contacts.cljs b/src/status_im/models/contacts.cljs index ec286b17a6..03194bc37c 100644 --- a/src/status_im/models/contacts.cljs +++ b/src/status_im/models/contacts.cljs @@ -1,5 +1,6 @@ (ns status-im.models.contacts (:require [status-im.persistence.realm :as r] + [status-im.utils.identicon :refer [identicon]] [status-im.persistence.realm-queries :refer [include-query exclude-query]])) @@ -8,9 +9,9 @@ (r/sorted :name :asc) r/collection->map)) -(defn create-contact [{:keys [name photo-path] :as contact}] +(defn create-contact [{:keys [name photo-path whisper-identity] :as contact}] (->> {:name (or name "") - :photo-path (or photo-path "")} + :photo-path (or photo-path (identicon whisper-identity 40))} (merge contact) (r/create :contacts))) diff --git a/src/status_im/utils/identicon.cljs b/src/status_im/utils/identicon.cljs new file mode 100644 index 0000000000..de585e4b04 --- /dev/null +++ b/src/status_im/utils/identicon.cljs @@ -0,0 +1,9 @@ +(ns status-im.utils.identicon + (:require [clojure.string :as s] + [status-im.utils.utils :as u])) + +(def identicon-js (u/require "identicon.js")) + +(defn identicon [hash options] + (str "data:image/png;base64," (.toString (new identicon-js hash options)))) +