parent
02f264251f
commit
9e72e52737
|
@ -1,13 +1,15 @@
|
||||||
(ns status-im.chat.subs
|
(ns status-im.chat.subs
|
||||||
(:require-macros [reagent.ratom :refer [reaction]])
|
(:require-macros [reagent.ratom :refer [reaction]])
|
||||||
(:require [re-frame.core :refer [register-sub dispatch]]
|
(:require [re-frame.core :refer [register-sub dispatch subscribe]]
|
||||||
[status-im.db :as db]
|
[status-im.db :as db]
|
||||||
;todo handlers in subs?...
|
;todo handlers in subs?...
|
||||||
[status-im.chat.suggestions :refer
|
[status-im.chat.suggestions :refer
|
||||||
[get-suggestions typing-command?]]
|
[get-suggestions typing-command?]]
|
||||||
[status-im.models.commands :as commands]
|
[status-im.models.commands :as commands]
|
||||||
[status-im.constants :refer [response-suggesstion-resize-duration]]
|
[status-im.constants :refer [response-suggesstion-resize-duration]]
|
||||||
[status-im.handlers.content-suggestions :refer [get-content-suggestions]]))
|
[status-im.handlers.content-suggestions :refer [get-content-suggestions]]
|
||||||
|
[status-im.chat.views.plain-message :as plain-message]
|
||||||
|
[status-im.chat.views.command :as command]))
|
||||||
|
|
||||||
(register-sub :chat-properties
|
(register-sub :chat-properties
|
||||||
(fn [db [_ properties]]
|
(fn [db [_ properties]]
|
||||||
|
@ -63,6 +65,18 @@
|
||||||
(get-in @db)
|
(get-in @db)
|
||||||
(reaction))))
|
(reaction))))
|
||||||
|
|
||||||
|
(register-sub :valid-plain-message?
|
||||||
|
(fn [_ _]
|
||||||
|
(let [input-message (subscribe [:get-chat-input-text])
|
||||||
|
staged-commands (subscribe [:get-chat-staged-commands])]
|
||||||
|
(reaction
|
||||||
|
(plain-message/message-valid? @staged-commands @input-message)))))
|
||||||
|
|
||||||
|
(register-sub :valid-command?
|
||||||
|
(fn [_ [_ validator]]
|
||||||
|
(let [input (subscribe [:get-chat-command-content])]
|
||||||
|
(reaction (command/valid? @input validator)))))
|
||||||
|
|
||||||
(register-sub :get-chat-command
|
(register-sub :get-chat-command
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
(reaction (commands/get-chat-command @db))))
|
(reaction (commands/get-chat-command @db))))
|
||||||
|
|
|
@ -11,10 +11,8 @@
|
||||||
[status-im.components.animation :as anim]
|
[status-im.components.animation :as anim]
|
||||||
[status-im.chat.views.plain-message :as plain-message]
|
[status-im.chat.views.plain-message :as plain-message]
|
||||||
[status-im.chat.views.command :as command]
|
[status-im.chat.views.command :as command]
|
||||||
[status-im.chat.views.response :as response]
|
|
||||||
[status-im.chat.styles.message-input :as st]
|
[status-im.chat.styles.message-input :as st]
|
||||||
[status-im.chat.styles.plain-message :as st-message]
|
[status-im.chat.styles.plain-message :as st-message]
|
||||||
[status-im.chat.styles.input :as st-command]
|
|
||||||
[status-im.chat.styles.response :as st-response]
|
[status-im.chat.styles.response :as st-response]
|
||||||
[status-im.constants :refer [response-input-hiding-duration]]))
|
[status-im.constants :refer [response-input-hiding-duration]]))
|
||||||
|
|
||||||
|
@ -36,45 +34,32 @@
|
||||||
(defn message-input-container [input]
|
(defn message-input-container [input]
|
||||||
[view st/message-input-container input])
|
[view st/message-input-container input])
|
||||||
|
|
||||||
(defview message-input [input-options validator]
|
(defview message-input [input-options]
|
||||||
[input-message [:get-chat-input-text]
|
[command? [:animations :command?]
|
||||||
command [:get-chat-command]
|
input-message [:get-chat-input-text]
|
||||||
command? [:animations :command?]
|
input-command [:get-chat-command-content]]
|
||||||
to-msg-id [:get-chat-command-to-msg-id]
|
|
||||||
input-command [:get-chat-command-content]
|
|
||||||
staged-commands [:get-chat-staged-commands]
|
|
||||||
typing-command? [:typing-command?]]
|
|
||||||
(let [dismiss-keyboard (not (or command typing-command?))]
|
|
||||||
[text-input (merge {:style (if command?
|
[text-input (merge {:style (if command?
|
||||||
st-response/command-input
|
st-response/command-input
|
||||||
st-message/message-input)
|
st-message/message-input)
|
||||||
:ref #(dispatch [:set-message-input %])
|
:ref #(dispatch [:set-message-input %])
|
||||||
:autoFocus false
|
:autoFocus false
|
||||||
:blurOnSubmit dismiss-keyboard
|
:blurOnSubmit false
|
||||||
:onChangeText (if command?
|
:onChangeText (if command?
|
||||||
command/set-input-message
|
command/set-input-message
|
||||||
plain-message/set-input-message)
|
plain-message/set-input-message)
|
||||||
:onSubmitEditing #(if command?
|
:onSubmitEditing (if command?
|
||||||
(command/try-send input-command validator)
|
command/send-command
|
||||||
(plain-message/try-send staged-commands
|
plain-message/send)}
|
||||||
input-message
|
|
||||||
dismiss-keyboard))}
|
|
||||||
(when command?
|
(when command?
|
||||||
{:accessibility-label :command-input})
|
{:accessibility-label :command-input})
|
||||||
input-options)
|
input-options)
|
||||||
(if command?
|
(if command? input-command input-message)])
|
||||||
input-command
|
|
||||||
input-message)]))
|
|
||||||
|
|
||||||
(defview plain-message-input-view [{:keys [input-options validator]}]
|
(defview plain-message-input-view [{:keys [input-options validator]}]
|
||||||
[input-message [:get-chat-input-text]
|
[command? [:animations :command?]
|
||||||
command [:get-chat-command]
|
|
||||||
command? [:animations :command?]
|
|
||||||
to-msg-id [:get-chat-command-to-msg-id]
|
|
||||||
input-command [:get-chat-command-content]
|
input-command [:get-chat-command-content]
|
||||||
staged-commands [:get-chat-staged-commands]
|
valid-plain-message? [:valid-plain-message?]
|
||||||
typing-command? [:typing-command?]]
|
valid-command? [:valid-command? validator]]
|
||||||
(let [dismiss-keyboard (not (or command typing-command?))]
|
|
||||||
[view st/input-container
|
[view st/input-container
|
||||||
[view st/input-view
|
[view st/input-view
|
||||||
[plain-message/commands-button]
|
[plain-message/commands-button]
|
||||||
|
@ -82,12 +67,9 @@
|
||||||
[message-input input-options validator]]
|
[message-input input-options validator]]
|
||||||
;; TODO emoticons: not implemented
|
;; TODO emoticons: not implemented
|
||||||
[plain-message/smile-button]
|
[plain-message/smile-button]
|
||||||
(if-not command?
|
(when (if command? valid-command? valid-plain-message?)
|
||||||
(when (plain-message/message-valid? staged-commands input-message)
|
(let [on-press (if command?
|
||||||
[send-button {:on-press #(plain-message/try-send staged-commands
|
command/send-command
|
||||||
input-message
|
plain-message/send)]
|
||||||
dismiss-keyboard)
|
[send-button {:on-press on-press
|
||||||
:accessibility-label :send-message}])
|
:accessibility-label :send-message}]))]])
|
||||||
(when (command/valid? input-command validator)
|
|
||||||
[send-button {:on-press command/send-command
|
|
||||||
:accessibility-label :stage-command}]))]]))
|
|
||||||
|
|
|
@ -14,9 +14,7 @@
|
||||||
(defn set-input-message [message]
|
(defn set-input-message [message]
|
||||||
(dispatch [:set-chat-input-text message]))
|
(dispatch [:set-chat-input-text message]))
|
||||||
|
|
||||||
(defn send [dismiss-keyboard]
|
(defn send []
|
||||||
(when dismiss-keyboard
|
|
||||||
(dismiss-keyboard!))
|
|
||||||
(dispatch [:send-chat-msg]))
|
(dispatch [:send-chat-msg]))
|
||||||
|
|
||||||
(defn message-valid? [staged-commands message]
|
(defn message-valid? [staged-commands message]
|
||||||
|
@ -24,15 +22,6 @@
|
||||||
(not= "!" message))
|
(not= "!" message))
|
||||||
(pos? (count staged-commands))))
|
(pos? (count staged-commands))))
|
||||||
|
|
||||||
(defn try-send [staged-commands message dismiss-keyboard]
|
|
||||||
(when (message-valid? staged-commands message)
|
|
||||||
(send dismiss-keyboard)))
|
|
||||||
|
|
||||||
(defn prepare-message-input [message-input]
|
|
||||||
(when message-input
|
|
||||||
(.clear message-input)
|
|
||||||
(.focus message-input)))
|
|
||||||
|
|
||||||
(defn button-animation-logic [{:keys [command? val]}]
|
(defn button-animation-logic [{:keys [command? val]}]
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(let [to-scale (if @command? 0 1)]
|
(let [to-scale (if @command? 0 1)]
|
||||||
|
|
Loading…
Reference in New Issue