add global-command to default_contacts

load browse first
prefill global-commands before bot's jails are loaded
This commit is contained in:
Roman Volosovskyi 2017-05-05 11:40:10 +03:00
parent 808aa46f4f
commit 4265e73f33
2 changed files with 48 additions and 27 deletions

View File

@ -1,4 +1,27 @@
{ {
"browse":
{
"name":
{
"en": "Browse"
},
"dapp?": true,
"bot-url": "local://browse-bot",
"global-command": {
"description":"Launch the browser",
"color": "#ffa500",
"name": "global",
"params": [{
"name": "url",
"placeholder":"URL",
"type":"text"
}],
"title":"Browser",
"registered-only":true,
"has-handler": false,
"fullscreen":true
}
},
"wallet": "wallet":
{ {
"name": "name":
@ -42,16 +65,6 @@
"bot-url": "local://demo-bot" "bot-url": "local://demo-bot"
}, },
"browse":
{
"name":
{
"en": "Browse"
},
"dapp?": true,
"bot-url": "local://browse-bot"
},
"0x0428c9d6c1aaaa8369a7c63819684f30e34396dc0907d49afeac85a0a774ccb919b3482097d992e66bcc538e7a0c6acf874c77748f396f53c0a102e10d1a37765b": "0x0428c9d6c1aaaa8369a7c63819684f30e34396dc0907d49afeac85a0a774ccb919b3482097d992e66bcc538e7a0c6acf874c77748f396f53c0a102e10d1a37765b":
{ {
"name": "name":

View File

@ -201,13 +201,21 @@
(defn add-new-contacts (defn add-new-contacts
[{:keys [contacts] :as db} [_ new-contacts]] [{:keys [contacts] :as db} [_ new-contacts]]
(let [identities (set (keys contacts)) (let [identities (set (keys contacts))
new-contacts' (->> new-contacts new-contacts' (->> new-contacts
(map #(update-pending-status contacts %)) (map #(update-pending-status contacts %))
(remove #(identities (:whisper-identity %))) (remove #(identities (:whisper-identity %)))
(map #(vector (:whisper-identity %) %)) (map #(vector (:whisper-identity %) %))
(into {}))] (into {}))
global-commands (->> new-contacts'
(keep (fn [[n {:keys [global-command]}]]
(when global-command
[(keyword n) (assoc global-command
:type :command
:bot n)])))
(into {}))]
(-> db (-> db
(update :global-commands merge global-commands)
(update :contacts merge new-contacts') (update :contacts merge new-contacts')
(assoc :new-contacts (vals new-contacts'))))) (assoc :new-contacts (vals new-contacts')))))
@ -234,23 +242,23 @@
:timestamp (random/timestamp) :timestamp (random/timestamp)
:contacts (mapv #(hash-map :identity %) contacts)}) :contacts (mapv #(hash-map :identity %) contacts)})
default-groups)]) default-groups)])
(doseq [[id {:keys [name photo-path public-key add-chat? has-global-command? (doseq [[id {:keys [name photo-path public-key add-chat? global-command
dapp? dapp-url dapp-hash bot-url]}] default-contacts] dapp? dapp-url dapp-hash bot-url]}] default-contacts]
(let [id' (clojure.core/name id)] (let [id' (clojure.core/name id)]
(when-not (get contacts id') (when-not (get contacts id')
(when add-chat? (when add-chat?
(dispatch [:add-chat id' {:name (:en name)}])) (dispatch [:add-chat id' {:name (:en name)}]))
(let [contact (let [contact
{:whisper-identity id' {:whisper-identity id'
:address (public-key->address id') :address (public-key->address id')
:name (:en name) :name (:en name)
:photo-path photo-path :photo-path photo-path
:public-key public-key :public-key public-key
:dapp? dapp? :dapp? dapp?
:dapp-url (:en dapp-url) :dapp-url (:en dapp-url)
:bot-url bot-url :bot-url bot-url
:has-global-command? has-global-command? :global-command global-command
:dapp-hash dapp-hash}] :dapp-hash dapp-hash}]
(dispatch [:add-contacts [contact]]) (dispatch [:add-contacts [contact]])
(when bot-url (when bot-url
(dispatch [:load-commands! contact])))))))))) (dispatch [:load-commands! contact]))))))))))