Command as the last message (#367)

This commit is contained in:
Alexander Pantyuhov 2016-10-19 00:45:09 +03:00
parent e239363c1e
commit dc3d9f8931
5 changed files with 36 additions and 18 deletions

View File

@ -4,13 +4,10 @@
text
image
touchable-highlight]]
[status-im.chats-list.views.inner-item :refer [chat-list-item-inner-view]]))
[status-im.chats-list.views.inner-item :refer [chat-list-item-inner-view]]
[taoensso.timbre :as log]))
(defn chat-list-item [[chat-id chat]]
[touchable-highlight {:on-press #(dispatch [:navigate-to :chat chat-id])}
[view
[chat-list-item-inner-view (merge chat
;; TODO stub data
{:chat-id chat-id
:new-messages-count 3
:online true})]]])
[chat-list-item-inner-view (assoc chat :chat-id chat-id)]]])

View File

@ -1,20 +1,37 @@
(ns status-im.chats-list.views.inner-item
(:require-macros [status-im.utils.views :refer [defview]])
(:require [status-im.components.react :refer [view image icon text]]
(:require [re-frame.core :refer [subscribe dispatch]]
[clojure.string :as str]
[status-im.components.react :refer [view image icon text]]
[status-im.components.chat-icon.screen :refer [chat-icon-view-chat-list]]
[status-im.models.commands :refer [parse-command-message-content]]
[status-im.chats-list.styles :as st]
[status-im.utils.utils :refer [truncate-str]]
[status-im.i18n :refer [label label-pluralize]]
[status-im.utils.datetime :as time]
[status-im.utils.gfycat.core :refer [generate-gfy]]
[status-im.constants :refer [console-chat-id]]
[clojure.string :as str]))
[status-im.constants :refer [console-chat-id
content-type-command
content-type-command-request]]
[taoensso.timbre :as log]))
(defn message-content [{:keys [content] :as message}]
(let [content (if message
(if (string? content)
content
(:content content)))]
(defmulti message-content (fn [{:keys [content-type] :as message}] content-type))
(defmethod message-content content-type-command
[{{:keys [command params]} :content}]
(let [kw (keyword (str "t/command-text-" (name command)))]
(label kw params)))
(defmethod message-content content-type-command-request
[{{:keys [content]} :content}]
content)
(defmethod message-content :default
[{:keys [content]}]
content)
(defn message-content-text [message]
(let [content (message-content message)]
(if (str/blank? content)
[text {:style st/last-message-text-no-messages}
(label :t/no-messages)]
@ -71,7 +88,7 @@
(when group-chat
[text {:style st/memebers-text}
(label-pluralize (inc (count contacts)) :t/members)])]
[message-content last-message]]
[message-content-text last-message]]
[view
(when last-message
[view st/status-container

View File

@ -65,7 +65,9 @@
(defn get-last-message
[chat-id]
(data-store/get-last-message chat-id))
(let [{:keys [content-type] :as message} (data-store/get-last-message chat-id)]
(when (and message (command-type? content-type))
(clojure.core/update message :content str-to-map))))
(defn get-unviewed
[]

View File

@ -31,8 +31,7 @@
[chat-id]
(-> (realm/get-by-field @realm/account-realm :message :chat-id chat-id)
(realm/sorted :timestamp :desc)
(realm/single)
(js->clj :keywordize-keys true)))
(realm/single-cljs)))
(defn get-unviewed
[]

View File

@ -139,6 +139,9 @@
:keypair-password-command-description ""
:help-command-description "Help"
:request "Request"
:command-text-location "Location: {{address}}"
:command-text-browse "Browsing webpage: {{webpage}}"
:command-text-send "Transaction: {{amount}} ETH"
;new-group
:group-chat-name "Chat name"