From 0e190c624b9ac4af34a477a045a0a1ee5e3b8d29 Mon Sep 17 00:00:00 2001 From: alwx Date: Sat, 24 Dec 2016 13:15:35 +0300 Subject: [PATCH] Default contacts (#580) --- images/contacts/auction-house.png | Bin 0 -> 2068 bytes resources/dapp.js | 24 ++++++++++ resources/default_contacts.json | 13 ++++++ src/status_im/chat/handlers.cljs | 7 +-- src/status_im/chat/handlers/wallet_chat.cljs | 23 ---------- src/status_im/chat/sign_up.cljs | 8 ++-- src/status_im/commands/handlers/jail.cljs | 12 +++-- src/status_im/commands/handlers/loading.cljs | 41 ++++++++++++++---- .../components/chat_icon/screen.cljs | 13 ++++-- src/status_im/contacts/default_contacts.cljs | 17 ++++++++ src/status_im/contacts/handlers.cljs | 1 - .../realm/schemas/account/v1/chat.cljs | 4 -- .../realm/schemas/account/v1/contact.cljs | 6 ++- src/status_im/handlers.cljs | 2 +- src/status_im/resources.cljs | 3 ++ src/status_im/utils/js_resources.cljs | 4 ++ 16 files changed, 123 insertions(+), 55 deletions(-) create mode 100644 images/contacts/auction-house.png create mode 100644 resources/dapp.js create mode 100644 resources/default_contacts.json delete mode 100644 src/status_im/chat/handlers/wallet_chat.cljs create mode 100644 src/status_im/contacts/default_contacts.cljs diff --git a/images/contacts/auction-house.png b/images/contacts/auction-house.png new file mode 100644 index 0000000000000000000000000000000000000000..59eebce4046ac12c32046997ca173afae8e56f68 GIT binary patch literal 2068 zcmV+v2Ye-XX9LK-sc=GIQU{Ppdjw~pYAh#}Nrb&_d$_Nq~LJHX; zf{axrU0(PHu`FZMn+P*d3yiMhD=!pY%IxAa=mHTH(;*YV3A?D%=l>!d-saqPwzG5E z2LyLHzvp|tJLfsK-}8GYgaE_C!{qz-?-&>uK!1Nfj7B5OW;5(|JM4BlY&ILl#>T+1 zEaY-IIF19yafpeDfl{eNe0)6O>Vm;wfWctEpFe+i zi=B{=0F_DwwOWm|v@}FTMFo8wgVvzK;UJxzooH%m!rQlR;dD9!-X_B^NJ~pYPEHQe z)6*f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Vx1v_`{TzViyVPRqL6iI-^ z{90gYW@cvivUQnk+_(`L85s-SUtlUt)09r93yLVQqtodye+(7iX2f4=YAUsV|Ng+M z5-|r39B^Ay!R^yjolb}FL&3$7%jGz8=8W6V-I^K`6GNRoeL5hb#7=Q>@shF z_pcns;p)|^9t{PSS(j?_=FQZ#YuEnS2ZRj6pt7=ZS(SbOFN%GorlwM5Wo14K6Dt%& zp{%S7yLRnbb`3AD64bJ@v#Imv&wH;-#GE^K4p~`QUX`T_7f^IVPzxx|(AL&Qu3Wi- z@$qqALxe0W%c8uz9DDcf^~oQepjNA?`ucjwKYsj3Zrr#bs$rQ42?;1E zDZ!2%J3^}@{cI*CCdk8w4{`tg{g58+E|bY{?AS5n=jXeg*Yicdrui5g93*vhb!cpC z45>2&mSvHfn~Q>i0<2xTRvgoO%x8Fbm^3sr;OWz+f=@_u`0!z9G#ac~vqqc~(#*%< zaFF))b~H6Lp{uJaD1(d{hQaRLyOEQVgN%#}=}eup7#53#ym|8mJv}|>?d|3DwxUw0 zgj%hJTCK*OJ$tZn db (assoc-in [:suggestions chat-id] hiccup) - (assoc-in [:web-view-url chat-id] webViewUrl) - (assoc-in [:has-suggestions? chat-id] (or hiccup webViewUrl))))) + (assoc-in [:web-view-url chat-id] web-view-url) + (assoc-in [:has-suggestions? chat-id] (or hiccup web-view-url))))) (defn suggestions-events-handler! [{:keys [current-chat-id] :as db} [[n data]]] diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index da4c62afa1..fd8a85d2d8 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -16,26 +16,32 @@ (def commands-js "commands.js") (defn load-commands! - [{:keys [current-chat-id]} [identity]] - (dispatch [::fetch-commands! (or identity current-chat-id)]) + [{:keys [current-chat-id contacts]} [identity]] + (let [identity (or identity current-chat-id) + contact (or (get contacts identity) + {:whisper-identity identity})] + (dispatch [::fetch-commands! contact])) ;; todo uncomment #_(if-let [{:keys [file]} (commands/get-by-chat-id identity)] (dispatch [::parse-commands! identity file]) (dispatch [::fetch-commands! identity]))) (defn fetch-commands! - [db [identity]] + [db [{:keys [whisper-identity dapp? dapp-url]}]] (when true ;-let [url (get-in db [:chats identity :dapp-url])] (cond - (= console-chat-id identity) - (dispatch [::validate-hash identity js-res/console-js]) + (= console-chat-id whisper-identity) + (dispatch [::validate-hash whisper-identity js-res/console-js]) - (= wallet-chat-id identity) - (dispatch [::validate-hash identity js-res/wallet-js]) + (= wallet-chat-id whisper-identity) + (dispatch [::validate-hash whisper-identity js-res/wallet-js]) + + (and dapp? dapp-url) + (dispatch [::validate-hash whisper-identity js-res/dapp-js]) :else - (dispatch [::validate-hash identity js-res/commands-js]) + (dispatch [::validate-hash whisper-identity js-res/commands-js]) #_(http-get (s/join "/" [url commands-js]) #(dispatch [::validate-hash identity %]) @@ -49,7 +55,7 @@ (defn get-hash-by-identity [db identity] - (get-in db [:chats identity :dapp-hash])) + (get-in db [:contacts identity :dapp-hash])) (defn get-hash-by-file [file] @@ -157,3 +163,20 @@ (reg-handler ::clear-commands-callbacks (fn [db [chat-id]] (assoc-in db [::commands-callbacks chat-id] nil))) + +(reg-handler :load-default-contacts! + (u/side-effect! + (fn [{:keys [chats]}] + (let [contacts (json->clj js-res/default-contacts-js)] + (doseq [{:keys [id name photo-path public-key add-chat? + dapp? dapp-url dapp-hash] :as contact} contacts] + (when-not (chats id) + (when add-chat? + (dispatch [:add-chat id {:name name}])) + (dispatch [:add-contacts [{:whisper-identity id + :name name + :photo-path photo-path + :public-key public-key + :dapp? dapp? + :dapp-url dapp-url + :dapp-hash dapp-hash}]]))))))) diff --git a/src/status_im/components/chat_icon/screen.cljs b/src/status_im/components/chat_icon/screen.cljs index fd45fac910..8e4797da40 100644 --- a/src/status_im/components/chat_icon/screen.cljs +++ b/src/status_im/components/chat_icon/screen.cljs @@ -5,9 +5,11 @@ text image icon]] + [taoensso.timbre :as log] [status-im.components.icons.custom-icons :refer [oct-icon]] [status-im.components.chat-icon.styles :as st] [status-im.components.styles :refer [default-chat-color]] + [status-im.resources :as resources] [status-im.constants :refer [console-chat-id]] [clojure.string :as s])) @@ -17,9 +19,14 @@ (first name)]]) (defn chat-icon [photo-path {:keys [size]}] - [image {:source {:uri photo-path} - :style (merge st/default-image-style - (st/image-style size))}]) + (let [photo (if (s/starts-with? photo-path "contacts://") + (->> (s/replace photo-path #"contacts://" "") + (keyword) + (get resources/contacts)) + {:uri photo-path})] + [image {:source photo + :style (merge st/default-image-style + (st/image-style size))}])) (defn dapp-badge [styles] [view (:online-view-wrapper styles) diff --git a/src/status_im/contacts/default_contacts.cljs b/src/status_im/contacts/default_contacts.cljs new file mode 100644 index 0000000000..dc6e976f9d --- /dev/null +++ b/src/status_im/contacts/default_contacts.cljs @@ -0,0 +1,17 @@ +(ns status-im.contacts.default-contacts + (:require [status-im.constants :refer [wallet-chat-id]] + [clojure.string :as s])) + +(def contacts + [{:whisper-identity wallet-chat-id + :name (s/capitalize wallet-chat-id) + :photo-path :icon_wallet_avatar + :dapp? true + :add-chat? true} + + {:whisper-identity "dapp-auction" + :name "Auction House" + :photo-path "http://auctionhouse.dappbench.com/images/auctionhouse.png" + :dapp? true + :dapp-url "http://auctionhouse.dappbench.com"} + ]) diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index 718d8dfe0a..f91038e9ba 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -274,4 +274,3 @@ 0 (dispatch [:remove-contact contact]) :default)) :cancel-text (label :t/cancel)})))) - diff --git a/src/status_im/data_store/realm/schemas/account/v1/chat.cljs b/src/status_im/data_store/realm/schemas/account/v1/chat.cljs index 15468bd5e9..6223b65c64 100644 --- a/src/status_im/data_store/realm/schemas/account/v1/chat.cljs +++ b/src/status_im/data_store/realm/schemas/account/v1/chat.cljs @@ -16,10 +16,6 @@ :timestamp :int :contacts {:type :list :objectType :chat-contact} - :dapp-url {:type :string - :optional true} - :dapp-hash {:type :int - :optional true} :removed-at {:type :int :optional true} :removed-from-at {:type :int diff --git a/src/status_im/data_store/realm/schemas/account/v1/contact.cljs b/src/status_im/data_store/realm/schemas/account/v1/contact.cljs index 3f8e176f88..d49edcbf74 100644 --- a/src/status_im/data_store/realm/schemas/account/v1/contact.cljs +++ b/src/status_im/data_store/realm/schemas/account/v1/contact.cljs @@ -16,7 +16,11 @@ :private-key {:type :string :optional true} :dapp? {:type :bool - :default false}}}) + :default false} + :dapp-url {:type :string + :optional true} + :dapp-hash {:type :int + :optional true}}}) (defn migration [old-realm new-realm] (log/debug "migrating contact schema")) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 3d05f1a7fb..ad13fa24c4 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -85,7 +85,7 @@ (dispatch [:initialize-db]) (dispatch [:load-accounts]) (dispatch [:init-console-chat]) - (dispatch [:init-wallet-chat]) + (dispatch [:load-default-contacts!]) (dispatch [:load-commands! console-chat-id]) (dispatch [:load-commands!])))) diff --git a/src/status_im/resources.cljs b/src/status_im/resources.cljs index 4b49c06d0e..c7e574dd4e 100644 --- a/src/status_im/resources.cljs +++ b/src/status_im/resources.cljs @@ -17,3 +17,6 @@ (def smile (js/require "./images/smile.png")) (def trash-icon (js/require "./images/trash.png")) (def v (js/require "./images/v.png")) + +(def contacts + {:auction-house (js/require "./images/contacts/auction-house.png")}) diff --git a/src/status_im/utils/js_resources.cljs b/src/status_im/utils/js_resources.cljs index 7e380e730b..ec162d86ef 100644 --- a/src/status_im/utils/js_resources.cljs +++ b/src/status_im/utils/js_resources.cljs @@ -1,10 +1,14 @@ (ns ^:figwheel-always status-im.utils.js-resources (:require-macros [status-im.utils.slurp :refer [slurp]])) +(def default-contacts-js (slurp "resources/default_contacts.json")) + (def commands-js (slurp "resources/commands.js")) (def console-js (slurp "resources/console.js")) (def status-js (slurp "resources/status.js")) (def wallet-js (str commands-js (slurp "resources/wallet.js"))) +(def dapp-js (str (slurp "resources/dapp.js"))) + (def webview-js (slurp "resources/webview.js")) (def web3 (str "if (typeof Web3 == 'undefined') {" (slurp "resources/web3.0_16_0.min.js")