store preview

This commit is contained in:
Roman Volosovskyi 2016-06-14 18:09:24 +03:00
parent 02f37e6c97
commit dfcf7cd47e
4 changed files with 37 additions and 28 deletions

View File

@ -17,7 +17,8 @@
[status-im.handlers.server :as server]
[status-im.utils.phone-number :refer [format-phone-number]]
[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
(fn [db [_ show-actions]]
@ -149,17 +150,18 @@
(commands/set-chat-command db command)
(assoc db :new-message (when-not (str/blank? text) message)))))
(defn prepare-command [identity chat-id staged-command]
(let [command-name (get-in staged-command [:command :name])
content {:command command-name
:content (:content staged-command)}]
{:msg-id (random/id)
:from identity
:to chat-id
:content content
:content-type content-type-command
:outgoing true
:handler (:handler staged-command)}))
(defn prepare-command
[identity chat-id {:keys [preview preview-string content command]}]
(let [content {:command (command :name)
:content content}]
{:msg-id (random/id)
:from identity
:to chat-id
:content content
:content-type content-type-command
:outgoing true
:preview preview-string
:rendered-preview preview}))
(defn prepare-staged-commans
[{:keys [current-chat-id identity] :as db} _]
@ -212,7 +214,8 @@
(defn save-commands-to-realm!
[{:keys [new-commands current-chat-id]} _]
(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!
[{:keys [new-commands current-chat-id] :as db}]

View File

@ -51,9 +51,9 @@
[view st/track-mark]
[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])]
(fn [content]
(fn [content preview]
(let [commands @commands-atom
{:keys [command content]}
(parse-command-msg-content commands content)]
@ -66,11 +66,10 @@
[view (st/command-image-view command)
[image {:source {:uri (:icon command)}
:style st/command-image}]]
[text {:style st/command-text}
;; TODO isn't smart
(if (= (:name command) "keypair-password")
"******"
content)]]))))
(if preview
preview
[text {:style st/command-text}
content])]))))
(defn set-chat-command [msg-id command]
(dispatch [:set-response-chat-command msg-id (keyword (:name command))]))
@ -126,9 +125,9 @@
[message-content-status message])
(defmethod message-content content-type-command
[wrapper {:keys [content] :as message}]
[wrapper {:keys [content rendered-preview] :as message}]
[wrapper message
[message-view message [message-content-command content]]])
[message-view message [message-content-command content rendered-preview]]])
(defmethod message-content :default
[wrapper {:keys [content-type content] :as message}]

View File

@ -3,11 +3,11 @@
[re-frame.core :refer [dispatch]]
[cljs.reader :refer [read-string]]
[status-im.utils.random :refer [timestamp]]
[status-im.db :as db]
[status-im.utils.logging :as log]
[clojure.string :refer [join split]]
[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
[m]
@ -21,7 +21,8 @@
{:outgoing false
:to nil
:same-author false
:same-direction false})
:same-direction false
:preview nil})
(defn save-message
;; todo remove chat-id parameter
@ -51,9 +52,13 @@
(r/sorted :timestamp :asc)
(r/collection->map))
(into '())
(map (fn [{:keys [content-type] :as message}]
(map (fn [{:keys [content-type preview] :as message}]
(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)))))
(defn update-message! [{:keys [msg-id] :as msg}]

View File

@ -33,7 +33,9 @@
:delivery-status {:type "string"
:optional true}
:same-author "bool"
:same-direction "bool"}}
:same-direction "bool"
:preview {:type :string
:optional true}}}
{:name :chat-contact
:properties {:identity "string"
:is-in-chat {:type "bool"