Skip to content

Commit

Permalink
Move command-content to js files (#779)
Browse files Browse the repository at this point in the history
  • Loading branch information
alwx authored and rasom committed Mar 1, 2017
1 parent 041b5ab commit d6f43d3
Show file tree
Hide file tree
Showing 41 changed files with 145 additions and 204 deletions.
22 changes: 22 additions & 0 deletions resources/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,12 @@ status.command({
);

return status.components.view({}, [text, image]);
},
shortPreview: function(params) {
return status.components.text(
{},
I18n.t('location_title') + ": " + params.address
);
}
}).param({
name: "address",
Expand Down Expand Up @@ -861,6 +867,14 @@ var send = {
[amount, currency]
);
},
shortPreview: function (params, context) {
return status.components.text(
{},
I18n.t('send_title') + ": "
+ status.localizeNumber(params.amount, context.delimiter, context.separator)
+ " ETH"
);
},
handler: sendTransaction,
validator: validateSend
};
Expand Down Expand Up @@ -894,6 +908,14 @@ status.command({
+ status.localizeNumber(params.amount, context.delimiter, context.separator)
+ " ETH";
},
shortPreview: function (params, context) {
return status.components.text(
{},
I18n.t('request_requesting') + " "
+ status.localizeNumber(params.amount, context.delimiter, context.separator)
+ " ETH"
);
},
validator: function(params) {
try {
var val = web3.toWei(params.amount, "ether");
Expand Down
33 changes: 26 additions & 7 deletions resources/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ I18n.translations = {
password_validation_title: 'Password',

faucet_incorrect_title: 'Incorrect faucet',
faucet_incorrect_description: 'Please, select a one from the list'
faucet_incorrect_description: 'Please, select a one from the list',

debug_mode_title: 'Debug mode',
debug_mode_description: 'Starts/stops a debug mode',

faucet_title: 'Faucet',
faucet_description: 'Get some ETH',
faucet_placeholder: 'Faucet URL'
},
ru: {
phone_title: 'Отправить номер телефона',
Expand Down Expand Up @@ -1735,22 +1742,28 @@ function faucetSuggestions(params) {

status.command({
name: "faucet",
title: "Faucet",
description: "Get some ETH",
title: I18n.t('faucet_title'),
description: I18n.t('faucet_description'),
color: "#7099e6",
registeredOnly: true,
params: [{
name: "url",
type: status.types.TEXT,
suggestions: faucetSuggestions,
placeholder: "Faucet URL"
placeholder: I18n.t('faucet_placeholder')
}],
preview: function (params) {
return status.components.text(
{},
params.url
);
},
shortPreview: function (params) {
return status.components.text(
{},
I18n.t('faucet_title') + ": " + params.url
);
},
validator: function (params, context) {
var f = faucets.map(function (entry) {
return entry.url;
Expand Down Expand Up @@ -1796,8 +1809,8 @@ function debugSuggestions(params) {

status.command({
name: "debug",
title: "Debug",
description: "Starts/stops a debug server",
title: I18n.t('debug_mode_title'),
description: I18n.t('debug_mode_description'),
color: "#7099e6",
registeredOnly: true,
params: [{
Expand All @@ -1808,7 +1821,13 @@ status.command({
preview: function (params) {
return status.components.text(
{},
"Debug mode: " + params.mode
I18n.t('debug_mode_title') + ": " + params.mode
);
},
shortPreview: function (params) {
return status.components.text(
{},
I18n.t('debug_mode_title') + ": " + params.mode
);
}
});
Expand Down
1 change: 1 addition & 0 deletions resources/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Command.prototype.create = function (com) {
this.icon = com.icon;
this.params = com.params || [];
this.preview = com.preview;
this["short-preview"] = com.shortPreview;
this["suggestions-trigger"] = com.suggestionsTrigger || "on-change";
this.fullscreen = com.fullscreen;
this.request = com.request;
Expand Down
34 changes: 20 additions & 14 deletions src/status_im/chat/handlers/commands.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -268,20 +268,26 @@

(register-handler :request-command-preview
(u/side-effect!
(fn [_ [_ {{:keys [command params content-command type]} :content
:keys [message-id chat-id on-requested] :as message}]]
(let [path [(if (= :response (keyword type)) :responses :commands)
(if content-command content-command command)
:preview]
params {:parameters params
:context (merge {:platform platform/platform} i18n/delimeters)}
callback #(do (when-let [result (get-in % [:result :returned])]
(dispatch [:set-in [:message-data :preview message-id]
(if (string? result)
result
(cu/generate-hiccup result))]))
(when on-requested (on-requested %)))]
(status/call-jail chat-id path params callback)))))
(fn [{:keys [chats]} [_ {{:keys [command params content-command type]} :content
:keys [message-id chat-id on-requested] :as message} data-type]]
(if-not (get-in chats [chat-id :commands-loaded])
(do (dispatch [:add-commands-loading-callback
chat-id
#(dispatch [:request-command-preview message data-type])])
(dispatch [:load-commands! chat-id]))
(let [data-type (or data-type :preview)
path [(if (= :response (keyword type)) :responses :commands)
(if content-command content-command command)
data-type]
params {:parameters params
:context (merge {:platform platform/platform} i18n/delimeters)}
callback #(do (when-let [result (get-in % [:result :returned])]
(dispatch [:set-in [:message-data data-type message-id]
(if (string? result)
result
(cu/generate-hiccup result))]))
(when on-requested (on-requested %)))]
(status/call-jail chat-id path params callback))))))

(register-handler :set-command-parameter
(fn [db [_ {:keys [value parameter]}]]
Expand Down
9 changes: 8 additions & 1 deletion src/status_im/chat/handlers/receive_message.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
:as c]
[cljs.reader :refer [read-string]]
[status-im.data-store.chats :as chats]
[status-im.utils.scheduler :as s]))
[status-im.utils.scheduler :as s]
[taoensso.timbre :as log]))

(defn store-message [{chat-id :chat-id :as message}]
(messages/save chat-id (dissoc message :new?)))
Expand Down Expand Up @@ -51,6 +52,7 @@
(when (get-in message [:content :command])
(dispatch [:request-command-preview message]))
(dispatch [::add-message chat-id' message'])
(dispatch [::set-last-message message'])
(when (= (:content-type message') content-type-command-request)
(dispatch [:add-request chat-id' message']))
(dispatch [:add-unviewed-message chat-id' message-id])
Expand Down Expand Up @@ -89,6 +91,11 @@
(fn [db [_ add-to-chat-id {:keys [chat-id new?] :as message}]]
(cu/add-message-to-db db add-to-chat-id chat-id message new?)))

(register-handler ::set-last-message
(fn [{:keys [chats] :as db} [_ {:keys [chat-id] :as message}]]
(dispatch [:request-command-preview message :short-preview])
(assoc-in db [:chats chat-id :last-message] message)))

(defn commands-loaded? [db chat-id]
(get-in db [:chats chat-id :commands-loaded]))

Expand Down
22 changes: 16 additions & 6 deletions src/status_im/chat/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,9 @@

(register-sub :get-commands-and-responses
(fn [db [_ chat-id]]
(reaction (or (->> (get-in @db [:chats chat-id])
((juxt :commands :responses))
(apply merge))
(->> (get @db :all-commands)
((juxt :commands :responses))
(apply merge))))))
(reaction (->> (get-in @db [:chats chat-id])
((juxt :commands :responses))
(apply merge)))))

(register-sub :get-chat-input-text
(fn [db _]
Expand Down Expand Up @@ -265,3 +262,16 @@
(fn [_ [_ id]]
(let [contacts (subscribe [:get :contacts])]
(reaction (:photo-path (@contacts id))))))

(register-sub :get-last-message
(fn [db [_ chat-id]]
(reaction
(let [{:keys [last-message messages]} (get-in @db [:chats chat-id])]
(first
(sort-by :clock-value > (conj messages last-message)))))))

(register-sub :get-last-message-short-preview
(fn [db [_ chat-id]]
(let [last-message (subscribe [:get-last-message chat-id])]
(reaction
(get-in @db [:message-data :short-preview (:message-id @last-message)])))))
12 changes: 7 additions & 5 deletions src/status_im/chats_list/styles.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@
:fontSize 12
:color text2-color})

(def last-message-text
(def last-message-container
{:margin-top 5
:margin-right 40
:color text1-color
:fontSize 14
:lineHeight 20})
:margin-right 40})

(def last-message-text
{:color text1-color
:fontSize 14
:lineHeight 20})

(def last-message-text-no-messages
(merge last-message-text
Expand Down
82 changes: 45 additions & 37 deletions src/status_im/chats_list/views/inner_item.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,49 @@
[status-im.utils.gfycat.core :refer [generate-gfy]]
[status-im.constants :refer [console-chat-id
content-type-command
content-type-command-request] :as c]
[taoensso.timbre :as log]))
content-type-wallet-command
content-type-command-request]]
[taoensso.timbre :as log]
[reagent.core :as r]))

(defmulti message-content (fn [{:keys [content-type]}] content-type))
(defn message-content-text [chat-id]
(let [message (subscribe [:get-last-message chat-id])
preview (subscribe [:get-last-message-short-preview chat-id])]
(r/create-class
{:component-will-mount
(fn []
(when (and (get-in @message [:content :command])
(not @preview))
(dispatch [:request-command-preview @message :short-preview])))

(defn command-content
[{{:keys [command content-command params]} :content}]
(let [kw (keyword (str "t/command-text-" (name (or content-command command))))]
(label kw params)))
:reagent-render
(fn [_]
[view]
(let [{:keys [content] :as message} @message
preview @preview]
[view st/last-message-container
(cond

(defmethod message-content content-type-command
[message]
(command-content message))
(not message)
[text {:style st/last-message-text-no-messages}
(label :t/no-messages)]

(defmethod message-content c/content-type-wallet-command
[message]
(command-content message))
(str/blank? content)
[text {:style st/last-message-text-no-messages}
""]

(defmethod message-content content-type-command-request
[message]
(command-content message))
(:content content)
[text {:style st/last-message-text
:number-of-lines 2}
(:content content)]

(defmethod message-content :default
[{:keys [content]}]
content)
(:command content)
preview

(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)]
[text {:style st/last-message-text
:number-of-lines 2}
content])))
:else
[text {:style st/last-message-text
:number-of-lines 2}
content])]))})))

(defview message-status [{:keys [chat-id contacts]}
{:keys [message-id message-status user-statuses message-type outgoing] :as msg}]
Expand Down Expand Up @@ -76,13 +85,12 @@
:font :medium}
unviewed-messages]]))

