From 9993ebd074bdc3ea4a764c5bd4168590ce697a8b Mon Sep 17 00:00:00 2001 From: Alexander Pantyuhov Date: Wed, 19 Oct 2016 00:45:09 +0300 Subject: [PATCH] Command as the last message (#367) Former-commit-id: dc3d9f8931c879062fc4e57ba1511fad78f3c7c5 --- .../chats_list/views/chat_list_item.cljs | 9 ++--- .../chats_list/views/inner_item.cljs | 35 ++++++++++++++----- src/status_im/data_store/messages.cljs | 4 ++- src/status_im/data_store/realm/messages.cljs | 3 +- src/status_im/translations/en.cljs | 3 ++ 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/status_im/chats_list/views/chat_list_item.cljs b/src/status_im/chats_list/views/chat_list_item.cljs index ddd650816f..d2a5fff6e8 100644 --- a/src/status_im/chats_list/views/chat_list_item.cljs +++ b/src/status_im/chats_list/views/chat_list_item.cljs @@ -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)]]]) diff --git a/src/status_im/chats_list/views/inner_item.cljs b/src/status_im/chats_list/views/inner_item.cljs index e87e37c7aa..89387de3f7 100644 --- a/src/status_im/chats_list/views/inner_item.cljs +++ b/src/status_im/chats_list/views/inner_item.cljs @@ -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 diff --git a/src/status_im/data_store/messages.cljs b/src/status_im/data_store/messages.cljs index 6dbc9ffbfd..210dc929b8 100644 --- a/src/status_im/data_store/messages.cljs +++ b/src/status_im/data_store/messages.cljs @@ -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 [] diff --git a/src/status_im/data_store/realm/messages.cljs b/src/status_im/data_store/realm/messages.cljs index c818d49c65..787885ff02 100644 --- a/src/status_im/data_store/realm/messages.cljs +++ b/src/status_im/data_store/realm/messages.cljs @@ -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 [] diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 101de3602c..e502cbc852 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -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"