Remove obsolete `:on-send` checking

This commit is contained in:
janherich 2018-01-30 17:17:20 +01:00
parent 0447912172
commit 3c406b24bb
No known key found for this signature in database
GPG Key ID: C23B473AFBE94D13
2 changed files with 22 additions and 54 deletions

View File

@ -53,8 +53,7 @@ Command.prototype.create = function (com) {
this.icon = com.icon; this.icon = com.icon;
this.params = com.params || []; this.params = com.params || [];
this.preview = com.preview; this.preview = com.preview;
this["short-preview"] = com.shortPreview; this["short-preview"] = com.shortPreview;
this["on-send"] = com.onSend;
this.fullscreen = com.fullscreen; this.fullscreen = com.fullscreen;
this.actions = com.actions; this.actions = com.actions;
this.request = com.request; this.request = com.request;

View File

@ -279,39 +279,28 @@
command-message)}))) command-message)})))
(defn proceed-command (defn proceed-command
"Proceed with command processing by setting up execution chain of events: "Proceed with command processing by setting up and executing chain of events:
1. Params validation
1. Command validation 2. Preview fetching"
2. Checking if command defined `onSend`
Second check is important because commands defining `onSend` are actually not
'sendable' and can't be treated as normal command messages, instead of actually
sending them, returned markup is displayed in the chat result box and command processing
ends there.
If it's normal command instead (determined by nil response to `:on-send` jail request),
processing continues by requesting command preview before actually sending the command
message."
[{:keys [current-chat-id chats] :as db} {{:keys [bot]} :command :as content} message-id current-time] [{:keys [current-chat-id chats] :as db} {{:keys [bot]} :command :as content} message-id current-time]
(let [params-template {:content content (let [params-template {:content content
:chat-id current-chat-id :chat-id current-chat-id
:group-id (when (get-in chats [current-chat-id :group-chat]) :group-id (when (get-in chats [current-chat-id :group-chat])
current-chat-id) current-chat-id)
:jail-id (or bot current-chat-id) :jail-id (or bot current-chat-id)
:message-id message-id :message-id message-id
:current-time current-time} :current-time current-time}
on-send-params (merge params-template preview-params (merge params-template
{:data-type :on-send {:data-type :preview
:event-after-creator (fn [_ jail-response] :event-after-creator (fn [command-message jail-response]
[::check-command-type [::send-command
jail-response (assoc-in command-message [:command :preview] jail-response)])})
params-template])}) validation-params (merge params-template
after-validation-events [[::request-command-data on-send-params]] {:data-type :validator
validation-params (merge params-template :event-after-creator (fn [_ jail-response]
{:data-type :validator [::proceed-validation
:event-after-creator (fn [_ jail-response] jail-response
[::proceed-validation [[::request-command-data preview-params]]])})]
jail-response
after-validation-events])})]
(request-command-data db validation-params))) (request-command-data db validation-params)))
;;;; Handlers ;;;; Handlers
@ -421,26 +410,6 @@
(set-chat-input-metadata nil) (set-chat-input-metadata nil)
(set-chat-input-text nil)))))) (set-chat-input-text nil))))))
(handlers/register-handler-fx
::check-command-type
[re-frame/trim-v]
(fn [{{:keys [current-chat-id] :as db} :db} [on-send-jail-response params-template]]
(if on-send-jail-response
;; `onSend` is defined, we have non-sendable command here, like `@browse`
{:db (-> db
(model/set-chat-ui-props {:result-box on-send-jail-response
:sending-in-progress? false})
(animation-events/choose-predefined-expandable-height :result-box :max))
::dismiss-keyboard nil}
;; regular command message, we need to fetch preview before sending the command message
(request-command-data
db
(merge params-template
{:data-type :preview
:event-after-creator (fn [command-message returned]
[::send-command (assoc-in command-message
[:command :preview] returned)])})))))
(defn command-complete? (defn command-complete?
[chat-command] [chat-command]
(= :complete (input-model/command-completion chat-command))) (= :complete (input-model/command-completion chat-command)))