Default contacts (#580)

This commit is contained in:
alwx 2016-12-24 13:15:35 +03:00
parent 3936c05ecd
commit 0e190c624b
16 changed files with 123 additions and 55 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

24
resources/dapp.js Normal file
View File

@ -0,0 +1,24 @@
I18n.translations = {
en: {
browse_title: 'Browser',
browse_description: 'Launch the browser'
}
};
status.command({
name: "browse",
title: I18n.t('browse_title'),
description: I18n.t('browse_description'),
color: "#ffa500",
fullscreen: true,
suggestionsTrigger: 'on-send',
params: [{
name: "url",
suggestions: function(params, context) {
return {webViewUrl: "dapp-url"};
},
type: status.types.TEXT
}]
});
status.autorun("browse");

View File

@ -0,0 +1,13 @@
[
{"id": "wallet",
"name": "Wallet",
"photo-path": "icon_wallet_avatar",
"add-chat?": true,
"dapp?": true},
{"id": "dapp-auction-house",
"name": "Auction House",
"photo-path": "contacts://auction-house",
"dapp?": true,
"dapp-url": "http://auctionhouse.dappbench.com"}
]

View File

@ -37,7 +37,6 @@
status-im.chat.handlers.faucet status-im.chat.handlers.faucet
[cljs.core.async :as a] [cljs.core.async :as a]
status-im.chat.handlers.webview-bridge status-im.chat.handlers.webview-bridge
status-im.chat.handlers.wallet-chat
status-im.chat.handlers.console status-im.chat.handlers.console
[taoensso.timbre :as log] [taoensso.timbre :as log]
[tailrecursion.priority-map :refer [priority-map-by]])) [tailrecursion.priority-map :refer [priority-map-by]]))
@ -343,7 +342,7 @@
;TODO: check if its new account / signup status / create console chat ;TODO: check if its new account / signup status / create console chat
(register-handler :initialize-chats (register-handler :initialize-chats
[(after #(dispatch [:load-unviewed-messages!])) [(after #(dispatch [:load-unviewed-messages!]))
(after #(dispatch [:init-wallet-chat]))] (after #(dispatch [:load-default-contacts!]))]
((enrich initialize-chats) load-chats!)) ((enrich initialize-chats) load-chats!))
(defmethod nav/preload-data! :chat (defmethod nav/preload-data! :chat
@ -399,9 +398,7 @@
:group-chat false :group-chat false
:is-active true :is-active true
:timestamp (.getTime (js/Date.)) :timestamp (.getTime (js/Date.))
:contacts [{:identity chat-id}] :contacts [{:identity chat-id}]}
:dapp-url nil
:dapp-hash nil}
chat))) chat)))
(defn add-new-chat (defn add-new-chat

View File

@ -1,23 +0,0 @@
(ns status-im.chat.handlers.wallet-chat
(:require [re-frame.core :refer [after enrich path dispatch]]
[status-im.utils.handlers :refer [register-handler] :as u]
[status-im.constants :refer [wallet-chat-id]]
[clojure.string :as s]))
(def dapp-contact
{:whisper-identity wallet-chat-id
:name (s/capitalize wallet-chat-id)
:dapp? true
:photo-path :icon_wallet_avatar})
(register-handler :init-wallet-chat
(u/side-effect!
(fn [{:keys [chats]}]
(when-not (chats wallet-chat-id)
(dispatch [:add-chat
wallet-chat-id
{:name "Wallet"
:dapp-url "http://192.168.1.125:3450"}])
(dispatch [:add-contacts [dapp-contact]])))))

View File

@ -173,9 +173,6 @@
(def console-chat (def console-chat
{:chat-id console-chat-id {:chat-id console-chat-id
:name (s/capitalize console-chat-id) :name (s/capitalize console-chat-id)
; todo remove/change dapp config fot console
:dapp-url "http://localhost:8185/resources"
:dapp-hash 858845357
:color default-chat-color :color default-chat-color
:group-chat false :group-chat false
:is-active true :is-active true
@ -189,4 +186,7 @@
{:whisper-identity console-chat-id {:whisper-identity console-chat-id
:name (s/capitalize console-chat-id) :name (s/capitalize console-chat-id)
:photo-path console-chat-id :photo-path console-chat-id
:dapp? true}) :dapp? true
; todo remove/change dapp config fot console
:dapp-url "http://localhost:8185/resources"
:dapp-hash 858845357})

View File

@ -42,13 +42,17 @@
:else nil))) :else nil)))
(defn suggestions-handler! (defn suggestions-handler!
[db [{:keys [chat-id]} {:keys [result]}]] [{:keys [contacts] :as db} [{:keys [chat-id]} {:keys [result]}]]
(let [{:keys [markup webViewUrl]} (:returned result) (let [{:keys [markup webViewUrl]} (:returned result)
hiccup (generate-hiccup markup)] {:keys [dapp? dapp-url]} (get contacts chat-id)
hiccup (generate-hiccup markup)
web-view-url (if (and (= webViewUrl "dapp-url") dapp? dapp-url)
dapp-url
webViewUrl)]
(-> db (-> db
(assoc-in [:suggestions chat-id] hiccup) (assoc-in [:suggestions chat-id] hiccup)
(assoc-in [:web-view-url chat-id] webViewUrl) (assoc-in [:web-view-url chat-id] web-view-url)
(assoc-in [:has-suggestions? chat-id] (or hiccup webViewUrl))))) (assoc-in [:has-suggestions? chat-id] (or hiccup web-view-url)))))
(defn suggestions-events-handler! (defn suggestions-events-handler!
[{:keys [current-chat-id] :as db} [[n data]]] [{:keys [current-chat-id] :as db} [[n data]]]

View File

@ -16,26 +16,32 @@
(def commands-js "commands.js") (def commands-js "commands.js")
(defn load-commands! (defn load-commands!
[{:keys [current-chat-id]} [identity]] [{:keys [current-chat-id contacts]} [identity]]
(dispatch [::fetch-commands! (or identity current-chat-id)]) (let [identity (or identity current-chat-id)
contact (or (get contacts identity)
{:whisper-identity identity})]
(dispatch [::fetch-commands! contact]))
;; todo uncomment ;; todo uncomment
#_(if-let [{:keys [file]} (commands/get-by-chat-id identity)] #_(if-let [{:keys [file]} (commands/get-by-chat-id identity)]
(dispatch [::parse-commands! identity file]) (dispatch [::parse-commands! identity file])
(dispatch [::fetch-commands! identity]))) (dispatch [::fetch-commands! identity])))
(defn fetch-commands! (defn fetch-commands!
[db [identity]] [db [{:keys [whisper-identity dapp? dapp-url]}]]
(when true (when true
;-let [url (get-in db [:chats identity :dapp-url])] ;-let [url (get-in db [:chats identity :dapp-url])]
(cond (cond
(= console-chat-id identity) (= console-chat-id whisper-identity)
(dispatch [::validate-hash identity js-res/console-js]) (dispatch [::validate-hash whisper-identity js-res/console-js])
(= wallet-chat-id identity) (= wallet-chat-id whisper-identity)
(dispatch [::validate-hash identity js-res/wallet-js]) (dispatch [::validate-hash whisper-identity js-res/wallet-js])
(and dapp? dapp-url)
(dispatch [::validate-hash whisper-identity js-res/dapp-js])
:else :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]) #_(http-get (s/join "/" [url commands-js])
#(dispatch [::validate-hash identity %]) #(dispatch [::validate-hash identity %])
@ -49,7 +55,7 @@
(defn get-hash-by-identity (defn get-hash-by-identity
[db identity] [db identity]
(get-in db [:chats identity :dapp-hash])) (get-in db [:contacts identity :dapp-hash]))
(defn get-hash-by-file (defn get-hash-by-file
[file] [file]
@ -157,3 +163,20 @@
(reg-handler ::clear-commands-callbacks (reg-handler ::clear-commands-callbacks
(fn [db [chat-id]] (fn [db [chat-id]]
(assoc-in db [::commands-callbacks chat-id] nil))) (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}]])))))))

