diff --git a/syng-im/src/syng_im/android/core.cljs b/syng-im/src/syng_im/android/core.cljs index b27489bb2c..3430b4aca9 100644 --- a/syng-im/src/syng_im/android/core.cljs +++ b/syng-im/src/syng_im/android/core.cljs @@ -32,7 +32,8 @@ (add-event-listener "hardwareBackPress" new-listener))))) (defn app-root [] - [navigator {:initial-route (clj->js {:view-id :chat-list}) + [navigator {:initial-route (clj->js {:view-id ;:chat-list + :chat}) :render-scene (fn [route nav] (log/debug "route" route) (when true ;; nav/*nav-render* diff --git a/syng-im/src/syng_im/components/chat/suggestions.cljs b/syng-im/src/syng_im/components/chat/suggestions.cljs new file mode 100644 index 0000000000..b68ed2b9cb --- /dev/null +++ b/syng-im/src/syng_im/components/chat/suggestions.cljs @@ -0,0 +1,47 @@ +(ns syng-im.components.chat.suggestions + (:require-macros + [natal-shell.core :refer [with-error-view]]) + (:require [clojure.string :as cstr] + [reagent.core :as r] + [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [syng-im.components.react :refer [view + image + text + list-view + list-item]] + [syng-im.utils.listview :refer [to-datasource]] + [syng-im.utils.utils :refer [log toast http-post]] + [syng-im.utils.logging :as log])) + +(defn suggestion-list-item [suggestion] + [view {:style {:flexDirection "row" + :marginVertical 5 + :marginHorizontal 10 + :height 20 + ;; :backgroundColor "white" + }} + [text {:underlineColorAndroid "#9CBFC0" + :style {:flex 1 + :marginLeft 18 + :lineHeight 18 + :fontSize 14 + :fontFamily "Avenir-Roman" + :color "#9CBFC0"}} + (:text suggestion)]]) + +(defn render-row [row section-id row-id] + (list-item [suggestion-list-item (js->clj row :keywordize-keys true)])) + +(defn suggestions-view [] + (let [suggestions (subscribe [:get-suggestions])] + (fn [] + (when @suggestions + [view {:style {:flexDirection "row" + :marginVertical 5 + :marginHorizontal 10 + :height 120 + :backgroundColor "#E5F5F6" + :borderRadius 5}} + [list-view {:dataSource (to-datasource @suggestions) + :renderRow render-row + :style {}}]])))) diff --git a/syng-im/src/syng_im/components/chat_message_new.cljs b/syng-im/src/syng_im/components/chat_message_new.cljs index 9b5f37a404..c4c7741c44 100644 --- a/syng-im/src/syng_im/components/chat_message_new.cljs +++ b/syng-im/src/syng_im/components/chat_message_new.cljs @@ -4,6 +4,7 @@ view image text-input]] + [syng-im.components.chat.suggestions :refer [suggestions-view]] [syng-im.utils.logging :as log] [syng-im.resources :as res] [reagent.core :as r])) @@ -13,39 +14,42 @@ (let [text (r/atom nil) chat-id (subscribe [:get-current-chat-id])] (fn [] - [view {:style {:flexDirection "row" - :margin 10 - :height 40 - :backgroundColor "#E5F5F6" - :borderRadius 5}} - [image {:source res/mic - :style {:marginTop 11 - :marginLeft 14 - :width 13 - :height 20}}] - [text-input {:underlineColorAndroid "#9CBFC0" - :style {:flex 1 - :marginLeft 18 - :lineHeight 42 - :fontSize 14 - :fontFamily "Avenir-Roman" - :color "#9CBFC0"} - :autoFocus true - :placeholder "Enter your message here" - :value @text - :onChangeText (fn [new-text] - (reset! text new-text) - (r/flush)) - :onSubmitEditing (fn [e] - (dispatch [:send-chat-msg @chat-id @text]) - (reset! text nil))}] - [image {:source res/smile - :style {:marginTop 11 - :marginRight 12 - :width 18 - :height 18}}] - [image {:source res/att - :style {:marginTop 14 - :marginRight 16 - :width 17 - :height 14}}]]))) + [view {:style {:flexDirection "column"}} + [view {:style {:flexDirection "row" + :margin 10 + :height 40 + :backgroundColor "#E5F5F6" + :borderRadius 5}} + [image {:source res/mic + :style {:marginTop 11 + :marginLeft 14 + :width 13 + :height 20}}] + [text-input {:underlineColorAndroid "#9CBFC0" + :style {:flex 1 + :marginLeft 18 + :lineHeight 42 + :fontSize 14 + :fontFamily "Avenir-Roman" + :color "#9CBFC0"} + :autoFocus true + :placeholder "Enter your message here" + :value @text + :onChangeText (fn [new-text] + (dispatch [:generate-suggestions new-text]) + (reset! text new-text) + (r/flush)) + :onSubmitEditing (fn [e] + (dispatch [:send-chat-msg @chat-id @text]) + (reset! text nil))}] + [image {:source res/smile + :style {:marginTop 11 + :marginRight 12 + :width 18 + :height 18}}] + [image {:source res/att + :style {:marginTop 14 + :marginRight 16 + :width 17 + :height 14}}]] + [suggestions-view]]))) diff --git a/syng-im/src/syng_im/components/contact_list/contact_list.cljs b/syng-im/src/syng_im/components/contact_list/contact_list.cljs index b355b0f46c..403f2235d3 100644 --- a/syng-im/src/syng_im/components/contact_list/contact_list.cljs +++ b/syng-im/src/syng_im/components/contact_list/contact_list.cljs @@ -8,11 +8,7 @@ list-item]] [syng-im.components.resources :as res] [syng-im.components.contact-list.contact :refer [contact-view]] - [syng-im.utils.logging :as log] - ;; [messenger.comm.intercom :as intercom] - ;; [messenger.components.contact-list.contact :refer [contact]] - ;; [messenger.components.iname :as in] - )) + [syng-im.utils.logging :as log])) (defn render-row [navigator row section-id row-id] (list-item [contact-view {:navigator navigator diff --git a/syng-im/src/syng_im/constants.cljs b/syng-im/src/syng_im/constants.cljs index c322156e43..be97d850af 100644 --- a/syng-im/src/syng_im/constants.cljs +++ b/syng-im/src/syng_im/constants.cljs @@ -2,7 +2,7 @@ (def ethereum-rpc-url "http://localhost:8545") -;; (def server-address "http://rpc0.syng.im:20000/") -(def server-address "http://10.0.3.2:3000/") +(def server-address "http://rpc0.syng.im:20000/") +;; (def server-address "http://10.0.3.2:3000/") (def text-content-type "text/plain") diff --git a/syng-im/src/syng_im/db.cljs b/syng-im/src/syng_im/db.cljs index ee9113836d..a2e39531b0 100644 --- a/syng-im/src/syng_im/db.cljs +++ b/syng-im/src/syng_im/db.cljs @@ -7,8 +7,9 @@ ;; initial state of app-db (def app-db {:greeting "Hello Clojure in iOS and Android!" :identity-password "replace-me-with-user-entered-password" - :contacts [] - :chat {:current-chat-id "0x0479a5ed1f38cadfad1db6cd56c4b659b0ebe052bbe9efa950f6660058519fa4ca6be2dda66afa80de96ab00eb97a2605d5267a1e8f4c2a166ab551f6826608cdd"} + :contacts [] + :chat {:current-chat-id "0x0479a5ed1f38cadfad1db6cd56c4b659b0ebe052bbe9efa950f6660058519fa4ca6be2dda66afa80de96ab00eb97a2605d5267a1e8f4c2a166ab551f6826608cdd" + :suggestions []} :chats {} :chats-updated-signal 0}) @@ -16,6 +17,7 @@ (def protocol-initialized-path [:protocol-initialized]) (def identity-password-path [:identity-password]) (def current-chat-id-path [:chat :current-chat-id]) +(def input-suggestions-path [:chat :suggestions]) (def updated-chats-signal-path [:chats-updated-signal]) (defn updated-chat-signal-path [chat-id] [:chats chat-id :chat-updated-signal]) diff --git a/syng-im/src/syng_im/handlers.cljs b/syng-im/src/syng_im/handlers.cljs index 790fed7eb3..4d99195b88 100644 --- a/syng-im/src/syng_im/handlers.cljs +++ b/syng-im/src/syng_im/handlers.cljs @@ -14,6 +14,7 @@ message-by-id]] [syng-im.handlers.server :as server] [syng-im.handlers.contacts :as contacts-service] + [syng-im.handlers.suggestions :as suggestions-service] [syng-im.models.chats :refer [create-chat]] [syng-im.models.chat :refer [signal-chat-updated @@ -143,3 +144,9 @@ (log/debug action "chat-id" chat-id) (nav-push navigator {:view-id :chat}) (set-current-chat-id db chat-id))) + +;; -- Chat -------------------------------------------------------------- + +(register-handler :generate-suggestions + (fn [db [_ text]] + (suggestions-service/generate-suggestions db text))) diff --git a/syng-im/src/syng_im/handlers/suggestions.cljs b/syng-im/src/syng_im/handlers/suggestions.cljs new file mode 100644 index 0000000000..85e9cc3879 --- /dev/null +++ b/syng-im/src/syng_im/handlers/suggestions.cljs @@ -0,0 +1,17 @@ +(ns syng-im.handlers.suggestions + (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [syng-im.db :as db] + [syng-im.utils.utils :refer [log on-error http-post]] + [syng-im.utils.logging :as log])) + +(def commands [{:text "!phone"} + {:text "!send"} + {:text "!request"} + {:text "!help"}]) + +(defn get-suggestions [text] + (when (= (get text 0) "!") + (filterv #(.startsWith (:text %) text) commands))) + +(defn generate-suggestions [db text] + (assoc-in db db/input-suggestions-path (get-suggestions text))) diff --git a/syng-im/src/syng_im/subs.cljs b/syng-im/src/syng_im/subs.cljs index d3a9b30b5e..dcf6fd4f74 100644 --- a/syng-im/src/syng_im/subs.cljs +++ b/syng-im/src/syng_im/subs.cljs @@ -1,6 +1,7 @@ (ns syng-im.subs (:require-macros [reagent.ratom :refer [reaction]]) (:require [re-frame.core :refer [register-sub]] + [syng-im.db :as db] [syng-im.models.chat :refer [current-chat-id chat-updated?]] [syng-im.models.chats :refer [chats-list @@ -24,6 +25,10 @@ (-> (current-chat-id @db) (reaction)))) +(register-sub :get-suggestions + (fn [db _] + (reaction (get-in @db db/input-suggestions-path)))) + ;; -- Chats list -------------------------------------------------------------- (register-sub :get-chats