Can response to request message by clicking on message only
Former-commit-id: 6840460ba9
This commit is contained in:
parent
0aa30d8f90
commit
763eb979b8
|
@ -87,13 +87,13 @@
|
||||||
"******"
|
"******"
|
||||||
content)]]))
|
content)]]))
|
||||||
|
|
||||||
(defn set-chat-command [command]
|
(defn set-chat-command [msg-id command]
|
||||||
(dispatch [:set-chat-command (:command command)]))
|
(dispatch [:set-response-chat-command msg-id (:command command)]))
|
||||||
|
|
||||||
(defn message-content-command-request [content outgoing text-color background-color]
|
(defn message-content-command-request [msg-id content outgoing text-color background-color]
|
||||||
(let [{:keys [command content]} (commands/parse-command-request-msg-content content)]
|
(let [{:keys [command content]} (commands/parse-command-request-msg-content content)]
|
||||||
[touchable-highlight {:onPress (fn []
|
[touchable-highlight {:onPress (fn []
|
||||||
(set-chat-command command))}
|
(set-chat-command msg-id command))}
|
||||||
[view {}
|
[view {}
|
||||||
[view {:style (merge {:marginTop 15
|
[view {:style (merge {:marginTop 15
|
||||||
:borderRadius 6
|
:borderRadius 6
|
||||||
|
@ -122,9 +122,9 @@
|
||||||
:top 8
|
:top 8
|
||||||
:left 6}}]]]]))
|
:left 6}}]]]]))
|
||||||
|
|
||||||
(defn message-content [{:keys [content-type content outgoing text-color background-color]}]
|
(defn message-content [{:keys [msg-id content-type content outgoing text-color background-color]}]
|
||||||
(if (= content-type content-type-command-request)
|
(if (= content-type content-type-command-request)
|
||||||
[message-content-command-request content outgoing text-color background-color]
|
[message-content-command-request msg-id content outgoing text-color background-color]
|
||||||
[view {:style (merge {:borderRadius 6}
|
[view {:style (merge {:borderRadius 6}
|
||||||
(if (= content-type text-content-type)
|
(if (= content-type text-content-type)
|
||||||
{:paddingVertical 12
|
{:paddingVertical 12
|
||||||
|
@ -175,7 +175,8 @@
|
||||||
:alignItems "flex-end"}
|
:alignItems "flex-end"}
|
||||||
{:alignSelf "flex-start"
|
{:alignSelf "flex-start"
|
||||||
:alignItems "flex-start"}))}
|
:alignItems "flex-start"}))}
|
||||||
[message-content {:content-type content-type
|
[message-content {:msg-id msg-id
|
||||||
|
:content-type content-type
|
||||||
:content content
|
:content content
|
||||||
:outgoing outgoing
|
:outgoing outgoing
|
||||||
:text-color text-color
|
:text-color text-color
|
||||||
|
|
|
@ -26,8 +26,12 @@
|
||||||
[:chats chat-id :input-text])
|
[:chats chat-id :input-text])
|
||||||
(defn chat-command-path [chat-id]
|
(defn chat-command-path [chat-id]
|
||||||
[:chats chat-id :command-input :command])
|
[:chats chat-id :command-input :command])
|
||||||
|
(defn chat-command-to-msg-id-path [chat-id]
|
||||||
|
[:chats chat-id :command-input :to-msg-id])
|
||||||
(defn chat-command-content-path [chat-id]
|
(defn chat-command-content-path [chat-id]
|
||||||
[:chats chat-id :command-input :content])
|
[:chats chat-id :command-input :content])
|
||||||
(defn chat-command-request-path [chat-id]
|
(defn chat-command-requests-path [chat-id]
|
||||||
[:chats chat-id :command-request])
|
[:chats chat-id :command-requests])
|
||||||
|
(defn chat-command-request-path [chat-id msg-id]
|
||||||
|
[:chats chat-id :command-requests msg-id])
|
||||||
(def new-group-path [:new-group])
|
(def new-group-path [:new-group])
|
||||||
|
|
|
@ -13,11 +13,13 @@
|
||||||
update-message!
|
update-message!
|
||||||
message-by-id]]
|
message-by-id]]
|
||||||
[syng-im.models.commands :refer [set-chat-command
|
[syng-im.models.commands :refer [set-chat-command
|
||||||
|
set-response-chat-command
|
||||||
set-chat-command-content
|
set-chat-command-content
|
||||||
set-chat-command-request]]
|
set-chat-command-request]]
|
||||||
[syng-im.handlers.server :as server]
|
[syng-im.handlers.server :as server]
|
||||||
[syng-im.handlers.contacts :as contacts-service]
|
[syng-im.handlers.contacts :as contacts-service]
|
||||||
[syng-im.handlers.suggestions :refer [get-command]]
|
[syng-im.handlers.suggestions :refer [get-command
|
||||||
|
handle-command]]
|
||||||
[syng-im.handlers.sign-up :as sign-up-service]
|
[syng-im.handlers.sign-up :as sign-up-service]
|
||||||
|
|
||||||
[syng-im.models.chats :refer [create-chat]]
|
[syng-im.models.chats :refer [create-chat]]
|
||||||
|
@ -163,7 +165,9 @@
|
||||||
:content-type text-content-type
|
:content-type text-content-type
|
||||||
:outgoing true}))]
|
:outgoing true}))]
|
||||||
(save-message chat-id msg)
|
(save-message chat-id msg)
|
||||||
(signal-chat-updated db chat-id))))
|
(-> db
|
||||||
|
(handle-command command content)
|
||||||
|
(signal-chat-updated chat-id)))))
|
||||||
|
|
||||||
(register-handler :send-group-chat-msg
|
(register-handler :send-group-chat-msg
|
||||||
(fn [db [action chat-id text]]
|
(fn [db [action chat-id text]]
|
||||||
|
@ -240,13 +244,17 @@
|
||||||
(fn [db [_ command-key]]
|
(fn [db [_ command-key]]
|
||||||
(set-chat-command db command-key)))
|
(set-chat-command db command-key)))
|
||||||
|
|
||||||
|
(register-handler :set-response-chat-command
|
||||||
|
(fn [db [_ to-msg-id command-key]]
|
||||||
|
(set-response-chat-command db to-msg-id command-key)))
|
||||||
|
|
||||||
(register-handler :set-chat-command-content
|
(register-handler :set-chat-command-content
|
||||||
(fn [db [_ content]]
|
(fn [db [_ content]]
|
||||||
(set-chat-command-content db content)))
|
(set-chat-command-content db content)))
|
||||||
|
|
||||||
(register-handler :set-chat-command-request
|
(register-handler :set-chat-command-request
|
||||||
(fn [db [_ handler]]
|
(fn [db [_ msg-id handler]]
|
||||||
(set-chat-command-request db handler)))
|
(set-chat-command-request db msg-id handler)))
|
||||||
|
|
||||||
(register-handler :show-contacts
|
(register-handler :show-contacts
|
||||||
(fn [db [action navigator]]
|
(fn [db [action navigator]]
|
||||||
|
|
|
@ -49,7 +49,6 @@
|
||||||
:outgoing false
|
:outgoing false
|
||||||
:from "console"
|
:from "console"
|
||||||
:to "me"}])
|
:to "me"}])
|
||||||
(dispatch [:set-chat-command-request nil])
|
|
||||||
(sync-contacts))
|
(sync-contacts))
|
||||||
(dispatch [:received-msg
|
(dispatch [:received-msg
|
||||||
{:msg-id (random/id)
|
{:msg-id (random/id)
|
||||||
|
@ -62,25 +61,28 @@
|
||||||
(defn send-code [code]
|
(defn send-code [code]
|
||||||
(dispatch [:sign-up-confirm code on-send-code-response]))
|
(dispatch [:sign-up-confirm code on-send-code-response]))
|
||||||
|
|
||||||
(defn- handle-confirmation-code [command-key content]
|
(defn- handle-confirmation-code [msg-id command-key content]
|
||||||
|
(dispatch [:set-chat-command-request msg-id nil])
|
||||||
(when (= command-key :confirmation-code)
|
(when (= command-key :confirmation-code)
|
||||||
(send-code content)))
|
(send-code content)))
|
||||||
|
|
||||||
;; -- Send phone number ----------------------------------------
|
;; -- Send phone number ----------------------------------------
|
||||||
(defn on-sign-up-response []
|
(defn on-sign-up-response []
|
||||||
(dispatch [:received-msg
|
(let [msg-id (random/id)]
|
||||||
{:msg-id (random/id)
|
(dispatch [:received-msg
|
||||||
:content (commands/format-command-request-msg-content
|
{:msg-id msg-id
|
||||||
:confirmation-code
|
:content (commands/format-command-request-msg-content
|
||||||
(str "Thanks! We've sent you a text message with a confirmation "
|
:confirmation-code
|
||||||
"code. Please provide that code to confirm your phone number"))
|
(str "Thanks! We've sent you a text message with a confirmation "
|
||||||
:content-type content-type-command-request
|
"code. Please provide that code to confirm your phone number"))
|
||||||
:outgoing false
|
:content-type content-type-command-request
|
||||||
:from "console"
|
:outgoing false
|
||||||
:to "me"}])
|
:from "console"
|
||||||
(dispatch [:set-chat-command-request handle-confirmation-code]))
|
:to "me"}])
|
||||||
|
(dispatch [:set-chat-command-request msg-id handle-confirmation-code])))
|
||||||
|
|
||||||
(defn- handle-phone [command-key content]
|
(defn- handle-phone [msg-id command-key content]
|
||||||
|
(dispatch [:set-chat-command-request msg-id nil])
|
||||||
(when (= command-key :phone)
|
(when (= command-key :phone)
|
||||||
(let [phone-number (format-phone-number content)]
|
(let [phone-number (format-phone-number content)]
|
||||||
(dispatch [:sign-up phone-number on-sign-up-response]))))
|
(dispatch [:sign-up phone-number on-sign-up-response]))))
|
||||||
|
@ -131,20 +133,22 @@
|
||||||
:from "console"
|
:from "console"
|
||||||
:to "me"}])
|
:to "me"}])
|
||||||
;; TODO highlight '!phone'
|
;; TODO highlight '!phone'
|
||||||
(dispatch [:received-msg
|
(let [msg-id (random/id)]
|
||||||
{:msg-id (random/id)
|
(dispatch [:received-msg
|
||||||
:content (commands/format-command-request-msg-content
|
{:msg-id msg-id
|
||||||
:phone
|
:content (commands/format-command-request-msg-content
|
||||||
(str "Your phone number is also required to use the app. Type the "
|
:phone
|
||||||
"exclamation mark or hit the icon to open the command list "
|
(str "Your phone number is also required to use the app. Type the "
|
||||||
"and choose the !phone command"))
|
"exclamation mark or hit the icon to open the command list "
|
||||||
:content-type content-type-command-request
|
"and choose the !phone command"))
|
||||||
:outgoing false
|
:content-type content-type-command-request
|
||||||
:from "console"
|
:outgoing false
|
||||||
:to "me"}])
|
:from "console"
|
||||||
(dispatch [:set-chat-command-request handle-phone]))
|
:to "me"}])
|
||||||
|
(dispatch [:set-chat-command-request msg-id handle-phone])))
|
||||||
|
|
||||||
(defn- handle-password [command-key content]
|
(defn- handle-password [msg-id command-key content]
|
||||||
|
(dispatch [:set-chat-command-request msg-id nil])
|
||||||
(when (= command-key :keypair-password)
|
(when (= command-key :keypair-password)
|
||||||
(save-password content)))
|
(save-password content)))
|
||||||
|
|
||||||
|
@ -164,24 +168,23 @@
|
||||||
:outgoing false
|
:outgoing false
|
||||||
:from "console"
|
:from "console"
|
||||||
:to "me"}])
|
:to "me"}])
|
||||||
(dispatch [:received-msg
|
(let [msg-id (random/id)]
|
||||||
{:msg-id (random/id)
|
(dispatch [:received-msg
|
||||||
:content (commands/format-command-request-msg-content
|
{:msg-id msg-id
|
||||||
:keypair-password
|
:content (commands/format-command-request-msg-content
|
||||||
(str "A key pair has been generated and saved to your device. "
|
:keypair-password
|
||||||
"Create a password to secure your key"))
|
(str "A key pair has been generated and saved to your device. "
|
||||||
:content-type content-type-command-request
|
"Create a password to secure your key"))
|
||||||
:outgoing false
|
:content-type content-type-command-request
|
||||||
:from "console"
|
:outgoing false
|
||||||
:to "me"}])
|
:from "console"
|
||||||
(dispatch [:set-chat-command-request handle-password])
|
:to "me"}])
|
||||||
|
(dispatch [:set-chat-command-request msg-id handle-password]))
|
||||||
;; (dispatch [:set-chat-command :keypair-password])
|
;; (dispatch [:set-chat-command :keypair-password])
|
||||||
db)
|
db)
|
||||||
|
|
||||||
;; TODO store command key in a separate field
|
;; TODO store command key in a separate field
|
||||||
(defn send-console-command [db command-key content]
|
(defn send-console-command [db command-key content]
|
||||||
(when-let [command-handler (commands/get-chat-command-request db)]
|
|
||||||
(command-handler command-key content))
|
|
||||||
{:msg-id (random/id)
|
{:msg-id (random/id)
|
||||||
:from "me"
|
:from "me"
|
||||||
:to "console"
|
:to "console"
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
|
||||||
[syng-im.db :as db]
|
[syng-im.db :as db]
|
||||||
[syng-im.models.chat :refer [current-chat-id]]
|
[syng-im.models.chat :refer [current-chat-id]]
|
||||||
[syng-im.models.commands :refer [commands suggestions]]
|
[syng-im.models.commands :refer [commands
|
||||||
|
suggestions
|
||||||
|
get-chat-command-request
|
||||||
|
get-chat-command-to-msg-id]]
|
||||||
[syng-im.utils.utils :refer [log on-error http-post]]
|
[syng-im.utils.utils :refer [log on-error http-post]]
|
||||||
[syng-im.utils.logging :as log]))
|
[syng-im.utils.logging :as log]))
|
||||||
|
|
||||||
|
@ -16,3 +19,9 @@
|
||||||
(when (= (get text 0) "!")
|
(when (= (get text 0) "!")
|
||||||
;; TODO change 'commands' to 'suggestions'
|
;; TODO change 'commands' to 'suggestions'
|
||||||
(first (filter #(= (:text %) text) commands))))
|
(first (filter #(= (:text %) text) commands))))
|
||||||
|
|
||||||
|
(defn handle-command [db command-key content]
|
||||||
|
(when-let [command-handler (get-chat-command-request db)]
|
||||||
|
(let [to-msg-id (get-chat-command-to-msg-id db)]
|
||||||
|
(command-handler to-msg-id command-key content)))
|
||||||
|
db)
|
||||||
|
|
|
@ -64,17 +64,30 @@
|
||||||
(defn get-chat-command [db]
|
(defn get-chat-command [db]
|
||||||
(get-in db (db/chat-command-path (current-chat-id db))))
|
(get-in db (db/chat-command-path (current-chat-id db))))
|
||||||
|
|
||||||
(defn set-chat-command [db command-key]
|
(defn set-response-chat-command [db msg-id command-key]
|
||||||
(-> db
|
(-> db
|
||||||
(set-chat-command-content nil)
|
(set-chat-command-content nil)
|
||||||
(assoc-in (db/chat-command-path (get-in db db/current-chat-id-path))
|
(assoc-in (db/chat-command-path (current-chat-id db))
|
||||||
(get-command command-key))))
|
(get-command command-key))
|
||||||
|
(assoc-in (db/chat-command-to-msg-id-path (current-chat-id db))
|
||||||
|
msg-id)))
|
||||||
|
|
||||||
|
(defn set-chat-command [db command-key]
|
||||||
|
(set-response-chat-command db nil command-key))
|
||||||
|
|
||||||
|
(defn get-chat-command-to-msg-id [db]
|
||||||
|
(get-in db (db/chat-command-to-msg-id-path (current-chat-id db))))
|
||||||
|
|
||||||
(defn get-chat-command-request [db]
|
(defn get-chat-command-request [db]
|
||||||
(get-in db (db/chat-command-request-path (current-chat-id db))))
|
(get-in db (db/chat-command-request-path (current-chat-id db)
|
||||||
|
(get-chat-command-to-msg-id db))))
|
||||||
|
|
||||||
(defn set-chat-command-request [db handler]
|
(defn set-chat-command-request [db msg-id handler]
|
||||||
(assoc-in db (db/chat-command-request-path (current-chat-id db)) handler))
|
(update-in db (db/chat-command-requests-path (current-chat-id db))
|
||||||
|
(fn [requests]
|
||||||
|
(if requests
|
||||||
|
(assoc requests msg-id handler)
|
||||||
|
{msg-id handler}))))
|
||||||
|
|
||||||
|
|
||||||
(defn- map-to-str
|
(defn- map-to-str
|
||||||
|
|
Loading…
Reference in New Issue