View File

@ -5,9 +5,11 @@
text text
image image
icon]] icon]]
[taoensso.timbre :as log]
[status-im.components.icons.custom-icons :refer [oct-icon]] [status-im.components.icons.custom-icons :refer [oct-icon]]
[status-im.components.chat-icon.styles :as st] [status-im.components.chat-icon.styles :as st]
[status-im.components.styles :refer [default-chat-color]] [status-im.components.styles :refer [default-chat-color]]
[status-im.resources :as resources]
[status-im.constants :refer [console-chat-id]] [status-im.constants :refer [console-chat-id]]
[clojure.string :as s])) [clojure.string :as s]))
@ -17,9 +19,14 @@
(first name)]]) (first name)]])
(defn chat-icon [photo-path {:keys [size]}] (defn chat-icon [photo-path {:keys [size]}]
[image {:source {:uri photo-path} (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 :style (merge st/default-image-style
(st/image-style size))}]) (st/image-style size))}]))
(defn dapp-badge [styles] (defn dapp-badge [styles]
[view (:online-view-wrapper styles) [view (:online-view-wrapper styles)

View File

@ -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"}
])

View File

@ -274,4 +274,3 @@
0 (dispatch [:remove-contact contact]) 0 (dispatch [:remove-contact contact])
:default)) :default))
:cancel-text (label :t/cancel)})))) :cancel-text (label :t/cancel)}))))

