parent
8f37885e18
commit
5d7005c64f
|
@ -17,7 +17,8 @@
|
||||||
[status-im.handlers.server :as server]
|
[status-im.handlers.server :as server]
|
||||||
[status-im.utils.phone-number :refer [format-phone-number]]
|
[status-im.utils.phone-number :refer [format-phone-number]]
|
||||||
[status-im.utils.datetime :as time]
|
[status-im.utils.datetime :as time]
|
||||||
[status-im.components.jail :as j]))
|
[status-im.components.jail :as j]
|
||||||
|
[status-im.commands.utils :refer [generate-hiccup]]))
|
||||||
|
|
||||||
(register-handler :set-show-actions
|
(register-handler :set-show-actions
|
||||||
(fn [db [_ show-actions]]
|
(fn [db [_ show-actions]]
|
||||||
|
@ -149,17 +150,18 @@
|
||||||
(commands/set-chat-command db command)
|
(commands/set-chat-command db command)
|
||||||
(assoc db :new-message (when-not (str/blank? text) message)))))
|
(assoc db :new-message (when-not (str/blank? text) message)))))
|
||||||
|
|
||||||
(defn prepare-command [identity chat-id staged-command]
|
(defn prepare-command
|
||||||
(let [command-name (get-in staged-command [:command :name])
|
[identity chat-id {:keys [preview preview-string content command]}]
|
||||||
content {:command command-name
|
(let [content {:command (command :name)
|
||||||
:content (:content staged-command)}]
|
:content content}]
|
||||||
{:msg-id (random/id)
|
{:msg-id (random/id)
|
||||||
:from identity
|
:from identity
|
||||||
:to chat-id
|
:to chat-id
|
||||||
:content content
|
:content content
|
||||||
:content-type content-type-command
|
:content-type content-type-command
|
||||||
:outgoing true
|
:outgoing true
|
||||||
:handler (:handler staged-command)}))
|
:preview preview-string
|
||||||
|
:rendered-preview preview}))
|
||||||
|
|
||||||
(defn prepare-staged-commans
|
(defn prepare-staged-commans
|
||||||
[{:keys [current-chat-id identity] :as db} _]
|
[{:keys [current-chat-id identity] :as db} _]
|
||||||
|
@ -212,7 +214,8 @@
|
||||||
(defn save-commands-to-realm!
|
(defn save-commands-to-realm!
|
||||||
[{:keys [new-commands current-chat-id]} _]
|
[{:keys [new-commands current-chat-id]} _]
|
||||||
(doseq [new-command new-commands]
|
(doseq [new-command new-commands]
|
||||||
(messages/save-message current-chat-id (dissoc new-command :handler))))
|
(messages/save-message current-chat-id
|
||||||
|
(dissoc new-command :rendered-preview))))
|
||||||
|
|
||||||
(defn invoke-commands-handlers!
|
(defn invoke-commands-handlers!
|
||||||
[{:keys [new-commands current-chat-id] :as db}]
|
[{:keys [new-commands current-chat-id] :as db}]
|
||||||
|
|
|
@ -51,9 +51,9 @@
|
||||||
[view st/track-mark]
|
[view st/track-mark]
|
||||||
[text {:style st/track-duration-text} "03:39"]]])
|
[text {:style st/track-duration-text} "03:39"]]])
|
||||||
|
|
||||||
(defn message-content-command [content]
|
(defn message-content-command [content preview]
|
||||||
(let [commands-atom (subscribe [:get-commands-and-responses])]
|
(let [commands-atom (subscribe [:get-commands-and-responses])]
|
||||||
(fn [content]
|
(fn [content preview]
|
||||||
(let [commands @commands-atom
|
(let [commands @commands-atom
|
||||||
{:keys [command content]}
|
{:keys [command content]}
|
||||||
(parse-command-msg-content commands content)]
|
(parse-command-msg-content commands content)]
|
||||||
|
@ -66,11 +66,10 @@
|
||||||
[view (st/command-image-view command)
|
[view (st/command-image-view command)
|
||||||
[image {:source {:uri (:icon command)}
|
[image {:source {:uri (:icon command)}
|
||||||
:style st/command-image}]]
|
:style st/command-image}]]
|
||||||
|
(if preview
|
||||||
|
preview
|
||||||
[text {:style st/command-text}
|
[text {:style st/command-text}
|
||||||
;; TODO isn't smart
|
content])]))))
|
||||||
(if (= (:name command) "keypair-password")
|
|
||||||
"******"
|
|
||||||
content)]]))))
|
|
||||||
|
|
||||||
(defn set-chat-command [msg-id command]
|
(defn set-chat-command [msg-id command]
|
||||||
(dispatch [:set-response-chat-command msg-id (keyword (:name command))]))
|
(dispatch [:set-response-chat-command msg-id (keyword (:name command))]))
|
||||||
|
@ -126,9 +125,9 @@
|
||||||
[message-content-status message])
|
[message-content-status message])
|
||||||
|
|
||||||
(defmethod message-content content-type-command
|
(defmethod message-content content-type-command
|
||||||
[wrapper {:keys [content] :as message}]
|
[wrapper {:keys [content rendered-preview] :as message}]
|
||||||
[wrapper message
|
[wrapper message
|
||||||
[message-view message [message-content-command content]]])
|
[message-view message [message-content-command content rendered-preview]]])
|
||||||
|
|
||||||
(defmethod message-content :default
|
(defmethod message-content :default
|
||||||
[wrapper {:keys [content-type content] :as message}]
|
[wrapper {:keys [content-type content] :as message}]
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
[re-frame.core :refer [dispatch]]
|
[re-frame.core :refer [dispatch]]
|
||||||
[cljs.reader :refer [read-string]]
|
[cljs.reader :refer [read-string]]
|
||||||
[status-im.utils.random :refer [timestamp]]
|
[status-im.utils.random :refer [timestamp]]
|
||||||
[status-im.db :as db]
|
|
||||||
[status-im.utils.logging :as log]
|
[status-im.utils.logging :as log]
|
||||||
[clojure.string :refer [join split]]
|
[clojure.string :refer [join split]]
|
||||||
[clojure.walk :refer [stringify-keys keywordize-keys]]
|
[clojure.walk :refer [stringify-keys keywordize-keys]]
|
||||||
[status-im.constants :as c]))
|
[status-im.constants :as c]
|
||||||
|
[status-im.commands.utils :refer [generate-hiccup]]))
|
||||||
|
|
||||||
(defn- map-to-str
|
(defn- map-to-str
|
||||||
[m]
|
[m]
|
||||||
|
@ -21,7 +21,8 @@
|
||||||
{:outgoing false
|
{:outgoing false
|
||||||
:to nil
|
:to nil
|
||||||
:same-author false
|
:same-author false
|
||||||
:same-direction false})
|
:same-direction false
|
||||||
|
:preview nil})
|
||||||
|
|
||||||
(defn save-message
|
(defn save-message
|
||||||
;; todo remove chat-id parameter
|
;; todo remove chat-id parameter
|
||||||
|
@ -51,9 +52,13 @@
|
||||||
(r/sorted :timestamp :asc)
|
(r/sorted :timestamp :asc)
|
||||||
(r/collection->map))
|
(r/collection->map))
|
||||||
(into '())
|
(into '())
|
||||||
(map (fn [{:keys [content-type] :as message}]
|
(map (fn [{:keys [content-type preview] :as message}]
|
||||||
(if (command-type? content-type)
|
(if (command-type? content-type)
|
||||||
(update message :content str-to-map)
|
(-> message
|
||||||
|
(update :content str-to-map)
|
||||||
|
(assoc :rendered-preview (generate-hiccup
|
||||||
|
(read-string preview)))
|
||||||
|
(dissoc :preview))
|
||||||
message)))))
|
message)))))
|
||||||
|
|
||||||
(defn update-message! [{:keys [msg-id] :as msg}]
|
(defn update-message! [{:keys [msg-id] :as msg}]
|
||||||
|
|
|
@ -33,7 +33,9 @@
|
||||||
:delivery-status {:type "string"
|
:delivery-status {:type "string"
|
||||||
:optional true}
|
:optional true}
|
||||||
:same-author "bool"
|
:same-author "bool"
|
||||||
:same-direction "bool"}}
|
:same-direction "bool"
|
||||||
|
:preview {:type :string
|
||||||
|
:optional true}}}
|
||||||
{:name :chat-contact
|
{:name :chat-contact
|
||||||
:properties {:identity "string"
|
:properties {:identity "string"
|
||||||
:is-in-chat {:type "bool"
|
:is-in-chat {:type "bool"
|
||||||
|
|
Loading…
Reference in New Issue