(defn chat-list-item-inner-view [{:keys [chat-id name color last-message
(defn chat-list-item-inner-view [{:keys [chat-id name color
online group-chat contacts public?]
:as chat}]
(let [last-message (or (first (sort-by :clock-value > (:messages chat)))
last-message)
name (or (get-contact-translated chat-id :name name)
(generate-gfy))
:as chat}]
(let [last-message (subscribe [:get-last-message chat-id])
name (or (get-contact-translated chat-id :name name)
(generate-gfy))
private-group? (and group-chat (not public?))
public-group? (and group-chat public?)]
[view st/chat-container
Expand All @@ -107,10 +115,10 @@
#_(when private-group?
[text {:style st/memebers-text}
(label-pluralize (inc (count contacts)) :t/members)])]
[message-content-text last-message]]
[message-content-text chat-id]]
[view
(when last-message
(when @last-message
[view st/status-container
[message-status chat last-message]
[message-timestamp last-message]])
[message-status chat @last-message]
[message-timestamp @last-message]])
[unviewed-indicator chat-id]]]))
4 changes: 0 additions & 4 deletions src/status_im/translations/af.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@
:chat-send-eth "{{amount}} ETH"
:chat-send-eth-to "{{amount}} ETH aan {{chat-name}}"
:chat-send-eth-from "{{amount}} ETH van {{chat-name}}"
:command-text-location "Ligging {{address}}"
:command-text-browse "Webblaaier-blad: {{webpage}}"
:command-text-send "Transaksie: {{amount}} ETH"
:command-text-help "Help"

;new-group
:group-chat-name "Bynaam"
Expand Down
4 changes: 0 additions & 4 deletions src/status_im/translations/ar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@
:chat-send-eth "{{amount}} ETH"
:chat-send-eth-to "{{amount}} ETH إلى {{chat-name}}"
:chat-send-eth-from "{{amount}} ETH من {{chat-name}}"
:command-text-location "الموقع {{address}}"
:command-text-browse "تصفح صفحة الويب {{webpage}}"
:command-text-send "المعاملة: {{amount}} ETH"
:command-text-help "المساعدة"

;new-group
:group-chat-name "اسم الدردشة"
Expand Down
4 changes: 0 additions & 4 deletions src/status_im/translations/de.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@
:chat-send-eth "{{amount}} ETH"
:chat-send-eth-to "{{amount}} ETH an {{chat-name}}"
:chat-send-eth-from "{{amount}} ETH von {{chat-name}}"
:command-text-location "Position: {{address}}"
:command-text-browse "Auf Webseite: {{webpage}}"
:command-text-send "Transaktion: {{amount}} ETH"
:command-text-help "Hilfe"

;new-group
:group-chat-name "Chatname"
Expand Down
Loading

0 comments on commit d6f43d3

Please sign in to comment.