View File

@ -16,10 +16,6 @@
:timestamp :int :timestamp :int
:contacts {:type :list :contacts {:type :list
:objectType :chat-contact} :objectType :chat-contact}
:dapp-url {:type :string
:optional true}
:dapp-hash {:type :int
:optional true}
:removed-at {:type :int :removed-at {:type :int
:optional true} :optional true}
:removed-from-at {:type :int :removed-from-at {:type :int

View File

@ -16,7 +16,11 @@
:private-key {:type :string :private-key {:type :string
:optional true} :optional true}
:dapp? {:type :bool :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] (defn migration [old-realm new-realm]
(log/debug "migrating contact schema")) (log/debug "migrating contact schema"))

View File

@ -85,7 +85,7 @@
(dispatch [:initialize-db]) (dispatch [:initialize-db])
(dispatch [:load-accounts]) (dispatch [:load-accounts])
(dispatch [:init-console-chat]) (dispatch [:init-console-chat])
(dispatch [:init-wallet-chat]) (dispatch [:load-default-contacts!])
(dispatch [:load-commands! console-chat-id]) (dispatch [:load-commands! console-chat-id])
(dispatch [:load-commands!])))) (dispatch [:load-commands!]))))

View File

@ -17,3 +17,6 @@
(def smile (js/require "./images/smile.png")) (def smile (js/require "./images/smile.png"))
(def trash-icon (js/require "./images/trash.png")) (def trash-icon (js/require "./images/trash.png"))
(def v (js/require "./images/v.png")) (def v (js/require "./images/v.png"))
(def contacts
{:auction-house (js/require "./images/contacts/auction-house.png")})

View File

@ -1,10 +1,14 @@
(ns ^:figwheel-always status-im.utils.js-resources (ns ^:figwheel-always status-im.utils.js-resources
(:require-macros [status-im.utils.slurp :refer [slurp]])) (: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 commands-js (slurp "resources/commands.js"))
(def console-js (slurp "resources/console.js")) (def console-js (slurp "resources/console.js"))
(def status-js (slurp "resources/status.js")) (def status-js (slurp "resources/status.js"))
(def wallet-js (str commands-js (slurp "resources/wallet.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 webview-js (slurp "resources/webview.js"))
(def web3 (str "if (typeof Web3 == 'undefined') {" (def web3 (str "if (typeof Web3 == 'undefined') {"
(slurp "resources/web3.0_16_0.min.js") (slurp "resources/web3.0_16_0.min.js")