Requesting message in group chat now contains recipient name (#1396); restructuring of commands
This commit is contained in:
parent
29ccf9546f
commit
a0de31ebb6
|
@ -424,7 +424,7 @@ function previewSend(params, context) {
|
|||
lineHeight: 18
|
||||
}
|
||||
},
|
||||
"to " + params["bot-db"]["public"]["recipient"]["name"]
|
||||
I18n.t('send_sending_to') + " " + params["bot-db"]["public"]["recipient"]["name"]
|
||||
);
|
||||
markup = [firstRow, secondRow];
|
||||
} else {
|
||||
|
@ -506,18 +506,51 @@ status.command({
|
|||
},
|
||||
prefill: [context["current-account"]["name"], val],
|
||||
prefillBotDb: {
|
||||
contact: context["current-account"]
|
||||
public: {
|
||||
recipient: context["current-account"]
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
preview: function (params, context) {
|
||||
var firstRow = status.components.text(
|
||||
{},
|
||||
I18n.t('request_requesting') + " "
|
||||
+ status.localizeNumber(params.amount, context.delimiter, context.separator)
|
||||
+ " ETH"
|
||||
);
|
||||
|
||||
var markup;
|
||||
|
||||
if (params["bot-db"]
|
||||
&& params["bot-db"]["public"]
|
||||
&& params["bot-db"]["public"]["recipient"]
|
||||
&& context["chat"]["group-chat"] === true) {
|
||||
|
||||
var secondRow = status.components.text(
|
||||
{
|
||||
style: {
|
||||
color: "#9199a0",
|
||||
fontSize: 14,
|
||||
lineHeight: 18
|
||||
}
|
||||
},
|
||||
I18n.t('request_requesting_from') + " " + params["bot-db"]["public"]["recipient"]["name"]
|
||||
);
|
||||
markup = [firstRow, secondRow];
|
||||
} else {
|
||||
markup = [firstRow];
|
||||
}
|
||||
|
||||
return {
|
||||
markup: status.components.text(
|
||||
{},
|
||||
I18n.t('request_requesting') + " "
|
||||
+ status.localizeNumber(params.amount, context.delimiter, context.separator)
|
||||
+ " ETH"
|
||||
markup: status.components.view(
|
||||
{
|
||||
style: {
|
||||
flexDirection: "column"
|
||||
}
|
||||
},
|
||||
markup
|
||||
)
|
||||
};
|
||||
},
|
||||
|
|
|
@ -13,12 +13,14 @@ I18n.translations = {
|
|||
send_explanation_2: 'usually within a minute.',
|
||||
send_explanation_3: 'probably within 30 seconds.',
|
||||
send_explanation_4: 'probably within a few seconds.',
|
||||
send_sending_to: 'to ',
|
||||
|
||||
eth: 'ETH',
|
||||
|
||||
request_title: 'Request ETH',
|
||||
request_description: 'Request a payment',
|
||||
request_requesting: 'Requesting ',
|
||||
request_requesting_from: 'from ',
|
||||
|
||||
validation_title: 'Amount',
|
||||
validation_amount_specified: 'Amount must be specified',
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
(handlers/side-effect!
|
||||
(fn [{:keys [contacts current-account-id chats] :as db}
|
||||
[_ {{:keys [command params content-command type]} :content
|
||||
:keys [message-id from chat-id on-requested jail-id] :as message} data-type]]
|
||||
:keys [message-id chat-id jail-id on-requested from] :as message} data-type]]
|
||||
(let [jail-id (or jail-id chat-id)
|
||||
jail-id' (if (get-in chats [jail-id :group-chat])
|
||||
(get-in chats [jail-id :command-suggestions (keyword command) :owner-id])
|
||||
|
|
|
@ -10,24 +10,24 @@
|
|||
|
||||
(def console-commands
|
||||
{:password
|
||||
(fn [params _]
|
||||
(dispatch [:create-account (params "password")]))
|
||||
(fn [{:keys [password]} _]
|
||||
(dispatch [:create-account password]))
|
||||
|
||||
:phone
|
||||
(fn [params id]
|
||||
(dispatch [:sign-up (params "phone") id]))
|
||||
(fn [{:keys [phone]} id]
|
||||
(dispatch [:sign-up phone id]))
|
||||
|
||||
:confirmation-code
|
||||
(fn [params id]
|
||||
(dispatch [:sign-up-confirm (params "code") id]))
|
||||
(fn [{:keys [code]} id]
|
||||
(dispatch [:sign-up-confirm code id]))
|
||||
|
||||
:faucet
|
||||
(fn [params id]
|
||||
(dispatch [:open-faucet (params "url") id]))
|
||||
(fn [{:keys [url]} id]
|
||||
(dispatch [:open-faucet url id]))
|
||||
|
||||
:debug
|
||||
(fn [params id]
|
||||
(let [debug-on? (= (params "mode") "On")]
|
||||
(fn [{:keys [mode]} id]
|
||||
(let [debug-on? (= mode "On")]
|
||||
(dispatch [:account-update {:debug? debug-on?}])
|
||||
(if debug-on?
|
||||
(do
|
||||
|
@ -49,10 +49,14 @@
|
|||
|
||||
(register-handler :invoke-console-command-handler!
|
||||
(u/side-effect!
|
||||
(fn [_ [_ {:keys [chat-id command-message] :as parameters}]]
|
||||
(let [{:keys [id command params]} command-message
|
||||
{:keys [name]} command]
|
||||
(dispatch [:prepare-command! chat-id parameters])
|
||||
(fn [_ [_ {{:keys [command
|
||||
params
|
||||
id]
|
||||
:as content} :command
|
||||
chat-id :chat-id
|
||||
:as all-params}]]
|
||||
(let [{:keys [name]} command]
|
||||
(dispatch [:prepare-command! chat-id all-params])
|
||||
((console-commands (keyword name)) params id)))))
|
||||
|
||||
(register-handler :set-message-status
|
||||
|
|
|
@ -168,10 +168,10 @@
|
|||
|
||||
(handlers/register-handler ::send-message
|
||||
(handlers/side-effect!
|
||||
(fn [{:keys [current-public-key current-account-id] :as db} [_ command-message chat-id]]
|
||||
(fn [{:keys [current-public-key current-account-id] :as db} [_ command chat-id]]
|
||||
(let [text (get-in db [:chats chat-id :input-text])
|
||||
data {:message text
|
||||
:command command-message
|
||||
:command command
|
||||
:chat-id chat-id
|
||||
:identity current-public-key
|
||||
:address current-account-id}]
|
||||
|
@ -179,41 +179,30 @@
|
|||
(dispatch [:set-chat-input-metadata nil chat-id])
|
||||
(dispatch [:set-chat-ui-props {:sending-in-progress? false}])
|
||||
(cond
|
||||
command-message
|
||||
command
|
||||
(dispatch [:check-commands-handlers! data])
|
||||
(not (str/blank? text))
|
||||
(dispatch [:prepare-message data]))))))
|
||||
|
||||
(handlers/register-handler :proceed-command
|
||||
(handlers/side-effect!
|
||||
(fn [db [_ command chat-id]]
|
||||
(let [jail-id (or (get-in command [:command :bot]) chat-id)]
|
||||
;:check-and-load-commands!
|
||||
(let [params
|
||||
{:command command
|
||||
:chat-id chat-id
|
||||
:jail-id jail-id}
|
||||
(fn [db [_ {{:keys [bot]} :command :as content} chat-id]]
|
||||
(let [params {:content content
|
||||
:chat-id chat-id
|
||||
:jail-id (or bot chat-id)}
|
||||
on-send-params (merge params
|
||||
{:data-type :on-send
|
||||
:after #(dispatch [::send-command %2 content chat-id])})
|
||||
after-validation #(dispatch [::request-command-data on-send-params])
|
||||
validation-params (merge params
|
||||
{:data-type :validator
|
||||
:after #(dispatch [::proceed-validation %2 after-validation])})]
|
||||
|
||||
on-send-params
|
||||
(merge params
|
||||
{:data-type :on-send
|
||||
:after (fn [_ res]
|
||||
(dispatch [::send-command res command chat-id]))})
|
||||
(dispatch [::request-command-data validation-params])))))
|
||||
|
||||
after-validation
|
||||
#(dispatch [::request-command-data on-send-params])
|
||||
|
||||
validation-params
|
||||
(merge params
|
||||
{:data-type :validator
|
||||
:after #(dispatch [::proceed-validation-messages
|
||||
command chat-id %2 after-validation])})]
|
||||
|
||||
(dispatch [::request-command-data validation-params]))))))
|
||||
|
||||
(handlers/register-handler ::proceed-validation-messages
|
||||
(handlers/register-handler ::proceed-validation
|
||||
(handlers/side-effect!
|
||||
(fn [db [_ command chat-id {:keys [markup validationHandler parameters]} proceed-fn]]
|
||||
(fn [db [_ {:keys [markup validationHandler parameters]} proceed-fn]]
|
||||
(let [set-errors #(do (dispatch [:set-chat-ui-props {:validation-messages %
|
||||
:sending-in-progress? false}]))]
|
||||
(cond
|
||||
|
@ -235,7 +224,7 @@
|
|||
|
||||
(handlers/register-handler ::send-command
|
||||
(handlers/side-effect!
|
||||
(fn [db [_ on-send {{:keys [fullscreen]} :command :as command} chat-id]]
|
||||
(fn [db [_ on-send {{:keys [fullscreen bot]} :command :as content} chat-id]]
|
||||
(if on-send
|
||||
(do
|
||||
(when fullscreen
|
||||
|
@ -244,9 +233,9 @@
|
|||
:sending-in-progress? false}])
|
||||
(react-comp/dismiss-keyboard!))
|
||||
(dispatch [::request-command-data
|
||||
{:command command
|
||||
{:content content
|
||||
:chat-id chat-id
|
||||
:jail-id (get-in command [:command :bot])
|
||||
:jail-id (or bot chat-id)
|
||||
:data-type :preview
|
||||
:after #(dispatch [::send-message % chat-id])}])))))
|
||||
|
||||
|
@ -256,8 +245,8 @@
|
|||
[_ {{:keys [command
|
||||
metadata
|
||||
args]
|
||||
:as c} :command
|
||||
:keys [message-id chat-id jail-id data-type after]}]]
|
||||
:as content} :content
|
||||
:keys [chat-id jail-id data-type after]}]]
|
||||
(let [{:keys [dapp? dapp-url name]} (get contacts chat-id)
|
||||
message-id (random/id)
|
||||
metadata (merge metadata
|
||||
|
@ -266,7 +255,10 @@
|
|||
:name (i18n/get-contact-translated chat-id :name name)}))
|
||||
owner-id (:owner-id command)
|
||||
bot-db (get bot-db chat-id)
|
||||
params (assoc (input-model/args->params c) :bot-db bot-db)
|
||||
params (merge (input-model/args->params content)
|
||||
{:bot-db bot-db
|
||||
:metadata metadata})
|
||||
|
||||
command-message {:command command
|
||||
:params params
|
||||
:to-message (:to-message-id metadata)
|
||||
|
@ -274,11 +266,12 @@
|
|||
:id message-id
|
||||
:chat-id chat-id
|
||||
:jail-id (or owner-id jail-id)}
|
||||
|
||||
request-data {:message-id message-id
|
||||
:chat-id chat-id
|
||||
:jail-id (or owner-id jail-id)
|
||||
:content {:command (:name command)
|
||||
:params (assoc params :metadata metadata :bot-db bot-db)
|
||||
:params params
|
||||
:type (:type command)}
|
||||
:on-requested #(after command-message %)}]
|
||||
(dispatch [:request-command-data request-data data-type])))))
|
||||
|
@ -344,11 +337,11 @@
|
|||
(dispatch [:update-seq-arguments chat-id])
|
||||
(dispatch [:send-current-message]))]
|
||||
(dispatch [::request-command-data
|
||||
{:command command
|
||||
{:content command
|
||||
:chat-id chat-id
|
||||
;;TODO(alwx): jail-id ?
|
||||
:data-type :validator
|
||||
:after #(dispatch [::proceed-validation-messages
|
||||
command chat-id %2 after-validation])}])))))
|
||||
:after #(dispatch [::proceed-validation %2 after-validation])}])))))
|
||||
|
||||
(handlers/register-handler :set-chat-seq-arg-input-text
|
||||
(fn [{:keys [current-chat-id] :as db} [_ text chat-id]]
|
||||
|
|
|
@ -22,19 +22,28 @@
|
|||
[status-im.utils.types :as types]))
|
||||
|
||||
(defn prepare-command
|
||||
[identity chat-id clock-value request
|
||||
{:keys [id preview preview-string params command
|
||||
to-message handler-data content-type]}]
|
||||
(let [content (or request {:command (command :name)
|
||||
:params params})]
|
||||
[identity chat-id clock-value
|
||||
{request-params :params
|
||||
request-command :command
|
||||
:keys [prefill prefillBotDb]
|
||||
:as request}
|
||||
{:keys [id params command to-message handler-data content-type]}]
|
||||
(let [content (if request
|
||||
{:command request-command
|
||||
:params (assoc request-params :bot-db (:bot-db params))
|
||||
:prefill prefill
|
||||
:prefill-bot-db prefillBotDb}
|
||||
{:command (:name command)
|
||||
:params params})
|
||||
content' (assoc content :handler-data handler-data
|
||||
:type (name (:type command))
|
||||
:content-command (:name command)
|
||||
:bot (:bot command))]
|
||||
{:message-id id
|
||||
:from identity
|
||||
:to chat-id
|
||||
:timestamp (time/now-ms)
|
||||
:content (assoc content :handler-data handler-data
|
||||
:type (name (:type command))
|
||||
:content-command (:name command)
|
||||
:bot (:bot command))
|
||||
:content content'
|
||||
:content-type (or content-type
|
||||
(if request
|
||||
content-type-command-request
|
||||
|
@ -50,50 +59,50 @@
|
|||
(and (= console-chat-id chat-id)
|
||||
(console/commands-names (keyword command-name))))
|
||||
|
||||
(register-handler :check-commands-handlers!
|
||||
(register-handler :check-commands-handlers!
|
||||
(u/side-effect!
|
||||
(fn [_ [_ {:keys [command message chat-id] :as params}]]
|
||||
(let [{:keys [command] :as message} command]
|
||||
(let [params' (assoc params :command-message message)
|
||||
command-name (:name (:command message))]
|
||||
(cond
|
||||
(console-command? chat-id command-name)
|
||||
(dispatch [:invoke-console-command-handler! params'])
|
||||
(let [{:keys [command] :as content} command]
|
||||
(cond
|
||||
(console-command? chat-id (:name command))
|
||||
(dispatch [:invoke-console-command-handler! params])
|
||||
|
||||
(:has-handler command)
|
||||
(dispatch [::invoke-command-handlers! params'])
|
||||
(:has-handler command)
|
||||
(dispatch [::invoke-command-handlers! params])
|
||||
|
||||
:else
|
||||
(dispatch [:prepare-command! chat-id params']))))
|
||||
:else
|
||||
(dispatch [:prepare-command! chat-id params])))
|
||||
(dispatch [:set-chat-ui-props {:sending-in-progress? false}]))))
|
||||
|
||||
(register-handler :prepare-command!
|
||||
(u/side-effect!
|
||||
(fn [{:keys [current-public-key network-status] :as db}
|
||||
[_ add-to-chat-id {:keys [chat-id command-message command] :as params}]]
|
||||
[_ add-to-chat-id {{:keys [handler-data
|
||||
command]
|
||||
:as content} :command
|
||||
chat-id :chat-id
|
||||
:as params}]]
|
||||
(let [clock-value (messages/get-last-clock-value chat-id)
|
||||
request (:request (:handler-data command))
|
||||
handler-data (:handler-data command)
|
||||
hidden-params (->> (:params (:command command))
|
||||
(filter #(= (:hidden %) true))
|
||||
request (:request handler-data)
|
||||
hidden-params (->> (:params command)
|
||||
(filter :hidden)
|
||||
(map :name))
|
||||
command' (->> (assoc command-message :handler-data handler-data)
|
||||
(prepare-command current-public-key chat-id clock-value request)
|
||||
command' (->> (prepare-command current-public-key chat-id clock-value request content)
|
||||
(cu/check-author-direction db chat-id))]
|
||||
(log/debug "Handler data: " request handler-data (dissoc params :commands :command-message))
|
||||
(log/debug "Handler data: " request handler-data params)
|
||||
(dispatch [:update-message-overhead! chat-id network-status])
|
||||
(dispatch [:set-chat-ui-props {:sending-in-progress? false}])
|
||||
(dispatch [::send-command! add-to-chat-id (assoc params :command command') hidden-params])
|
||||
(when (cu/console? chat-id)
|
||||
(dispatch [:console-respond-command params]))
|
||||
(when (and (= "send" (get-in command-message [:command :name]))
|
||||
(when (and (= "send" (:name command))
|
||||
(not= add-to-chat-id wallet-chat-id))
|
||||
(let [ct (if request
|
||||
c/content-type-wallet-request
|
||||
c/content-type-wallet-command)
|
||||
command-message' (assoc command-message :id (random/id)
|
||||
:content-type ct)
|
||||
params' (assoc params :command-message command-message')]
|
||||
(let [ct (if request
|
||||
c/content-type-wallet-request
|
||||
c/content-type-wallet-command)
|
||||
content' (assoc content :id (random/id)
|
||||
:content-type ct)
|
||||
params' (assoc params :command content')]
|
||||
(dispatch [:prepare-command! wallet-chat-id params'])))))))
|
||||
|
||||
(register-handler ::send-command!
|
||||
|
@ -129,30 +138,30 @@
|
|||
(register-handler ::invoke-command-handlers!
|
||||
(u/side-effect!
|
||||
(fn [{:keys [bot-db accounts current-account-id] :as db}
|
||||
[_ {:keys [chat-id address command-message]
|
||||
:as parameters}]]
|
||||
(let [{:keys [id command params]} command-message
|
||||
{:keys [type name bot owner-id]} command
|
||||
path [(if (= :command type) :commands :responses)
|
||||
name
|
||||
:handler]
|
||||
to (get-in db [:contacts chat-id :address])
|
||||
identity (or owner-id bot chat-id)
|
||||
bot-db (get bot-db (or bot chat-id))
|
||||
params {:parameters (assoc params :bot-db bot-db)
|
||||
:context {:from address
|
||||
:to to
|
||||
:current-account (get accounts current-account-id)
|
||||
:message-id id}}]
|
||||
[_ {{:keys [command
|
||||
params
|
||||
id]} :command
|
||||
:keys [chat-id address]
|
||||
:as orig-params}]]
|
||||
(let [{:keys [type name bot owner-id]} command
|
||||
handler-type (if (= :command type) :commands :responses)
|
||||
to (get-in db [:contacts chat-id :address])
|
||||
identity (or owner-id bot chat-id)
|
||||
bot-db (get bot-db (or bot chat-id))
|
||||
params {:parameters params
|
||||
:context {:from address
|
||||
:to to
|
||||
:current-account (get accounts current-account-id)
|
||||
:message-id id}}]
|
||||
(dispatch
|
||||
[:check-and-load-commands!
|
||||
identity
|
||||
#(status/call-jail
|
||||
{:jail-id identity
|
||||
:path path
|
||||
:path [handler-type name :handler]
|
||||
:params params
|
||||
:callback (fn [res]
|
||||
(dispatch [:command-handler! chat-id parameters res]))})])))))
|
||||
(dispatch [:command-handler! chat-id orig-params res]))})])))))
|
||||
|
||||
(register-handler :prepare-message
|
||||
(u/side-effect!
|
||||
|
|
|
@ -158,7 +158,7 @@
|
|||
(let [params (:params command)]
|
||||
(->> args
|
||||
(map-indexed (fn [i value]
|
||||
(vector (get-in params [i :name]) value)))
|
||||
[(keyword (get-in params [i :name])) value]))
|
||||
(into {}))))
|
||||
|
||||
(defn command-dependent-context-params
|
||||
|
|
|
@ -77,12 +77,12 @@
|
|||
markup (subscribe [:get-in [:message-data :preview message-id :markup]])]
|
||||
(fn [{:keys [message-id content from incoming-group]}]
|
||||
(let [commands @commands-atom
|
||||
{:keys [prefill prefillBotDb params]
|
||||
{:keys [prefill prefill-bot-db prefillBotDb params]
|
||||
text-content :text} content
|
||||
{:keys [command content]} (parse-command-request commands content)
|
||||
command (if (and params command)
|
||||
(merge command {:prefill prefill
|
||||
:prefill-bot-db prefillBotDb})
|
||||
:prefill-bot-db (or prefill-bot-db prefillBotDb)})
|
||||
command)]
|
||||
[view st/comand-request-view
|
||||
[touchable-highlight
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
(defn command-handler!
|
||||
[_ [chat-id
|
||||
{:keys [command-message] :as parameters}
|
||||
{:keys [command] :as params}
|
||||
{:keys [result error]}]]
|
||||
(let [{:keys [context returned]} result
|
||||
{handler-error :error} returned]
|
||||
|
@ -25,14 +25,14 @@
|
|||
(dispatch [:set-chat-ui-props {:validation-messages (cu/generate-hiccup markup)}]))
|
||||
|
||||
result
|
||||
(let [command' (assoc command-message :handler-data returned)
|
||||
parameters' (assoc parameters :command command')]
|
||||
(let [command' (assoc command :handler-data returned)
|
||||
params' (assoc params :command command')]
|
||||
(if (:eth_sendTransaction context)
|
||||
(dispatch [:wait-for-transaction (:id command-message) parameters'])
|
||||
(dispatch [:prepare-command! chat-id parameters'])))
|
||||
(dispatch [:wait-for-transaction (:id command) params'])
|
||||
(dispatch [:prepare-command! chat-id params'])))
|
||||
|
||||
(not (or error handler-error))
|
||||
(dispatch [:prepare-command! chat-id parameters])
|
||||
(dispatch [:prepare-command! chat-id params])
|
||||
|
||||
:else nil)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue