This commit is contained in:
Roman Volosovskyi 2016-12-01 12:27:32 +02:00
parent 4854021005
commit a99af99b7b
3 changed files with 50 additions and 20 deletions

View File

@ -81,6 +81,19 @@
vals vals
(reaction)))) (reaction))))
(register-sub :get-chat-staged-commands-ids
(fn [db _]
(->> [:chats (:current-chat-id @db) :staged-commands]
(get-in @db)
vals
(keep :to-message)
(reaction))))
(register-sub :staged-response?
(fn [_ [_ id]]
(let [commands (subscribe [:get-chat-staged-commands])]
(reaction (some #(= id (:to-message %)) @commands)))))
(register-sub :get-chat-staged-commands-scroll-height (register-sub :get-chat-staged-commands-scroll-height
(fn [db _] (fn [db _]
(let [{:keys [staged-commands (let [{:keys [staged-commands
@ -177,8 +190,12 @@
(register-sub :get-requests (register-sub :get-requests
(fn [db] (fn [db]
(let [chat-id (subscribe [:get-current-chat-id])] (let [chat-id (subscribe [:get-current-chat-id])
(reaction (get-in @db [:chats @chat-id :requests]))))) staged-ids (subscribe [:get-chat-staged-commands-ids])]
(reaction
(let [ids (set @staged-ids)
requests (get-in @db [:chats @chat-id :requests])]
(remove #(ids (:message-id %)) requests))))))
(register-sub :get-requests-map (register-sub :get-requests-map
(fn [db] (fn [db]

View File

@ -26,32 +26,34 @@
(def min-scale 1) (def min-scale 1)
(def max-scale 1.3) (def max-scale 1.3)
(defn button-animation [val to-value loop? answered?] (defn button-animation [val to-value loop? answered? staged?]
(anim/anim-sequence (anim/anim-sequence
[(anim/anim-delay [(anim/anim-delay
(if (and @loop? (not @answered?)) (if (and @loop? (or @staged? (not @answered?)))
request-message-icon-scale-delay request-message-icon-scale-delay
0)) 0))
(anim/spring val {:toValue to-value})])) (anim/spring val {:toValue to-value})]))
(defn request-button-animation-logic (defn request-button-animation-logic
[{:keys [to-value val loop? answered?] :as context}] [{:keys [to-value val loop? answered? staged?] :as context}]
(anim/start (anim/start
(button-animation val to-value loop? answered?) (button-animation val to-value loop? answered? staged?)
#(if (and @loop? (not @answered?)) #(if (and @loop? (or @staged? (not @answered?)))
(let [new-value (if (= to-value min-scale) max-scale min-scale) (let [new-value (if (= to-value min-scale) max-scale min-scale)
context' (assoc context :to-value new-value)] context' (assoc context :to-value new-value)]
(request-button-animation-logic context')) (request-button-animation-logic context'))
(anim/start (anim/start
(button-animation val min-scale loop? answered?))))) (button-animation val min-scale loop? answered? staged?)))))
(defn request-button [message-id command status-initialized? top-offset?] (defn request-button [message-id command status-initialized? top-offset?]
(let [scale-anim-val (anim/create-value min-scale) (let [scale-anim-val (anim/create-value min-scale)
answered? (subscribe [:is-request-answered? message-id]) answered? (subscribe [:is-request-answered? message-id])
staged? (subscribe [:staged-response? message-id])
loop? (r/atom true) loop? (r/atom true)
context {:to-value max-scale context {:to-value max-scale
:val scale-anim-val :val scale-anim-val
:answered? answered? :answered? answered?
:staged? staged?
:loop? loop?}] :loop? loop?}]
(r/create-class (r/create-class
{:component-did-mount {:component-did-mount
@ -78,11 +80,11 @@
status-initialized? (subscribe [:get :status-module-initialized?])] status-initialized? (subscribe [:get :status-module-initialized?])]
(fn [{:keys [message-id content from incoming-group]}] (fn [{:keys [message-id content from incoming-group]}]
(let [commands @commands-atom (let [commands @commands-atom
params (:params content) params (:params content)
{:keys [command content]} (parse-command-request commands content) {:keys [command content]} (parse-command-request commands content)
command (if (and params command) command (if (and params command)
(merge command {:set-params params}) (merge command {:set-params params})
command)] command)]
[view st/comand-request-view [view st/comand-request-view
[touchable-highlight [touchable-highlight
{:on-press (when (and (not @answered?) @status-initialized?) {:on-press (when (and (not @answered?) @status-initialized?)
@ -92,13 +94,13 @@
[text {:style st/command-request-from-text [text {:style st/command-request-from-text
:font :default} :font :default}
from]) from])
[text {:style st/style-message-text [text {:style st/style-message-text
:on-layout #(reset! top-offset {:specified? true :on-layout #(reset! top-offset {:specified? true
:value (-> (.-nativeEvent %) :value (-> (.-nativeEvent %)
(.-layout) (.-layout)
(.-height) (.-height)
(> 25))}) (> 25))})
:font :default} :font :default}
content]]] content]]]
(when (:request-text command) (when (:request-text command)
[view st/command-request-text-view [view st/command-request-text-view

View File

@ -64,9 +64,20 @@
(when status (when status
(call-module #(.startNode status on-result)))) (call-module #(.startNode status on-result))))
(defonce account-creation? (atom false))
(defn create-account [password on-result] (defn create-account [password on-result]
(when status (when status
(call-module #(.createAccount status password on-result)))) (let [callback (fn [data]
(reset! account-creation? true)
(on-result data))]
(swap! account-creation?
(fn [creation?]
(if-not creation?
(do
(call-module #(.createAccount status password callback))
true)
false))))))
(defn recover-account [passphrase password on-result] (defn recover-account [passphrase password on-result]
(when status (when status