From 34f1e2fa171db157cc4e5130c92c929105f4b85b Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 8 Jun 2016 15:14:35 +0300 Subject: [PATCH 01/53] fetch commands.js init Former-commit-id: 0f4581476d52eaf91a4dacd1d248b73c7d141c8b --- src/status_im/android/core.cljs | 1 - src/status_im/chat/handlers.cljs | 5 + src/status_im/chat/sign_up.cljs | 3 + src/status_im/chat/suggestions.cljs | 36 +++--- src/status_im/chat/views/suggestions.cljs | 47 ++++--- src/status_im/commands/handlers.cljs | 148 ++++++++++++++++++++++ src/status_im/handlers.cljs | 16 +-- src/status_im/models/commands.cljs | 6 - src/status_im/persistence/realm.cljs | 4 + src/status_im/utils/utils.cljs | 6 +- 10 files changed, 204 insertions(+), 68 deletions(-) create mode 100644 src/status_im/commands/handlers.cljs diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 080a91fa54..c864b06ec6 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -56,7 +56,6 @@ (dispatch [:load-user-phone-number]) (dispatch [:load-contacts]) ;; load commands from remote server (todo: uncomment) - ;; (dispatch [:load-commands]) (dispatch [:init-console-chat]) (dispatch [:init-chat]) (init-back-button-handler!) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 0d0af3a2f3..253342baee 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -250,9 +250,14 @@ ([{:keys [messages current-chat-id] :as db} _] (assoc-in db [:chats current-chat-id :messages] messages))) +(defn load-commands! + [{:keys [current-chat-id]}] + (dispatch [:load-commands! current-chat-id])) + (register-handler :init-chat (-> load-messages! ((enrich init-chat)) + ((after load-commands!)) debug)) (defn initialize-chats diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index 9633d94464..0c59915e31 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -184,6 +184,9 @@ (def console-chat {:chat-id "console" :name "console" + ; todo remove/change dapp config fot console + :dapp-url "http://localhost:8185" + :dapp-hash 123 :color default-chat-color :group-chat false :is-active true diff --git a/src/status_im/chat/suggestions.cljs b/src/status_im/chat/suggestions.cljs index dcdc0d3db4..c5a0a8a53b 100644 --- a/src/status_im/chat/suggestions.cljs +++ b/src/status_im/chat/suggestions.cljs @@ -2,22 +2,29 @@ (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] [status-im.db :as db] [status-im.models.commands :refer [commands - suggestions - get-commands - get-chat-command-request - get-chat-command-to-msg-id - clear-staged-commands]] + get-commands + get-chat-command-request + get-chat-command-to-msg-id + clear-staged-commands]] [status-im.utils.utils :refer [log on-error http-get]] [clojure.string :as s])) (defn suggestion? [text] (= (get text 0) "!")) -(defn get-suggestions [db text] - (if (suggestion? text) - ;; TODO change 'commands' to 'suggestions' - (filterv #(.startsWith (:text %) text) (get-commands db)) - [])) +(defn can-be-suggested? [text] + (fn [{:keys [name]}] + (.startsWith (str "!" name) text))) + +(defn get-suggestions + [{:keys [current-chat-id] :as db} text] + (let [commands (get-in db [:chats current-chat-id :commands])] + (if (suggestion? text) + ;; TODO change 'commands' to 'suggestions' + (->> commands + vals + (filter (can-be-suggested? text))) + []))) (defn get-command [db text] (when (suggestion? text) @@ -45,15 +52,6 @@ staged-commands)) (clear-staged-commands db))) -(defn execute-commands-js [body] - (.eval js/window body) - (let [commands (.-commands js/window)] - (dispatch [:set-commands (map #(update % :command keyword) - (js->clj commands :keywordize-keys true))]))) - -(defn load-commands [] - (http-get "chat-commands.js" execute-commands-js nil)) - (defn check-suggestion [db message] (when-let [suggestion-text (when (string? message) (re-matches #"^![^\s]+\s" message))] diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 9a170cd5a5..039554d390 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -1,11 +1,12 @@ (ns status-im.chat.views.suggestions + (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch]] [status-im.components.react :refer [view - text - icon - touchable-highlight - list-view - list-item]] + text + icon + touchable-highlight + list-view + list-item]] [status-im.utils.listview :refer [to-datasource]] [status-im.chat.styles.suggestions :as st])) @@ -13,11 +14,11 @@ (dispatch [:set-chat-command command])) (defn suggestion-list-item - [{:keys [description command] - label :text + [{:keys [description] + label :name :as suggestion}] [touchable-highlight - {:onPress #(set-command-input (keyword command))} + {:onPress #(set-command-input (keyword label))} [view st/suggestion-container [view st/suggestion-sub-container [view (st/suggestion-background suggestion) @@ -28,19 +29,17 @@ (defn render-row [row _ _] (list-item [suggestion-list-item row])) -(defn suggestions-view [] - (let [suggestions-atom (subscribe [:get-suggestions])] - (fn [] - (let [suggestions @suggestions-atom] - (when (seq suggestions) - [view - [touchable-highlight {:style st/drag-down-touchable - :onPress (fn [] - ;; TODO hide suggestions? - )} - [view - [icon :drag_down st/drag-down-icon]]] - [view (st/suggestions-container (count suggestions)) - [list-view {:dataSource (to-datasource suggestions) - :enableEmptySections true - :renderRow render-row}]]]))))) +(defview suggestions-view [] + [suggestions [:get-suggestions]] + (when (seq suggestions) + [view + [touchable-highlight {:style st/drag-down-touchable + :onPress (fn [] + ;; TODO hide suggestions? + )} + [view + [icon :drag_down st/drag-down-icon]]] + [view (st/suggestions-container (count suggestions)) + [list-view {:dataSource (to-datasource suggestions) + :enableEmptySections true + :renderRow render-row}]]])) diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers.cljs new file mode 100644 index 0000000000..7f8657d7b2 --- /dev/null +++ b/src/status_im/commands/handlers.cljs @@ -0,0 +1,148 @@ +(ns status-im.commands.handlers + (:require [re-frame.core :refer [register-handler after dispatch subscribe + trim-v debug]] + [status-im.utils.handlers :as u] + [status-im.components.react :as r] + [status-im.utils.utils :refer [http-get toast]] + [clojure.string :as s])) + +;; commands loading flow +; ┌────────────────────────────┐ +; │ user starts chat with dapp │ +; └────────────────────────────┘ +; │ +; ▼ +; ┌───────────────────────┐ +; │ fetch current │ +; │ `commands.js` hash │ +; └───────────────────────┘ +; │ +; ▼ +; ┌───────────────────────────┐ +; │try to fetch `commands.js` │ +; └───────────────────────────┘ +; │ +; ▼ +;┌───┐ ┌─────────────────────────┐ ┌───┐ +;│no ├────────│ there is `commands.js` │────┤yes│ +;└─┬─┘ └─────────────────────────┘ └─┬─┘ +; │ │ +; │ ▼ +; │ ┌───────────────────┐ +; │ ┌────┐ │ Is file's hash │ +; │ │nope├─────────────────│ equal to current? │ +; │ └─┬──┘ └───────────────────┘ +; │ │ │ +; │ │ ┌─┴─┐ +; │ │ │yes│ +; │ │ └─┬─┘ +; │ │ │ +; │ │ ▼ +; │ │ ┌────┐ ┌──────────────────────────┐ ┌────┐ +; │ │ │fail├──│ ask `otto` to handle js │──┤succ│ +; │ │ └──┬─┘ └──────────────────────────┘ └─┬──┘ +; │ │ │ │ +; │ │ │ ▼ +; │ │ │ ┌────────────────────────────┐ +; │ │ ▼ │ save commands │ +; │ │ ┌────────────────────────┐ │ save js ? │ +; │ │ │the dapp emit a message │ │ add some API object form │ +; │ └─▶│ saying js is broken │ │ otto to app-db │ +; │ └────────────────────────┘ └────────────────────────────┘ +; │ │ │ +; │ │ │ +; │ ┌───────────────────┘ ▼ +; │ │ ┌─────────────────────────┐ +; │ │ │ if it is necessary show │ +; │ ▼ │ as fullscreen │ +; │ ┌───────────┐ └─────────────────────────┘ +; │ │ │ │ +; └─▶│ Fin' │◀──────────────────────────────────────────┘ +; │ │ +; └───────────┘ + +(defn reg-handler + ([name handler] (reg-handler name nil handler)) + ([name middleware handler] + (register-handler name [debug trim-v middleware] handler))) + +(def commands-js "commands.js") + +(defn fetch-commands! + [db [identity]] + (when-let [url (:dapp-url (get-in db [:chats identity]))] + (http-get (s/join "/" [url commands-js]) + #(dispatch [::validate-hash identity %]) + #(dispatch [::loading-failed! identity ::file-was-not-found])))) + +(defn dispatch-loaded! + [db [identity file]] + (if (::valid-hash db) + (dispatch [::parse-commands! identity file]) + (dispatch [::loading-failed! identity ::wrong-hash]))) + +(defn get-hash-by-dentity + [db identity] + (get-in db [:chats identity :dapp-hash])) + +(defn get-hash-by-file + [file] + ;; todo implement + 123) + +(defn get-jail [] + (.-Jail (.-NativeModules r/react))) + +(defn parse [file success-callback fail-callback] + (.parse (get-jail) file success-callback fail-callback)) + +(defn json->clj [json] + (js->clj (.parse js/JSON json) :keywordize-keys true)) + +(defn parse-commands! [_ [identity file]] + (parse file + (fn [result] + (let [commands (json->clj result)] + (dispatch [::add-commands identity commands]))) + #(dispatch [::loading-failed! identity ::error-in-jail %]))) + +(defn validate-hash + [db [identity file]] + (let [valid? (= (get-hash-by-dentity db identity) + (get-hash-by-file file))] + (assoc db ::valid-hash valid?))) + +(defn save-commands! + [db] + #_(realm/save (::new-commands db))) + +(defn add-commands + [db [id commands-obj]] + (let [commands (:commands commands-obj)] + (-> db + (update-in [:chats id :commands] merge commands) + (assoc db ::new-commands commands)))) + +(defn loading-failed + [db [id reason details]] + (let [url (get-in db [:chats id :dapp-url])] + (toast (s/join "\n" ["commands.js loading failed" + url + id + (name reason) + details])))) + +(reg-handler :load-commands! (u/side-effect! fetch-commands!)) + +(reg-handler ::validate-hash + (after dispatch-loaded!) + validate-hash) + +(reg-handler ::parse-commands! (u/side-effect! parse-commands!)) + +(reg-handler ::add-commands + (after save-commands!) + add-commands) + +(reg-handler ::loading-failed! (u/side-effect! loading-failed)) + diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 6aa74b5c5f..02d7d9e760 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -5,8 +5,6 @@ [status-im.db :refer [app-db schema]] [status-im.persistence.simple-kv-store :as kv] [status-im.protocol.state.storage :as storage] - [status-im.models.commands :refer [set-commands]] - [status-im.chat.suggestions :refer [load-commands]] [status-im.utils.logging :as log] [status-im.utils.crypt :refer [gen-random-bytes]] [status-im.utils.handlers :as u] @@ -17,7 +15,8 @@ status-im.discovery.handlers status-im.new-group.handlers status-im.participants.handlers - status-im.protocol.handlers)) + status-im.protocol.handlers + status-im.commands.handlers)) ;; -- Middleware ------------------------------------------------------------ ;; @@ -75,17 +74,6 @@ (fn [_ _] (log/debug "crypt initialized")))) -(register-handler :load-commands - (u/side-effect! - (fn [_ [action]] - (log/debug action) - (load-commands)))) - -(register-handler :set-commands - (fn [db [action commands]] - (log/debug action commands) - (set-commands db commands))) - ;; -- User data -------------------------------------------------------------- (register-handler :load-user-phone-number (fn [db [_]] diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index a9ba2ffd26..48e808bf12 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -64,12 +64,6 @@ ;; (get db :commands) commands) -(defn set-commands [db commands] - (assoc db :commands commands)) - -;; todo delete -(def suggestions (filterv :suggestion commands)) - (defn get-command [db command-key] (first (filter #(= command-key (:command %)) (get-commands db)))) diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index 5d304828fe..fa471355b1 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -51,6 +51,10 @@ :timestamp "int" :contacts {:type "list" :objectType "chat-contact"} + :dapp-url {:type :string + :optional true} + :dapp-hash {:type :int + :optional true} :last-msg-id "string"}} {:name :tag :primaryKey :name diff --git a/src/status_im/utils/utils.cljs b/src/status_im/utils/utils.cljs index c20a6c1e2a..b317dd0301 100644 --- a/src/status_im/utils/utils.cljs +++ b/src/status_im/utils/utils.cljs @@ -41,10 +41,8 @@ (toast (str error)))))))) (defn http-get - ([action on-success on-error] - (-> (.fetch js/window - (str const/server-address action) - (clj->js {:method "GET"})) + ([url on-success on-error] + (-> (.fetch js/window url (clj->js {:method "GET"})) (.then (fn [response] (log response) (.text response))) From 5f2d8e63c72b4a1af7aa4d257c85efaf64535dde Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 8 Jun 2016 15:15:23 +0300 Subject: [PATCH 02/53] jail module Former-commit-id: 32422310e81ee2190eeb11eb05738d4710dd1280 --- .../main/java/com/statusim/JailModule.java | 27 ++++++++++++++ .../main/java/com/statusim/JailPackage.java | 37 +++++++++++++++++++ .../main/java/com/statusim/MainActivity.java | 1 + 3 files changed, 65 insertions(+) create mode 100644 android/app/src/main/java/com/statusim/JailModule.java create mode 100644 android/app/src/main/java/com/statusim/JailPackage.java diff --git a/android/app/src/main/java/com/statusim/JailModule.java b/android/app/src/main/java/com/statusim/JailModule.java new file mode 100644 index 0000000000..eed3852cbb --- /dev/null +++ b/android/app/src/main/java/com/statusim/JailModule.java @@ -0,0 +1,27 @@ +package com.statusim; + +import com.facebook.react.bridge.Callback; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; + +public class JailModule extends ReactContextBaseJavaModule { + + public JailModule(ReactApplicationContext reactContext) { + super(reactContext); + } + + @Override + public String getName() { + return "Jail"; + } + + @ReactMethod + public void parse(String js, Callback succ, Callback fail) { + succ.invoke("{\"commands\":{\"request-money\":" + + "{\"description\":\"olala!\",\"name\":\"request-money\"," + + "\"params\":{\"foo\":{\"type\":\"string\"}}}}," + + "\"responses\":{}}"); + } +} + diff --git a/android/app/src/main/java/com/statusim/JailPackage.java b/android/app/src/main/java/com/statusim/JailPackage.java new file mode 100644 index 0000000000..c1c71d94f1 --- /dev/null +++ b/android/app/src/main/java/com/statusim/JailPackage.java @@ -0,0 +1,37 @@ +package com.statusim; + +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.JavaScriptModule; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Created by rasom on 07.06.16. + */ +public class JailPackage implements ReactPackage { + + @Override + public List> createJSModules() { + return Collections.emptyList(); + } + + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } + + @Override + public List createNativeModules( + ReactApplicationContext reactContext) { + List modules = new ArrayList<>(); + + modules.add(new JailModule(reactContext)); + + return modules; + } +} diff --git a/android/app/src/main/java/com/statusim/MainActivity.java b/android/app/src/main/java/com/statusim/MainActivity.java index 3d411d9213..bbfa9caf05 100644 --- a/android/app/src/main/java/com/statusim/MainActivity.java +++ b/android/app/src/main/java/com/statusim/MainActivity.java @@ -76,6 +76,7 @@ public class MainActivity extends ReactActivity { protected List getPackages() { return Arrays.asList( new MainReactPackage(), + new JailPackage(), new RealmReactPackage(), new VectorIconsPackage(), new ReactNativeContacts(), From 2920984b0ce1aadf03ece702b10583d0bdb3ea43 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 9 Jun 2016 12:49:02 +0300 Subject: [PATCH 03/53] react-native-status dependency and other Former-commit-id: 76e2887b17fdc7321998280fe28895fdc314f6ea --- .re-natal | 5 ++- android/app/build.gradle | 1 + .../main/java/com/statusim/JailModule.java | 27 -------------- .../main/java/com/statusim/JailPackage.java | 37 ------------------- .../main/java/com/statusim/MainActivity.java | 1 + android/settings.gradle | 3 ++ package.json | 3 +- src/status_im/chat/sign_up.cljs | 2 +- src/status_im/commands/handlers.cljs | 5 ++- 9 files changed, 14 insertions(+), 70 deletions(-) delete mode 100644 android/app/src/main/java/com/statusim/JailModule.java delete mode 100644 android/app/src/main/java/com/statusim/JailPackage.java diff --git a/.re-natal b/.re-natal index 1455b14c43..f1c7bbd66b 100644 --- a/.re-natal +++ b/.re-natal @@ -1,7 +1,7 @@ { "name": "StatusIm", "interface": "reagent", - "androidHost": "localhost", + "androidHost": "10.0.3.2", "modules": [ "react-native-contacts", "react-native-invertible-scroll-view", @@ -16,7 +16,8 @@ "react-native-randombytes", "dismissKeyboard", "react-native-linear-gradient", - "react-native-android-sms-listener" + "react-native-android-sms-listener", + "react-native-status" ], "imageDirs": [ "images" diff --git a/android/app/build.gradle b/android/app/build.gradle index 379551061c..95beff7a12 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -130,6 +130,7 @@ dependencies { compile project(':react-native-i18n') compile project(':react-native-linear-gradient') compile project(':ReactNativeAndroidSmsListener') + compile project(':react-native-status') // compile(name:'geth', ext:'aar') compile(group: 'status-im', name: 'android-geth', version: '1.4.0-201604110816-a97a114', ext: 'aar') diff --git a/android/app/src/main/java/com/statusim/JailModule.java b/android/app/src/main/java/com/statusim/JailModule.java deleted file mode 100644 index eed3852cbb..0000000000 --- a/android/app/src/main/java/com/statusim/JailModule.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.statusim; - -import com.facebook.react.bridge.Callback; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactContextBaseJavaModule; -import com.facebook.react.bridge.ReactMethod; - -public class JailModule extends ReactContextBaseJavaModule { - - public JailModule(ReactApplicationContext reactContext) { - super(reactContext); - } - - @Override - public String getName() { - return "Jail"; - } - - @ReactMethod - public void parse(String js, Callback succ, Callback fail) { - succ.invoke("{\"commands\":{\"request-money\":" + - "{\"description\":\"olala!\",\"name\":\"request-money\"," + - "\"params\":{\"foo\":{\"type\":\"string\"}}}}," + - "\"responses\":{}}"); - } -} - diff --git a/android/app/src/main/java/com/statusim/JailPackage.java b/android/app/src/main/java/com/statusim/JailPackage.java deleted file mode 100644 index c1c71d94f1..0000000000 --- a/android/app/src/main/java/com/statusim/JailPackage.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.statusim; - -import com.facebook.react.ReactPackage; -import com.facebook.react.bridge.JavaScriptModule; -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.uimanager.ViewManager; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Created by rasom on 07.06.16. - */ -public class JailPackage implements ReactPackage { - - @Override - public List> createJSModules() { - return Collections.emptyList(); - } - - @Override - public List createViewManagers(ReactApplicationContext reactContext) { - return Collections.emptyList(); - } - - @Override - public List createNativeModules( - ReactApplicationContext reactContext) { - List modules = new ArrayList<>(); - - modules.add(new JailModule(reactContext)); - - return modules; - } -} diff --git a/android/app/src/main/java/com/statusim/MainActivity.java b/android/app/src/main/java/com/statusim/MainActivity.java index bbfa9caf05..dc1a4cd324 100644 --- a/android/app/src/main/java/com/statusim/MainActivity.java +++ b/android/app/src/main/java/com/statusim/MainActivity.java @@ -17,6 +17,7 @@ import java.util.Arrays; import java.util.List; import java.util.Properties; import java.io.File; +import com.statusim.Jail.JailPackage; import com.i18n.reactnativei18n.ReactNativeI18n; import io.realm.react.RealmReactPackage; diff --git a/android/settings.gradle b/android/settings.gradle index 141db02933..a42e8ee4c2 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -18,3 +18,6 @@ include ':react-native-linear-gradient' project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android') include ':ReactNativeAndroidSmsListener' project(':ReactNativeAndroidSmsListener').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-sms-listener/android') + +include ':react-native-status' +project(':react-native-status').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-status/android') diff --git a/package.json b/package.json index f325b8e9f3..e6ea438243 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "react-native-loading-spinner-overlay": "0.0.8", "react-native-randombytes": "^2.0.0", "react-native-vector-icons": "^1.3.4", - "realm": "^0.11.1" + "realm": "^0.11.1", + "react-native-status": "git+ssh://git@github.com/status-im/react-native-status" } } diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index 0c59915e31..b182354e15 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -186,7 +186,7 @@ :name "console" ; todo remove/change dapp config fot console :dapp-url "http://localhost:8185" - :dapp-hash 123 + :dapp-hash 834331894 :color default-chat-color :group-chat false :is-active true diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers.cljs index 7f8657d7b2..fc9e2a8ad3 100644 --- a/src/status_im/commands/handlers.cljs +++ b/src/status_im/commands/handlers.cljs @@ -87,8 +87,8 @@ (defn get-hash-by-file [file] - ;; todo implement - 123) + ;; todo tbd hashing algorithm + (hash file)) (defn get-jail [] (.-Jail (.-NativeModules r/react))) @@ -110,6 +110,7 @@ [db [identity file]] (let [valid? (= (get-hash-by-dentity db identity) (get-hash-by-file file))] + (println "hsh " (hash file)) (assoc db ::valid-hash valid?))) (defn save-commands! From 6a9d1af886d547ce2c96160c4a5f34a845180535 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 9 Jun 2016 14:41:25 +0300 Subject: [PATCH 04/53] store commands.js Former-commit-id: 72768fc7ddb430782b17b44b2b956f4828a3d2e9 --- src/status_im/commands/handlers.cljs | 31 ++++++++++++++++---------- src/status_im/navigation/handlers.cljs | 3 +-- src/status_im/persistence/realm.cljs | 12 +++++++++- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers.cljs index fc9e2a8ad3..f7c713f5e5 100644 --- a/src/status_im/commands/handlers.cljs +++ b/src/status_im/commands/handlers.cljs @@ -4,7 +4,8 @@ [status-im.utils.handlers :as u] [status-im.components.react :as r] [status-im.utils.utils :refer [http-get toast]] - [clojure.string :as s])) + [clojure.string :as s] + [status-im.persistence.realm :as realm])) ;; commands loading flow ; ┌────────────────────────────┐ @@ -44,8 +45,8 @@ ; │ │ │ │ ; │ │ │ ▼ ; │ │ │ ┌────────────────────────────┐ -; │ │ ▼ │ save commands │ -; │ │ ┌────────────────────────┐ │ save js ? │ +; │ │ ▼ │ │ +; │ │ ┌────────────────────────┐ │ save commands-js │ ; │ │ │the dapp emit a message │ │ add some API object form │ ; │ └─▶│ saying js is broken │ │ otto to app-db │ ; │ └────────────────────────┘ └────────────────────────────┘ @@ -68,6 +69,12 @@ (def commands-js "commands.js") +(defn load-commands! + [_ [identity]] + (if-let [{:keys [file]} (realm/get-one-by-field :commands :chat-id identity)] + (dispatch [::parse-commands! identity file]) + (dispatch [::fetch-commands! identity]))) + (defn fetch-commands! [db [identity]] (when-let [url (:dapp-url (get-in db [:chats identity]))] @@ -103,27 +110,26 @@ (parse file (fn [result] (let [commands (json->clj result)] - (dispatch [::add-commands identity commands]))) + (dispatch [::add-commands identity file commands]))) #(dispatch [::loading-failed! identity ::error-in-jail %]))) (defn validate-hash [db [identity file]] (let [valid? (= (get-hash-by-dentity db identity) (get-hash-by-file file))] - (println "hsh " (hash file)) (assoc db ::valid-hash valid?))) -(defn save-commands! - [db] - #_(realm/save (::new-commands db))) - (defn add-commands - [db [id commands-obj]] + [db [id _ commands-obj]] (let [commands (:commands commands-obj)] (-> db (update-in [:chats id :commands] merge commands) (assoc db ::new-commands commands)))) +(defn save-commands-js! + [_ [id file]] + (realm/create-object :commands {:chat-id id :file file})) + (defn loading-failed [db [id reason details]] (let [url (get-in db [:chats id :dapp-url])] @@ -133,7 +139,8 @@ (name reason) details])))) -(reg-handler :load-commands! (u/side-effect! fetch-commands!)) +(reg-handler :load-commands! (u/side-effect! load-commands!)) +(reg-handler ::fetch-commands! (u/side-effect! fetch-commands!)) (reg-handler ::validate-hash (after dispatch-loaded!) @@ -142,7 +149,7 @@ (reg-handler ::parse-commands! (u/side-effect! parse-commands!)) (reg-handler ::add-commands - (after save-commands!) + (after save-commands-js!) add-commands) (reg-handler ::loading-failed! (u/side-effect! loading-failed)) diff --git a/src/status_im/navigation/handlers.cljs b/src/status_im/navigation/handlers.cljs index c47134e429..9e249c6186 100644 --- a/src/status_im/navigation/handlers.cljs +++ b/src/status_im/navigation/handlers.cljs @@ -1,6 +1,5 @@ (ns status-im.navigation.handlers - (:require [re-frame.core :refer [register-handler dispatch debug enrich - after]])) + (:require [re-frame.core :refer [register-handler dispatch debug enrich after]])) (defn push-view [db view-id] (-> db diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index fa471355b1..fd6e9857ad 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -1,7 +1,6 @@ (ns status-im.persistence.realm (:require [cljs.reader :refer [read-string]] [status-im.components.styles :refer [default-chat-color]] - [status-im.utils.logging :as log] [status-im.utils.types :refer [to-string]] [status-im.utils.utils :as u]) (:refer-clojure :exclude [exists?])) @@ -56,6 +55,10 @@ :dapp-hash {:type :int :optional true} :last-msg-id "string"}} + {:name :commands + :primaryKey :chat-id + :properties {:chat-id "string" + :file "string"}} {:name :tag :primaryKey :name :properties {:name "string" @@ -98,6 +101,10 @@ ([schema-name obj update?] (.create realm (to-string schema-name) (clj->js obj) update?))) +(defn create-object + [schema-name obj] + (write (fn [] (create schema-name obj true)))) + (defmulti to-query (fn [schema-name operator field value] operator)) @@ -162,3 +169,6 @@ (defn collection->map [collection] (-> (.map collection (fn [object _ _] object)) (js->clj :keywordize-keys true))) + +(defn get-one-by-field [schema-name field value] + (single-cljs (get-by-field schema-name field value))) From 75649d46aa4eda76e95bf06700d47d900c4b1328 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 9 Jun 2016 16:06:39 +0300 Subject: [PATCH 05/53] tests Former-commit-id: 84747296959ca9de8185c026967d61d12e60cace --- src/status_im/commands/handlers.cljs | 72 +++---------------- .../status_im/test/commands/handlers.cljs | 20 ++++++ test/cljs/status_im/test/runner.cljs | 6 +- 3 files changed, 32 insertions(+), 66 deletions(-) create mode 100644 test/cljs/status_im/test/commands/handlers.cljs diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers.cljs index f7c713f5e5..66e2528ea5 100644 --- a/src/status_im/commands/handlers.cljs +++ b/src/status_im/commands/handlers.cljs @@ -7,61 +7,6 @@ [clojure.string :as s] [status-im.persistence.realm :as realm])) -;; commands loading flow -; ┌────────────────────────────┐ -; │ user starts chat with dapp │ -; └────────────────────────────┘ -; │ -; ▼ -; ┌───────────────────────┐ -; │ fetch current │ -; │ `commands.js` hash │ -; └───────────────────────┘ -; │ -; ▼ -; ┌───────────────────────────┐ -; │try to fetch `commands.js` │ -; └───────────────────────────┘ -; │ -; ▼ -;┌───┐ ┌─────────────────────────┐ ┌───┐ -;│no ├────────│ there is `commands.js` │────┤yes│ -;└─┬─┘ └─────────────────────────┘ └─┬─┘ -; │ │ -; │ ▼ -; │ ┌───────────────────┐ -; │ ┌────┐ │ Is file's hash │ -; │ │nope├─────────────────│ equal to current? │ -; │ └─┬──┘ └───────────────────┘ -; │ │ │ -; │ │ ┌─┴─┐ -; │ │ │yes│ -; │ │ └─┬─┘ -; │ │ │ -; │ │ ▼ -; │ │ ┌────┐ ┌──────────────────────────┐ ┌────┐ -; │ │ │fail├──│ ask `otto` to handle js │──┤succ│ -; │ │ └──┬─┘ └──────────────────────────┘ └─┬──┘ -; │ │ │ │ -; │ │ │ ▼ -; │ │ │ ┌────────────────────────────┐ -; │ │ ▼ │ │ -; │ │ ┌────────────────────────┐ │ save commands-js │ -; │ │ │the dapp emit a message │ │ add some API object form │ -; │ └─▶│ saying js is broken │ │ otto to app-db │ -; │ └────────────────────────┘ └────────────────────────────┘ -; │ │ │ -; │ │ │ -; │ ┌───────────────────┘ ▼ -; │ │ ┌─────────────────────────┐ -; │ │ │ if it is necessary show │ -; │ ▼ │ as fullscreen │ -; │ ┌───────────┐ └─────────────────────────┘ -; │ │ │ │ -; └─▶│ Fin' │◀──────────────────────────────────────────┘ -; │ │ -; └───────────┘ - (defn reg-handler ([name handler] (reg-handler name nil handler)) ([name middleware handler] @@ -88,7 +33,7 @@ (dispatch [::parse-commands! identity file]) (dispatch [::loading-failed! identity ::wrong-hash]))) -(defn get-hash-by-dentity +(defn get-hash-by-identity [db identity] (get-in db [:chats identity :dapp-hash])) @@ -115,22 +60,21 @@ (defn validate-hash [db [identity file]] - (let [valid? (= (get-hash-by-dentity db identity) + (let [valid? (= (get-hash-by-identity db identity) (get-hash-by-file file))] (assoc db ::valid-hash valid?))) (defn add-commands - [db [id _ commands-obj]] - (let [commands (:commands commands-obj)] - (-> db - (update-in [:chats id :commands] merge commands) - (assoc db ::new-commands commands)))) + [db [id _ {:keys [commands responses]}]] + (-> db + (update-in [:chats id :commands] merge commands) + (update-in [:chats id :responses] merge responses))) (defn save-commands-js! [_ [id file]] (realm/create-object :commands {:chat-id id :file file})) -(defn loading-failed +(defn loading-failed! [db [id reason details]] (let [url (get-in db [:chats id :dapp-url])] (toast (s/join "\n" ["commands.js loading failed" @@ -152,5 +96,5 @@ (after save-commands-js!) add-commands) -(reg-handler ::loading-failed! (u/side-effect! loading-failed)) +(reg-handler ::loading-failed! (u/side-effect! loading-failed!)) diff --git a/test/cljs/status_im/test/commands/handlers.cljs b/test/cljs/status_im/test/commands/handlers.cljs new file mode 100644 index 0000000000..92225b5f9e --- /dev/null +++ b/test/cljs/status_im/test/commands/handlers.cljs @@ -0,0 +1,20 @@ +(ns status-im.test.commands.handlers + (:require [cljs.test :refer-macros [deftest is]] + [status-im.commands.handlers :as h])) + +(deftest test-validate-hash + (let [file "some-js" + db (-> {} + (assoc-in [:chats :user :dapp-hash] -731917028) + (assoc-in [:chats :user2 :dapp-hash] 123))] + (is (::h/valid-hash (h/validate-hash db [:user file]))) + (is (not (::h/valid-hash (h/validate-hash db [:user2 file])))) + (is (not (::h/valid-hash (h/validate-hash db [:user3 file])))))) + +(deftest test-add-commands + (let [obj {:commands {:test {:name "name" + :description "desc"}} + :responses {:test-r {:name "r" + :description "desc-r"}}} + db (h/add-commands {} [:user nil obj])] + (is (= obj (select-keys (get-in db [:chats :user]) [:commands :responses]))))) diff --git a/test/cljs/status_im/test/runner.cljs b/test/cljs/status_im/test/runner.cljs index 14bda7de00..fef2b15ecf 100644 --- a/test/cljs/status_im/test/runner.cljs +++ b/test/cljs/status_im/test/runner.cljs @@ -1,5 +1,7 @@ (ns status-im.test.runner (:require [doo.runner :refer-macros [doo-tests]] - [status-im.test.handlers])) + [status-im.test.handlers] + [status-im.test.commands.handlers])) -(doo-tests 'status-im.test.handlers) +(doo-tests 'status-im.test.handlers + 'status-im.test.commands.handlers) From 5689bf787e6e157ef49801e7ad6bf168904a5dfa Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 9 Jun 2016 19:34:09 +0300 Subject: [PATCH 06/53] console commands/responses Former-commit-id: 61b6599bd37d8a2d9e6214993ca4ff2fb5e3a8bc --- src/status_im/chat/handlers.cljs | 4 ++-- src/status_im/chat/suggestions.cljs | 13 ++++------- src/status_im/chat/views/command.cljs | 2 +- src/status_im/chat/views/message.cljs | 2 +- src/status_im/chat/views/staged_command.cljs | 2 +- src/status_im/chat/views/suggestions.cljs | 23 ++++++++++--------- src/status_im/commands/handlers.cljs | 19 ++++++++++++++- src/status_im/contacts/handlers.cljs | 1 - .../handlers/content_suggestions.cljs | 2 +- src/status_im/models/commands.cljs | 20 ++++------------ 10 files changed, 45 insertions(+), 43 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 253342baee..4023473b83 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -68,7 +68,7 @@ (update-input-text db text)) (defn update-command [db [_ text]] - (let [{:keys [command]} (suggestions/check-suggestion db text)] + (let [[command] (suggestions/check-suggestion db text)] (commands/set-chat-command db command))) (register-handler :set-chat-input-text @@ -99,7 +99,7 @@ (defn prepare-message [{:keys [identity current-chat-id] :as db} _] (let [text (get-in db [:chats current-chat-id :input-text]) - {:keys [command]} (suggestions/check-suggestion db (str text " ")) + [command] (suggestions/check-suggestion db (str text " ")) message (check-author-direction db current-chat-id {:msg-id (random/id) diff --git a/src/status_im/chat/suggestions.cljs b/src/status_im/chat/suggestions.cljs index c5a0a8a53b..842a64ea32 100644 --- a/src/status_im/chat/suggestions.cljs +++ b/src/status_im/chat/suggestions.cljs @@ -20,10 +20,7 @@ [{:keys [current-chat-id] :as db} text] (let [commands (get-in db [:chats current-chat-id :commands])] (if (suggestion? text) - ;; TODO change 'commands' to 'suggestions' - (->> commands - vals - (filter (can-be-suggested? text))) + (filter (fn [[_ v]] ((can-be-suggested? text) v)) commands) []))) (defn get-command [db text] @@ -55,10 +52,10 @@ (defn check-suggestion [db message] (when-let [suggestion-text (when (string? message) (re-matches #"^![^\s]+\s" message))] - (let [suggestion-text' (s/trim suggestion-text) - [suggestion] (filter #(= suggestion-text' (:text %)) - (get-commands db))] - suggestion))) + (let [suggestion-text' (s/trim suggestion-text)] + (->> (get-commands db) + (filter #(= suggestion-text' (->> % second :name (str "!")))) + first)))) (defn typing-command? [db] (-> db diff --git a/src/status_im/chat/views/command.cljs b/src/status_im/chat/views/command.cljs index 2b550dc7bf..039f949c9b 100644 --- a/src/status_im/chat/views/command.cljs +++ b/src/status_im/chat/views/command.cljs @@ -32,7 +32,7 @@ [content-suggestions-view] [view st/command-input-container [view (st/command-text-container command) - [text {:style st/command-text} (:text command)]] + [text {:style st/command-text} (str "!" (:name command))]] [text-input (merge {:style st/command-input :autoFocus true :onChangeText set-input-message diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index ceb430fc76..0b6494acf8 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -73,7 +73,7 @@ (dispatch [:set-response-chat-command msg-id (:command command)])) (defn label [{:keys [command]}] - (->> (name command) + (->> (when command (name command)) (str "request-"))) (defn message-content-command-request diff --git a/src/status_im/chat/views/staged_command.cljs b/src/status_im/chat/views/staged_command.cljs index be8c811459..92f72b0508 100644 --- a/src/status_im/chat/views/staged_command.cljs +++ b/src/status_im/chat/views/staged_command.cljs @@ -16,7 +16,7 @@ [view st/staged-command-background [view st/staged-command-info-container [view (st/staged-command-text-container command) - [text {:style st/staged-command-text} (:text command)]] + [text {:style st/staged-command-text} (str "!" (:name command))]] [touchable-highlight {:style st/staged-command-cancel :onPress #(cancel-command-input staged-command)} [image {:source res/icon-close-gray diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 039554d390..67c55ff148 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -14,17 +14,18 @@ (dispatch [:set-chat-command command])) (defn suggestion-list-item - [{:keys [description] - label :name - :as suggestion}] - [touchable-highlight - {:onPress #(set-command-input (keyword label))} - [view st/suggestion-container - [view st/suggestion-sub-container - [view (st/suggestion-background suggestion) - [text {:style st/suggestion-text} label]] - [text {:style st/value-text} label] - [text {:style st/description-text} description]]]]) + [[command {:keys [description] + name :name + :as suggestion}]] + (let [label (str "!" name)] + [touchable-highlight + {:onPress #(set-command-input command)} + [view st/suggestion-container + [view st/suggestion-sub-container + [view (st/suggestion-background suggestion) + [text {:style st/suggestion-text} label]] + [text {:style st/value-text} label] + [text {:style st/description-text} description]]]])) (defn render-row [row _ _] (list-item [suggestion-list-item row])) diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers.cljs index 66e2528ea5..75811d9656 100644 --- a/src/status_im/commands/handlers.cljs +++ b/src/status_im/commands/handlers.cljs @@ -51,11 +51,28 @@ (defn json->clj [json] (js->clj (.parse js/JSON json) :keywordize-keys true)) +;; todo remove this +(def res {:commands {:location {:description "Send location" + :color "#9a5dcf" + :name "location"} + :phone {:description "Send phone number" + :color "#5fc48d" + :name "phone"} + :help {:description "Help" :color "#9a5dcf" :name "help"}} + :responses {:money {:description "Send money" :color "#5fc48d" :name "money"} + :confirmation-code {:description "Confirmation code" + :color "#7099e6" + :name "confirmationCode"} + :keypair-password {:description "" + :color "#7099e6" + :name "keypair-password"}}}) + (defn parse-commands! [_ [identity file]] (parse file (fn [result] (let [commands (json->clj result)] - (dispatch [::add-commands identity file commands]))) + ;; todo use commands from jail + (dispatch [::add-commands identity file res]))) #(dispatch [::loading-failed! identity ::error-in-jail %]))) (defn validate-hash diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index acb9be9b6c..2fd7e586c4 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -96,7 +96,6 @@ (remove #(identities (:whisper-identity %))) (map #(vector (:whisper-identity %) %)) (into {}))] - (println new-contacts') (-> db (update :contacts merge new-contacts') (assoc :new-contacts (vals new-contacts'))))) diff --git a/src/status_im/handlers/content_suggestions.cljs b/src/status_im/handlers/content_suggestions.cljs index f4457f931f..b8c193a8eb 100644 --- a/src/status_im/handlers/content_suggestions.cljs +++ b/src/status_im/handlers/content_suggestions.cljs @@ -14,7 +14,7 @@ (defn get-content-suggestions [db command text] (or (when command - (when-let [command-suggestions ((:command command) suggestions)] + (when-let [command-suggestions ((keyword (:name command)) suggestions)] (filterv (fn [s] (and (.startsWith (:value s) (or text "")) (not= (:value s) text))) diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index 48e808bf12..84b53d47e5 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -35,16 +35,6 @@ :icon {:uri "icon_lock_gray"} :suggestion true :handler #(dispatch [:sign-up-confirm %])} - {:command :send - :text "!send" - :description (label :t/send-command-description) - :color "#9a5dcf" - :suggestion true} - {:command :request - :text "!request" - :description (label :t/request-command-description) - :color "#48ba30" - :suggestion true} {:command :keypair-password :text "!keypair-password" :description (label :t/keypair-password-command-description) @@ -59,13 +49,11 @@ :color "#9a5dcf" :suggestion true}]) -(defn get-commands [db] - ;; todo: temp. must be '(get db :commands)' - ;; (get db :commands) - commands) +(defn get-commands [{:keys [current-chat-id] :as db}] + (or (get-in db [:chats current-chat-id :commands]) {})) (defn get-command [db command-key] - (first (filter #(= command-key (:command %)) (get-commands db)))) + ((get-commands db) command-key)) (defn find-command [commands command-key] (first (filter #(= command-key (:command %)) commands))) @@ -126,4 +114,4 @@ (update content :command #(find-command commands (keyword %)))) (defn parse-command-request [commands content] - (update content :command #(find-command commands (keyword %)))) + (update content :command #((keyword %) commands))) From 195482f4314a2bc3e3de9e104bc6671e8e110dba Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 10 Jun 2016 15:17:46 +0300 Subject: [PATCH 07/53] commands/responses from loaded commands.js in chat Former-commit-id: 0319f9334c4de4dfef4e147ca4f7cbcb0b6b61c6 --- src/status_im/chat/handlers.cljs | 26 +++++----- src/status_im/chat/subs.cljs | 12 +++++ src/status_im/chat/views/message.cljs | 60 +++++++++++------------ src/status_im/chat/views/plain_input.cljs | 16 +++--- src/status_im/commands/handlers.cljs | 5 +- src/status_im/models/commands.cljs | 11 +++-- 6 files changed, 69 insertions(+), 61 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 4023473b83..98d9830521 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -102,22 +102,22 @@ [command] (suggestions/check-suggestion db (str text " ")) message (check-author-direction db current-chat-id - {:msg-id (random/id) - :chat-id current-chat-id - :content text - :to current-chat-id - :from identity - :content-type text-content-type - :outgoing true - :timestamp (time/now-ms)})] + {:msg-id (random/id) + :chat-id current-chat-id + :content text + :to current-chat-id + :from identity + :content-type text-content-type + :outgoing true + :timestamp (time/now-ms)})] (if command (commands/set-chat-command db command) (assoc db :new-message (when-not (str/blank? text) message))))) (defn prepare-command [identity chat-id staged-command] - (let [command-key (get-in staged-command [:command :command]) - content {:command (name command-key) - :content (:content staged-command)}] + (let [command-name (get-in staged-command [:command :name]) + content {:command command-name + :content (:content staged-command)}] {:msg-id (random/id) :from identity :to chat-id @@ -301,9 +301,9 @@ (defmethod nav/preload-data! :chat [{:keys [current-chat-id] :as db} [_ _ id]] - (let [chat-id (or id current-chat-id) + (let [chat-id (or id current-chat-id) messages (get-in db [:chats chat-id :messages]) - db' (assoc db :current-chat-id chat-id)] + db' (assoc db :current-chat-id chat-id)] (if (seq messages) db' (-> db' diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index d5df5f5716..c9de7660e5 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -50,6 +50,18 @@ (fn [db _] (reaction (commands/get-commands @db)))) +(register-sub :get-responses + (fn [db _] + (let [current-chat (@db :current-chat-id)] + (reaction (or (get-in @db [:chats current-chat :responses]) {}))))) + +(register-sub :get-commands-and-responses + (fn [db _] + (let [current-chat (@db :current-chat-id)] + (reaction _ (or (->> (get-in @db [:chats current-chat]) + ((juxt :commands :responses)) + (apply merge)) {}))))) + (register-sub :get-chat-input-text (fn [db _] (->> [:chats (:current-chat-id @db) :input-text] diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 0b6494acf8..b1215423f2 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -1,18 +1,19 @@ (ns status-im.chat.views.message + (:require-macros [status-im.utils.views :refer [defview]]) (:require [clojure.string :as s] [re-frame.core :refer [subscribe dispatch]] [status-im.components.react :refer [view - text - image - touchable-highlight]] + text + image + touchable-highlight]] [status-im.chat.styles.message :as st] [status-im.models.commands :refer [parse-command-msg-content - parse-command-request]] + parse-command-request]] [status-im.resources :as res] [status-im.constants :refer [text-content-type - content-type-status - content-type-command - content-type-command-request]])) + content-type-status + content-type-command + content-type-command-request]])) (defn message-date [{:keys [date]}] [view {} @@ -51,7 +52,7 @@ [text {:style st/track-duration-text} "03:39"]]]) (defn message-content-command [content] - (let [commands-atom (subscribe [:get-commands])] + (let [commands-atom (subscribe [:get-commands-and-responses])] (fn [content] (let [commands @commands-atom {:keys [command content]} @@ -60,8 +61,8 @@ [view st/command-container [view (st/command-view command) [text {:style st/command-name} - (:text command)]]] - [image {:source (:icon command) + (str "!" (:name command))]]] + [image {:source {:uri (:icon command)} :style st/command-image}] [text {:style st/command-text} ;; TODO isn't smart @@ -70,34 +71,29 @@ content)]])))) (defn set-chat-command [msg-id command] - (dispatch [:set-response-chat-command msg-id (:command command)])) + (dispatch [:set-response-chat-command msg-id (keyword (:name command))])) (defn label [{:keys [command]}] (->> (when command (name command)) (str "request-"))) -(defn message-content-command-request +(defview message-content-command-request [{:keys [msg-id content from incoming-group]}] - (let [commands-atom (subscribe [:get-commands])] - (fn [{:keys [msg-id content from incoming-group]}] - (let [commands @commands-atom - {:keys [command content]} (parse-command-request commands content)] - [touchable-highlight {:onPress #(set-chat-command msg-id command) - :accessibility-label (label command)} - [view st/comand-request-view - [view st/command-request-message-view - (when incoming-group - [text {:style st/command-request-from-text} - from]) - [text {:style st/style-message-text} - content]] - [view (st/command-request-image-view command) - [image {:source (:request-icon command) - :style st/command-request-image}]] - (when (:request-text command) - [view st/command-request-text-view - [text {:style st/style-sub-text} - (:request-text command)]])]])))) + [commands [:get-responses]] + (let [{:keys [command content]} (parse-command-request commands content)] + [touchable-highlight {:onPress #(set-chat-command msg-id command) + :accessibility-label (label command)} + [view st/comand-request-view + [view st/command-request-message-view + (when incoming-group + [text {:style st/command-request-from-text} from]) + [text {:style st/style-message-text} content]] + [view (st/command-request-image-view command) + [image {:source {:uri (:icon command)} + :style st/command-request-image}]] + (when-let [request-text (:request-text command)] + [view st/command-request-text-view + [text {:style st/style-sub-text} request-text]])]])) (defn message-view [message content] diff --git a/src/status_im/chat/views/plain_input.cljs b/src/status_im/chat/views/plain_input.cljs index dcbc75780a..b932d53032 100644 --- a/src/status_im/chat/views/plain_input.cljs +++ b/src/status_im/chat/views/plain_input.cljs @@ -10,22 +10,18 @@ (defn set-input-message [message] (dispatch [:set-chat-input-text message])) -(defn send [chat input-message] - (let [{:keys [group-chat chat-id]} chat] - (dispatch [:send-chat-msg]))) +(defn send [] (dispatch [:send-chat-msg])) (defn message-valid? [staged-commands message] (or (and (pos? (count message)) (not= "!" message)) (pos? (count staged-commands)))) -(defn try-send [chat staged-commands message] - (when (message-valid? staged-commands message) - (send chat message))) +(defn try-send [staged-commands message] + (when (message-valid? staged-commands message) (send))) (defn plain-message-input-view [] - (let [chat (subscribe [:get-current-chat]) - input-message-atom (subscribe [:get-chat-input-text]) + (let [input-message-atom (subscribe [:get-chat-input-text]) staged-commands-atom (subscribe [:get-chat-staged-commands]) typing-command? (subscribe [:typing-command?])] (fn [] @@ -42,13 +38,13 @@ [text-input {:style st/message-input :autoFocus (pos? (count @staged-commands-atom)) :onChangeText set-input-message - :onSubmitEditing #(try-send @chat @staged-commands-atom + :onSubmitEditing #(try-send @staged-commands-atom input-message)} input-message] ;; TODO emoticons: not implemented [icon :smile st/smile-icon] (when (message-valid? @staged-commands-atom input-message) - [touchable-highlight {:on-press #(send @chat input-message) + [touchable-highlight {:on-press #(send) :accessibility-label :send-message} [view st/send-container [icon :send st/send-icon]]])]])))) diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers.cljs index 75811d9656..9caf18473b 100644 --- a/src/status_im/commands/handlers.cljs +++ b/src/status_im/commands/handlers.cljs @@ -63,9 +63,10 @@ :confirmation-code {:description "Confirmation code" :color "#7099e6" :name "confirmationCode"} - :keypair-password {:description "" + :keypair-password {:description "Keypair password" :color "#7099e6" - :name "keypair-password"}}}) + :name "keypair-password" + :icon "http://localhost:8185/images/deliveryfailed.png"}}}) (defn parse-commands! [_ [identity file]] (parse file diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index 84b53d47e5..896d53d2c7 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -52,8 +52,11 @@ (defn get-commands [{:keys [current-chat-id] :as db}] (or (get-in db [:chats current-chat-id :commands]) {})) -(defn get-command [db command-key] - ((get-commands db) command-key)) +(defn get-command [{:keys [current-chat-id] :as db} command-key] + ((or (->> (get-in db [:chats current-chat-id]) + ((juxt :commands :responses)) + (apply merge)) + {}) command-key)) (defn find-command [commands command-key] (first (filter #(= command-key (:command %)) commands))) @@ -74,7 +77,7 @@ [{:keys [current-chat-id] :as db} msg-id command-key] (update-in db [:chats current-chat-id :command-input] merge {:content nil - :command (get-command db command-key) + :command (merge (get-command db command-key)) :to-msg-id msg-id})) (defn set-chat-command [db command-key] @@ -111,7 +114,7 @@ #(assoc % msg-id handler))) (defn parse-command-msg-content [commands content] - (update content :command #(find-command commands (keyword %)))) + (update content :command #((keyword %) commands))) (defn parse-command-request [commands content] (update content :command #((keyword %) commands))) From 836ebc2a3044e1efe728fa752012e2ed4c4ac192 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 10 Jun 2016 16:08:21 +0300 Subject: [PATCH 08/53] resopnse icon in message Former-commit-id: 13a40fae93e4de115a28742a5b1a96f5c3c791c8 --- src/status_im/chat/styles/message.cljs | 16 ++++++++++++---- src/status_im/chat/views/message.cljs | 8 +++++--- src/status_im/commands/handlers.cljs | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/status_im/chat/styles/message.cljs b/src/status_im/chat/styles/message.cljs index 79e3cb24a7..2357e7e0f2 100644 --- a/src/status_im/chat/styles/message.cljs +++ b/src/status_im/chat/styles/message.cljs @@ -146,6 +146,17 @@ :borderRadius 50 :backgroundColor (:color command)}) +(defn command-image-view + [command] + {:position :absolute + :top 0 + :right 0 + :width 24 + :height 24 + :borderRadius 50 + :backgroundColor (:color command) + :alignItems :center}) + (def command-request-image {:position :absolute :top 9 @@ -178,12 +189,9 @@ :color color-white}) (def command-image - {:position :absolute - :top 4 - :right 0 + {:margin-top 5 :width 12 :height 13}) - (def command-text (merge style-message-text {:marginTop 8 diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index b1215423f2..93c0cec826 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -62,11 +62,13 @@ [view (st/command-view command) [text {:style st/command-name} (str "!" (:name command))]]] - [image {:source {:uri (:icon command)} - :style st/command-image}] + ;; todo doesn't reflect design + [view (st/command-image-view command) + [image {:source {:uri (:icon command)} + :style st/command-image}]] [text {:style st/command-text} ;; TODO isn't smart - (if (= (:command command) :keypair-password) + (if (= (:name command) "keypair-password") "******" content)]])))) diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers.cljs index 9caf18473b..d413a3b011 100644 --- a/src/status_im/commands/handlers.cljs +++ b/src/status_im/commands/handlers.cljs @@ -66,7 +66,7 @@ :keypair-password {:description "Keypair password" :color "#7099e6" :name "keypair-password" - :icon "http://localhost:8185/images/deliveryfailed.png"}}}) + :icon "icon_lock_white"}}}) (defn parse-commands! [_ [identity file]] (parse file From f6da400ec8ed5a8f816d837b4e4c3d6ac45efae9 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 10 Jun 2016 17:04:12 +0300 Subject: [PATCH 09/53] jail component Former-commit-id: 3aef0f2d9cfccfa240f39da8d8f77f3fba4760f5 --- src/status_im/commands/handlers.cljs | 21 ++++++++------------- src/status_im/components/jail.cljs | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 src/status_im/components/jail.cljs diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers.cljs index d413a3b011..9c43f0ab55 100644 --- a/src/status_im/commands/handlers.cljs +++ b/src/status_im/commands/handlers.cljs @@ -5,7 +5,8 @@ [status-im.components.react :as r] [status-im.utils.utils :refer [http-get toast]] [clojure.string :as s] - [status-im.persistence.realm :as realm])) + [status-im.persistence.realm :as realm] + [status-im.components.jail :as j])) (defn reg-handler ([name handler] (reg-handler name nil handler)) @@ -42,12 +43,6 @@ ;; todo tbd hashing algorithm (hash file)) -(defn get-jail [] - (.-Jail (.-NativeModules r/react))) - -(defn parse [file success-callback fail-callback] - (.parse (get-jail) file success-callback fail-callback)) - (defn json->clj [json] (js->clj (.parse js/JSON json) :keywordize-keys true)) @@ -69,12 +64,12 @@ :icon "icon_lock_white"}}}) (defn parse-commands! [_ [identity file]] - (parse file - (fn [result] - (let [commands (json->clj result)] - ;; todo use commands from jail - (dispatch [::add-commands identity file res]))) - #(dispatch [::loading-failed! identity ::error-in-jail %]))) + (j/parse identity file + (fn [result] + (let [commands (json->clj result)] + ;; todo use commands from jail + (dispatch [::add-commands identity file res]))) + #(dispatch [::loading-failed! identity ::error-in-jail %]))) (defn validate-hash [db [identity file]] diff --git a/src/status_im/components/jail.cljs b/src/status_im/components/jail.cljs new file mode 100644 index 0000000000..23e904417b --- /dev/null +++ b/src/status_im/components/jail.cljs @@ -0,0 +1,15 @@ +(ns status-im.components.jail + (:require [status-im.components.react :as r])) + +(def jail (.-Jail (.-NativeModules r/react))) + +(defn parse [chat-id file success-callback fail-callback] + (.parse jail chat-id file success-callback fail-callback)) + +(defn call + [chat-id path params callback] + (.call jail chat-id (clj->js path) (clj->js params) callback)) + +(defn add-listener + [chat-id callback] + (.addListener jail chat-id callback)) From 4301c813f4a516f08f8257277bee4ab2fd5b1405 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 14 Jun 2016 14:19:56 +0300 Subject: [PATCH 10/53] parsing of commands.js, command's handler, suggestions handler in jail (commit contains .aar oops) Former-commit-id: ab93b21a4c2d0ed573f1d588c537baec9e068e0a --- android/app/build.gradle | 6 +- .../libs/geth-android-16.aar.REMOVED.git-id | 1 + resources/commands.js | 176 ++++++++++++++++++ resources/status.js | 77 ++++++++ src/status_im/chat/handlers.cljs | 44 ++++- src/status_im/chat/sign_up.cljs | 6 +- .../chat/styles/content_suggestions.cljs | 27 ++- src/status_im/chat/suggestions.cljs | 3 +- .../chat/views/content_suggestions.cljs | 6 +- src/status_im/commands/handlers.cljs | 129 ++++++++++--- src/status_im/components/jail.cljs | 95 +++++++++- src/status_im/models/commands.cljs | 43 ----- 12 files changed, 505 insertions(+), 108 deletions(-) create mode 100644 android/app/libs/geth-android-16.aar.REMOVED.git-id create mode 100644 resources/commands.js create mode 100644 resources/status.js diff --git a/android/app/build.gradle b/android/app/build.gradle index 95beff7a12..edc54bc340 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -131,8 +131,9 @@ dependencies { compile project(':react-native-linear-gradient') compile project(':ReactNativeAndroidSmsListener') compile project(':react-native-status') -// compile(name:'geth', ext:'aar') - compile(group: 'status-im', name: 'android-geth', version: '1.4.0-201604110816-a97a114', ext: 'aar') + // todo replace this when jail will be integrated into geth + compile (name: "geth-android-16", ext:"aar") + //compile(group: 'status-im', name: 'android-geth', version: '1.4.0-201604110816-a97a114', ext: 'aar') compile fileTree(dir: "node_modules/realm/android/libs", include: ["*.jar"]) } @@ -142,3 +143,4 @@ task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' } + diff --git a/android/app/libs/geth-android-16.aar.REMOVED.git-id b/android/app/libs/geth-android-16.aar.REMOVED.git-id new file mode 100644 index 0000000000..ae91163656 --- /dev/null +++ b/android/app/libs/geth-android-16.aar.REMOVED.git-id @@ -0,0 +1 @@ +030bd1fbceae92a86d43251c4306e9113b8e51f4 \ No newline at end of file diff --git a/resources/commands.js b/resources/commands.js new file mode 100644 index 0000000000..bc0a456671 --- /dev/null +++ b/resources/commands.js @@ -0,0 +1,176 @@ +status.command({ + name: "location", + description: "Send location", + color: "#9a5dcf" +}).param({ + name: "address", + type: status.types.STRING +}); + +function text(options, s) { + return ["text", options, s]; +} + +function view(options, elements) { + return ["view", options].concat(elements); +} + +function image(options) { + return ["image", options]; +} + +function touchable(options, element) { + return ["touchable", options, element]; +} + +function scrollView(options, elements) { + return ["scroll-view", options].concat(elements); +} + +var phones = [ + { + number: "89171111111", + description: "Number format 1" + }, + { + number: "89371111111", + description: "Number format 1" + }, + { + number: "+79171111111", + description: "Number format 2" + }, + { + number: "9171111111", + description: "Number format 3" + } +]; + +function suggestionsContainerStyle(suggestionsCount) { + return { + marginVertical: 1, + marginHorizontal: 0, + height: Math.min(150, (56 * suggestionsCount)), + backgroundColor: "white", + borderRadius: 5 + }; +} + +var suggestionContainerStyle = { + paddingLeft: 16, + backgroundColor: "white" +}; + +var suggestionSubContainerStyle = { + height: 56, + borderBottomWidth: 1, + borderBottomColor: "#0000001f" +}; + +var valueStyle = { + marginTop: 9, + fontSize: 14, + fontFamily: "font", + color: "#000000de" +}; + +var descriptionStyle = { + marginTop: 1.5, + fontSize: 14, + fontFamily: "font", + color: "#838c93de" +}; + +function startsWith(str1, str2) { + return str1.lastIndexOf(str2, 0) == 0 && str1 != str2; +} + +function phoneSuggestions(params) { + var ph, suggestions; + if (!params.value || params.value == "") { + ph = phones; + } else { + ph = phones.filter(function (phone) { + return startsWith(phone.number, params.value); + }); + } + + if (ph.length == 0) { + return; + } + + suggestions = ph.map(function (phone) { + return touchable( + {onPress: [status.events.SET_VALUE, phone.number]}, + view(suggestionContainerStyle, + [view(suggestionSubContainerStyle, + [ + text({style: valueStyle}, phone.number), + text({style: descriptionStyle}, phone.description) + ])]) + ); + }); + + return scrollView(suggestionsContainerStyle(ph.length), suggestions); +} + +status.response({ + name: "phone", + description: "Send phone number", + color: "#5fc48d", + params: [{ + name: "phone", + type: status.types.PHONE_NUMBER, + suggestions: phoneSuggestions + }], + handler: function (params) { + return { + event: "sign-up", + params: [params.value] + }; + } +}); + +status.command({ + name: "help", + description: "Help", + color: "#9a5dcf", + params: [{ + name: "query", + type: status.types.STRING + }] +}); + +status.response({ + name: "confirmation-code", + color: "#7099e6", + description: "Confirmation code", + parameters: [{ + name: "code", + type: status.types.NUMBER + }], + handler: function (params) { + return { + event: "confirm-sign-up", + params: [params.value] + }; + } +}); + +status.response({ + name: "keypair", + color: "#7099e6", + description: "Keypair password", + icon: "icon_lock_white", + parameters: [{ + name: "password", + type: status.types.PASSWORD + }], + handler: function (params) { + return { + event: "save-password", + params: [params.value] + }; + } +}); + diff --git a/resources/status.js b/resources/status.js new file mode 100644 index 0000000000..e53cb7e174 --- /dev/null +++ b/resources/status.js @@ -0,0 +1,77 @@ +var _status_catalog = { + commands: {}, + responses: {} +}; + +function Command() { +} +function Response() { +} + +Command.prototype.addToCatalog = function () { + _status_catalog.commands[this.name] = this; +}; + +Command.prototype.param = function (parameter) { + this.params.push(parameter); + + return this; +}; + +Command.prototype.create = function (com) { + this.name = com.name; + this.description = com.description; + this.handler = com.handler; + this.color = com.color; + this.icon = com.icon; + this.params = com.params || []; + this.addToCatalog(); + + return this; +}; + + +Response.prototype = Object.create(Command.prototype); +Response.prototype.addToCatalog = function () { + _status_catalog.responses[this.name] = this; +}; +Response.prototype.onReceiveResponse = function (handler) { + this.onReceive = handler; +}; + +function call(pathStr, paramsStr) { + var params = JSON.parse(paramsStr), + path = JSON.parse(pathStr), + fn, res; + + fn = path.reduce(function (catalog, name) { + if (catalog && catalog[name]) { + return catalog[name]; + } + }, + _status_catalog + ); + + res = fn(params); + + return JSON.stringify(res); +} + +var status = { + command: function (n, d, h) { + var command = new Command(); + return command.create(n, d, h); + }, + response: function (n, d, h) { + var response = new Response(); + return response.create(n, d, h); + }, + types: { + STRING: 'string', + PHONE_NUMBER: 'phone-number', + PASSWORD: 'password' + }, + events: { + SET_VALUE: 'set-value' + } +}; diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 98d9830521..f6686ff3b9 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -16,7 +16,8 @@ [status-im.persistence.realm :as r] [status-im.handlers.server :as server] [status-im.utils.phone-number :refer [format-phone-number]] - [status-im.utils.datetime :as time])) + [status-im.utils.datetime :as time] + [status-im.components.jail :as j])) (register-handler :set-show-actions (fn [db [_ show-actions]] @@ -41,7 +42,24 @@ (assoc-in [:chats current-chat-id :command-input] {}) (update-in [:chats current-chat-id :input-text] safe-trim)))) +(defn invoke-suggestions-handler! + [{:keys [current-chat-id] :as db} _] + (let [commands (get-in db [:chats current-chat-id :commands]) + {:keys [command content]} (get-in db [:chats current-chat-id :command-input])] + (let [path [(if (commands command) :commands :responses) + (:name command) + :params + 0 + :suggestions] + params {:value content}] + (j/call current-chat-id + path + params + #(dispatch [:suggestions-handler {:command command + :content content} %]))))) + (register-handler :set-chat-command-content + (after invoke-suggestions-handler!) (fn [db [_ content]] (commands/set-chat-command-content db content))) @@ -55,11 +73,13 @@ {:keys [command content]} (get-in db [:chats current-chat-id :command-input]) command-info {:command command - :content content - :handler (:handler command)}] - (commands/stage-command db command-info)))) + :content content}] + (-> db + (commands/stage-command command-info) + (assoc :staged-command command-info))))) (register-handler :set-response-chat-command + (after invoke-suggestions-handler!) (fn [db [_ to-msg-id command-key]] (commands/set-response-chat-command db to-msg-id command-key))) @@ -179,6 +199,20 @@ (doseq [new-command new-commands] (messages/save-message current-chat-id (dissoc new-command :handler)))) +(defn invoke-commands-handlers! + [{:keys [new-commands current-chat-id] :as db}] + (let [commands (get-in db [:chats current-chat-id :commands])] + (doseq [{:keys [content] :as com} new-commands] + (let [{:keys [command content]} content + path [(if (commands command) :commands :responses) + command + :handler] + params {:value content}] + (j/call current-chat-id + path + params + #(dispatch [:command-handler! com %])))))) + (defn handle-commands [{:keys [new-commands]}] (doseq [{{content :content} :content @@ -196,6 +230,8 @@ ((after send-message!)) ((after save-message-to-realm!)) ((after save-commands-to-realm!)) + ;; todo maybe it is better to track if it was handled or not + ((after invoke-commands-handlers!)) ((after handle-commands)))) (register-handler :unstage-command diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index b182354e15..e4140eab16 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -173,7 +173,7 @@ (dispatch [:received-msg {:msg-id msg-id :content (command-content - :keypair-password + :keypair (label :t/keypair-generated)) :content-type content-type-command-request :outgoing false @@ -185,8 +185,8 @@ {:chat-id "console" :name "console" ; todo remove/change dapp config fot console - :dapp-url "http://localhost:8185" - :dapp-hash 834331894 + :dapp-url "http://localhost:8185/resources" + :dapp-hash 858845357 :color default-chat-color :group-chat false :is-active true diff --git a/src/status_im/chat/styles/content_suggestions.cljs b/src/status_im/chat/styles/content_suggestions.cljs index 198468a549..01b328fc78 100644 --- a/src/status_im/chat/styles/content_suggestions.cljs +++ b/src/status_im/chat/styles/content_suggestions.cljs @@ -1,22 +1,21 @@ (ns status-im.chat.styles.content-suggestions (:require [status-im.components.styles :refer [font - color-light-blue-transparent - color-white - color-black - color-blue - color-blue-transparent - selected-message-color - online-color - separator-color - text1-color - text2-color - text3-color]])) + color-light-blue-transparent + color-white + color-black + color-blue + color-blue-transparent + selected-message-color + online-color + separator-color + text1-color + text2-color + text3-color]])) (def suggestion-height 56) (def suggestion-container - {:flexDirection :column - :paddingLeft 16 + {:paddingLeft 16 :backgroundColor color-white}) (def suggestion-sub-container @@ -37,7 +36,7 @@ :color text2-color}) (defn suggestions-container [suggestions-count] - {:flexDirection :row + {:flex 1 :marginVertical 1 :marginHorizontal 0 :height (min 150 (* suggestion-height suggestions-count)) diff --git a/src/status_im/chat/suggestions.cljs b/src/status_im/chat/suggestions.cljs index 842a64ea32..73f90e884d 100644 --- a/src/status_im/chat/suggestions.cljs +++ b/src/status_im/chat/suggestions.cljs @@ -1,8 +1,7 @@ (ns status-im.chat.suggestions (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] [status-im.db :as db] - [status-im.models.commands :refer [commands - get-commands + [status-im.models.commands :refer [get-commands get-chat-command-request get-chat-command-to-msg-id clear-staged-commands]] diff --git a/src/status_im/chat/views/content_suggestions.cljs b/src/status_im/chat/views/content_suggestions.cljs index 20fb1df9e5..1578f9484e 100644 --- a/src/status_im/chat/views/content_suggestions.cljs +++ b/src/status_im/chat/views/content_suggestions.cljs @@ -24,13 +24,11 @@ (list-item [suggestion-list-item row])) (defview content-suggestions-view [] - [suggestions [:get-content-suggestions]] + [suggestions [:get :current-suggestion]] (when (seq suggestions) [view [touchable-highlight {:style st/drag-down-touchable ;; TODO hide suggestions? :onPress (fn [])} [view [icon :drag_down st/drag-down-icon]]] - [view (st/suggestions-container (count suggestions)) - [list-view {:dataSource (to-datasource suggestions) - :renderRow render-row}]]])) + suggestions])) diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers.cljs index 9c43f0ab55..8d63368e00 100644 --- a/src/status_im/commands/handlers.cljs +++ b/src/status_im/commands/handlers.cljs @@ -6,7 +6,11 @@ [status-im.utils.utils :refer [http-get toast]] [clojure.string :as s] [status-im.persistence.realm :as realm] - [status-im.components.jail :as j])) + [status-im.components.jail :as j] + [clojure.walk :as w] + [status-im.components.react :refer [text scroll-view view + image touchable-highlight]] + [clojure.set :as set])) (defn reg-handler ([name handler] (reg-handler name nil handler)) @@ -17,9 +21,12 @@ (defn load-commands! [_ [identity]] - (if-let [{:keys [file]} (realm/get-one-by-field :commands :chat-id identity)] - (dispatch [::parse-commands! identity file]) - (dispatch [::fetch-commands! identity]))) + (dispatch [::fetch-commands! identity]) + ;; todo uncomment + #_(if-let [{:keys [file]} (realm/get-one-by-field :commands :chat-id + identity)] + (dispatch [::parse-commands! identity file]) + (dispatch [::fetch-commands! identity]))) (defn fetch-commands! [db [identity]] @@ -43,38 +50,28 @@ ;; todo tbd hashing algorithm (hash file)) -(defn json->clj [json] - (js->clj (.parse js/JSON json) :keywordize-keys true)) - -;; todo remove this -(def res {:commands {:location {:description "Send location" - :color "#9a5dcf" - :name "location"} - :phone {:description "Send phone number" - :color "#5fc48d" - :name "phone"} - :help {:description "Help" :color "#9a5dcf" :name "help"}} - :responses {:money {:description "Send money" :color "#5fc48d" :name "money"} - :confirmation-code {:description "Confirmation code" - :color "#7099e6" - :name "confirmationCode"} - :keypair-password {:description "Keypair password" - :color "#7099e6" - :name "keypair-password" - :icon "icon_lock_white"}}}) +(defn json->cljs [json] + (if (= json "undefined") + nil + (js->clj (.parse js/JSON json) :keywordize-keys true))) (defn parse-commands! [_ [identity file]] (j/parse identity file (fn [result] - (let [commands (json->clj result)] + (let [commands (json->cljs result)] ;; todo use commands from jail - (dispatch [::add-commands identity file res]))) - #(dispatch [::loading-failed! identity ::error-in-jail %]))) + (dispatch [::add-commands identity file commands]))) + #_(dispatch [::loading-failed! identity ::error-in-jail %]))) (defn validate-hash [db [identity file]] - (let [valid? (= (get-hash-by-identity db identity) - (get-hash-by-file file))] + (let [valid? true + ;; todo check + #_(= (get-hash-by-identity db identity) + (get-hash-by-file file))] + (println :hash + (get-hash-by-identity db identity) + (get-hash-by-file file)) (assoc db ::valid-hash valid?))) (defn add-commands @@ -96,6 +93,76 @@ (name reason) details])))) +(defn init-render-command! + [_ [chat-id command message-id data]] + (j/call chat-id [command :render] data + (fn [res] + (dispatch [::render-command chat-id message-id (json->cljs res)])))) + +(def elements + {:text text + :view view + :scroll-view scroll-view + :image image + :touchable touchable-highlight}) + +(defn get-element [n] + (elements (keyword (.toLowerCase n)))) + +(def events #{:onPress}) + +(defn wrap-event [event] + #(dispatch [:suggestions-event! event])) + +(defn check-events [m] + (let [ks (set (keys m)) + evs (set/intersection ks events)] + (reduce #(update %1 %2 wrap-event) m evs))) + +(defn generate-hiccup [markup] + ;; todo implement validation + (w/prewalk + (fn [el] + (if (and (vector? el) (string? (first el))) + (-> el + (update 0 get-element) + (update 1 check-events)) + el)) + markup)) + +(defn render-command + [db [chat-id message-id markup]] + (let [hiccup (generate-hiccup markup)] + (assoc-in db [:rendered-commands chat-id message-id] hiccup))) + +(def console-events + {:save-password #(dispatch [:save-password %]) + :sign-up #(dispatch [:sign-up %]) + :confirm-sign-up #(dispatch [:sign-up-confirm %])}) + +(def regular-events {}) + +(defn command-nadler! + [_ [{:keys [to]} response]] + (let [{:keys [event params]} (json->cljs response) + events (if (= "console" to) + (merge regular-events console-events) + regular-events)] + (when-let [handler (events (keyword event))] + (apply handler params)))) + +(defn suggestions-handler + [db [_ response-json]] + (let [response (json->cljs response-json)] + (println response) + (assoc db :current-suggestion (generate-hiccup response)))) + +(defn suggestions-events-handler! + [db [[n data]]] + (case (keyword n) + :set-value (dispatch [:set-chat-command-content data]) + db)) + (reg-handler :load-commands! (u/side-effect! load-commands!)) (reg-handler ::fetch-commands! (u/side-effect! fetch-commands!)) @@ -111,3 +178,9 @@ (reg-handler ::loading-failed! (u/side-effect! loading-failed!)) +(reg-handler :init-render-command! init-render-command!) +(reg-handler ::render-command render-command) + +(reg-handler :command-handler! (u/side-effect! command-nadler!)) +(reg-handler :suggestions-handler suggestions-handler) +(reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!)) diff --git a/src/status_im/components/jail.cljs b/src/status_im/components/jail.cljs index 23e904417b..66b596619d 100644 --- a/src/status_im/components/jail.cljs +++ b/src/status_im/components/jail.cljs @@ -1,15 +1,94 @@ (ns status-im.components.jail (:require [status-im.components.react :as r])) +(def status-js + "var _status_catalog = { + commands: {}, + responses: {} +}; + +function Command() { +} +function Response() { +} + +Command.prototype.addToCatalog = function () { + _status_catalog.commands[this.name] = this; +}; + +Command.prototype.param = function (parameter) { + this.params.push(parameter); + + return this; +}; + +Command.prototype.create = function (com) { + this.name = com.name; + this.description = com.description; + this.handler = com.handler; + this.color = com.color; + this.icon = com.icon; + this.params = com.params || []; + this.addToCatalog(); + + return this; +}; + + +Response.prototype = Object.create(Command.prototype); +Response.prototype.addToCatalog = function () { + _status_catalog.responses[this.name] = this; +}; +Response.prototype.onReceiveResponse = function (handler) { + this.onReceive = handler; +}; + +function call(pathStr, paramsStr) { + var params = JSON.parse(paramsStr), + path = JSON.parse(pathStr), + fn, res; + + fn = path.reduce(function (catalog, name) { + if (catalog && catalog[name]) { + return catalog[name]; + } + }, + _status_catalog + ); + + res = fn(params); + + return JSON.stringify(res); +} + +var status = { + command: function (n, d, h) { + var command = new Command(); + return command.create(n, d, h); + }, + response: function (n, d, h) { + var response = new Response(); + return response.create(n, d, h); + }, + types: { + STRING: 'string', + PHONE_NUMBER: 'phone-number', + PASSWORD: 'password' + }, + events: { + SET_VALUE: 'set-value' + } +};") + (def jail (.-Jail (.-NativeModules r/react))) +(.init jail status-js) -(defn parse [chat-id file success-callback fail-callback] - (.parse jail chat-id file success-callback fail-callback)) +(defn parse [chat-id file callback] + (.parse jail chat-id file callback)) -(defn call - [chat-id path params callback] - (.call jail chat-id (clj->js path) (clj->js params) callback)) +(defn cljs->json [data] + (.stringify js/JSON (clj->js data))) -(defn add-listener - [chat-id callback] - (.addListener jail chat-id callback)) +(defn call [chat-id path params callback] + (println :call chat-id (cljs->json path) (cljs->json params)) + (.call jail chat-id (cljs->json path) (cljs->json params) callback)) diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index 896d53d2c7..7da49a9b4b 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -6,49 +6,6 @@ [status-im.components.styles :refer [color-blue color-dark-mint]] [status-im.i18n :refer [label]])) -;; todo delete -(def commands [{:command :money - :text "!money" - :description (label :t/money-command-description) - :color color-dark-mint - :request-icon {:uri "icon_lock_white"} - :icon {:uri "icon_lock_gray"} - :suggestion true} - {:command :location - :text "!location" - :description (label :t/location-command-description) - :color "#9a5dcf" - :suggestion true} - {:command :phone - :text "!phone" - :description (label :t/phone-command-description) - :color color-dark-mint - :request-text (label :t/phone-request-text) - :suggestion true - :handler #(dispatch [:sign-up %])} - {:command :confirmation-code - :text "!confirmationCode" - :description (label :t/confirmation-code-command-description) - :request-text (label :t/confirmation-code-request-text) - :color color-blue - :request-icon {:uri "icon_lock_white"} - :icon {:uri "icon_lock_gray"} - :suggestion true - :handler #(dispatch [:sign-up-confirm %])} - {:command :keypair-password - :text "!keypair-password" - :description (label :t/keypair-password-command-description) - :color color-blue - :request-icon {:uri "icon_lock_white"} - :icon {:uri "icon_lock_gray"} - :suggestion false - :handler #(dispatch [:save-password %])} - {:command :help - :text "!help" - :description (label :t/help-command-description) - :color "#9a5dcf" - :suggestion true}]) - (defn get-commands [{:keys [current-chat-id] :as db}] (or (get-in db [:chats current-chat-id :commands]) {})) From b9973cee6d5b077827adc3b3eb83849c305b15c5 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 14 Jun 2016 15:56:03 +0300 Subject: [PATCH 11/53] cleanup Former-commit-id: 62e68fc3da0c6edd1bcd820ab6d7157b66280a3e --- resources/commands.js | 41 +++----- resources/status.js | 27 ++++++ src/status_im/commands/handlers/jail.cljs | 57 +++++++++++ .../{handlers.cljs => handlers/loading.cljs} | 95 +------------------ src/status_im/commands/utils.cljs | 46 +++++++++ src/status_im/components/jail.cljs | 35 ++++++- src/status_im/handlers.cljs | 3 +- .../status_im/test/commands/handlers.cljs | 2 +- 8 files changed, 183 insertions(+), 123 deletions(-) create mode 100644 src/status_im/commands/handlers/jail.cljs rename src/status_im/commands/{handlers.cljs => handlers/loading.cljs} (52%) create mode 100644 src/status_im/commands/utils.cljs diff --git a/resources/commands.js b/resources/commands.js index bc0a456671..552d036ce5 100644 --- a/resources/commands.js +++ b/resources/commands.js @@ -7,26 +7,6 @@ status.command({ type: status.types.STRING }); -function text(options, s) { - return ["text", options, s]; -} - -function view(options, elements) { - return ["view", options].concat(elements); -} - -function image(options) { - return ["image", options]; -} - -function touchable(options, element) { - return ["touchable", options, element]; -} - -function scrollView(options, elements) { - return ["scroll-view", options].concat(elements); -} - var phones = [ { number: "89171111111", @@ -100,18 +80,27 @@ function phoneSuggestions(params) { } suggestions = ph.map(function (phone) { - return touchable( + return status.components.touchable( {onPress: [status.events.SET_VALUE, phone.number]}, - view(suggestionContainerStyle, - [view(suggestionSubContainerStyle, + status.components.view(suggestionContainerStyle, + [status.components.view(suggestionSubContainerStyle, [ - text({style: valueStyle}, phone.number), - text({style: descriptionStyle}, phone.description) + status.components.text( + {style: valueStyle}, + phone.number + ), + status.components.text( + {style: descriptionStyle}, + phone.description + ) ])]) ); }); - return scrollView(suggestionsContainerStyle(ph.length), suggestions); + return status.components.scrollView( + suggestionsContainerStyle(ph.length), + suggestions + ); } status.response({ diff --git a/resources/status.js b/resources/status.js index e53cb7e174..e62559fae6 100644 --- a/resources/status.js +++ b/resources/status.js @@ -57,6 +57,26 @@ function call(pathStr, paramsStr) { return JSON.stringify(res); } +function text(options, s) { + return ['text', options, s]; +} + +function view(options, elements) { + return ['view', options].concat(elements); +} + +function image(options) { + return ['image', options]; +} + +function touchable(options, element) { + return ['touchable', options, element]; +} + +function scrollView(options, elements) { + return ['scroll-view', options].concat(elements); +} + var status = { command: function (n, d, h) { var command = new Command(); @@ -73,5 +93,12 @@ var status = { }, events: { SET_VALUE: 'set-value' + }, + components: { + view: view, + text: text, + image: image, + touchable: touchable, + scrollView: scrollView } }; diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs new file mode 100644 index 0000000000..26192ec502 --- /dev/null +++ b/src/status_im/commands/handlers/jail.cljs @@ -0,0 +1,57 @@ +(ns status-im.commands.handlers.jail + (:require [re-frame.core :refer [register-handler after dispatch subscribe + trim-v debug]] + [status-im.utils.handlers :as u] + [status-im.utils.utils :refer [http-get toast]] + [status-im.components.jail :as j] + + [status-im.components.react :refer [text scroll-view view + image touchable-highlight]] + [status-im.commands.utils :refer [json->cljs generate-hiccup + reg-handler]])) + +(defn init-render-command! + [_ [chat-id command message-id data]] + (j/call chat-id [command :render] data + (fn [res] + (dispatch [::render-command chat-id message-id (json->cljs res)])))) + +(defn render-command + [db [chat-id message-id markup]] + (let [hiccup (generate-hiccup markup)] + (assoc-in db [:rendered-commands chat-id message-id] hiccup))) + +(def console-events + {:save-password #(dispatch [:save-password %]) + :sign-up #(dispatch [:sign-up %]) + :confirm-sign-up #(dispatch [:sign-up-confirm %])}) + +(def regular-events {}) + +(defn command-nadler! + [_ [{:keys [to]} response]] + (let [{:keys [event params]} (json->cljs response) + events (if (= "console" to) + (merge regular-events console-events) + regular-events)] + (when-let [handler (events (keyword event))] + (apply handler params)))) + +(defn suggestions-handler + [db [_ response-json]] + (let [response (json->cljs response-json)] + (println response) + (assoc db :current-suggestion (generate-hiccup response)))) + +(defn suggestions-events-handler! + [db [[n data]]] + (case (keyword n) + :set-value (dispatch [:set-chat-command-content data]) + db)) + +(reg-handler :init-render-command! init-render-command!) +(reg-handler ::render-command render-command) + +(reg-handler :command-handler! (u/side-effect! command-nadler!)) +(reg-handler :suggestions-handler suggestions-handler) +(reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!)) diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers/loading.cljs similarity index 52% rename from src/status_im/commands/handlers.cljs rename to src/status_im/commands/handlers/loading.cljs index 8d63368e00..3f8ce95762 100644 --- a/src/status_im/commands/handlers.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -1,21 +1,12 @@ -(ns status-im.commands.handlers +(ns status-im.commands.handlers.loading (:require [re-frame.core :refer [register-handler after dispatch subscribe trim-v debug]] [status-im.utils.handlers :as u] - [status-im.components.react :as r] [status-im.utils.utils :refer [http-get toast]] [clojure.string :as s] [status-im.persistence.realm :as realm] [status-im.components.jail :as j] - [clojure.walk :as w] - [status-im.components.react :refer [text scroll-view view - image touchable-highlight]] - [clojure.set :as set])) - -(defn reg-handler - ([name handler] (reg-handler name nil handler)) - ([name middleware handler] - (register-handler name [debug trim-v middleware] handler))) + [status-im.commands.utils :refer [json->cljs reg-handler]])) (def commands-js "commands.js") @@ -50,11 +41,6 @@ ;; todo tbd hashing algorithm (hash file)) -(defn json->cljs [json] - (if (= json "undefined") - nil - (js->clj (.parse js/JSON json) :keywordize-keys true))) - (defn parse-commands! [_ [identity file]] (j/parse identity file (fn [result] @@ -93,76 +79,6 @@ (name reason) details])))) -(defn init-render-command! - [_ [chat-id command message-id data]] - (j/call chat-id [command :render] data - (fn [res] - (dispatch [::render-command chat-id message-id (json->cljs res)])))) - -(def elements - {:text text - :view view - :scroll-view scroll-view - :image image - :touchable touchable-highlight}) - -(defn get-element [n] - (elements (keyword (.toLowerCase n)))) - -(def events #{:onPress}) - -(defn wrap-event [event] - #(dispatch [:suggestions-event! event])) - -(defn check-events [m] - (let [ks (set (keys m)) - evs (set/intersection ks events)] - (reduce #(update %1 %2 wrap-event) m evs))) - -(defn generate-hiccup [markup] - ;; todo implement validation - (w/prewalk - (fn [el] - (if (and (vector? el) (string? (first el))) - (-> el - (update 0 get-element) - (update 1 check-events)) - el)) - markup)) - -(defn render-command - [db [chat-id message-id markup]] - (let [hiccup (generate-hiccup markup)] - (assoc-in db [:rendered-commands chat-id message-id] hiccup))) - -(def console-events - {:save-password #(dispatch [:save-password %]) - :sign-up #(dispatch [:sign-up %]) - :confirm-sign-up #(dispatch [:sign-up-confirm %])}) - -(def regular-events {}) - -(defn command-nadler! - [_ [{:keys [to]} response]] - (let [{:keys [event params]} (json->cljs response) - events (if (= "console" to) - (merge regular-events console-events) - regular-events)] - (when-let [handler (events (keyword event))] - (apply handler params)))) - -(defn suggestions-handler - [db [_ response-json]] - (let [response (json->cljs response-json)] - (println response) - (assoc db :current-suggestion (generate-hiccup response)))) - -(defn suggestions-events-handler! - [db [[n data]]] - (case (keyword n) - :set-value (dispatch [:set-chat-command-content data]) - db)) - (reg-handler :load-commands! (u/side-effect! load-commands!)) (reg-handler ::fetch-commands! (u/side-effect! fetch-commands!)) @@ -177,10 +93,3 @@ add-commands) (reg-handler ::loading-failed! (u/side-effect! loading-failed!)) - -(reg-handler :init-render-command! init-render-command!) -(reg-handler ::render-command render-command) - -(reg-handler :command-handler! (u/side-effect! command-nadler!)) -(reg-handler :suggestions-handler suggestions-handler) -(reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!)) diff --git a/src/status_im/commands/utils.cljs b/src/status_im/commands/utils.cljs new file mode 100644 index 0000000000..aa79a29eb4 --- /dev/null +++ b/src/status_im/commands/utils.cljs @@ -0,0 +1,46 @@ +(ns status-im.commands.utils + (:require [clojure.set :as set] + [clojure.walk :as w] + [re-frame.core :refer [register-handler dispatch trim-v debug]])) + +(defn json->cljs [json] + (if (= json "undefined") + nil + (js->clj (.parse js/JSON json) :keywordize-keys true))) + + +(def elements + {:text text + :view view + :scroll-view scroll-view + :image image + :touchable touchable-highlight}) + +(defn get-element [n] + (elements (keyword (.toLowerCase n)))) + +(def events #{:onPress}) + +(defn wrap-event [event] + #(dispatch [:suggestions-event! event])) + +(defn check-events [m] + (let [ks (set (keys m)) + evs (set/intersection ks events)] + (reduce #(update %1 %2 wrap-event) m evs))) + +(defn generate-hiccup [markup] + ;; todo implement validation + (w/prewalk + (fn [el] + (if (and (vector? el) (string? (first el))) + (-> el + (update 0 get-element) + (update 1 check-events)) + el)) + markup)) + +(defn reg-handler + ([name handler] (reg-handler name nil handler)) + ([name middleware handler] + (register-handler name [debug trim-v middleware] handler))) diff --git a/src/status_im/components/jail.cljs b/src/status_im/components/jail.cljs index 66b596619d..416968912f 100644 --- a/src/status_im/components/jail.cljs +++ b/src/status_im/components/jail.cljs @@ -61,6 +61,26 @@ function call(pathStr, paramsStr) { return JSON.stringify(res); } +function text(options, s) { + return ['text', options, s]; +} + +function view(options, elements) { + return ['view', options].concat(elements); +} + +function image(options) { + return ['image', options]; +} + +function touchable(options, element) { + return ['touchable', options, element]; +} + +function scrollView(options, elements) { + return ['scroll-view', options].concat(elements); +} + var status = { command: function (n, d, h) { var command = new Command(); @@ -77,11 +97,22 @@ var status = { }, events: { SET_VALUE: 'set-value' + }, + components: { + view: view, + text: text, + image: image, + touchable: touchable, + scrollView: scrollView } };") -(def jail (.-Jail (.-NativeModules r/react))) -(.init jail status-js) +(def jail + (when (exists? (.-NativeModules r/react)) + (.-Jail (.-NativeModules r/react)))) + +(when jail + (.init jail status-js)) (defn parse [chat-id file callback] (.parse jail chat-id file callback)) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 02d7d9e760..bb48cec2d5 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -16,7 +16,8 @@ status-im.new-group.handlers status-im.participants.handlers status-im.protocol.handlers - status-im.commands.handlers)) + status-im.commands.handlers.loading + status-im.commands.handlers.jail)) ;; -- Middleware ------------------------------------------------------------ ;; diff --git a/test/cljs/status_im/test/commands/handlers.cljs b/test/cljs/status_im/test/commands/handlers.cljs index 92225b5f9e..cf356be4e2 100644 --- a/test/cljs/status_im/test/commands/handlers.cljs +++ b/test/cljs/status_im/test/commands/handlers.cljs @@ -1,6 +1,6 @@ (ns status-im.test.commands.handlers (:require [cljs.test :refer-macros [deftest is]] - [status-im.commands.handlers :as h])) + [status-im.commands.handlers.loading :as h])) (deftest test-validate-hash (let [file "some-js" From 8f37885e18dcaef6a0276e2175d1dd87185f6282 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 14 Jun 2016 17:36:39 +0300 Subject: [PATCH 12/53] staged command preview Former-commit-id: 02f37e6c976db010c219bb1ba81e54d036f6ab0e --- resources/commands.js | 12 ++++++++ resources/status.js | 1 + src/status_im/chat/handlers.cljs | 31 +++++++++++++++----- src/status_im/chat/views/staged_command.cljs | 15 +++++----- src/status_im/commands/handlers/jail.cljs | 17 +++++++++-- src/status_im/commands/utils.cljs | 2 ++ src/status_im/components/jail.cljs | 1 + 7 files changed, 60 insertions(+), 19 deletions(-) diff --git a/resources/commands.js b/resources/commands.js index 552d036ce5..b4820adf51 100644 --- a/resources/commands.js +++ b/resources/commands.js @@ -160,6 +160,18 @@ status.response({ event: "save-password", params: [params.value] }; + }, + preview: function (params) { + return status.components.text( + { + style: { + marginTop: 5, + marginHorizontal: 0, + fontSize: 14, + fontFamily: "font", + color: "black" + } + }, "*****"); } }); diff --git a/resources/status.js b/resources/status.js index e62559fae6..c25535b159 100644 --- a/resources/status.js +++ b/resources/status.js @@ -25,6 +25,7 @@ Command.prototype.create = function (com) { this.color = com.color; this.icon = com.icon; this.params = com.params || []; + this.preview = com.preview; this.addToCatalog(); return this; diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index f6686ff3b9..2c5892a579 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -45,18 +45,18 @@ (defn invoke-suggestions-handler! [{:keys [current-chat-id] :as db} _] (let [commands (get-in db [:chats current-chat-id :commands]) - {:keys [command content]} (get-in db [:chats current-chat-id :command-input])] - (let [path [(if (commands command) :commands :responses) + {:keys [command content]} (get-in db [:chats current-chat-id :command-input]) + path [(if (commands command) :commands :responses) (:name command) :params 0 :suggestions] - params {:value content}] - (j/call current-chat-id - path - params - #(dispatch [:suggestions-handler {:command command - :content content} %]))))) + params {:value content}] + (j/call current-chat-id + path + params + #(dispatch [:suggestions-handler {:command command + :content content} %])))) (register-handler :set-chat-command-content (after invoke-suggestions-handler!) @@ -67,7 +67,22 @@ [{:keys [current-chat-id] :as db} text] (assoc-in db [:chats current-chat-id :input-text] text)) + +(defn invoke-command-preview! + [{:keys [current-chat-id staged-command] :as db} _] + (let [commands (get-in db [:chats current-chat-id :commands]) + {:keys [command content]} staged-command + path [(if (commands command) :commands :responses) + (:name command) + :preview] + params {:value content}] + (j/call current-chat-id + path + params + #(dispatch [:command-preview current-chat-id %])))) + (register-handler :stage-command + (after invoke-command-preview!) (fn [{:keys [current-chat-id] :as db} _] (let [db (update-input-text db nil) {:keys [command content]} diff --git a/src/status_im/chat/views/staged_command.cljs b/src/status_im/chat/views/staged_command.cljs index 92f72b0508..424367c56e 100644 --- a/src/status_im/chat/views/staged_command.cljs +++ b/src/status_im/chat/views/staged_command.cljs @@ -1,9 +1,9 @@ (ns status-im.chat.views.staged-command (:require [re-frame.core :refer [subscribe dispatch]] [status-im.components.react :refer [view - image - text - touchable-highlight]] + image + text + touchable-highlight]] [status-im.resources :as res] [status-im.chat.styles.input :as st])) @@ -21,8 +21,7 @@ :onPress #(cancel-command-input staged-command)} [image {:source res/icon-close-gray :style st/staged-command-cancel-icon}]]] - [text {:style st/staged-command-content} - ;; TODO isn't smart - (if (= (:command command) :keypair-password) - "******" - (:content staged-command))]]])) + (if-let [preview (:preview staged-command)] + preview + [text {:style st/staged-command-content} + (:content staged-command)])]])) diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index 26192ec502..436f1d75cd 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -5,8 +5,6 @@ [status-im.utils.utils :refer [http-get toast]] [status-im.components.jail :as j] - [status-im.components.react :refer [text scroll-view view - image touchable-highlight]] [status-im.commands.utils :refer [json->cljs generate-hiccup reg-handler]])) @@ -40,13 +38,25 @@ (defn suggestions-handler [db [_ response-json]] (let [response (json->cljs response-json)] - (println response) (assoc db :current-suggestion (generate-hiccup response)))) (defn suggestions-events-handler! [db [[n data]]] (case (keyword n) :set-value (dispatch [:set-chat-command-content data]) + ;; todo show error? + nil)) + +(defn command-preview + [db [chat-id response-json]] + (if-let [response (json->cljs response-json)] + (let [path [:chats chat-id :staged-commands] + commands-cnt (count (get-in db path))] + ;; todo (dec commands-cnt) looks like hack have to find better way to + ;; do this + (update-in db (conj path (dec commands-cnt)) assoc + :preview (generate-hiccup response) + :preview-string (str response))) db)) (reg-handler :init-render-command! init-render-command!) @@ -55,3 +65,4 @@ (reg-handler :command-handler! (u/side-effect! command-nadler!)) (reg-handler :suggestions-handler suggestions-handler) (reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!)) +(reg-handler :command-preview command-preview) diff --git a/src/status_im/commands/utils.cljs b/src/status_im/commands/utils.cljs index aa79a29eb4..bf4639f5dc 100644 --- a/src/status_im/commands/utils.cljs +++ b/src/status_im/commands/utils.cljs @@ -1,6 +1,8 @@ (ns status-im.commands.utils (:require [clojure.set :as set] [clojure.walk :as w] + [status-im.components.react :refer [text scroll-view view + image touchable-highlight]] [re-frame.core :refer [register-handler dispatch trim-v debug]])) (defn json->cljs [json] diff --git a/src/status_im/components/jail.cljs b/src/status_im/components/jail.cljs index 416968912f..d58cf9e2c1 100644 --- a/src/status_im/components/jail.cljs +++ b/src/status_im/components/jail.cljs @@ -29,6 +29,7 @@ Command.prototype.create = function (com) { this.color = com.color; this.icon = com.icon; this.params = com.params || []; + this.preview = com.preview; this.addToCatalog(); return this; From 5d7005c64f24f9cb017af719d4070c00637504e9 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 14 Jun 2016 18:09:24 +0300 Subject: [PATCH 13/53] store preview Former-commit-id: dfcf7cd47e63a0eaad02df0bc05ff561bafa0f72 --- src/status_im/chat/handlers.cljs | 29 +++++++++++++++------------ src/status_im/chat/views/message.cljs | 17 ++++++++-------- src/status_im/models/messages.cljs | 15 +++++++++----- src/status_im/persistence/realm.cljs | 4 +++- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 2c5892a579..d7d6b4cc60 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -17,7 +17,8 @@ [status-im.handlers.server :as server] [status-im.utils.phone-number :refer [format-phone-number]] [status-im.utils.datetime :as time] - [status-im.components.jail :as j])) + [status-im.components.jail :as j] + [status-im.commands.utils :refer [generate-hiccup]])) (register-handler :set-show-actions (fn [db [_ show-actions]] @@ -149,17 +150,18 @@ (commands/set-chat-command db command) (assoc db :new-message (when-not (str/blank? text) message))))) -(defn prepare-command [identity chat-id staged-command] - (let [command-name (get-in staged-command [:command :name]) - content {:command command-name - :content (:content staged-command)}] - {:msg-id (random/id) - :from identity - :to chat-id - :content content - :content-type content-type-command - :outgoing true - :handler (:handler staged-command)})) +(defn prepare-command + [identity chat-id {:keys [preview preview-string content command]}] + (let [content {:command (command :name) + :content content}] + {:msg-id (random/id) + :from identity + :to chat-id + :content content + :content-type content-type-command + :outgoing true + :preview preview-string + :rendered-preview preview})) (defn prepare-staged-commans [{:keys [current-chat-id identity] :as db} _] @@ -212,7 +214,8 @@ (defn save-commands-to-realm! [{:keys [new-commands current-chat-id]} _] (doseq [new-command new-commands] - (messages/save-message current-chat-id (dissoc new-command :handler)))) + (messages/save-message current-chat-id + (dissoc new-command :rendered-preview)))) (defn invoke-commands-handlers! [{:keys [new-commands current-chat-id] :as db}] diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 93c0cec826..8f3ed5cb27 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -51,9 +51,9 @@ [view st/track-mark] [text {:style st/track-duration-text} "03:39"]]]) -(defn message-content-command [content] +(defn message-content-command [content preview] (let [commands-atom (subscribe [:get-commands-and-responses])] - (fn [content] + (fn [content preview] (let [commands @commands-atom {:keys [command content]} (parse-command-msg-content commands content)] @@ -66,11 +66,10 @@ [view (st/command-image-view command) [image {:source {:uri (:icon command)} :style st/command-image}]] - [text {:style st/command-text} - ;; TODO isn't smart - (if (= (:name command) "keypair-password") - "******" - content)]])))) + (if preview + preview + [text {:style st/command-text} + content])])))) (defn set-chat-command [msg-id command] (dispatch [:set-response-chat-command msg-id (keyword (:name command))])) @@ -126,9 +125,9 @@ [message-content-status message]) (defmethod message-content content-type-command - [wrapper {:keys [content] :as message}] + [wrapper {:keys [content rendered-preview] :as message}] [wrapper message - [message-view message [message-content-command content]]]) + [message-view message [message-content-command content rendered-preview]]]) (defmethod message-content :default [wrapper {:keys [content-type content] :as message}] diff --git a/src/status_im/models/messages.cljs b/src/status_im/models/messages.cljs index 5c8c17fa5f..0193217439 100644 --- a/src/status_im/models/messages.cljs +++ b/src/status_im/models/messages.cljs @@ -3,11 +3,11 @@ [re-frame.core :refer [dispatch]] [cljs.reader :refer [read-string]] [status-im.utils.random :refer [timestamp]] - [status-im.db :as db] [status-im.utils.logging :as log] [clojure.string :refer [join split]] [clojure.walk :refer [stringify-keys keywordize-keys]] - [status-im.constants :as c])) + [status-im.constants :as c] + [status-im.commands.utils :refer [generate-hiccup]])) (defn- map-to-str [m] @@ -21,7 +21,8 @@ {:outgoing false :to nil :same-author false - :same-direction false}) + :same-direction false + :preview nil}) (defn save-message ;; todo remove chat-id parameter @@ -51,9 +52,13 @@ (r/sorted :timestamp :asc) (r/collection->map)) (into '()) - (map (fn [{:keys [content-type] :as message}] + (map (fn [{:keys [content-type preview] :as message}] (if (command-type? content-type) - (update message :content str-to-map) + (-> message + (update :content str-to-map) + (assoc :rendered-preview (generate-hiccup + (read-string preview))) + (dissoc :preview)) message))))) (defn update-message! [{:keys [msg-id] :as msg}] diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index fd6e9857ad..8ed342537a 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -33,7 +33,9 @@ :delivery-status {:type "string" :optional true} :same-author "bool" - :same-direction "bool"}} + :same-direction "bool" + :preview {:type :string + :optional true}}} {:name :chat-contact :properties {:identity "string" :is-in-chat {:type "bool" From 9aa89420c61cdd0ca3ac85d619b906b30f6c3668 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 14 Jun 2016 18:33:06 +0300 Subject: [PATCH 14/53] check empty :preview Former-commit-id: 3e60fd36a0f394cb218148cf4cb981e20763cf02 --- src/status_im/chat/views/message.cljs | 7 ++++--- src/status_im/models/messages.cljs | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 8f3ed5cb27..7bf6ee480e 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -63,9 +63,10 @@ [text {:style st/command-name} (str "!" (:name command))]]] ;; todo doesn't reflect design - [view (st/command-image-view command) - [image {:source {:uri (:icon command)} - :style st/command-image}]] + (when-let [icon (:icon command)] + [view (st/command-image-view command) + [image {:source {:uri icon} + :style st/command-image}]]) (if preview preview [text {:style st/command-text} diff --git a/src/status_im/models/messages.cljs b/src/status_im/models/messages.cljs index 0193217439..3d6611a887 100644 --- a/src/status_im/models/messages.cljs +++ b/src/status_im/models/messages.cljs @@ -56,8 +56,9 @@ (if (command-type? content-type) (-> message (update :content str-to-map) - (assoc :rendered-preview (generate-hiccup - (read-string preview))) + (assoc :rendered-preview (when preview + (generate-hiccup + (read-string preview)))) (dissoc :preview)) message))))) From 83a19a8817748f7f7617408761d02d0ff7c62eeb Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 15 Jun 2016 11:47:45 +0300 Subject: [PATCH 15/53] suggestions from jail Former-commit-id: 77a53cf0402d61b74e4bbd72dea6c11a88595b0d --- src/status_im/chat/handlers.cljs | 3 ++- src/status_im/chat/subs.cljs | 4 +--- src/status_im/chat/views/content_suggestions.cljs | 2 +- src/status_im/chat/views/request_message.cljs | 4 ++-- src/status_im/chat/views/response_suggestions.cljs | 5 +---- src/status_im/commands/handlers/jail.cljs | 4 ++-- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index d66ab6440b..130635175a 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -61,7 +61,8 @@ path params #(dispatch [:suggestions-handler {:command command - :content content} %])))) + :content content + :chat-id current-chat-id} %])))) (register-handler :start-cancel-command (u/side-effect! diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index fc805b3183..2402bed67a 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -106,6 +106,4 @@ (register-sub :get-content-suggestions (fn [db _] - (let [command (reaction (commands/get-chat-command @db)) - text (reaction (commands/get-chat-command-content @db))] - (reaction (get-content-suggestions @command @text))))) + (reaction (get-in @db [:suggestions (:current-chat-id @db)])))) diff --git a/src/status_im/chat/views/content_suggestions.cljs b/src/status_im/chat/views/content_suggestions.cljs index bcf5103606..d2eb8b63b4 100644 --- a/src/status_im/chat/views/content_suggestions.cljs +++ b/src/status_im/chat/views/content_suggestions.cljs @@ -24,7 +24,7 @@ (list-item [suggestion-list-item row])) (defview content-suggestions-view [] - [suggestions [:get :current-suggestion]] + [suggestions [:get-content-suggestions]] (when (seq suggestions) [view st/container [touchable-highlight {:style st/drag-down-touchable diff --git a/src/status_im/chat/views/request_message.cljs b/src/status_im/chat/views/request_message.cljs index 907fc52311..0e5117769a 100644 --- a/src/status_im/chat/views/request_message.cljs +++ b/src/status_im/chat/views/request_message.cljs @@ -59,9 +59,9 @@ [touchable-highlight {:on-press (fn [] (reset! loop? false) (set-chat-command msg-id command)) - :style st/command-request-image-touchable + :style st/command-request-image-touchable} ;:accessibility-label (label command) - } + [animated-view {:style (st/command-request-image-view command scale-anim-val)} [image {:source {:uri (:icon command)} :style st/command-request-image}]]])}))) diff --git a/src/status_im/chat/views/response_suggestions.cljs b/src/status_im/chat/views/response_suggestions.cljs index 54eed3bb7d..bffe80175b 100644 --- a/src/status_im/chat/views/response_suggestions.cljs +++ b/src/status_im/chat/views/response_suggestions.cljs @@ -32,7 +32,4 @@ (defview response-suggestions-view [] [suggestions [:get-content-suggestions]] (when (seq suggestions) - [view st/suggestions-container - [list-view {:dataSource (to-datasource suggestions) - :keyboardShouldPersistTaps true - :renderRow render-row}]])) + suggestions)) diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index 436f1d75cd..2e45635869 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -36,9 +36,9 @@ (apply handler params)))) (defn suggestions-handler - [db [_ response-json]] + [db [{:keys [chat-id]} response-json]] (let [response (json->cljs response-json)] - (assoc db :current-suggestion (generate-hiccup response)))) + (assoc-in db [:suggestions chat-id] (generate-hiccup response)))) (defn suggestions-events-handler! [db [[n data]]] From 3c62b9224834e10ba2c21aaa6bca56cab91e3231 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 22 Jun 2016 12:56:43 +0300 Subject: [PATCH 16/53] move statusgo to artifactory Former-commit-id: c1e5a64836df78eed48a9f51fc5e2c15990cb8bb --- android/app/build.gradle | 4 +--- .../app/libs/geth-android-16.aar.REMOVED.git-id | 1 - .../src/main/java/com/statusim/GethService.java | 17 +++-------------- 3 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 android/app/libs/geth-android-16.aar.REMOVED.git-id diff --git a/android/app/build.gradle b/android/app/build.gradle index 4182c69686..2a8bf6a0c8 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -132,9 +132,7 @@ dependencies { compile project(':ReactNativeAndroidSmsListener') compile project(':react-native-camera') compile project(':react-native-status') - // todo replace this when jail will be integrated into geth - compile (name: "geth-android-16", ext:"aar") - //compile(group: 'status-im', name: 'android-geth', version: '1.4.0-201604110816-a97a114', ext: 'aar') + compile(group: 'status-im', name: 'status-go', version: '0.1.0-201606220917-ec4b9a', ext: 'aar') compile fileTree(dir: "node_modules/realm/android/libs", include: ["*.jar"]) } diff --git a/android/app/libs/geth-android-16.aar.REMOVED.git-id b/android/app/libs/geth-android-16.aar.REMOVED.git-id deleted file mode 100644 index ae91163656..0000000000 --- a/android/app/libs/geth-android-16.aar.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -030bd1fbceae92a86d43251c4306e9113b8e51f4 \ No newline at end of file diff --git a/android/app/src/main/java/com/statusim/GethService.java b/android/app/src/main/java/com/statusim/GethService.java index 7967807cbd..54defce661 100644 --- a/android/app/src/main/java/com/statusim/GethService.java +++ b/android/app/src/main/java/com/statusim/GethService.java @@ -5,7 +5,6 @@ import android.content.Intent; import android.os.Handler; import android.os.AsyncTask; import android.os.IBinder; -import android.os.Looper; import android.os.Message; import android.os.Messenger; import android.support.annotation.Nullable; @@ -14,7 +13,7 @@ import android.os.Environment; import java.lang.ref.WeakReference; -import com.github.ethereum.go_ethereum.cmd.Geth; +import com.github.status_im.status_go.Statusgo; import java.io.File; @@ -78,20 +77,11 @@ public class GethService extends Service { extStore.getAbsolutePath() : getApplicationInfo().dataDir; - final Runnable addPeer = new Runnable() { - public void run() { - Log.w("Geth", "adding peer"); - Geth.run("--exec admin.addPeer(\"enode://e2f28126720452aa82f7d3083e49e6b3945502cb94d9750a15e27ee310eed6991618199f878e5fbc7dfa0e20f0af9554b41f491dc8f1dbae8f0f2d37a3a613aa@139.162.13.89:55555\") attach http://localhost:8545"); - } - }; - new Thread(new Runnable() { public void run() { - Geth.run("--shh --ipcdisable --nodiscover --rpc --rpcapi db,eth,net,web3,shh,admin --fast --datadir=" + dataFolder); + Statusgo.doStartNode(dataFolder); } }).start(); - - handler.postDelayed(addPeer, 5000); } @Nullable @@ -103,8 +93,7 @@ public class GethService extends Service { @Override public void onCreate() { super.onCreate(); - System.loadLibrary("gethraw"); - System.loadLibrary("geth"); + System.loadLibrary("statusgo"); if (!isGethInitialized) { isGethInitialized = true; From 6e20f11ed8788fa4e62e6da12d497a0f7471d9a4 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 23 Jun 2016 15:47:58 +0300 Subject: [PATCH 17/53] adapt animation Former-commit-id: 831132ccef8f9280f0f2601f540894d2469723ba --- src/status_im/chat/constants.cljs | 6 +++ src/status_im/chat/handlers.cljs | 17 +++---- src/status_im/chat/handlers/animation.cljs | 49 +++++++++---------- src/status_im/chat/screen.cljs | 1 - src/status_im/chat/styles/message_input.cljs | 5 +- src/status_im/chat/styles/response.cljs | 6 +-- src/status_im/chat/subs.cljs | 8 +-- .../chat/views/content_suggestions.cljs | 34 ------------- src/status_im/chat/views/plain_message.cljs | 22 +++++---- src/status_im/chat/views/response.cljs | 4 +- .../chat/views/response_suggestions.cljs | 32 +----------- src/status_im/commands/handlers/jail.cljs | 6 ++- src/status_im/commands/handlers/loading.cljs | 3 -- src/status_im/commands/utils.cljs | 2 +- src/status_im/components/jail.cljs | 2 +- src/status_im/handlers.cljs | 1 + 16 files changed, 66 insertions(+), 132 deletions(-) create mode 100644 src/status_im/chat/constants.cljs delete mode 100644 src/status_im/chat/views/content_suggestions.cljs diff --git a/src/status_im/chat/constants.cljs b/src/status_im/chat/constants.cljs new file mode 100644 index 0000000000..e9d95a4ed9 --- /dev/null +++ b/src/status_im/chat/constants.cljs @@ -0,0 +1,6 @@ +(ns status-im.chat.constants) + +(def input-height 56) +(def request-info-height 61) +(def response-height-normal 211) +(def minimum-suggestion-height (+ input-height request-info-height)) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 451a4f32ec..c1627a957e 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -3,7 +3,6 @@ [status-im.models.commands :as commands] [clojure.string :as str] [status-im.components.styles :refer [default-chat-color]] - [status-im.chat.styles.response :refer [request-info-height response-height-normal]] [status-im.chat.suggestions :as suggestions] [status-im.protocol.api :as api] [status-im.models.messages :as messages] @@ -20,9 +19,7 @@ [status-im.utils.phone-number :refer [format-phone-number]] [status-im.utils.datetime :as time] [status-im.components.jail :as j] - [status-im.commands.utils :refer [generate-hiccup]] - [status-im.chat.handlers.animation :refer [update-response-height - get-response-height]])) + [status-im.commands.utils :refer [generate-hiccup]])) (register-handler :set-show-actions (fn [db [_ show-actions]] @@ -74,16 +71,12 @@ (fn [{:keys [current-chat-id] :as db} [_ content]] (as-> db db (commands/set-chat-command-content db content) - (assoc-in db [:chats current-chat-id :input-text] nil) - (if (commands/get-chat-command-to-msg-id db) - (update-response-height db) - db)))) + (assoc-in db [:chats current-chat-id :input-text] nil)))) (defn update-input-text [{:keys [current-chat-id] :as db} text] (assoc-in db [:chats current-chat-id :input-text] text)) - (defn invoke-command-preview! [{:keys [current-chat-id staged-command] :as db} _] (let [commands (get-in db [:chats current-chat-id :commands]) @@ -123,7 +116,8 @@ (register-handler :set-response-chat-command [(after invoke-suggestions-handler!) (after #(dispatch [:command-edit-mode])) - (after #(dispatch [:animate-show-response]))] + ;(after #(dispatch [:animate-show-response])) + ] (fn [db [_ to-msg-id command-key]] (commands/set-response-chat-command db to-msg-id command-key))) @@ -304,7 +298,8 @@ (register-handler :set-chat-command [(after #(dispatch [:command-edit-mode])) - (after #(dispatch [:animate-show-response]))] + ;(after #(dispatch [:animate-show-response])) + ] (fn [db [_ command-key]] (commands/set-chat-command db command-key))) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 994a32e85f..2bd08c7a3b 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -1,14 +1,15 @@ (ns status-im.chat.handlers.animation - (:require [re-frame.core :refer [register-handler after dispatch]] + (:require [re-frame.core :refer [register-handler after dispatch debug]] [re-frame.middleware :refer [path]] [status-im.models.commands :as commands] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] - [status-im.chat.styles.message-input :refer [input-height]] - [status-im.chat.styles.response :refer [request-info-height response-height-normal]] + [status-im.chat.constants :refer [input-height request-info-height + response-height-normal minimum-suggestion-height]] [status-im.chat.styles.response-suggestions :as response-suggestions-styles] [status-im.constants :refer [response-input-hiding-duration]])) -(def zero-height input-height) +;; todo magic value +(def middle-height 270) (defn animation-handler ([name handler] (animation-handler name nil handler)) @@ -19,25 +20,21 @@ (after #(dispatch [:text-edit-mode])) (fn [db _] (assoc db - :to-response-height zero-height + :to-response-height input-height :messages-offset 0))) -(defn get-response-height [db] - (let [command (commands/get-chat-command db) - text (commands/get-chat-command-content db) - suggestions (get-content-suggestions command text) - suggestions-height (reduce + 0 (map #(if (:header %) - response-suggestions-styles/header-height - response-suggestions-styles/suggestion-height) - suggestions))] - (+ zero-height +(defn get-response-height + [{:keys [current-chat-id] :as db}] + (let [suggestions (get-in db [:suggestions current-chat-id]) + suggestions-height (if suggestions middle-height 0)] + (+ input-height (min response-height-normal (+ suggestions-height request-info-height))))) (defn update-response-height [db] (assoc-in db [:animations :to-response-height] (get-response-height db))) (register-handler :animate-show-response - (after #(dispatch [:command-edit-mode])) + [(after #(dispatch [:command-edit-mode]))] (fn [db _] (-> db (assoc-in [:animations :messages-offset] request-info-height) @@ -54,26 +51,28 @@ db)))) (register-handler :fix-response-height - (fn [db [_ vy current]] + (fn [{:keys [current-chat-id] :as db} [_ vy current]] (let [max-height (get-in db [:animations :response-height-max]) - ;; todo magic value - middle 270 moving-down? (pos? vy) moving-up? (not moving-down?) - under-middle-position? (<= current middle) + under-middle-position? (<= current middle-height) over-middle-position? (not under-middle-position?) - min-height (+ zero-height request-info-height) - new-fixed (cond (and under-middle-position? moving-down?) - min-height + suggestions (get-in db [:suggestions current-chat-id]) + new-fixed (cond (not suggestions) + minimum-suggestion-height (and under-middle-position? moving-up?) - middle + middle-height (and over-middle-position? moving-down?) - middle + middle-height (and over-middle-position? moving-up?) - max-height)] + max-height + + (and under-middle-position? + moving-down?) + minimum-suggestion-height)] (-> db (assoc-in [:animations :to-response-height] new-fixed) (update-in [:animations :response-height-changed] inc))))) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 4927858f1e..f9394aeb5a 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -18,7 +18,6 @@ [status-im.components.invertible-scroll-view :refer [invertible-scroll-view]] [status-im.components.toolbar :refer [toolbar]] [status-im.chat.views.message :refer [chat-message]] - [status-im.chat.views.content-suggestions :refer [content-suggestions-view]] [status-im.chat.views.suggestions :refer [suggestions-view]] [status-im.chat.views.response :refer [response-view]] [status-im.chat.views.new-message :refer [chat-message-new]] diff --git a/src/status_im/chat/styles/message_input.cljs b/src/status_im/chat/styles/message_input.cljs index ccde0a7994..e999f749a9 100644 --- a/src/status_im/chat/styles/message_input.cljs +++ b/src/status_im/chat/styles/message_input.cljs @@ -1,8 +1,7 @@ (ns status-im.chat.styles.message-input (:require [status-im.components.styles :refer [color-white - color-blue]])) - -(def input-height 56) + color-blue]] + [status-im.chat.constants :refer [input-height]])) (def message-input-container {:flex 1 diff --git a/src/status_im/chat/styles/response.cljs b/src/status_im/chat/styles/response.cljs index 918bd28eec..8963f8a1fe 100644 --- a/src/status_im/chat/styles/response.cljs +++ b/src/status_im/chat/styles/response.cljs @@ -6,10 +6,8 @@ text2-color chat-background color-black]] - [status-im.chat.styles.message-input :refer [input-height]])) - -(def response-height-normal 211) -(def request-info-height 61) + [status-im.chat.constants :refer [input-height request-info-height + response-height-normal]])) (def drag-container {:height 16 diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 36da63fe4f..20bcf239ce 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -1,15 +1,15 @@ (ns status-im.chat.subs (:require-macros [reagent.ratom :refer [reaction]]) - (:require [re-frame.core :refer [register-sub dispatch subscribe]] + (:require [re-frame.core :refer [register-sub dispatch subscribe path]] [status-im.db :as db] - ;todo handlers in subs?... [status-im.chat.suggestions :refer [get-suggestions typing-command?]] [status-im.models.commands :as commands] [status-im.constants :refer [response-suggesstion-resize-duration]] [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])) + [status-im.chat.views.command :as command] + [status-im.chat.constants :as c])) (register-sub :chat-properties (fn [db [_ properties]] @@ -123,7 +123,7 @@ (reaction (get-in @db [:suggestions (:current-chat-id @db)])))) (register-sub :command? - (fn [db ] + (fn [db] (->> (get-in @db [:edit-mode (:current-chat-id @db)]) (= :command) (reaction)))) diff --git a/src/status_im/chat/views/content_suggestions.cljs b/src/status_im/chat/views/content_suggestions.cljs deleted file mode 100644 index d2eb8b63b4..0000000000 --- a/src/status_im/chat/views/content_suggestions.cljs +++ /dev/null @@ -1,34 +0,0 @@ -(ns status-im.chat.views.content-suggestions - (:require-macros [status-im.utils.views :refer [defview]]) - (:require [re-frame.core :refer [subscribe dispatch]] - [status-im.components.react :refer [view - icon - text - touchable-highlight - list-view - list-item]] - [status-im.chat.styles.content-suggestions :as st] - [status-im.utils.listview :refer [to-datasource]])) - -(defn set-command-content [content] - (dispatch [:set-chat-command-content content])) - -(defn suggestion-list-item [{:keys [value description]}] - [touchable-highlight {:onPress #(set-command-content value)} - [view st/suggestion-container - [view st/suggestion-sub-container - [text {:style st/value-text} value] - [text {:style st/description-text} description]]]]) - -(defn render-row [row _ _] - (list-item [suggestion-list-item row])) - -(defview content-suggestions-view [] - [suggestions [:get-content-suggestions]] - (when (seq suggestions) - [view st/container - [touchable-highlight {:style st/drag-down-touchable - ;; TODO hide suggestions? - :onPress (fn [])} - [view [icon :drag_down st/drag-down-icon]]] - suggestions])) diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index 69829dae14..f9abe83f25 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -24,15 +24,16 @@ (defn button-animation-logic [{:keys [command? val]}] (fn [_] (let [to-scale (if @command? 0 1)] - (anim/start (anim/spring val {:toValue to-scale}))))) + (anim/start (anim/spring val {:toValue to-scale + :tension 30}))))) (defn list-container [min] (fn [{:keys [command? width]}] (let [n-width (if @command? min 56) - delay (if @command? 100 0)] + delay (if @command? 100 0)] (anim/start (anim/timing width {:toValue n-width :duration response-input-hiding-duration - :delay delay}))))) + :delay delay}))))) (defn commands-button [] (let [command? (subscribe [:command?]) @@ -62,19 +63,20 @@ (fn [_] (let [to-scale (if @command? 0 1)] (when-not @command? (anim/set-value width 56)) - (anim/start (anim/spring val {:toValue to-scale}) + (anim/start (anim/spring val {:toValue to-scale + :tension 30}) (fn [e] (when (and @command? (.-finished e)) (anim/set-value width 0.1))))))) (defn smile-button [] - (let [command? (subscribe [:command?]) - buttons-scale (anim/create-value (if @command? 1 0)) + (let [command? (subscribe [:command?]) + buttons-scale (anim/create-value (if @command? 1 0)) container-width (anim/create-value (if @command? 0.1 56)) - context {:command? command? - :val buttons-scale - :width container-width} - on-update (smile-animation-logic context)] + context {:command? command? + :val buttons-scale + :width container-width} + on-update (smile-animation-logic context)] (r/create-class {:component-did-mount on-update diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index faec7629fe..a079ef805a 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -13,7 +13,6 @@ [status-im.components.drag-drop :as drag] [status-im.chat.views.response-suggestions :refer [response-suggestions-view]] [status-im.chat.styles.response :as st] - [status-im.chat.styles.message-input :refer [input-height]] [status-im.components.animation :as anim] [status-im.components.react :as react])) @@ -112,5 +111,4 @@ (let [response-height (anim/create-value 0)] [container response-height [request-info response-height] - [response-suggestions-view] - [view st/input-placeholder]])) + [response-suggestions-view]])) diff --git a/src/status_im/chat/views/response_suggestions.cljs b/src/status_im/chat/views/response_suggestions.cljs index bffe80175b..3c6f9b549d 100644 --- a/src/status_im/chat/views/response_suggestions.cljs +++ b/src/status_im/chat/views/response_suggestions.cljs @@ -1,35 +1,7 @@ (ns status-im.chat.views.response-suggestions (:require-macros [status-im.utils.views :refer [defview]]) - (:require [re-frame.core :refer [subscribe dispatch]] - [status-im.components.react :refer [view - icon - text - touchable-highlight - list-view - list-item]] - [status-im.chat.styles.response-suggestions :as st] - [status-im.utils.listview :refer [to-datasource]])) - -(defn set-command-content [content] - (dispatch [:set-chat-command-content content])) - -(defn header-list-item [{:keys [header]}] - [view st/header-container - [text {:style st/header-text} header]]) - -(defn suggestion-list-item [{:keys [value description]}] - [touchable-highlight {:onPress #(set-command-content value)} - [view st/suggestion-container - [view st/suggestion-sub-container - [text {:style st/value-text} value] - [text {:style st/description-text} description]]]]) - -(defn render-row [row _ _] - (list-item (if (:header row) - [header-list-item row] - [suggestion-list-item row]))) + (:require [re-frame.core :refer [subscribe dispatch]])) (defview response-suggestions-view [] [suggestions [:get-content-suggestions]] - (when (seq suggestions) - suggestions)) + (when (seq suggestions) suggestions)) diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index 2e45635869..07a041b01d 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -50,7 +50,7 @@ (defn command-preview [db [chat-id response-json]] (if-let [response (json->cljs response-json)] - (let [path [:chats chat-id :staged-commands] + (let [path [:chats chat-id :staged-commands] commands-cnt (count (get-in db path))] ;; todo (dec commands-cnt) looks like hack have to find better way to ;; do this @@ -63,6 +63,8 @@ (reg-handler ::render-command render-command) (reg-handler :command-handler! (u/side-effect! command-nadler!)) -(reg-handler :suggestions-handler suggestions-handler) +(reg-handler :suggestions-handler + (after #(dispatch [:animate-show-response])) + suggestions-handler) (reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!)) (reg-handler :command-preview command-preview) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index 3f8ce95762..66ee37977d 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -55,9 +55,6 @@ ;; todo check #_(= (get-hash-by-identity db identity) (get-hash-by-file file))] - (println :hash - (get-hash-by-identity db identity) - (get-hash-by-file file)) (assoc db ::valid-hash valid?))) (defn add-commands diff --git a/src/status_im/commands/utils.cljs b/src/status_im/commands/utils.cljs index bf4639f5dc..1c07a5fe8e 100644 --- a/src/status_im/commands/utils.cljs +++ b/src/status_im/commands/utils.cljs @@ -45,4 +45,4 @@ (defn reg-handler ([name handler] (reg-handler name nil handler)) ([name middleware handler] - (register-handler name [debug trim-v middleware] handler))) + (register-handler name [#_debug trim-v middleware] handler))) diff --git a/src/status_im/components/jail.cljs b/src/status_im/components/jail.cljs index d58cf9e2c1..7efc67c13b 100644 --- a/src/status_im/components/jail.cljs +++ b/src/status_im/components/jail.cljs @@ -122,5 +122,5 @@ var status = { (.stringify js/JSON (clj->js data))) (defn call [chat-id path params callback] - (println :call chat-id (cljs->json path) (cljs->json params)) + ;(println :call chat-id (cljs->json path) (cljs->json params)) (.call jail chat-id (cljs->json path) (cljs->json params) callback)) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 6540a30948..f229403e07 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -9,6 +9,7 @@ [status-im.utils.crypt :refer [gen-random-bytes]] [status-im.utils.handlers :as u] status-im.chat.handlers + status-im.chat.handlers.animation status-im.group-settings.handlers status-im.navigation.handlers status-im.contacts.handlers From 43b943505c01269a96c5c86d817c0ac1eee44c25 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 23 Jun 2016 16:11:21 +0300 Subject: [PATCH 18/53] adapt animation & cleanup Former-commit-id: d07688136f0f23ced1363189ed9f5d5f6c8d2e00 --- src/status_im/chat/handlers/animation.cljs | 2 - .../chat/styles/response_suggestions.cljs | 59 ------------------- src/status_im/chat/views/response.cljs | 13 +++- .../chat/views/response_suggestions.cljs | 7 --- 4 files changed, 11 insertions(+), 70 deletions(-) delete mode 100644 src/status_im/chat/styles/response_suggestions.cljs delete mode 100644 src/status_im/chat/views/response_suggestions.cljs diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 2bd08c7a3b..a1ea5c98a5 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -1,11 +1,9 @@ (ns status-im.chat.handlers.animation (:require [re-frame.core :refer [register-handler after dispatch debug]] [re-frame.middleware :refer [path]] - [status-im.models.commands :as commands] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.chat.constants :refer [input-height request-info-height response-height-normal minimum-suggestion-height]] - [status-im.chat.styles.response-suggestions :as response-suggestions-styles] [status-im.constants :refer [response-input-hiding-duration]])) ;; todo magic value diff --git a/src/status_im/chat/styles/response_suggestions.cljs b/src/status_im/chat/styles/response_suggestions.cljs deleted file mode 100644 index 2561f2ae53..0000000000 --- a/src/status_im/chat/styles/response_suggestions.cljs +++ /dev/null @@ -1,59 +0,0 @@ -(ns status-im.chat.styles.response-suggestions - (:require [status-im.components.styles :refer [font - font-medium - color-light-blue-transparent - color-white - color-black - color-blue - color-blue-transparent - selected-message-color - online-color - separator-color - text1-color - text2-color - text3-color]])) - -(def header-height 50) -(def suggestion-height 56) - -(def header-container - {:paddingLeft 16 - :height header-height - :backgroundColor color-white}) - -(def header-text - {:marginTop 18 - :fontSize 13 - :fontFamily font-medium - :color text2-color}) - -(def suggestion-container - {:flexDirection :column - :paddingLeft 16 - :height suggestion-height - :backgroundColor color-white}) - -(def suggestion-sub-container - {:height suggestion-height - :borderBottomWidth 1 - :borderBottomColor separator-color}) - -(def value-text - {:marginTop 10 - :fontSize 12 - :fontFamily font - :color text1-color}) - -(def description-text - {:marginTop 2 - :fontSize 12 - :fontFamily font - :color text2-color}) - -(def suggestions-container - {:flexDirection :row - :flex 1 - :marginVertical 1 - :marginHorizontal 0 - :backgroundColor color-white - :borderRadius 5}) diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index a079ef805a..4336ce9c04 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -11,7 +11,6 @@ text-input touchable-highlight]] [status-im.components.drag-drop :as drag] - [status-im.chat.views.response-suggestions :refer [response-suggestions-view]] [status-im.chat.styles.response :as st] [status-im.components.animation :as anim] [status-im.components.react :as react])) @@ -107,8 +106,18 @@ (into [animated-view {:style (st/response-view response-height)}] children))}))) +(defview placeholder [] + [suggestions [:get-content-suggestions]] + (when (seq suggestions) + [view st/input-placeholder])) + +(defview response-suggestions-view [] + [suggestions [:get-content-suggestions]] + (when (seq suggestions) suggestions)) + (defn response-view [] (let [response-height (anim/create-value 0)] [container response-height [request-info response-height] - [response-suggestions-view]])) + [response-suggestions-view] + [placeholder]])) diff --git a/src/status_im/chat/views/response_suggestions.cljs b/src/status_im/chat/views/response_suggestions.cljs deleted file mode 100644 index 3c6f9b549d..0000000000 --- a/src/status_im/chat/views/response_suggestions.cljs +++ /dev/null @@ -1,7 +0,0 @@ -(ns status-im.chat.views.response-suggestions - (:require-macros [status-im.utils.views :refer [defview]]) - (:require [re-frame.core :refer [subscribe dispatch]])) - -(defview response-suggestions-view [] - [suggestions [:get-content-suggestions]] - (when (seq suggestions) suggestions)) From 157393bd7aca7a3c56297b4999b859373c70de2e Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 23 Jun 2016 19:07:31 +0300 Subject: [PATCH 19/53] handle errors from jail Former-commit-id: 40dd0063d20cb56ce9d34d05b9720a7d66410d00 --- android/app/build.gradle | 2 +- src/status_im/chat/views/response.cljs | 4 ++- src/status_im/commands/handlers/jail.cljs | 37 +++++++++++++------- src/status_im/commands/handlers/loading.cljs | 20 ++++++----- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index e86f611f36..e7e086763c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -133,7 +133,7 @@ dependencies { compile project(':react-native-camera') compile project(':react-native-status') compile project(':react-native-orientation') - compile(group: 'status-im', name: 'status-go', version: '0.1.0-201606220917-ec4b9a', ext: 'aar') + compile(group: 'status-im', name: 'status-go', version: '0.1.0-201606231357-85abe1', ext: 'aar') compile fileTree(dir: "node_modules/realm/android/libs", include: ["*.jar"]) } diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 4336ce9c04..71933d6d8d 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -85,7 +85,9 @@ (defn container-animation-logic [{:keys [to-value val]}] (fn [_] (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value}))))) + (anim/start (anim/spring val {:toValue to-value + :tension 50 + :friction 10}))))) (defn container [response-height & children] (let [;; todo to-response-height, cur-response-height must be specific diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index 07a041b01d..f7fd12067a 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -26,19 +26,30 @@ (def regular-events {}) -(defn command-nadler! - [_ [{:keys [to]} response]] - (let [{:keys [event params]} (json->cljs response) - events (if (= "console" to) - (merge regular-events console-events) - regular-events)] - (when-let [handler (events (keyword event))] - (apply handler params)))) +(defn print-error! [error] + (toast error) + (println error)) -(defn suggestions-handler +(defn command-hadler! + [_ [{:keys [to] :as command} response]] + (let [{:keys [error result]} (json->cljs response)] + (if error + (let [m (str "Error on command handling!\n" command error)] + (print-error! m)) + (let [{:keys [event params]} result + events (if (= "console" to) + (merge regular-events console-events) + regular-events)] + (when-let [handler (events (keyword event))] + (apply handler params)))))) + +(defn suggestions-handler! [db [{:keys [chat-id]} response-json]] - (let [response (json->cljs response-json)] - (assoc-in db [:suggestions chat-id] (generate-hiccup response)))) + (let [{:keys [error result]} (json->cljs response-json)] + (when error + (let [m (str "Error on param suggestions!\n" error)] + (print-error! m))) + (assoc-in db [:suggestions chat-id] (generate-hiccup result)))) (defn suggestions-events-handler! [db [[n data]]] @@ -62,9 +73,9 @@ (reg-handler :init-render-command! init-render-command!) (reg-handler ::render-command render-command) -(reg-handler :command-handler! (u/side-effect! command-nadler!)) +(reg-handler :command-handler! (u/side-effect! command-hadler!)) (reg-handler :suggestions-handler (after #(dispatch [:animate-show-response])) - suggestions-handler) + suggestions-handler!) (reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!)) (reg-handler :command-preview command-preview) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index 66ee37977d..d65bf21ec0 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -44,10 +44,10 @@ (defn parse-commands! [_ [identity file]] (j/parse identity file (fn [result] - (let [commands (json->cljs result)] - ;; todo use commands from jail - (dispatch [::add-commands identity file commands]))) - #_(dispatch [::loading-failed! identity ::error-in-jail %]))) + (let [{:keys [error result]} (json->cljs result)] + (if error + (dispatch [::loading-failed! identity ::error-in-jail error]) + (dispatch [::add-commands identity file result])))))) (defn validate-hash [db [identity file]] @@ -70,11 +70,13 @@ (defn loading-failed! [db [id reason details]] (let [url (get-in db [:chats id :dapp-url])] - (toast (s/join "\n" ["commands.js loading failed" - url - id - (name reason) - details])))) + (let [m (s/join "\n" ["commands.js loading failed" + url + id + (name reason) + details])] + (toast m) + (println m)))) (reg-handler :load-commands! (u/side-effect! load-commands!)) (reg-handler ::fetch-commands! (u/side-effect! fetch-commands!)) From e84af2595fe1fcd9285c782dabf96e07429cb7c5 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 24 Jun 2016 15:38:51 +0300 Subject: [PATCH 20/53] (slurp "status.js") Former-commit-id: 82c6688648ed771b687d82b91b4167739609f30d --- src/status_im/components/jail.cljs | 108 +---------------------------- src/status_im/utils/slurp.clj | 5 ++ 2 files changed, 7 insertions(+), 106 deletions(-) create mode 100644 src/status_im/utils/slurp.clj diff --git a/src/status_im/components/jail.cljs b/src/status_im/components/jail.cljs index 7efc67c13b..758d620706 100644 --- a/src/status_im/components/jail.cljs +++ b/src/status_im/components/jail.cljs @@ -1,112 +1,8 @@ (ns status-im.components.jail + (:require-macros [status-im.utils.slurp :refer [slurp]]) (:require [status-im.components.react :as r])) -(def status-js - "var _status_catalog = { - commands: {}, - responses: {} -}; - -function Command() { -} -function Response() { -} - -Command.prototype.addToCatalog = function () { - _status_catalog.commands[this.name] = this; -}; - -Command.prototype.param = function (parameter) { - this.params.push(parameter); - - return this; -}; - -Command.prototype.create = function (com) { - this.name = com.name; - this.description = com.description; - this.handler = com.handler; - this.color = com.color; - this.icon = com.icon; - this.params = com.params || []; - this.preview = com.preview; - this.addToCatalog(); - - return this; -}; - - -Response.prototype = Object.create(Command.prototype); -Response.prototype.addToCatalog = function () { - _status_catalog.responses[this.name] = this; -}; -Response.prototype.onReceiveResponse = function (handler) { - this.onReceive = handler; -}; - -function call(pathStr, paramsStr) { - var params = JSON.parse(paramsStr), - path = JSON.parse(pathStr), - fn, res; - - fn = path.reduce(function (catalog, name) { - if (catalog && catalog[name]) { - return catalog[name]; - } - }, - _status_catalog - ); - - res = fn(params); - - return JSON.stringify(res); -} - -function text(options, s) { - return ['text', options, s]; -} - -function view(options, elements) { - return ['view', options].concat(elements); -} - -function image(options) { - return ['image', options]; -} - -function touchable(options, element) { - return ['touchable', options, element]; -} - -function scrollView(options, elements) { - return ['scroll-view', options].concat(elements); -} - -var status = { - command: function (n, d, h) { - var command = new Command(); - return command.create(n, d, h); - }, - response: function (n, d, h) { - var response = new Response(); - return response.create(n, d, h); - }, - types: { - STRING: 'string', - PHONE_NUMBER: 'phone-number', - PASSWORD: 'password' - }, - events: { - SET_VALUE: 'set-value' - }, - components: { - view: view, - text: text, - image: image, - touchable: touchable, - scrollView: scrollView - } -};") +(def status-js (slurp "resources/status.js")) (def jail (when (exists? (.-NativeModules r/react)) diff --git a/src/status_im/utils/slurp.clj b/src/status_im/utils/slurp.clj new file mode 100644 index 0000000000..194b1384b5 --- /dev/null +++ b/src/status_im/utils/slurp.clj @@ -0,0 +1,5 @@ +(ns status-im.utils.slurp + (:refer-clojure :exclude [slurp])) + +(defmacro slurp [file] + (clojure.core/slurp file)) From 771f046e9620926a87bacba4df0e3c33080a74dc Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sat, 25 Jun 2016 16:28:45 +0300 Subject: [PATCH 21/53] handle responses from jail Former-commit-id: 7632de08cfb67b72dffd881e0fba5d099e7726c2 --- resources/commands.js | 2 +- resources/status.js | 4 ++ src/status_im/commands/handlers/jail.cljs | 66 ++++++++++---------- src/status_im/commands/handlers/loading.cljs | 5 +- src/status_im/commands/utils.cljs | 3 +- src/status_im/components/jail.cljs | 11 +++- src/status_im/utils/types.cljs | 5 +- 7 files changed, 53 insertions(+), 43 deletions(-) diff --git a/resources/commands.js b/resources/commands.js index 47bd9909d4..94c631b979 100644 --- a/resources/commands.js +++ b/resources/commands.js @@ -124,7 +124,7 @@ status.response({ status.command({ name: "help", description: "Help", - color: "#9a5dcf", + color: "#7099e6", params: [{ name: "query", type: status.types.STRING diff --git a/resources/status.js b/resources/status.js index c25535b159..924decbf47 100644 --- a/resources/status.js +++ b/resources/status.js @@ -53,6 +53,10 @@ function call(pathStr, paramsStr) { _status_catalog ); + if(!fn) { + return null; + } + res = fn(params); return JSON.stringify(res); diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index f7fd12067a..ce2f8be32b 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -4,15 +4,14 @@ [status-im.utils.handlers :as u] [status-im.utils.utils :refer [http-get toast]] [status-im.components.jail :as j] - - [status-im.commands.utils :refer [json->cljs generate-hiccup - reg-handler]])) + [status-im.utils.types :refer [json->clj]] + [status-im.commands.utils :refer [generate-hiccup reg-handler]] + [clojure.string :as s])) (defn init-render-command! [_ [chat-id command message-id data]] (j/call chat-id [command :render] data - (fn [res] - (dispatch [::render-command chat-id message-id (json->cljs res)])))) + #(dispatch [::render-command chat-id message-id %]))) (defn render-command [db [chat-id message-id markup]] @@ -26,30 +25,19 @@ (def regular-events {}) -(defn print-error! [error] - (toast error) - (println error)) - (defn command-hadler! - [_ [{:keys [to] :as command} response]] - (let [{:keys [error result]} (json->cljs response)] - (if error - (let [m (str "Error on command handling!\n" command error)] - (print-error! m)) - (let [{:keys [event params]} result - events (if (= "console" to) - (merge regular-events console-events) - regular-events)] - (when-let [handler (events (keyword event))] - (apply handler params)))))) + [_ [{:keys [to]} {:keys [result]} ]] + (when result + (let [{:keys [event params]} result + events (if (= "console" to) + (merge regular-events console-events) + regular-events)] + (when-let [handler (events (keyword event))] + (apply handler params))))) (defn suggestions-handler! - [db [{:keys [chat-id]} response-json]] - (let [{:keys [error result]} (json->cljs response-json)] - (when error - (let [m (str "Error on param suggestions!\n" error)] - (print-error! m))) - (assoc-in db [:suggestions chat-id] (generate-hiccup result)))) + [db [{:keys [chat-id]} {:keys [result]} ]] + (assoc-in db [:suggestions chat-id] (generate-hiccup result))) (defn suggestions-events-handler! [db [[n data]]] @@ -59,23 +47,35 @@ nil)) (defn command-preview - [db [chat-id response-json]] - (if-let [response (json->cljs response-json)] + [db [chat-id {:keys [result]}]] + (println :wuuut) + (if result (let [path [:chats chat-id :staged-commands] commands-cnt (count (get-in db path))] ;; todo (dec commands-cnt) looks like hack have to find better way to ;; do this (update-in db (conj path (dec commands-cnt)) assoc - :preview (generate-hiccup response) - :preview-string (str response))) + :preview (generate-hiccup result) + :preview-string (str result))) db)) +(defn print-error-message! [message] + (fn [_ params] + (when (:error (last params)) + (toast (s/join "\n" [message params])) + (println message params)))) + (reg-handler :init-render-command! init-render-command!) (reg-handler ::render-command render-command) -(reg-handler :command-handler! (u/side-effect! command-hadler!)) +(reg-handler :command-handler! + (after (print-error-message! "Error on command handling")) + (u/side-effect! command-hadler!)) (reg-handler :suggestions-handler - (after #(dispatch [:animate-show-response])) + [(after #(dispatch [:animate-show-response])) + (after (print-error-message! "Error on param suggestions"))] suggestions-handler!) (reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!)) -(reg-handler :command-preview command-preview) +(reg-handler :command-preview + (after (print-error-message! "Error on command preview")) + command-preview) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index d65bf21ec0..74b08e7d86 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -6,7 +6,8 @@ [clojure.string :as s] [status-im.persistence.realm :as realm] [status-im.components.jail :as j] - [status-im.commands.utils :refer [json->cljs reg-handler]])) + [status-im.utils.types :refer [json->clj]] + [status-im.commands.utils :refer [reg-handler]])) (def commands-js "commands.js") @@ -44,7 +45,7 @@ (defn parse-commands! [_ [identity file]] (j/parse identity file (fn [result] - (let [{:keys [error result]} (json->cljs result)] + (let [{:keys [error result]} (json->clj result)] (if error (dispatch [::loading-failed! identity ::error-in-jail error]) (dispatch [::add-commands identity file result])))))) diff --git a/src/status_im/commands/utils.cljs b/src/status_im/commands/utils.cljs index 1c07a5fe8e..8ae48bf0e7 100644 --- a/src/status_im/commands/utils.cljs +++ b/src/status_im/commands/utils.cljs @@ -5,12 +5,11 @@ image touchable-highlight]] [re-frame.core :refer [register-handler dispatch trim-v debug]])) -(defn json->cljs [json] +(defn json->clj [json] (if (= json "undefined") nil (js->clj (.parse js/JSON json) :keywordize-keys true))) - (def elements {:text text :view view diff --git a/src/status_im/components/jail.cljs b/src/status_im/components/jail.cljs index 758d620706..daf278f4f8 100644 --- a/src/status_im/components/jail.cljs +++ b/src/status_im/components/jail.cljs @@ -1,6 +1,7 @@ (ns status-im.components.jail (:require-macros [status-im.utils.slurp :refer [slurp]]) - (:require [status-im.components.react :as r])) + (:require [status-im.components.react :as r] + [status-im.utils.types :as t])) (def status-js (slurp "resources/status.js")) @@ -18,5 +19,9 @@ (.stringify js/JSON (clj->js data))) (defn call [chat-id path params callback] - ;(println :call chat-id (cljs->json path) (cljs->json params)) - (.call jail chat-id (cljs->json path) (cljs->json params) callback)) + (println :call chat-id (cljs->json path) (cljs->json params)) + (let [cb (fn [r] + (let [r' (t/json->clj r)] + (println r') + (callback r')))] + (.call jail chat-id (cljs->json path) (cljs->json params) cb))) diff --git a/src/status_im/utils/types.cljs b/src/status_im/utils/types.cljs index 93c942df77..d30d09804b 100644 --- a/src/status_im/utils/types.cljs +++ b/src/status_im/utils/types.cljs @@ -11,5 +11,6 @@ (defn clj->json [data] (.stringify js/JSON (clj->js data))) -(defn json->clj [data] - (js->clj (.parse js/JSON data) :keywordize-keys true)) +(defn json->clj [json] + (when-not (= json "undefined") + (js->clj (.parse js/JSON json) :keywordize-keys true))) From 4b33910c805647cebd22e1e722f10fe953a647af Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sat, 25 Jun 2016 16:38:24 +0300 Subject: [PATCH 22/53] cleanup Former-commit-id: 923b2af64859a25d279877c672f3bc99d694710c --- src/status_im/commands/handlers/jail.cljs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index ce2f8be32b..b2d1ac67af 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -48,7 +48,6 @@ (defn command-preview [db [chat-id {:keys [result]}]] - (println :wuuut) (if result (let [path [:chats chat-id :staged-commands] commands-cnt (count (get-in db path))] From 4ed06ff622ffaecdb33f5e2ec4d9a8f3a04fc950 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sat, 25 Jun 2016 18:44:37 +0300 Subject: [PATCH 23/53] first attempt Former-commit-id: 6cd5e29c8aba3f47e612b1b1127bf5b826bb7dbf --- src/status_im/chat/constants.cljs | 1 + src/status_im/chat/handlers.cljs | 26 +++-- src/status_im/chat/handlers/animation.cljs | 74 ++++++++------ src/status_im/chat/screen.cljs | 36 ++++--- src/status_im/chat/styles/suggestions.cljs | 34 +++--- src/status_im/chat/subs.cljs | 7 +- src/status_im/chat/views/new_message.cljs | 6 +- src/status_im/chat/views/plain_message.cljs | 2 +- src/status_im/chat/views/suggestions.cljs | 108 +++++++++++++++++--- src/status_im/db.cljs | 1 - 10 files changed, 201 insertions(+), 94 deletions(-) diff --git a/src/status_im/chat/constants.cljs b/src/status_im/chat/constants.cljs index e9d95a4ed9..f37aff957e 100644 --- a/src/status_im/chat/constants.cljs +++ b/src/status_im/chat/constants.cljs @@ -4,3 +4,4 @@ (def request-info-height 61) (def response-height-normal 211) (def minimum-suggestion-height (+ input-height request-info-height)) +(def minimum-command-suggestions-height (+ input-height 22)) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index c1627a957e..3d1d213cab 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -19,6 +19,7 @@ [status-im.utils.phone-number :refer [format-phone-number]] [status-im.utils.datetime :as time] [status-im.components.jail :as j] + [status-im.utils.types :refer [json->clj]] [status-im.commands.utils :refer [generate-hiccup]])) (register-handler :set-show-actions @@ -93,7 +94,7 @@ (register-handler :stage-command (after invoke-command-preview!) (fn [{:keys [current-chat-id] :as db} _] - (let [db (update-input-text db nil) + (let [db (update-input-text db nil) {:keys [command content]} (get-in db [:chats current-chat-id :command-input]) command-info {:command command @@ -115,9 +116,7 @@ (register-handler :set-response-chat-command [(after invoke-suggestions-handler!) - (after #(dispatch [:command-edit-mode])) - ;(after #(dispatch [:animate-show-response])) - ] + (after #(dispatch [:command-edit-mode]))] (fn [db [_ to-msg-id command-key]] (commands/set-response-chat-command db to-msg-id command-key))) @@ -133,8 +132,17 @@ db)) db)) +(defn check-suggestions + [{:keys [current-chat-id] :as db} [_ text]] + (assoc-in db + [:command-suggestions current-chat-id] + (suggestions/get-suggestions db text))) + (register-handler :set-chat-input-text - ((enrich update-command) update-text)) + [(enrich update-command) + (enrich check-suggestions) + (after #(dispatch [:animate-command-suggestions]))] + update-text) (defn console? [s] (= "console" s)) @@ -437,9 +445,11 @@ ((after save-chat!)) ((after open-chat!)))) -(register-handler :switch-command-suggestions - (fn [db [_]] - (suggestions/switch-command-suggestions db))) +(register-handler :switch-command-suggestions! + (u/side-effect! + (fn [db] + (let [text (if (suggestions/typing-command? db) "" "!")] + (dispatch [:set-chat-input-text text]))))) (defn remove-chat [{:keys [current-chat-id] :as db} _] diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index a1ea5c98a5..80ca0ac379 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -3,6 +3,7 @@ [re-frame.middleware :refer [path]] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.chat.constants :refer [input-height request-info-height + minimum-command-suggestions-height response-height-normal minimum-suggestion-height]] [status-im.constants :refer [response-input-hiding-duration]])) @@ -19,45 +20,45 @@ (fn [db _] (assoc db :to-response-height input-height - :messages-offset 0))) + :messages-offset? false))) -(defn get-response-height - [{:keys [current-chat-id] :as db}] - (let [suggestions (get-in db [:suggestions current-chat-id]) - suggestions-height (if suggestions middle-height 0)] - (+ input-height - (min response-height-normal (+ suggestions-height request-info-height))))) +(def response-height (+ input-height response-height-normal)) (defn update-response-height [db] - (assoc-in db [:animations :to-response-height] (get-response-height db))) + (assoc-in db [:animations :to-response-height] response-height)) -(register-handler :animate-show-response +(register-handler :animate-command-suggestions + (fn [{:keys [current-chat-id] :as db} _] + (let [suggestions? (seq (get-in db [:command-suggestions current-chat-id])) + current (get-in db [:animations :command-suggestions-height]) + height (if suggestions? middle-height 0.1)] + (-> db + (update :animations assoc + :messages-offset? suggestions? + :messages-offset-max 22 + :command-suggestions-height height) + (update-in [:animations :commands-height-changed] + (if (and suggestions? (not= 0.1 current)) + identity inc)))))) + +(animation-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] - (fn [db _] - (-> db - (assoc-in [:animations :messages-offset] request-info-height) - (update-response-height)))) + (fn [db] + (assoc db :messages-offset? true + :messages-offset-max request-info-height + :to-response-height response-height))) -(animation-handler :set-response-max-height - (fn [db [_ height]] - (let [prev-height (:response-height-max db)] - (if (not= height prev-height) - (let [db (assoc db :response-height-max height)] - (if (= prev-height (:to-response-height db)) - (assoc db :to-response-height height) - db)) - db)))) - -(register-handler :fix-response-height +(defn fix-height + [height-key height-signal-key suggestions-key minimum] (fn [{:keys [current-chat-id] :as db} [_ vy current]] - (let [max-height (get-in db [:animations :response-height-max]) + (let [max-height (get-in db [:layout-height]) moving-down? (pos? vy) moving-up? (not moving-down?) under-middle-position? (<= current middle-height) over-middle-position? (not under-middle-position?) - suggestions (get-in db [:suggestions current-chat-id]) + suggestions (get-in db [suggestions-key current-chat-id]) new-fixed (cond (not suggestions) - minimum-suggestion-height + minimum (and under-middle-position? moving-up?) middle-height @@ -70,7 +71,20 @@ (and under-middle-position? moving-down?) - minimum-suggestion-height)] + minimum)] + (println height-key new-fixed) (-> db - (assoc-in [:animations :to-response-height] new-fixed) - (update-in [:animations :response-height-changed] inc))))) + (assoc-in [:animations height-key] new-fixed) + (update-in [:animations height-signal-key] inc))))) + +(register-handler :fix-commands-suggestions-height + (fix-height :command-suggestions-height + :commands-height-changed + :command-suggestions + minimum-command-suggestions-height)) + +(register-handler :fix-response-height + (fix-height :to-response-height + :response-height-changed + :suggestions + minimum-suggestion-height)) diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index f9394aeb5a..71718746cf 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -18,7 +18,7 @@ [status-im.components.invertible-scroll-view :refer [invertible-scroll-view]] [status-im.components.toolbar :refer [toolbar]] [status-im.chat.views.message :refer [chat-message]] - [status-im.chat.views.suggestions :refer [suggestions-view]] + [status-im.chat.views.suggestions :refer [suggestion-container]] [status-im.chat.views.response :refer [response-view]] [status-im.chat.views.new-message :refer [chat-message-new]] [status-im.i18n :refer [label label-pluralize]] @@ -228,20 +228,19 @@ :keyboardShouldPersistTaps true :dataSource (to-datasource-inverted messages)}])) -(defn messages-container-animation-logic [{:keys [to-value val]}] +(defn messages-container-animation-logic + [{:keys [offset? val max]}] (fn [_] - (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value}) - (fn [arg] - (when (.-finished arg) - (dispatch [:set-animation ::messages-offset-current to-value]))))))) + (let [to-value (if @offset? @max 0)] + (anim/start (anim/spring val {:toValue to-value}))))) (defn messages-container [messages] - (let [to-messages-offset (subscribe [:animations :messages-offset]) - cur-messages-offset (subscribe [:animations ::messages-offset-current]) - messages-offset (anim/create-value (or @cur-messages-offset 0)) - context {:to-value to-messages-offset - :val messages-offset} + (let [messages-offset? (subscribe [:animations :messages-offset?]) + maximum-offset (subscribe [:animations :messages-offset-max]) + messages-offset (anim/create-value 0) + context {:offset? messages-offset? + :val messages-offset + :max maximum-offset} on-update (messages-container-animation-logic context)] (r/create-class {:component-did-mount @@ -250,7 +249,7 @@ on-update :reagent-render (fn [messages] - @to-messages-offset + @messages-offset? [animated-view {:style (st/messages-container messages-offset)} messages])}))) @@ -259,16 +258,19 @@ show-actions-atom [:show-actions] command [:get-chat-command] command? [:command?] - to-msg-id [:get-chat-command-to-msg-id]] - [view {:style st/chat-view + suggestions [:get-suggestions] + to-msg-id [:get-chat-command-to-msg-id] + layout-height [:get :layout-height]] + [view {:style st/chat-view :onLayout (fn [event] (let [height (.. event -nativeEvent -layout -height)] - (dispatch [:set-response-max-height height])))} + (when (not= height layout-height) + (dispatch [:set :layout-height height]))))} [chat-toolbar] [messages-container [messages-view group-chat]] (when group-chat [typing-all]) [response-view] - (when-not command? [suggestions-view]) + (when-not command? [suggestion-container]) [chat-message-new] (when show-actions-atom [actions-view])]) diff --git a/src/status_im/chat/styles/suggestions.cljs b/src/status_im/chat/styles/suggestions.cljs index 0c35347f79..2d1d89525f 100644 --- a/src/status_im/chat/styles/suggestions.cljs +++ b/src/status_im/chat/styles/suggestions.cljs @@ -1,16 +1,16 @@ (ns status-im.chat.styles.suggestions (:require [status-im.components.styles :refer [font - color-light-blue-transparent - color-white - color-black - color-blue - color-blue-transparent - selected-message-color - online-color - separator-color - text1-color - text2-color - text3-color]])) + color-light-blue-transparent + color-white + color-black + color-blue + color-blue-transparent + selected-message-color + online-color + separator-color + text1-color + text2-color + text3-color]])) (def suggestion-height 88) @@ -59,11 +59,19 @@ :backgroundColor color-white :borderRadius 5}) -(def container - {:backgroundColor color-white}) +(defn container [height] + {:flexDirection :column + :position :absolute + :left 0 + :right 0 + :bottom 0 + :height height + :backgroundColor color-white + :elevation 2}) (def drag-down-touchable {:height 22 + :background-color color-white :alignItems :center :justifyContent :center}) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 20bcf239ce..4d197b1aad 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -43,11 +43,8 @@ (register-sub :get-suggestions (fn [db _] - (let [input-text (->> (:current-chat-id @db) - db/chat-input-text-path - (get-in @db) - (reaction))] - (reaction (get-suggestions @db @input-text))))) + (let [chat-id (subscribe [:get-current-chat-id])] + (reaction (get-in @db [:command-suggestions @chat-id]))))) (register-sub :get-commands (fn [db _] diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 67280885c4..1434651b1f 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -21,19 +21,19 @@ command? [:command?]] [plain-message-input-view (when command? - (case (:command command) + (case (keyword (:name command)) :phone {:input-options {:keyboardType :phone-pad} :validator valid-mobile-number?} :keypair {:input-options {:secureTextEntry true}} :confirmation-code {:input-options {:keyboardType :numeric}} :money {:input-options {:keyboardType :numeric}} :request {:input-options {:keyboardType :numeric}} - ;; todo maybe nil is finr for now :) + ;; todo maybe nil is fine for now :) nil #_(throw (js/Error. "Uknown command type"))))]) (defview chat-message-new [] [staged-commands [:get-chat-staged-commands]] [view st/new-message-container - (when (and staged-commands (pos? (count staged-commands))) + (when (seq staged-commands) [staged-commands-view staged-commands]) [show-input]]) diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index f9abe83f25..12ccadd664 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -52,7 +52,7 @@ on-update :reagent-render (fn [] - [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions]) + [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions!]) :disabled @command?} [animated-view {:style (st/message-input-button-touchable container-width)} diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 202150423f..3eba75a4ea 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -6,9 +6,14 @@ icon touchable-highlight list-view - list-item]] + list-item + animated-view]] [status-im.utils.listview :refer [to-datasource]] - [status-im.chat.styles.suggestions :as st])) + [status-im.chat.styles.suggestions :as st] + [reagent.core :as r] + [status-im.components.animation :as anim] + [status-im.components.drag-drop :as drag] + [status-im.components.react :as react])) (defn set-command-input [command] (dispatch [:set-chat-command command])) @@ -31,18 +36,89 @@ (list-item [suggestion-list-item row])) -(defview suggestions-view [] - [suggestions [:get-suggestions]] - (when (seq suggestions) - [view st/container - [touchable-highlight {:style st/drag-down-touchable - :onPress (fn [] - ;; TODO hide suggestions? - )} +(defn suggestions-view [] + (let + [suggestions (subscribe [:get-suggestions])] + (r/create-class + {:reagent-render + (fn [] + [view (st/suggestions-container (count @suggestions)) + [list-view {:dataSource (to-datasource @suggestions) + :enableEmptySections true + :keyboardShouldPersistTaps true + :renderRow render-row}]])}))) + +;; todo bad name. Ideas? +(defn enough-dy [gesture] + (> (Math/abs (.-dy gesture)) 10)) + +(defn on-move [response-height kb-height orientation] + (fn [_ gesture] + (when (enough-dy gesture) + (let [w (react/get-dimensions "window") + ;; depending on orientation use height or width of screen + prop (if (= :portrait @orientation) + :height + :width) + ;; subtract keyboard height to get "real height" of screen + ;; then subtract gesture position to get suggestions height + ;; todo maybe it is better to use margin-top instead height + ;; it is not obvious + to-value (- (prop w) @kb-height (.-moveY gesture))] + (anim/start + (anim/spring response-height {:toValue to-value})))))) + +(defn on-release [response-height] + (fn [_ gesture] + (when (enough-dy gesture) + (dispatch [:fix-commands-suggestions-height + (.-vy gesture) + ;; todo access to "private" property + ;; better to find another way... + (.-_value response-height)])))) + +(defn pan-responder [response-height kb-height orientation] + (drag/create-pan-responder + {:on-move (on-move response-height kb-height orientation) + :on-release (on-release response-height)})) + +(defn header [h] + (let [orientation (subscribe [:get :orientation]) + kb-height (subscribe [:get :keyboard-height]) + pan-responder (pan-responder h kb-height orientation)] + (fn [_] [view - [icon :drag_down st/drag-down-icon]]] - [view (st/suggestions-container (count suggestions)) - [list-view {:dataSource (to-datasource suggestions) - :enableEmptySections true - :keyboardShouldPersistTaps true - :renderRow render-row}]]])) + (merge (drag/pan-handlers pan-responder) + {:style st/drag-down-touchable}) + [icon :drag_down st/drag-down-icon]]))) + +(defn container-animation-logic [{:keys [to-value val]}] + (fn [_] + (let [to-value @to-value] + (anim/start (anim/spring val {:toValue to-value + :tension 50 + :friction 10}))))) + +(defn container [h & elements] + (let [;; todo to-response-height, cur-response-height must be specific + ;; for each chat + to-response-height (subscribe [:animations :command-suggestions-height]) + changed (subscribe [:animations :commands-height-changed]) + context {:to-value to-response-height + :val h} + on-update (container-animation-logic context)] + (r/create-class + {:component-did-mount + on-update + :component-did-update + on-update + :reagent-render + (fn [h & elements] + @changed + (into [animated-view {:style (st/container h)}] elements))}))) + +(defn suggestion-container [] + (let [h (anim/create-value 0)] + [container h + [header h] + [suggestions-view] ])) diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index 7c07c77636..08f3e8abf0 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -38,7 +38,6 @@ :phone-number ""} :disable-group-creation false :animations {:to-response-height 0.1 - :messages-offset 0 ;; todo clear this :tabs-bar-value (anim/create-value 0)}}) From e4309050b35c7178673728f05894e85668dd5365 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sat, 25 Jun 2016 21:30:43 +0300 Subject: [PATCH 24/53] some improvements Former-commit-id: 28a0d10367a52b3949592af80e672e808a4bbafd --- src/status_im/chat/handlers.cljs | 5 ++--- src/status_im/chat/handlers/animation.cljs | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 3d1d213cab..b7ff184891 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -305,9 +305,8 @@ (commands/unstage-command db staged-command))) (register-handler :set-chat-command - [(after #(dispatch [:command-edit-mode])) - ;(after #(dispatch [:animate-show-response])) - ] + [(after invoke-suggestions-handler!) + (after #(dispatch [:command-edit-mode]))] (fn [db [_ command-key]] (commands/set-chat-command db command-key))) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 80ca0ac379..b3faa364c4 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -16,11 +16,11 @@ (register-handler name [(path :animations) middleware] handler))) (animation-handler :animate-cancel-command - (after #(dispatch [:text-edit-mode])) - (fn [db _] - (assoc db - :to-response-height input-height - :messages-offset? false))) + (after #(dispatch [:text-edit-mode])) + (fn [db _] + (assoc db + :to-response-height input-height + :messages-offset? false))) (def response-height (+ input-height response-height-normal)) @@ -41,12 +41,14 @@ (if (and suggestions? (not= 0.1 current)) identity inc)))))) -(animation-handler :animate-show-response +(register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] - (fn [db] - (assoc db :messages-offset? true + (fn [{:keys [current-chat-id] :as db}] + (let [suggestions? (seq (get-in db [:suggestions current-chat-id])) + height (if suggestions? middle-height minimum-suggestion-height)] + (update db :animations assoc :messages-offset? true :messages-offset-max request-info-height - :to-response-height response-height))) + :to-response-height height)))) (defn fix-height [height-key height-signal-key suggestions-key minimum] @@ -72,7 +74,6 @@ (and under-middle-position? moving-down?) minimum)] - (println height-key new-fixed) (-> db (assoc-in [:animations height-key] new-fixed) (update-in [:animations height-signal-key] inc))))) From 2493000dfb8fb729928f9497125a8a5f4bbcb4f4 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sun, 26 Jun 2016 12:11:23 +0300 Subject: [PATCH 25/53] autoselect command Former-commit-id: 7f156a69cf6b28e43bf8e5de28cc0a8f28cfce1a --- src/status_im/chat/handlers.cljs | 13 +++++-- src/status_im/chat/handlers/animation.cljs | 45 +++++++++++----------- src/status_im/chat/subs.cljs | 10 +---- 3 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index b7ff184891..cca8759284 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -134,12 +134,18 @@ (defn check-suggestions [{:keys [current-chat-id] :as db} [_ text]] - (assoc-in db - [:command-suggestions current-chat-id] - (suggestions/get-suggestions db text))) + (let [suggestions (suggestions/get-suggestions db text)] + (assoc-in db [:command-suggestions current-chat-id] suggestions))) + +(defn select-suggestion! + [{:keys [current-chat-id] :as db} [_ text]] + (let [suggestions (get-in db [:command-suggestions current-chat-id])] + (when (= 1 (count suggestions)) + (dispatch [:set-chat-command (ffirst suggestions)])))) (register-handler :set-chat-input-text [(enrich update-command) + (after select-suggestion!) (enrich check-suggestions) (after #(dispatch [:animate-command-suggestions]))] update-text) @@ -497,6 +503,7 @@ (assoc-in db [:edit-mode current-chat-id] mode))) (register-handler :command-edit-mode + [(after #(dispatch [:set-chat-input-text ""]))] (edit-mode-handler :command)) (register-handler :text-edit-mode diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index b3faa364c4..4dd4af37dc 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -16,11 +16,11 @@ (register-handler name [(path :animations) middleware] handler))) (animation-handler :animate-cancel-command - (after #(dispatch [:text-edit-mode])) - (fn [db _] - (assoc db - :to-response-height input-height - :messages-offset? false))) + (after #(dispatch [:text-edit-mode])) + (fn [db _] + (assoc db + :to-response-height input-height + :messages-offset? false))) (def response-height (+ input-height response-height-normal)) @@ -30,8 +30,8 @@ (register-handler :animate-command-suggestions (fn [{:keys [current-chat-id] :as db} _] (let [suggestions? (seq (get-in db [:command-suggestions current-chat-id])) - current (get-in db [:animations :command-suggestions-height]) - height (if suggestions? middle-height 0.1)] + current (get-in db [:animations :command-suggestions-height]) + height (if suggestions? middle-height 0.1)] (-> db (update :animations assoc :messages-offset? suggestions? @@ -53,27 +53,26 @@ (defn fix-height [height-key height-signal-key suggestions-key minimum] (fn [{:keys [current-chat-id] :as db} [_ vy current]] - (let [max-height (get-in db [:layout-height]) - moving-down? (pos? vy) - moving-up? (not moving-down?) + (let [max-height (get-in db [:layout-height]) + moving-down? (pos? vy) + moving-up? (not moving-down?) under-middle-position? (<= current middle-height) - over-middle-position? (not under-middle-position?) - suggestions (get-in db [suggestions-key current-chat-id]) - new-fixed (cond (not suggestions) - minimum + over-middle-position? (not under-middle-position?) + suggestions (get-in db [suggestions-key current-chat-id]) + new-fixed (cond (not suggestions) + minimum - (and under-middle-position? moving-up?) - middle-height + (and under-middle-position? moving-up?) + middle-height - (and over-middle-position? moving-down?) - middle-height + (and over-middle-position? moving-down?) + middle-height - (and over-middle-position? moving-up?) - max-height + (and over-middle-position? moving-up?) + max-height - (and under-middle-position? - moving-down?) - minimum)] + (and under-middle-position? moving-down?) + minimum)] (-> db (assoc-in [:animations height-key] new-fixed) (update-in [:animations height-signal-key] inc))))) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 4d197b1aad..0c878b8057 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -1,15 +1,11 @@ (ns status-im.chat.subs (:require-macros [reagent.ratom :refer [reaction]]) (:require [re-frame.core :refer [register-sub dispatch subscribe path]] - [status-im.db :as db] - [status-im.chat.suggestions :refer - [get-suggestions typing-command?]] [status-im.models.commands :as commands] [status-im.constants :refer [response-suggesstion-resize-duration]] [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] - [status-im.chat.constants :as c])) + [status-im.chat.views.command :as command])) (register-sub :chat-properties (fn [db [_ properties]] @@ -111,10 +107,6 @@ (fn [db [_ chat-id]] (reaction (get-in @db [:chats chat-id])))) -(register-sub :typing-command? - (fn [db _] - (reaction (typing-command? @db)))) - (register-sub :get-content-suggestions (fn [db _] (reaction (get-in @db [:suggestions (:current-chat-id @db)])))) From f5464c18bfd8ded06ecea5d4f03e2eb0a2563d22 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 10:24:27 +0300 Subject: [PATCH 26/53] loading of console's commands.js without running server Former-commit-id: a3de75127aecc0ec3987c53bf3d067aff07e6ab1 --- src/status_im/commands/handlers/loading.cljs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index 74b08e7d86..417175bc8a 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -1,4 +1,5 @@ (ns status-im.commands.handlers.loading + (:require-macros [status-im.utils.slurp :refer [slurp]]) (:require [re-frame.core :refer [register-handler after dispatch subscribe trim-v debug]] [status-im.utils.handlers :as u] @@ -23,9 +24,11 @@ (defn fetch-commands! [db [identity]] (when-let [url (:dapp-url (get-in db [:chats identity]))] - (http-get (s/join "/" [url commands-js]) - #(dispatch [::validate-hash identity %]) - #(dispatch [::loading-failed! identity ::file-was-not-found])))) + (if (= "console" identity) + (dispatch [::validate-hash identity (slurp "resources/commands.js")]) + (http-get (s/join "/" [url commands-js]) + #(dispatch [::validate-hash identity %]) + #(dispatch [::loading-failed! identity ::file-was-not-found]))))) (defn dispatch-loaded! [db [identity file]] From eedd1c118622095d8137a1cc02d126224d005883 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 12:07:14 +0300 Subject: [PATCH 27/53] custom register-handler & response icon animation Former-commit-id: e7b328aa2742fa6645ff19fcaf8e93a052681026 --- src/status_im/chat/handlers.cljs | 4 +- src/status_im/chat/handlers/animation.cljs | 3 +- src/status_im/chat/styles/message.cljs | 8 +-- src/status_im/chat/views/message.cljs | 21 +------- src/status_im/chat/views/request_message.cljs | 50 +++++++------------ src/status_im/chat/views/response.cljs | 11 ++-- src/status_im/chat/views/suggestions.cljs | 11 ++-- src/status_im/commands/handlers/jail.cljs | 3 +- src/status_im/commands/utils.cljs | 5 +- src/status_im/handlers.cljs | 4 +- src/status_im/utils/handlers.cljs | 8 ++- 11 files changed, 51 insertions(+), 77 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index cca8759284..4181c2c587 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -1,5 +1,5 @@ (ns status-im.chat.handlers - (:require [re-frame.core :refer [register-handler enrich after debug dispatch]] + (:require [re-frame.core :refer [enrich after debug dispatch]] [status-im.models.commands :as commands] [clojure.string :as str] [status-im.components.styles :refer [default-chat-color]] @@ -12,7 +12,7 @@ [status-im.chat.sign-up :as sign-up-service] [status-im.models.chats :as chats] [status-im.navigation.handlers :as nav] - [status-im.utils.handlers :as u] + [status-im.utils.handlers :refer [register-handler] :as u] [status-im.persistence.realm :as r] [status-im.handlers.server :as server] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 4dd4af37dc..48715ee0a1 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -1,5 +1,6 @@ (ns status-im.chat.handlers.animation - (:require [re-frame.core :refer [register-handler after dispatch debug]] + (:require [re-frame.core :refer [after dispatch debug]] + [status-im.utils.handlers :refer [register-handler]] [re-frame.middleware :refer [path]] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.chat.constants :refer [input-height request-info-height diff --git a/src/status_im/chat/styles/message.cljs b/src/status_im/chat/styles/message.cljs index 5bb60573d4..76d4a91904 100644 --- a/src/status_im/chat/styles/message.cljs +++ b/src/status_im/chat/styles/message.cljs @@ -153,15 +153,13 @@ :backgroundColor (:color command) :transform [{:scale scale}]}) -(defn command-image-view - [command] +(def command-image-view {:position :absolute :top 0 :right 0 :width 24 :height 24 :borderRadius 50 - :backgroundColor (:color command) :alignItems :center}) (def command-request-image @@ -198,7 +196,9 @@ (def command-image {:margin-top 5 :width 12 - :height 13}) + :height 13 + :tintColor :#a9a9a9cc}) + (def command-text (merge style-message-text {:marginTop 8 diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 656cb72631..069a18e9da 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -69,7 +69,7 @@ (str "!" (:name command))]]] ;; todo doesn't reflect design (when-let [icon (:icon command)] - [view (st/command-image-view command) + [view st/command-image-view [image {:source {:uri icon} :style st/command-image}]]) (if preview @@ -84,25 +84,6 @@ (->> (when command (name command)) (str "request-"))) -;; todo remove (merging leftover) -#_(defview message-content-command-request - [{:keys [msg-id content from incoming-group]}] - [commands [:get-responses]] - (let [{:keys [command content]} (parse-command-request commands content)] - [touchable-highlight {:onPress #(set-chat-command msg-id command) - :accessibility-label (label command)} - [view st/comand-request-view - [view st/command-request-message-view - (when incoming-group - [text {:style st/command-request-from-text} from]) - [text {:style st/style-message-text} content]] - [view (st/command-request-image-view command) - [image {:source {:uri (:icon command)} - :style st/command-request-image}]] - (when-let [request-text (:request-text command)] - [view st/command-request-text-view - [text {:style st/style-sub-text} request-text]])]])) - (defn message-view [message content] [view (st/message-view message) diff --git a/src/status_im/chat/views/request_message.cljs b/src/status_im/chat/views/request_message.cljs index 0e5117769a..77e5834327 100644 --- a/src/status_im/chat/views/request_message.cljs +++ b/src/status_im/chat/views/request_message.cljs @@ -19,49 +19,37 @@ (->> (name command) (str "request-"))) -(defn request-button-animation-logic [{:keys [to-value val loop?]}] - (fn [_] - (let [loop? @loop? - minimum 1 - maximum 1.3 - to-scale (if loop? - (or @to-value maximum) - minimum)] - (anim/start - (anim/anim-sequence - [(anim/anim-delay (if loop? request-message-icon-scale-delay 0)) - (anim/spring val {:toValue to-scale})]) - (fn [arg] - (when (.-finished arg) - (dispatch [:set-animation ::request-button-scale-current to-scale]) - (when loop? - (dispatch [:set-animation ::request-button-scale (if (= to-scale minimum) - maximum - minimum)])))))))) +(def min-scale 1) +(def max-scale 1.3) + +(defn request-button-animation-logic + [{:keys [to-value val loop?] :as context}] + (anim/start + (anim/anim-sequence + [(anim/anim-delay (if @loop? request-message-icon-scale-delay 0)) + (anim/spring val {:toValue to-value})]) + #(when @loop? + (let [new-value (if (= to-value min-scale) max-scale min-scale) + context' (assoc context :to-value new-value)] + (request-button-animation-logic context'))))) (defn request-button [msg-id command] - (let [to-scale (subscribe [:animations ::request-button-scale]) - cur-scale (subscribe [:animations ::request-button-scale-current]) - scale-anim-val (anim/create-value (or @cur-scale 1)) + (let [scale-anim-val (anim/create-value min-scale) loop? (r/atom true) - context {:to-value to-scale + context {:to-value max-scale :val scale-anim-val - :loop? loop?} - on-update (request-button-animation-logic context)] + :loop? loop?}] (r/create-class {:component-did-mount - on-update - :component-did-update - on-update + #(request-button-animation-logic context) + :component-will-unmount + #(reset! loop? false) :reagent-render (fn [msg-id command] - @to-scale [touchable-highlight {:on-press (fn [] (reset! loop? false) (set-chat-command msg-id command)) :style st/command-request-image-touchable} - ;:accessibility-label (label command) - [animated-view {:style (st/command-request-image-view command scale-anim-val)} [image {:source {:uri (:icon command)} :style st/command-request-image}]]])}))) diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 71933d6d8d..03f5e3ce7c 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -83,11 +83,10 @@ [icon :close-white st/cancel-icon]]]]]))) (defn container-animation-logic [{:keys [to-value val]}] - (fn [_] - (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value - :tension 50 - :friction 10}))))) + (let [to-value @to-value] + (anim/start (anim/spring val {:toValue to-value + :tension 50 + :friction 10})))) (defn container [response-height & children] (let [;; todo to-response-height, cur-response-height must be specific @@ -96,7 +95,7 @@ changed (subscribe [:animations :response-height-changed]) context {:to-value to-response-height :val response-height} - on-update (container-animation-logic context)] + on-update #(container-animation-logic context)] (r/create-class {:component-did-mount on-update diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 3eba75a4ea..26b0cc7f94 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -93,11 +93,10 @@ [icon :drag_down st/drag-down-icon]]))) (defn container-animation-logic [{:keys [to-value val]}] - (fn [_] - (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value - :tension 50 - :friction 10}))))) + (let [to-value @to-value] + (anim/start (anim/spring val {:toValue to-value + :tension 50 + :friction 10})))) (defn container [h & elements] (let [;; todo to-response-height, cur-response-height must be specific @@ -106,7 +105,7 @@ changed (subscribe [:animations :commands-height-changed]) context {:to-value to-response-height :val h} - on-update (container-animation-logic context)] + on-update #(container-animation-logic context)] (r/create-class {:component-did-mount on-update diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index b2d1ac67af..d5852f5ee7 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -1,6 +1,5 @@ (ns status-im.commands.handlers.jail - (:require [re-frame.core :refer [register-handler after dispatch subscribe - trim-v debug]] + (:require [re-frame.core :refer [after dispatch subscribe trim-v debug]] [status-im.utils.handlers :as u] [status-im.utils.utils :refer [http-get toast]] [status-im.components.jail :as j] diff --git a/src/status_im/commands/utils.cljs b/src/status_im/commands/utils.cljs index 8ae48bf0e7..ca03a910cf 100644 --- a/src/status_im/commands/utils.cljs +++ b/src/status_im/commands/utils.cljs @@ -3,7 +3,8 @@ [clojure.walk :as w] [status-im.components.react :refer [text scroll-view view image touchable-highlight]] - [re-frame.core :refer [register-handler dispatch trim-v debug]])) + [re-frame.core :refer [register-handler dispatch trim-v debug]] + [status-im.utils.handlers :refer [register-handler]])) (defn json->clj [json] (if (= json "undefined") @@ -44,4 +45,4 @@ (defn reg-handler ([name handler] (reg-handler name nil handler)) ([name middleware handler] - (register-handler name [#_debug trim-v middleware] handler))) + (register-handler name [trim-v middleware] handler))) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index f229403e07..789d2256e0 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -1,13 +1,13 @@ (ns status-im.handlers (:require - [re-frame.core :refer [register-handler after dispatch debug]] + [re-frame.core :refer [after dispatch debug]] [schema.core :as s :include-macros true] [status-im.db :refer [app-db schema]] [status-im.persistence.simple-kv-store :as kv] [status-im.protocol.state.storage :as storage] [status-im.utils.logging :as log] [status-im.utils.crypt :refer [gen-random-bytes]] - [status-im.utils.handlers :as u] + [status-im.utils.handlers :refer [register-handler] :as u] status-im.chat.handlers status-im.chat.handlers.animation status-im.group-settings.handlers diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index f14ce02a79..083196375e 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -1,4 +1,5 @@ -(ns status-im.utils.handlers) +(ns status-im.utils.handlers + (:require [re-frame.core :refer [after dispatch debug] :as re-core])) (defn side-effect! "Middleware for handlers that will not affect db." @@ -6,3 +7,8 @@ (fn [db params] (handler db params) db)) + +(defn register-handler + ([name handler] (register-handler name nil handler)) + ([name middleware handler] + (re-core/register-handler name [#_debug middleware] handler))) From 6f9881af55349b63bceeb67387bbc74dabe420a4 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 12:22:52 +0300 Subject: [PATCH 28/53] tint-color for response's icon Former-commit-id: 3289053ff86022ffdfaecf248452c6073af864c1 --- src/status_im/chat/styles/message.cljs | 41 +++++++++++++------------- src/status_im/chat/views/message.cljs | 2 +- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/status_im/chat/styles/message.cljs b/src/status_im/chat/styles/message.cljs index 5bb60573d4..93f1472389 100644 --- a/src/status_im/chat/styles/message.cljs +++ b/src/status_im/chat/styles/message.cljs @@ -1,15 +1,15 @@ (ns status-im.chat.styles.message (:require [status-im.components.styles :refer [font - color-light-blue-transparent - color-white - color-black - color-blue - selected-message-color - online-color - text1-color - text2-color]] + color-light-blue-transparent + color-white + color-black + color-blue + selected-message-color + online-color + text1-color + text2-color]] [status-im.constants :refer [text-content-type - content-type-command]])) + content-type-command]])) (def style-message-text {:fontSize 14 @@ -153,16 +153,13 @@ :backgroundColor (:color command) :transform [{:scale scale}]}) -(defn command-image-view - [command] - {:position :absolute - :top 0 - :right 0 - :width 24 - :height 24 - :borderRadius 50 - :backgroundColor (:color command) - :alignItems :center}) +(def command-image-view + {:position :absolute + :top 0 + :right 0 + :width 24 + :height 24 + :alignItems :center}) (def command-request-image {:position :absolute @@ -197,8 +194,10 @@ (def command-image {:margin-top 5 - :width 12 - :height 13}) + :width 12 + :height 13 + :tint-color :#a9a9a9cc}) + (def command-text (merge style-message-text {:marginTop 8 diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 656cb72631..87dc476731 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -69,7 +69,7 @@ (str "!" (:name command))]]] ;; todo doesn't reflect design (when-let [icon (:icon command)] - [view (st/command-image-view command) + [view st/command-image-view [image {:source {:uri icon} :style st/command-image}]]) (if preview From b1e8a6c30fc6746830d1dcd375ac527a1ebc07e9 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 12:33:46 +0300 Subject: [PATCH 29/53] fix exclamation mark for response messages Former-commit-id: 2894baa0e10b8c8b199524b4071b7710f8c92c58 --- src/status_im/chat/views/message.cljs | 36 +++++++++----------- src/status_im/commands/handlers/loading.cljs | 9 +++-- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 87dc476731..bed514f2f9 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -56,26 +56,22 @@ [view st/track-mark] [text {:style st/track-duration-text} "03:39"]]]) -(defn message-content-command [content preview] - (let [commands-atom (subscribe [:get-commands-and-responses])] - (fn [content preview] - (let [commands @commands-atom - {:keys [command content]} - (parse-command-msg-content commands content)] - [view st/content-command-view - [view st/command-container - [view (st/command-view command) - [text {:style st/command-name} - (str "!" (:name command))]]] - ;; todo doesn't reflect design - (when-let [icon (:icon command)] - [view st/command-image-view - [image {:source {:uri icon} - :style st/command-image}]]) - (if preview - preview - [text {:style st/command-text} - content])])))) +(defview message-content-command [content preview] + [commands [:get-commands-and-responses]] + (let [{:keys [command content]} (parse-command-msg-content commands content) + {:keys [name icon type]} command] + [view st/content-command-view + [view st/command-container + [view (st/command-view command) + [text {:style st/command-name} + (str (if (= :command type) "!" "") name)]]] + (when icon + [view st/command-image-view + [image {:source {:uri icon} + :style st/command-image}]]) + (if preview + preview + [text {:style st/command-text} content])])) (defn set-chat-command [msg-id command] (dispatch [:set-response-chat-command msg-id (keyword (:name command))])) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index 417175bc8a..2291ade0fc 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -61,11 +61,16 @@ (get-hash-by-file file))] (assoc db ::valid-hash valid?))) +(defn mark-as [as coll] + (->> coll + (map (fn [[k v]] [k (assoc v :type as)])) + (into {}))) + (defn add-commands [db [id _ {:keys [commands responses]}]] (-> db - (update-in [:chats id :commands] merge commands) - (update-in [:chats id :responses] merge responses))) + (update-in [:chats id :commands] merge (mark-as :command commands)) + (update-in [:chats id :responses] merge (mark-as :response responses)))) (defn save-commands-js! [_ [id file]] From f382e543c49c98b43dc4b1ccd2009c6c5f55cee4 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 14:35:33 +0300 Subject: [PATCH 30/53] cleanup debug & simplify messages-offset Former-commit-id: de5eb9bee0ea89eca46a5b55e593c94a56b7029f --- src/status_im/chat/constants.cljs | 4 +- src/status_im/chat/handlers.cljs | 3 +- src/status_im/chat/handlers/animation.cljs | 21 +++------ src/status_im/chat/screen.cljs | 55 ++++++++++------------ src/status_im/chat/subs.cljs | 12 ++++- src/status_im/handlers.cljs | 8 +--- src/status_im/utils/handlers.cljs | 2 +- 7 files changed, 51 insertions(+), 54 deletions(-) diff --git a/src/status_im/chat/constants.cljs b/src/status_im/chat/constants.cljs index f37aff957e..d61bd707ca 100644 --- a/src/status_im/chat/constants.cljs +++ b/src/status_im/chat/constants.cljs @@ -4,4 +4,6 @@ (def request-info-height 61) (def response-height-normal 211) (def minimum-suggestion-height (+ input-height request-info-height)) -(def minimum-command-suggestions-height (+ input-height 22)) +(def suggestions-header-height 22) +(def minimum-command-suggestions-height + (+ input-height suggestions-header-height)) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 4181c2c587..70c7f50de7 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -366,8 +366,7 @@ (register-handler :init-chat (-> load-messages! ((enrich init-chat)) - ((after load-commands!)) - debug)) + ((after load-commands!)))) (defn initialize-chats [{:keys [loaded-chats] :as db} _] diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 48715ee0a1..76047831af 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -19,9 +19,7 @@ (animation-handler :animate-cancel-command (after #(dispatch [:text-edit-mode])) (fn [db _] - (assoc db - :to-response-height input-height - :messages-offset? false))) + (assoc db :to-response-height input-height))) (def response-height (+ input-height response-height-normal)) @@ -32,24 +30,19 @@ (fn [{:keys [current-chat-id] :as db} _] (let [suggestions? (seq (get-in db [:command-suggestions current-chat-id])) current (get-in db [:animations :command-suggestions-height]) - height (if suggestions? middle-height 0.1)] + height (if suggestions? middle-height 0.1) + changed? (if (and suggestions? (not= 0.1 current)) + identity inc)] (-> db - (update :animations assoc - :messages-offset? suggestions? - :messages-offset-max 22 - :command-suggestions-height height) - (update-in [:animations :commands-height-changed] - (if (and suggestions? (not= 0.1 current)) - identity inc)))))) + (update :animations assoc :command-suggestions-height height) + (update-in [:animations :commands-height-changed] changed?))))) (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] (fn [{:keys [current-chat-id] :as db}] (let [suggestions? (seq (get-in db [:suggestions current-chat-id])) height (if suggestions? middle-height minimum-suggestion-height)] - (update db :animations assoc :messages-offset? true - :messages-offset-max request-info-height - :to-response-height height)))) + (assoc-in db [:animations :to-response-height] height)))) (defn fix-height [height-key height-signal-key suggestions-key minimum] diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 71718746cf..0652d5109d 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -41,10 +41,10 @@ :background-color background-color)))) (defview chat-icon [] - [chat-id [:chat :chat-id] + [chat-id [:chat :chat-id] group-chat [:chat :group-chat] - name [:chat :name] - color [:chat :color]] + name [:chat :name] + color [:chat :color]] ;; TODO stub data ('online' property) [chat-icon-view-action chat-id group-chat name color true]) @@ -98,10 +98,10 @@ subtitle])]]]) (defview menu-item-icon-profile [] - [chat-id [:chat :chat-id] + [chat-id [:chat :chat-id] group-chat [:chat :group-chat] - name [:chat :name] - color [:chat :color]] + name [:chat :name] + color [:chat :color]] ;; TODO stub data ('online' property) [chat-icon-view-menu-item chat-id group-chat name color true]) @@ -140,12 +140,12 @@ :icon-style {:width 20 :height 13} :handler #(dispatch [:show-group-settings])}] - [{:title (label :t/profile) + [{:title (label :t/profile) :custom-icon [menu-item-icon-profile] - :icon :menu_group - :icon-style {:width 25 - :height 19} - :handler #(dispatch [:show-profile @chat-id])} + :icon :menu_group + :icon-style {:width 25 + :height 19} + :handler #(dispatch [:show-profile @chat-id])} {:title (label :t/search-chat) :subtitle (label :t/not-implemented) :icon :search_gray_copy @@ -218,29 +218,26 @@ :custom-action [toolbar-action]}]))) (defview messages-view [group-chat] - [messages [:chat :messages] - contacts [:chat :contacts]] - (let [contacts' (contacts-by-identity contacts)] - [list-view {:renderRow (message-row contacts' group-chat (count messages)) - :renderScrollComponent #(invertible-scroll-view (js->clj %)) - :onEndReached #(dispatch [:load-more-messages]) - :enableEmptySections true - :keyboardShouldPersistTaps true - :dataSource (to-datasource-inverted messages)}])) + [messages [:chat :messages] + contacts [:chat :contacts]] + (let [contacts' (contacts-by-identity contacts)] + [list-view {:renderRow (message-row contacts' group-chat (count messages)) + :renderScrollComponent #(invertible-scroll-view (js->clj %)) + :onEndReached #(dispatch [:load-more-messages]) + :enableEmptySections true + :keyboardShouldPersistTaps true + :dataSource (to-datasource-inverted messages)}])) (defn messages-container-animation-logic - [{:keys [offset? val max]}] + [{:keys [offset val]}] (fn [_] - (let [to-value (if @offset? @max 0)] - (anim/start (anim/spring val {:toValue to-value}))))) + (anim/start (anim/spring val {:toValue @offset})))) (defn messages-container [messages] - (let [messages-offset? (subscribe [:animations :messages-offset?]) - maximum-offset (subscribe [:animations :messages-offset-max]) + (let [offset (subscribe [:messages-offset]) messages-offset (anim/create-value 0) - context {:offset? messages-offset? - :val messages-offset - :max maximum-offset} + context {:offset offset + :val messages-offset} on-update (messages-container-animation-logic context)] (r/create-class {:component-did-mount @@ -249,7 +246,7 @@ on-update :reagent-render (fn [messages] - @messages-offset? + @offset [animated-view {:style (st/messages-container messages-offset)} messages])}))) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 0c878b8057..c5340917e0 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -3,6 +3,7 @@ (:require [re-frame.core :refer [register-sub dispatch subscribe path]] [status-im.models.commands :as commands] [status-im.constants :refer [response-suggesstion-resize-duration]] + [status-im.chat.constants :as c] [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])) @@ -72,7 +73,7 @@ (register-sub :valid-plain-message? (fn [_ _] - (let [input-message (subscribe [:get-chat-input-text]) + (let [input-message (subscribe [:get-chat-input-text]) staged-commands (subscribe [:get-chat-staged-commands])] (reaction (plain-message/message-valid? @staged-commands @input-message))))) @@ -116,3 +117,12 @@ (->> (get-in @db [:edit-mode (:current-chat-id @db)]) (= :command) (reaction)))) + +(register-sub :messages-offset + (fn [] + (let [command? (subscribe [:command?]) + suggestions (subscribe [:get-suggestions])] + ;; todo fix magic values + (reaction (cond @command? c/request-info-height + (seq @suggestions) c/suggestions-header-height + :else 0))))) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 789d2256e0..7829563fe5 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -40,16 +40,12 @@ (defn set-el [db [_ k v]] (assoc db k v)) -(register-handler :set - debug - set-el) +(register-handler :set set-el) (defn set-in [db [_ path v]] (assoc-in db path v)) -(register-handler :set-in - debug - set-in) +(register-handler :set-in set-in) (register-handler :set-animation (fn [db [_ k v]] diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 083196375e..4d2777e335 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -11,4 +11,4 @@ (defn register-handler ([name handler] (register-handler name nil handler)) ([name middleware handler] - (re-core/register-handler name [#_debug middleware] handler))) + (re-core/register-handler name [debug middleware] handler))) From bebe03fca9565948ea59b34580f23b80995b5c46 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 14:58:37 +0300 Subject: [PATCH 31/53] fix duplication a bit Former-commit-id: 103b6ba0eb331c30b329be00cbd693a148132e44 --- src/status_im/chat/suggestions_responder.cljs | 39 ++++++++++++ src/status_im/chat/views/response.cljs | 59 ++++-------------- src/status_im/chat/views/suggestions.cljs | 60 +++++-------------- src/status_im/utils/handlers.cljs | 2 +- 4 files changed, 67 insertions(+), 93 deletions(-) create mode 100644 src/status_im/chat/suggestions_responder.cljs diff --git a/src/status_im/chat/suggestions_responder.cljs b/src/status_im/chat/suggestions_responder.cljs new file mode 100644 index 0000000000..eebdd45608 --- /dev/null +++ b/src/status_im/chat/suggestions_responder.cljs @@ -0,0 +1,39 @@ +(ns status-im.chat.suggestions-responder + (:require [status-im.components.drag-drop :as drag] + [status-im.components.animation :as anim] + [status-im.components.react :as react] + [re-frame.core :refer [dispatch]])) + +;; todo bad name. Ideas? +(defn enough-dy [gesture] + (> (Math/abs (.-dy gesture)) 10)) + +(defn on-move [response-height kb-height orientation] + (fn [_ gesture] + (when (enough-dy gesture) + (let [w (react/get-dimensions "window") + ;; depending on orientation use height or width of screen + prop (if (= :portrait @orientation) + :height + :width) + ;; subtract keyboard height to get "real height" of screen + ;; then subtract gesture position to get suggestions height + ;; todo maybe it is better to use margin-top instead height + ;; it is not obvious + to-value (- (prop w) @kb-height (.-moveY gesture))] + (anim/start + (anim/spring response-height {:toValue to-value})))))) + +(defn on-release [response-height handler-name] + (fn [_ gesture] + (when (enough-dy gesture) + (dispatch [handler-name + (.-vy gesture) + ;; todo access to "private" property + ;; better to find another way... + (.-_value response-height)])))) + +(defn pan-responder [response-height kb-height orientation handler-name] + (drag/create-pan-responder + {:on-move (on-move response-height kb-height orientation) + :on-release (on-release response-height handler-name)})) diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index 03f5e3ce7c..b81763c9f6 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -13,7 +13,7 @@ [status-im.components.drag-drop :as drag] [status-im.chat.styles.response :as st] [status-im.components.animation :as anim] - [status-im.components.react :as react])) + [status-im.chat.suggestions-responder :as resp])) (defn drag-icon [] [view st/drag-container @@ -32,45 +32,14 @@ ;; TODO stub data: request message info "By ???, MMM 1st at HH:mm"]]) -;; todo bad name. Ideas? -(defn enough-dy [gesture] - (> (Math/abs (.-dy gesture)) 10)) - -(defn on-move [response-height kb-height orientation] - (fn [_ gesture] - (when (enough-dy gesture) - (let [w (react/get-dimensions "window") - ;; depending on orientation use height or width of screen - prop (if (= :portrait @orientation) - :height - :width) - ;; subtract keyboard height to get "real height" of screen - ;; then subtract gesture position to get suggestions height - ;; todo maybe it is better to use margin-top instead height - ;; it is not obvious - to-value (- (prop w) @kb-height (.-moveY gesture))] - (anim/start - (anim/spring response-height {:toValue to-value})))))) - -(defn on-release [response-height] - (fn [_ gesture] - (when (enough-dy gesture) - (dispatch [:fix-response-height - (.-vy gesture) - ;; todo access to "private" property - ;; better to find another way... - (.-_value response-height)])))) - -(defn pan-responder [response-height kb-height orientation] - (drag/create-pan-responder - {:on-move (on-move response-height kb-height orientation) - :on-release (on-release response-height)})) - (defn request-info [response-height] - (let [orientation (subscribe [:get :orientation]) - kb-height (subscribe [:get :keyboard-height]) - pan-responder (pan-responder response-height kb-height orientation) - command (subscribe [:get-chat-command])] + (let [orientation (subscribe [:get :orientation]) + kb-height (subscribe [:get :keyboard-height]) + pan-responder (resp/pan-responder response-height + kb-height + orientation + :fix-response-height) + command (subscribe [:get-chat-command])] (fn [response-height] [view (merge (drag/pan-handlers pan-responder) {:style (st/request-info (:color @command))}) @@ -84,18 +53,16 @@ (defn container-animation-logic [{:keys [to-value val]}] (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value - :tension 50 - :friction 10})))) + (anim/start (anim/spring val {:toValue to-value})))) (defn container [response-height & children] (let [;; todo to-response-height, cur-response-height must be specific ;; for each chat to-response-height (subscribe [:animations :to-response-height]) - changed (subscribe [:animations :response-height-changed]) - context {:to-value to-response-height - :val response-height} - on-update #(container-animation-logic context)] + changed (subscribe [:animations :response-height-changed]) + context {:to-value to-response-height + :val response-height} + on-update #(container-animation-logic context)] (r/create-class {:component-did-mount on-update diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 26b0cc7f94..38336670fc 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -13,7 +13,8 @@ [reagent.core :as r] [status-im.components.animation :as anim] [status-im.components.drag-drop :as drag] - [status-im.components.react :as react])) + [status-im.components.react :as react] + [status-im.chat.suggestions-responder :as resp])) (defn set-command-input [command] (dispatch [:set-chat-command command])) @@ -48,64 +49,31 @@ :keyboardShouldPersistTaps true :renderRow render-row}]])}))) -;; todo bad name. Ideas? -(defn enough-dy [gesture] - (> (Math/abs (.-dy gesture)) 10)) - -(defn on-move [response-height kb-height orientation] - (fn [_ gesture] - (when (enough-dy gesture) - (let [w (react/get-dimensions "window") - ;; depending on orientation use height or width of screen - prop (if (= :portrait @orientation) - :height - :width) - ;; subtract keyboard height to get "real height" of screen - ;; then subtract gesture position to get suggestions height - ;; todo maybe it is better to use margin-top instead height - ;; it is not obvious - to-value (- (prop w) @kb-height (.-moveY gesture))] - (anim/start - (anim/spring response-height {:toValue to-value})))))) - -(defn on-release [response-height] - (fn [_ gesture] - (when (enough-dy gesture) - (dispatch [:fix-commands-suggestions-height - (.-vy gesture) - ;; todo access to "private" property - ;; better to find another way... - (.-_value response-height)])))) - -(defn pan-responder [response-height kb-height orientation] - (drag/create-pan-responder - {:on-move (on-move response-height kb-height orientation) - :on-release (on-release response-height)})) - (defn header [h] (let [orientation (subscribe [:get :orientation]) - kb-height (subscribe [:get :keyboard-height]) - pan-responder (pan-responder h kb-height orientation)] + kb-height (subscribe [:get :keyboard-height]) + pan-responder (resp/pan-responder h + kb-height + orientation + :fix-commands-suggestions-height)] (fn [_] [view (merge (drag/pan-handlers pan-responder) - {:style st/drag-down-touchable}) + {:style st/drag-down-touchable}) [icon :drag_down st/drag-down-icon]]))) (defn container-animation-logic [{:keys [to-value val]}] (let [to-value @to-value] - (anim/start (anim/spring val {:toValue to-value - :tension 50 - :friction 10})))) + (anim/start (anim/spring val {:toValue to-value})))) (defn container [h & elements] (let [;; todo to-response-height, cur-response-height must be specific ;; for each chat to-response-height (subscribe [:animations :command-suggestions-height]) - changed (subscribe [:animations :commands-height-changed]) - context {:to-value to-response-height - :val h} - on-update #(container-animation-logic context)] + changed (subscribe [:animations :commands-height-changed]) + context {:to-value to-response-height + :val h} + on-update #(container-animation-logic context)] (r/create-class {:component-did-mount on-update @@ -120,4 +88,4 @@ (let [h (anim/create-value 0)] [container h [header h] - [suggestions-view] ])) + [suggestions-view]])) diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 4d2777e335..083196375e 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -11,4 +11,4 @@ (defn register-handler ([name handler] (register-handler name nil handler)) ([name middleware handler] - (re-core/register-handler name [debug middleware] handler))) + (re-core/register-handler name [#_debug middleware] handler))) From 4e25602eba60d709c96367bbd7caa5f935fb6e2d Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 15:12:53 +0300 Subject: [PATCH 32/53] cleanup Former-commit-id: 70f204681b94eeed4bde0aaf970a4a0e53058452 --- src/status_im/chat/handlers.cljs | 42 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index c1627a957e..ffe6830993 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -46,10 +46,10 @@ (defn invoke-suggestions-handler! [{:keys [current-chat-id] :as db} _] - (let [commands (get-in db [:chats current-chat-id :commands]) - {:keys [command content]} (get-in db [:chats current-chat-id :command-input]) - path [(if (commands command) :commands :responses) - (:name command) + (let [{:keys [command content]} (get-in db [:chats current-chat-id :command-input]) + {:keys [name type]} command + path [(if (= :command type) :commands :responses) + name :params 0 :suggestions] @@ -78,11 +78,11 @@ (assoc-in db [:chats current-chat-id :input-text] text)) (defn invoke-command-preview! - [{:keys [current-chat-id staged-command] :as db} _] - (let [commands (get-in db [:chats current-chat-id :commands]) - {:keys [command content]} staged-command - path [(if (commands command) :commands :responses) - (:name command) + [{:keys [current-chat-id staged-command]} _] + (let [{:keys [command content]} staged-command + {:keys [name type]} command + path [(if (= :command type) :commands :responses) + name :preview] params {:value content}] (j/call current-chat-id @@ -258,18 +258,18 @@ (dissoc new-command :rendered-preview)))) (defn invoke-commands-handlers! - [{:keys [new-commands current-chat-id] :as db}] - (let [commands (get-in db [:chats current-chat-id :commands])] - (doseq [{:keys [content] :as com} new-commands] - (let [{:keys [command content]} content - path [(if (commands command) :commands :responses) - command - :handler] - params {:value content}] - (j/call current-chat-id - path - params - #(dispatch [:command-handler! com %])))))) + [{:keys [new-commands current-chat-id]}] + (doseq [{:keys [content] :as com} new-commands] + (let [{:keys [command content]} content + type (:type command) + path [(if (= :command type) :commands :responses) + command + :handler] + params {:value content}] + (j/call current-chat-id + path + params + #(dispatch [:command-handler! com %]))))) (defn handle-commands [{:keys [new-commands]}] From a987ffee7ce1249764077df4699aa4187b374cdf Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 16:44:54 +0300 Subject: [PATCH 33/53] missed conflict Former-commit-id: 8d13f5dc3686e7b98548593ae1b0d2089bf74f8b --- src/status_im/models/messages.cljs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/status_im/models/messages.cljs b/src/status_im/models/messages.cljs index 8bf815e520..c010719ab1 100644 --- a/src/status_im/models/messages.cljs +++ b/src/status_im/models/messages.cljs @@ -47,24 +47,6 @@ #{c/content-type-command c/content-type-command-request} type)) -<<<<<<< HEAD -(defn get-messages [chat-id] - (->> (-> (r/get-by-field :msgs :chat-id chat-id) - (r/sorted :timestamp :desc) - (r/collection->map)) - (into '()) - ;; todo why reverse? - reverse - (map (fn [{:keys [content-type preview] :as message}] - (if (command-type? content-type) - (-> message - (update :content str-to-map) - (assoc :rendered-preview (when preview - (generate-hiccup - (read-string preview)))) - (dissoc :preview)) - message))))) -======= (defn get-messages ([chat-id] (get-messages chat-id 0)) ([chat-id from] @@ -78,7 +60,6 @@ (if (command-type? content-type) (update message :content str-to-map) message)))))) ->>>>>>> develop (defn update-message! [{:keys [msg-id] :as msg}] (log/debug "update-message!" msg) From 5e94fb9b7b255fd9534ad49c2d7594787f8b42b6 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 18:38:44 +0300 Subject: [PATCH 34/53] first parameter Former-commit-id: 013e4e79ae3c7336c5b6a4d502cd7aa25e1bc1c5 --- resources/commands.js | 10 +++++---- resources/status.js | 5 +++-- src/status_im/android/core.cljs | 1 - src/status_im/chat/subs.cljs | 9 ++++++++ src/status_im/chat/views/new_message.cljs | 26 +++++++++++++---------- src/status_im/models/commands.cljs | 7 +++--- 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/resources/commands.js b/resources/commands.js index 94c631b979..ee5cac345b 100644 --- a/resources/commands.js +++ b/resources/commands.js @@ -4,7 +4,8 @@ status.command({ color: "#9a5dcf" }).param({ name: "address", - type: status.types.STRING + type: status.types.TEXT, + placeholder: "Address" }); var phones = [ @@ -110,8 +111,9 @@ status.response({ color: "#5fc48d", params: [{ name: "phone", - type: status.types.PHONE_NUMBER, - suggestions: phoneSuggestions + type: status.types.PHONE, + suggestions: phoneSuggestions, + placeholder: "Phone number" }], handler: function (params) { return { @@ -127,7 +129,7 @@ status.command({ color: "#7099e6", params: [{ name: "query", - type: status.types.STRING + type: status.types.TEXT }] }); diff --git a/resources/status.js b/resources/status.js index 924decbf47..2eec9a3d44 100644 --- a/resources/status.js +++ b/resources/status.js @@ -92,8 +92,9 @@ var status = { return response.create(n, d, h); }, types: { - STRING: 'string', - PHONE_NUMBER: 'phone-number', + TEXT: 'text', + NUMBER: 'number', + PHONE: 'phone', PASSWORD: 'password' }, events: { diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index e20c9fcfc1..e69e22cc2f 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -82,7 +82,6 @@ (dispatch [:initialize-protocol]) (dispatch [:load-user-phone-number]) (dispatch [:load-contacts]) - ;; load commands from remote server (todo: uncomment) (dispatch [:init-console-chat]) (dispatch [:init-chat]) (init-back-button-handler!) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index c5340917e0..b9f08f0402 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -87,6 +87,15 @@ (fn [db _] (reaction (commands/get-chat-command @db)))) +(register-sub :get-command-parameter + (fn [db] + (let [command (subscribe [:get-chat-command]) + chat-id (subscribe [:get-current-chat-id])] + (reaction + (let [path [:chats @chat-id :command-input :parameter-idx] + n (get-in @db path)] + (when n (nth (:params @command) n))))))) + (register-sub :get-chat-command-content (fn [db _] (reaction (commands/get-chat-command-content @db)))) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 1434651b1f..2a1e2cd892 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -16,20 +16,24 @@ (for [command staged-commands] ^{:key command} [staged-command-view command])]) +(defn get-options [{:keys [type placeholder]}] + (let [options (case (keyword type) + :phone {:input-options {:keyboardType :phone-pad} + :validator valid-mobile-number?} + :password {:input-options {:secureTextEntry true}} + :number {:input-options {:keyboardType :numeric}} + ;; todo maybe nil is fine for now :) + nil #_(throw (js/Error. "Uknown command type")))] + (println :plc placeholder) + (if placeholder + (assoc-in options [:input-options :placeholder] placeholder) + options))) + (defview show-input [] - [command [:get-chat-command] + [parameter [:get-command-parameter] command? [:command?]] [plain-message-input-view - (when command? - (case (keyword (:name command)) - :phone {:input-options {:keyboardType :phone-pad} - :validator valid-mobile-number?} - :keypair {:input-options {:secureTextEntry true}} - :confirmation-code {:input-options {:keyboardType :numeric}} - :money {:input-options {:keyboardType :numeric}} - :request {:input-options {:keyboardType :numeric}} - ;; todo maybe nil is fine for now :) - nil #_(throw (js/Error. "Uknown command type"))))]) + (when command? (get-options parameter))]) (defview chat-message-new [] [staged-commands [:get-chat-staged-commands]] diff --git a/src/status_im/models/commands.cljs b/src/status_im/models/commands.cljs index aa426640eb..1ebb70dccb 100644 --- a/src/status_im/models/commands.cljs +++ b/src/status_im/models/commands.cljs @@ -34,9 +34,10 @@ (defn set-response-chat-command [{:keys [current-chat-id] :as db} msg-id command-key] (update-in db [:chats current-chat-id :command-input] merge - {:content nil - :command (get-command db command-key) - :to-msg-id msg-id})) + {:content nil + :command (get-command db command-key) + :parameter-idx 0 + :to-msg-id msg-id})) (defn set-chat-command [db command-key] (set-response-chat-command db nil command-key)) From 7c50d95cef097389b6644fbb642b71d853915bb7 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 09:27:21 +0300 Subject: [PATCH 35/53] commands input Former-commit-id: e6414c7101ccc6ece44a059e07e49e7d68f580c1 --- src/status_im/chat/handlers/animation.cljs | 20 ++++++++++++---- .../chat/styles/content_suggestions.cljs | 9 -------- src/status_im/chat/styles/dragdown.cljs | 12 ++++++++++ src/status_im/chat/styles/input.cljs | 4 ++-- src/status_im/chat/styles/suggestions.cljs | 10 -------- src/status_im/chat/subs.cljs | 10 +++++--- src/status_im/chat/views/command.cljs | 2 +- src/status_im/chat/views/message_input.cljs | 3 +++ src/status_im/chat/views/response.cljs | 23 +++++++++++-------- src/status_im/chat/views/suggestions.cljs | 5 ++-- 10 files changed, 57 insertions(+), 41 deletions(-) create mode 100644 src/status_im/chat/styles/dragdown.cljs diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 76047831af..837991d98b 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -37,11 +37,21 @@ (update :animations assoc :command-suggestions-height height) (update-in [:animations :commands-height-changed] changed?))))) +(defn get-minimum-height + [{:keys [current-chat-id] :as db}] + (let [path [:chats current-chat-id :command-input :command :type] + type (get-in db path)] + (if (= :response type) + minimum-suggestion-height + minimum-command-suggestions-height))) + (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] (fn [{:keys [current-chat-id] :as db}] (let [suggestions? (seq (get-in db [:suggestions current-chat-id])) - height (if suggestions? middle-height minimum-suggestion-height)] + height (if suggestions? + middle-height + (get-minimum-height db))] (assoc-in db [:animations :to-response-height] height)))) (defn fix-height @@ -54,7 +64,7 @@ over-middle-position? (not under-middle-position?) suggestions (get-in db [suggestions-key current-chat-id]) new-fixed (cond (not suggestions) - minimum + (minimum db) (and under-middle-position? moving-up?) middle-height @@ -66,7 +76,7 @@ max-height (and under-middle-position? moving-down?) - minimum)] + (minimum db))] (-> db (assoc-in [:animations height-key] new-fixed) (update-in [:animations height-signal-key] inc))))) @@ -75,10 +85,10 @@ (fix-height :command-suggestions-height :commands-height-changed :command-suggestions - minimum-command-suggestions-height)) + (constantly minimum-command-suggestions-height))) (register-handler :fix-response-height (fix-height :to-response-height :response-height-changed :suggestions - minimum-suggestion-height)) + get-minimum-height)) diff --git a/src/status_im/chat/styles/content_suggestions.cljs b/src/status_im/chat/styles/content_suggestions.cljs index 99c64afc20..97c403bca7 100644 --- a/src/status_im/chat/styles/content_suggestions.cljs +++ b/src/status_im/chat/styles/content_suggestions.cljs @@ -45,12 +45,3 @@ (def container {:backgroundColor color-white}) - -(def drag-down-touchable - {:height 22 - :alignItems :center - :justifyContent :center}) - -(def drag-down-icon - {:width 16 - :height 16}) diff --git a/src/status_im/chat/styles/dragdown.cljs b/src/status_im/chat/styles/dragdown.cljs new file mode 100644 index 0000000000..7505021a6f --- /dev/null +++ b/src/status_im/chat/styles/dragdown.cljs @@ -0,0 +1,12 @@ +(ns status-im.chat.styles.dragdown + (:require [status-im.components.styles :refer [color-white]])) + +(def drag-down-touchable + {:height 22 + :background-color color-white + :alignItems :center + :justifyContent :center}) + +(def drag-down-icon + {:width 16 + :height 16}) diff --git a/src/status_im/chat/styles/input.cljs b/src/status_im/chat/styles/input.cljs index 53e02cb16e..50f6fbfba7 100644 --- a/src/status_im/chat/styles/input.cljs +++ b/src/status_im/chat/styles/input.cljs @@ -21,8 +21,8 @@ {:flexDirection :column :marginTop 16 :marginBottom 16 - :marginLeft 16 - :marginRight 0 + :marginLeft 0 + :marginRight 8 :backgroundColor color :height 24 :borderRadius 50}) diff --git a/src/status_im/chat/styles/suggestions.cljs b/src/status_im/chat/styles/suggestions.cljs index 2d1d89525f..2e97d206b1 100644 --- a/src/status_im/chat/styles/suggestions.cljs +++ b/src/status_im/chat/styles/suggestions.cljs @@ -68,13 +68,3 @@ :height height :backgroundColor color-white :elevation 2}) - -(def drag-down-touchable - {:height 22 - :background-color color-white - :alignItems :center - :justifyContent :center}) - -(def drag-down-icon - {:width 16 - :height 16}) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index c5340917e0..5ca88dd550 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -121,8 +121,12 @@ (register-sub :messages-offset (fn [] (let [command? (subscribe [:command?]) + command (subscribe [:get-chat-command]) suggestions (subscribe [:get-suggestions])] ;; todo fix magic values - (reaction (cond @command? c/request-info-height - (seq @suggestions) c/suggestions-header-height - :else 0))))) + (reaction + (let [type (:type @command)] + (cond (and @command? (= type :response)) c/request-info-height + (and @command? (= type :command)) c/suggestions-header-height + (seq @suggestions) c/suggestions-header-height + :else 0)))))) diff --git a/src/status_im/chat/views/command.cljs b/src/status_im/chat/views/command.cljs index 21951d0bc7..c5f65f0130 100644 --- a/src/status_im/chat/views/command.cljs +++ b/src/status_im/chat/views/command.cljs @@ -29,7 +29,7 @@ (defn command-icon [command] [view (st/command-text-container command) - [text {:style st/command-text} (:text command)]]) + [text {:style st/command-text} (str "!" (:name command))]]) (defn cancel-button [] [touchable-highlight {:on-press cancel-command-input} diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index 1df66f9c3d..fcf0ce6492 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -47,12 +47,15 @@ (defview plain-message-input-view [{:keys [input-options validator]}] [command? [:command?] + {:keys [type] :as command} [:get-chat-command] input-command [:get-chat-command-content] valid-plain-message? [:valid-plain-message?] valid-command? [:valid-command? validator]] [view st/input-container [view st/input-view [plain-message/commands-button] + (when (and command? (= :command type)) + [command/command-icon command]) [message-input-container [message-input input-options validator]] ;; TODO emoticons: not implemented diff --git a/src/status_im/chat/views/response.cljs b/src/status_im/chat/views/response.cljs index b81763c9f6..eaad55d093 100644 --- a/src/status_im/chat/views/response.cljs +++ b/src/status_im/chat/views/response.cljs @@ -12,6 +12,7 @@ touchable-highlight]] [status-im.components.drag-drop :as drag] [status-im.chat.styles.response :as st] + [status-im.chat.styles.dragdown :as ddst] [status-im.components.animation :as anim] [status-im.chat.suggestions-responder :as resp])) @@ -41,15 +42,19 @@ :fix-response-height) command (subscribe [:get-chat-command])] (fn [response-height] - [view (merge (drag/pan-handlers pan-responder) - {:style (st/request-info (:color @command))}) - [drag-icon] - [view st/inner-container - [command-icon nil] - [info-container @command] - [touchable-highlight {:on-press #(dispatch [:start-cancel-command])} - [view st/cancel-container - [icon :close-white st/cancel-icon]]]]]))) + (if (= :response (:type @command)) + [view (merge (drag/pan-handlers pan-responder) + {:style (st/request-info (:color @command))}) + [drag-icon] + [view st/inner-container + [command-icon nil] + [info-container @command] + [touchable-highlight {:on-press #(dispatch [:start-cancel-command])} + [view st/cancel-container + [icon :close-white st/cancel-icon]]]]] + [view (merge (drag/pan-handlers pan-responder) + {:style ddst/drag-down-touchable}) + [icon :drag_down ddst/drag-down-icon]])))) (defn container-animation-logic [{:keys [to-value val]}] (let [to-value @to-value] diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 38336670fc..6004eb56ac 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -10,6 +10,7 @@ animated-view]] [status-im.utils.listview :refer [to-datasource]] [status-im.chat.styles.suggestions :as st] + [status-im.chat.styles.dragdown :as ddst] [reagent.core :as r] [status-im.components.animation :as anim] [status-im.components.drag-drop :as drag] @@ -59,8 +60,8 @@ (fn [_] [view (merge (drag/pan-handlers pan-responder) - {:style st/drag-down-touchable}) - [icon :drag_down st/drag-down-icon]]))) + {:style ddst/drag-down-touchable}) + [icon :drag_down ddst/drag-down-icon]]))) (defn container-animation-logic [{:keys [to-value val]}] (let [to-value @to-value] From 579269ebca8dcc57fb7635dadd37d814943c61ef Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 09:36:03 +0300 Subject: [PATCH 36/53] fix message offset Former-commit-id: 026b678e2079a1e0216307a41a0efba8e064bdab --- src/status_im/chat/handlers/animation.cljs | 2 +- src/status_im/chat/subs.cljs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 837991d98b..ec9f40289c 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -43,7 +43,7 @@ type (get-in db path)] (if (= :response type) minimum-suggestion-height - minimum-command-suggestions-height))) + 0.1))) (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index ee803b5cd7..d8c5b545cb 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -131,11 +131,12 @@ (fn [] (let [command? (subscribe [:command?]) command (subscribe [:get-chat-command]) + command-suggestions (subscribe [:get-content-suggestions]) suggestions (subscribe [:get-suggestions])] - ;; todo fix magic values (reaction (let [type (:type @command)] (cond (and @command? (= type :response)) c/request-info-height - (and @command? (= type :command)) c/suggestions-header-height + (and @command? (= type :command) (seq @command-suggestions)) + c/suggestions-header-height (seq @suggestions) c/suggestions-header-height :else 0)))))) From 3fc913b682d5c1d8b4b2d42354b38edefe1b7540 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 11:24:46 +0300 Subject: [PATCH 37/53] commands canceling Former-commit-id: 471f637e0d420666dce3c807f011b25c371ab63b --- src/status_im/chat/handlers.cljs | 85 ++++++++++++-------- src/status_im/chat/styles/input.cljs | 7 +- src/status_im/chat/styles/message_input.cljs | 2 +- src/status_im/chat/styles/response.cljs | 5 +- src/status_im/chat/subs.cljs | 31 +++++-- src/status_im/chat/views/command.cljs | 12 ++- src/status_im/chat/views/message_input.cljs | 23 +++--- src/status_im/chat/views/new_message.cljs | 5 +- src/status_im/chat/views/plain_message.cljs | 3 +- 9 files changed, 110 insertions(+), 63 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index db9f710d26..a5af15c8a1 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -45,33 +45,44 @@ (update-in [:chats current-chat-id :input-text] safe-trim)))) (defn invoke-suggestions-handler! - [{:keys [current-chat-id] :as db} _] - (let [{:keys [command content]} (get-in db [:chats current-chat-id :command-input]) - {:keys [name type]} command - path [(if (= :command type) :commands :responses) - name - :params - 0 - :suggestions] - params {:value content}] - (j/call current-chat-id - path - params - #(dispatch [:suggestions-handler {:command command - :content content - :chat-id current-chat-id} %])))) + [{:keys [current-chat-id canceled-command] :as db} _] + (when-not canceled-command + (let [{:keys [command content]} (get-in db [:chats current-chat-id :command-input]) + {:keys [name type]} command + path [(if (= :command type) :commands :responses) + name + :params + 0 + :suggestions] + params {:value content}] + (j/call current-chat-id + path + params + #(dispatch [:suggestions-handler {:command command + :content content + :chat-id current-chat-id} %]))))) (register-handler :start-cancel-command (u/side-effect! (fn [db _] (dispatch [:animate-cancel-command])))) +(def command-prefix "c ") + +(defn cancel-command! + [{:keys [canceled-command]}] + (when canceled-command + (dispatch [:start-cancel-command]))) + (register-handler :set-chat-command-content - [(after invoke-suggestions-handler!)] + [(after invoke-suggestions-handler!) + (after cancel-command!)] (fn [{:keys [current-chat-id] :as db} [_ content]] - (as-> db db - (commands/set-chat-command-content db content) - (assoc-in db [:chats current-chat-id :input-text] nil)))) + (let [starts-as-command? (str/starts-with? content command-prefix)] + (as-> db db + (commands/set-chat-command-content db content) + (assoc-in db [:chats current-chat-id :input-text] nil) + (assoc db :canceled-command (not starts-as-command?)))))) (defn update-input-text [{:keys [current-chat-id] :as db} text] @@ -81,10 +92,10 @@ [{:keys [current-chat-id staged-command]} _] (let [{:keys [command content]} staged-command {:keys [name type]} command - path [(if (= :command type) :commands :responses) - name - :preview] - params {:value content}] + path [(if (= :command type) :commands :responses) + name + :preview] + params {:value content}] (j/call current-chat-id path params @@ -93,7 +104,7 @@ (register-handler :stage-command (after invoke-command-preview!) (fn [{:keys [current-chat-id] :as db} _] - (let [db (update-input-text db nil) + (let [db (update-input-text db nil) {:keys [command content]} (get-in db [:chats current-chat-id :command-input]) command-info {:command command @@ -120,8 +131,12 @@ (commands/set-response-chat-command db to-msg-id command-key))) (defn update-text - [db [_ text]] - (update-input-text db text)) + [{:keys [current-chat-id] :as db} [_ text]] + (let [suggestions (get-in db [:command-suggestions current-chat-id])] + (println :hui (count suggestions) text :bla) + (if-not (= 1 (count suggestions)) + (update-input-text db text) + db))) (defn update-command [db [_ text]] (if-not (commands/get-chat-command db) @@ -145,9 +160,8 @@ (register-handler :set-chat-input-text [(enrich update-command) (after select-suggestion!) - (enrich check-suggestions) (after #(dispatch [:animate-command-suggestions]))] - update-text) + ((enrich update-text) check-suggestions)) (defn console? [s] (= "console" s)) @@ -187,7 +201,7 @@ (defn prepare-message [{:keys [identity current-chat-id] :as db} _] - (let [text (get-in db [:chats current-chat-id :input-text]) + (let [text (get-in db [:chats current-chat-id :input-text]) [command] (suggestions/check-suggestion db (str text " ")) message (check-author-direction db current-chat-id @@ -312,8 +326,11 @@ (register-handler :set-chat-command [(after invoke-suggestions-handler!) (after #(dispatch [:command-edit-mode]))] - (fn [db [_ command-key]] - (commands/set-chat-command db command-key))) + (fn [{:keys [current-chat-id] :as db} [_ command-key]] + (-> db + (commands/set-chat-command command-key) + (assoc-in [:chats current-chat-id :command-input :content] "c ") + (assoc :disable-input true)))) (register-handler :init-console-chat (fn [db [_]] @@ -406,9 +423,9 @@ (defmethod nav/preload-data! :chat [{:keys [current-chat-id] :as db} [_ _ id]] - (let [chat-id (or id current-chat-id) + (let [chat-id (or id current-chat-id) messages (get-in db [:chats chat-id :messages]) - db' (assoc db :current-chat-id chat-id)] + db' (assoc db :current-chat-id chat-id)] (if (seq messages) db' (-> db' @@ -499,8 +516,8 @@ (assoc-in db [:edit-mode current-chat-id] mode))) (register-handler :command-edit-mode - [(after #(dispatch [:set-chat-input-text ""]))] (edit-mode-handler :command)) (register-handler :text-edit-mode + (after #(dispatch [:set-chat-input-text ""])) (edit-mode-handler :text)) diff --git a/src/status_im/chat/styles/input.cljs b/src/status_im/chat/styles/input.cljs index 50f6fbfba7..6dd49b23be 100644 --- a/src/status_im/chat/styles/input.cljs +++ b/src/status_im/chat/styles/input.cljs @@ -16,12 +16,17 @@ :backgroundColor color-white :elevation 4}) +(def command-container + {:left 0 + :backgroundColor :white + :position :absolute}) + (defn command-text-container [{:keys [color]}] {:flexDirection :column :marginTop 16 :marginBottom 16 - :marginLeft 0 + :marginLeft 16 :marginRight 8 :backgroundColor color :height 24 diff --git a/src/status_im/chat/styles/message_input.cljs b/src/status_im/chat/styles/message_input.cljs index e999f749a9..c27a359646 100644 --- a/src/status_im/chat/styles/message_input.cljs +++ b/src/status_im/chat/styles/message_input.cljs @@ -4,7 +4,7 @@ [status-im.chat.constants :refer [input-height]])) (def message-input-container - {:flex 1 + {:flex 1 :marginRight 0}) (def input-container diff --git a/src/status_im/chat/styles/response.cljs b/src/status_im/chat/styles/response.cljs index 8963f8a1fe..a0a5c08cd5 100644 --- a/src/status_im/chat/styles/response.cljs +++ b/src/status_im/chat/styles/response.cljs @@ -83,11 +83,12 @@ :width 12 :height 12}) -(def command-input +(defn command-input [ml disbale?] {:flex 1 :marginRight 16 + :margin-left (- ml 5) :marginTop -2 :padding 0 :fontSize 14 :fontFamily font - :color text1-color}) + :color (if disbale? color-white text1-color)}) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index d8c5b545cb..eee09009cf 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -127,16 +127,33 @@ (= :command) (reaction)))) +(register-sub :command-type + (fn [] + (let [command (subscribe [:get-chat-command])] + (reaction (:type @command))))) + (register-sub :messages-offset (fn [] (let [command? (subscribe [:command?]) - command (subscribe [:get-chat-command]) + type (subscribe [:command-type]) command-suggestions (subscribe [:get-content-suggestions]) suggestions (subscribe [:get-suggestions])] (reaction - (let [type (:type @command)] - (cond (and @command? (= type :response)) c/request-info-height - (and @command? (= type :command) (seq @command-suggestions)) - c/suggestions-header-height - (seq @suggestions) c/suggestions-header-height - :else 0)))))) + (cond (and @command? (= @type :response)) + c/request-info-height + + (and @command? (= @type :command) (seq @command-suggestions)) + c/suggestions-header-height + + (and (not @command?) (seq @suggestions)) + c/suggestions-header-height + + :else 0))))) + +(register-sub :command-icon-width + (fn [] + (let [width (subscribe [:get :command-icon-width]) + type (subscribe [:command-type])] + (reaction (if (= :command @type) + @width + 0))))) diff --git a/src/status_im/chat/views/command.cljs b/src/status_im/chat/views/command.cljs index c5f65f0130..49f5135b7e 100644 --- a/src/status_im/chat/views/command.cljs +++ b/src/status_im/chat/views/command.cljs @@ -27,9 +27,15 @@ (when (valid? message validator) (send-command))) -(defn command-icon [command] - [view (st/command-text-container command) - [text {:style st/command-text} (str "!" (:name command))]]) +(defview command-icon [command] + [icon-width [:get :command-icon-width]] + [view st/command-container + [view {:style (st/command-text-container command) + :onLayout (fn [event] + (let [width (.. event -nativeEvent -layout -width)] + (when (not= icon-width width) + (dispatch [:set :command-icon-width width]))))} + [text {:style st/command-text} (str "!" (:name command))]]]) (defn cancel-button [] [touchable-highlight {:on-press cancel-command-input} diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index fcf0ce6492..f9c5676ee5 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -21,24 +21,27 @@ (defn message-input-container [input] [view st/message-input-container input]) -(def plain-input-options +(defn plain-input-options [disbale?] {:style st-message/message-input - :onChangeText plain-message/set-input-message + :onChangeText (when-not disbale? plain-message/set-input-message) + :editable (not disbale?) :onSubmitEditing plain-message/send}) -(def command-input-options - {:style st-response/command-input +(defn command-input-options [icon-width disbale?] + {:style (st-response/command-input icon-width disbale?) :onChangeText command/set-input-message :onSubmitEditing command/send-command}) (defview message-input [input-options] [command? [:command?] input-message [:get-chat-input-text] - input-command [:get-chat-command-content]] + input-command [:get-chat-command-content] + icon-width [:command-icon-width] + disbale? [:get :disable-input]] [text-input (merge (if command? - command-input-options - plain-input-options) + (command-input-options icon-width disbale?) + (plain-input-options disbale?)) {:autoFocus false :blurOnSubmit false :accessibility-label :input} @@ -54,8 +57,6 @@ [view st/input-container [view st/input-view [plain-message/commands-button] - (when (and command? (= :command type)) - [command/command-icon command]) [message-input-container [message-input input-options validator]] ;; TODO emoticons: not implemented @@ -65,4 +66,6 @@ command/send-command plain-message/send)] [send-button {:on-press on-press - :accessibility-label :send-message}]))]]) + :accessibility-label :send-message}])) + (when (and command? (= :command type)) + [command/command-icon command])]]) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 2a1e2cd892..737a3f1344 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -24,10 +24,7 @@ :number {:input-options {:keyboardType :numeric}} ;; todo maybe nil is fine for now :) nil #_(throw (js/Error. "Uknown command type")))] - (println :plc placeholder) - (if placeholder - (assoc-in options [:input-options :placeholder] placeholder) - options))) + (assoc-in options [:input-options :placeholder] ""))) (defview show-input [] [parameter [:get-command-parameter] diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index 12ccadd664..86f06a7e6a 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -33,7 +33,8 @@ delay (if @command? 100 0)] (anim/start (anim/timing width {:toValue n-width :duration response-input-hiding-duration - :delay delay}))))) + :delay delay}) + #(dispatch [:set :disable-input false]))))) (defn commands-button [] (let [command? (subscribe [:command?]) From 00384bc79a59d240b9b01b86e67671381c1a32d8 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 11:55:56 +0300 Subject: [PATCH 38/53] fix responses animation Former-commit-id: 5af33a99caa3840d9865bd15b92e78918ebff59e --- src/status_im/chat/handlers.cljs | 10 +++++++--- src/status_im/chat/handlers/animation.cljs | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index a5af15c8a1..d5d5a1d63b 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -78,11 +78,13 @@ [(after invoke-suggestions-handler!) (after cancel-command!)] (fn [{:keys [current-chat-id] :as db} [_ content]] - (let [starts-as-command? (str/starts-with? content command-prefix)] + (let [starts-as-command? (str/starts-with? content command-prefix) + path [:chats current-chat-id :command-input :command :type] + command? (= :command (get-in db path))] (as-> db db (commands/set-chat-command-content db content) (assoc-in db [:chats current-chat-id :input-text] nil) - (assoc db :canceled-command (not starts-as-command?)))))) + (assoc db :canceled-command (and command? (not starts-as-command?))))))) (defn update-input-text [{:keys [current-chat-id] :as db} text] @@ -128,7 +130,9 @@ [(after invoke-suggestions-handler!) (after #(dispatch [:command-edit-mode]))] (fn [db [_ to-msg-id command-key]] - (commands/set-response-chat-command db to-msg-id command-key))) + (-> db + (commands/set-response-chat-command to-msg-id command-key) + (assoc :canceled-command false)))) (defn update-text [{:keys [current-chat-id] :as db} [_ text]] diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index ec9f40289c..4ae299dc71 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -52,6 +52,7 @@ height (if suggestions? middle-height (get-minimum-height db))] + (println "hei" suggestions? ) (assoc-in db [:animations :to-response-height] height)))) (defn fix-height From e4e30b85e44998d347fec6a0031cdf9197b532a0 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 11:58:37 +0300 Subject: [PATCH 39/53] prevent command cancelling Former-commit-id: e8d79e2efa1158ff1a27b3606b5e41d524229332 --- src/status_im/chat/views/message_input.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status_im/chat/views/message_input.cljs b/src/status_im/chat/views/message_input.cljs index f9c5676ee5..c96b36f22e 100644 --- a/src/status_im/chat/views/message_input.cljs +++ b/src/status_im/chat/views/message_input.cljs @@ -29,7 +29,7 @@ (defn command-input-options [icon-width disbale?] {:style (st-response/command-input icon-width disbale?) - :onChangeText command/set-input-message + :onChangeText (when-not disbale? command/set-input-message) :onSubmitEditing command/send-command}) (defview message-input [input-options] From cc850f3d7c6ff27ae215dcafbc6b1b860186efe3 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 12:10:06 +0300 Subject: [PATCH 40/53] placeholders Former-commit-id: dfaf0806a0afd7bc33300ef8020f7006ccb3ca56 --- src/status_im/chat/views/new_message.cljs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/status_im/chat/views/new_message.cljs b/src/status_im/chat/views/new_message.cljs index 737a3f1344..54bb81f2d7 100644 --- a/src/status_im/chat/views/new_message.cljs +++ b/src/status_im/chat/views/new_message.cljs @@ -16,7 +16,7 @@ (for [command staged-commands] ^{:key command} [staged-command-view command])]) -(defn get-options [{:keys [type placeholder]}] +(defn get-options [{:keys [type placeholder]} command-type] (let [options (case (keyword type) :phone {:input-options {:keyboardType :phone-pad} :validator valid-mobile-number?} @@ -24,13 +24,18 @@ :number {:input-options {:keyboardType :numeric}} ;; todo maybe nil is fine for now :) nil #_(throw (js/Error. "Uknown command type")))] - (assoc-in options [:input-options :placeholder] ""))) + (if (= :response command-type) + (if placeholder + (assoc-in options [:input-options :placeholder] placeholder) + options) + (assoc-in options [:input-options :placeholder] "")))) (defview show-input [] [parameter [:get-command-parameter] - command? [:command?]] + command? [:command?] + type [:command-type]] [plain-message-input-view - (when command? (get-options parameter))]) + (when command? (get-options parameter type))]) (defview chat-message-new [] [staged-commands [:get-chat-staged-commands]] From 5c5406021709b91c2aaa8cd7b12daed8429b4ba7 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 13:48:53 +0300 Subject: [PATCH 41/53] staged command content Former-commit-id: fe8ef287aab19af92bc01cda54382f8605a66949 --- src/status_im/chat/handlers.cljs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index d5d5a1d63b..26f7683ac1 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -107,10 +107,11 @@ (after invoke-command-preview!) (fn [{:keys [current-chat-id] :as db} _] (let [db (update-input-text db nil) - {:keys [command content]} - (get-in db [:chats current-chat-id :command-input]) - command-info {:command command - :content content}] + {:keys [command content]} (get-in db [:chats current-chat-id :command-input]) + content' (if (= :command (:type command)) + (subs content 2) + content) + command-info {:command command :content content'}] (-> db ;(assoc-in [:chats current-chat-id :command-input :command] nil) (commands/stage-command command-info) From 63fb7dce9491bf45e988278c5d97d285a8e8925b Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 14:28:43 +0300 Subject: [PATCH 42/53] locations Former-commit-id: 58675d5509a140b64934d6fd1ad04f1d098ad4f3 --- resources/commands.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/resources/commands.js b/resources/commands.js index ee5cac345b..1191fdd311 100644 --- a/resources/commands.js +++ b/resources/commands.js @@ -1,7 +1,36 @@ status.command({ name: "location", description: "Send location", - color: "#9a5dcf" + color: "#9a5dcf", + preview: function (params) { + var text = status.components.text( + { + style: { + marginTop: 5, + marginHorizontal: 0, + fontSize: 14, + fontFamily: "font", + color: "black" + } + }, params.value); + var uri = "https://maps.googleapis.com/maps/api/staticmap?center=" + + params.value + + "&size=100x100&maptype=roadmap&key=AIzaSyBNsj1qoQEYPb3IllmWMAscuXW0eeuYqAA&language=en" + + "&markers=size:mid%7Ccolor:0xff0000%7Clabel:%7C" + + params.value; + + var image = status.components.image( + { + source: {uri: uri}, + style: { + width: 100, + height: 100 + } + } + ); + + return status.components.view({}, [text, image]); + } }).param({ name: "address", type: status.types.TEXT, From 989309aa8c358440b4950878846f957709d04ae9 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 16:30:59 +0300 Subject: [PATCH 43/53] command suggestions design Former-commit-id: a1556ee3357c7dc05450791e33780ec62aecb36b --- src/status_im/chat/handlers.cljs | 2 - src/status_im/chat/handlers/animation.cljs | 9 ++-- src/status_im/chat/styles/suggestions.cljs | 16 ++++--- src/status_im/chat/views/suggestions.cljs | 53 ++++++++++++++-------- src/status_im/utils/handlers.cljs | 2 +- 5 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 26f7683ac1..ae8f747d2b 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -113,7 +113,6 @@ content) command-info {:command command :content content'}] (-> db - ;(assoc-in [:chats current-chat-id :command-input :command] nil) (commands/stage-command command-info) (assoc :staged-command command-info))))) @@ -138,7 +137,6 @@ (defn update-text [{:keys [current-chat-id] :as db} [_ text]] (let [suggestions (get-in db [:command-suggestions current-chat-id])] - (println :hui (count suggestions) text :bla) (if-not (= 1 (count suggestions)) (update-input-text db text) db))) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 4ae299dc71..9a98c088f0 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -30,8 +30,10 @@ (fn [{:keys [current-chat-id] :as db} _] (let [suggestions? (seq (get-in db [:command-suggestions current-chat-id])) current (get-in db [:animations :command-suggestions-height]) - height (if suggestions? middle-height 0.1) - changed? (if (and suggestions? (not= 0.1 current)) + height (if suggestions? middle-height 10) + changed? (if (and suggestions? + (not (nil? current)) + (not= 10 current)) identity inc)] (-> db (update :animations assoc :command-suggestions-height height) @@ -43,7 +45,7 @@ type (get-in db path)] (if (= :response type) minimum-suggestion-height - 0.1))) + 10))) (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] @@ -52,7 +54,6 @@ height (if suggestions? middle-height (get-minimum-height db))] - (println "hei" suggestions? ) (assoc-in db [:animations :to-response-height] height)))) (defn fix-height diff --git a/src/status_im/chat/styles/suggestions.cljs b/src/status_im/chat/styles/suggestions.cljs index 2e97d206b1..15ae5a1b9a 100644 --- a/src/status_im/chat/styles/suggestions.cljs +++ b/src/status_im/chat/styles/suggestions.cljs @@ -12,22 +12,23 @@ text2-color text3-color]])) -(def suggestion-height 88) +(def suggestion-height 60) + +(def suggestion-highlight + {:margin-left 57}) (def suggestion-container - {:flexDirection :column - :paddingLeft 16 - :backgroundColor color-white}) + {:backgroundColor color-white}) (def suggestion-sub-container {:height suggestion-height :borderBottomWidth 1 - :borderBottomColor separator-color}) + :borderBottomColor separator-color + :flex-direction :row}) (defn suggestion-background [{:keys [color]}] - {:alignSelf :flex-start - :marginTop 10 + {:marginTop 10 :height 24 :backgroundColor color :borderRadius 50}) @@ -55,6 +56,7 @@ {:flexDirection :row :marginVertical 1 :marginHorizontal 0 + :flex 1 :height (min 168 (* suggestion-height suggestions-count)) :backgroundColor color-white :borderRadius 5}) diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 6004eb56ac..53f7f68b5c 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -2,6 +2,7 @@ (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch]] [status-im.components.react :refer [view + scroll-view text icon touchable-highlight @@ -15,7 +16,8 @@ [status-im.components.animation :as anim] [status-im.components.drag-drop :as drag] [status-im.components.react :as react] - [status-im.chat.suggestions-responder :as resp])) + [status-im.chat.suggestions-responder :as resp] + [status-im.chat.constants :as c])) (defn set-command-input [command] (dispatch [:set-chat-command command])) @@ -26,29 +28,39 @@ :as suggestion}]] (let [label (str "!" name)] [touchable-highlight - {:onPress #(set-command-input command)} + {:onPress #(set-command-input command) + :style st/suggestion-highlight} [view st/suggestion-container [view st/suggestion-sub-container - [view (st/suggestion-background suggestion) - [text {:style st/suggestion-text} label]] - [text {:style st/value-text} label] - [text {:style st/description-text} description]]]])) + [view {:flex 0.6} + [text {:style st/value-text} label] + [text {:style st/description-text} description]] + [view {:flex 0.4 + :flex-direction :column + :align-items :flex-end + :margin-right 16} + [view (st/suggestion-background suggestion) + [text {:style st/suggestion-text} label]]]]]])) (defn render-row [row _ _] (list-item [suggestion-list-item row])) +(defn title [s] + [view {:margin-left 57 + :margin-bottom 16} + [text {:style {:font-size 13 + :color :#8f838c93}} s]]) -(defn suggestions-view [] - (let - [suggestions (subscribe [:get-suggestions])] - (r/create-class - {:reagent-render - (fn [] - [view (st/suggestions-container (count @suggestions)) - [list-view {:dataSource (to-datasource @suggestions) - :enableEmptySections true - :keyboardShouldPersistTaps true - :renderRow render-row}]])}))) +(defview suggestions-view [] + [suggestions [:get-suggestions] + requests [:get :chat-requests]] + [scroll-view + (when requests [title "Requests"]) + [title "Commands"] + [view (st/suggestions-container (count suggestions)) + [list-view {:dataSource (to-datasource suggestions) + :keyboardShouldPersistTaps true + :renderRow render-row}]]]) (defn header [h] (let [orientation (subscribe [:get :orientation]) @@ -64,7 +76,7 @@ [icon :drag_down ddst/drag-down-icon]]))) (defn container-animation-logic [{:keys [to-value val]}] - (let [to-value @to-value] + (when-let [to-value @to-value] (anim/start (anim/spring val {:toValue to-value})))) (defn container [h & elements] @@ -86,7 +98,8 @@ (into [animated-view {:style (st/container h)}] elements))}))) (defn suggestion-container [] - (let [h (anim/create-value 0)] + (let [h (anim/create-value 10)] [container h [header h] - [suggestions-view]])) + [suggestions-view] + [view {:height c/input-height}]])) diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 083196375e..4d2777e335 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -11,4 +11,4 @@ (defn register-handler ([name handler] (register-handler name nil handler)) ([name middleware handler] - (re-core/register-handler name [#_debug middleware] handler))) + (re-core/register-handler name [debug middleware] handler))) From d6fd77697d3f8f6061e7a873f435725638254b87 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 29 Jun 2016 18:54:01 +0300 Subject: [PATCH 44/53] requests in suggestions window Former-commit-id: 0761a1da1b881561edcc0e05465894b105d5ad9d --- src/status_im/chat/handlers.cljs | 15 ++++-- src/status_im/chat/handlers/animation.cljs | 3 +- src/status_im/chat/handlers/requests.cljs | 41 ++++++++++++++ src/status_im/chat/styles/suggestions.cljs | 62 ++++++++++++++++++---- src/status_im/chat/subs.cljs | 10 ++++ src/status_im/chat/views/suggestions.cljs | 44 ++++++++++----- src/status_im/constants.cljs | 2 +- src/status_im/handlers.cljs | 3 +- src/status_im/persistence/realm.cljs | 22 +++++++- 9 files changed, 171 insertions(+), 31 deletions(-) create mode 100644 src/status_im/chat/handlers/requests.cljs diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index ae8f747d2b..7015df6723 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -7,7 +7,8 @@ [status-im.protocol.api :as api] [status-im.models.messages :as messages] [status-im.constants :refer [text-content-type - content-type-command]] + content-type-command + content-type-command-request]] [status-im.utils.random :as random] [status-im.chat.sign-up :as sign-up-service] [status-im.models.chats :as chats] @@ -381,6 +382,7 @@ (dispatch [:load-commands! current-chat-id])) (register-handler :init-chat + (after #(dispatch [:load-requests!])) (-> load-messages! ((enrich init-chat)) ((after load-commands!)))) @@ -408,6 +410,11 @@ [{:keys [new-message]} [_ {chat-id :from}]] (messages/save-message chat-id new-message)) +(defn dispatch-request! + [{:keys [new-message]} [_ {chat-id :from}]] + (when (= (:content-type new-message) content-type-command-request) + (dispatch [:add-request chat-id new-message]))) + (defn receive-message [db [_ {chat-id :from :as message}]] (let [message' (check-author-direction db chat-id message)] @@ -416,8 +423,9 @@ (assoc :new-message message')))) (register-handler :received-msg - (-> receive-message - ((after store-message!)))) + [(after store-message!) + (after dispatch-request!)] + receive-message) (register-handler :group-received-msg (u/side-effect! @@ -429,6 +437,7 @@ (let [chat-id (or id current-chat-id) messages (get-in db [:chats chat-id :messages]) db' (assoc db :current-chat-id chat-id)] + (dispatch [:load-requests! chat-id]) (if (seq messages) db' (-> db' diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index 9a98c088f0..dd5218ac0a 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -1,7 +1,6 @@ (ns status-im.chat.handlers.animation - (:require [re-frame.core :refer [after dispatch debug]] + (:require [re-frame.core :refer [after dispatch debug path]] [status-im.utils.handlers :refer [register-handler]] - [re-frame.middleware :refer [path]] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.chat.constants :refer [input-height request-info-height minimum-command-suggestions-height diff --git a/src/status_im/chat/handlers/requests.cljs b/src/status_im/chat/handlers/requests.cljs new file mode 100644 index 0000000000..828e952b81 --- /dev/null +++ b/src/status_im/chat/handlers/requests.cljs @@ -0,0 +1,41 @@ +(ns status-im.chat.handlers.requests + (:require [re-frame.core :refer [after]] + [status-im.utils.handlers :refer [register-handler]] + [status-im.persistence.realm :as realm])) + +(defn store-request! + [{:keys [new-request]}] + (realm/write + (fn [] + (realm/create :requests new-request)))) + +(defn add-request + [db [_ chat-id {:keys [msg-id content]}]] + (let [request {:chat-id chat-id + :message-id msg-id + :type (:command content) + :added (js/Date.)} + request' (update request :type keyword)] + (-> db + (update-in [:chats chat-id :requests] conj request') + (assoc :new-request request)))) + +(defn load-requests! + [{:keys [current-chat-id] :as db} [_ chat-id]] + (let [chat-id' (or chat-id current-chat-id) + requests (-> :requests + ;; todo maybe limit is needed + (realm/get-by-fieds {:chat-id chat-id' + :status "open"}) + (realm/sorted :added :desc) + (realm/collection->map)) + requests' (->> requests + (map #(update % :type keyword)) + (into '()))] + (assoc-in db [:chats chat-id' :requests] requests'))) + +(register-handler :add-request + (after store-request!) + add-request) + +(register-handler :load-requests! load-requests!) diff --git a/src/status_im/chat/styles/suggestions.cljs b/src/status_im/chat/styles/suggestions.cljs index 15ae5a1b9a..e21cd4c620 100644 --- a/src/status_im/chat/styles/suggestions.cljs +++ b/src/status_im/chat/styles/suggestions.cljs @@ -3,6 +3,7 @@ color-light-blue-transparent color-white color-black + color-gray color-blue color-blue-transparent selected-message-color @@ -26,6 +27,15 @@ :borderBottomColor separator-color :flex-direction :row}) +(def command-description-container + {:flex 0.6}) + +(def command-label-container + {:flex 0.4 + :flex-direction :column + :align-items :flex-end + :margin-right 16}) + (defn suggestion-background [{:keys [color]}] {:marginTop 10 @@ -40,6 +50,14 @@ :fontFamily font :color color-white}) +(def title-container + {:margin-left 57 + :margin-bottom 16}) + +(def title-text + {:font-size 13 + :color :#8f838c93}) + (def value-text {:marginTop 6 :fontSize 14 @@ -52,15 +70,6 @@ :fontFamily font :color text2-color}) -(defn suggestions-container [suggestions-count] - {:flexDirection :row - :marginVertical 1 - :marginHorizontal 0 - :flex 1 - :height (min 168 (* suggestion-height suggestions-count)) - :backgroundColor color-white - :borderRadius 5}) - (defn container [height] {:flexDirection :column :position :absolute @@ -70,3 +79,38 @@ :height height :backgroundColor color-white :elevation 2}) + +(def request-container + {:height 56 + :flex-direction :row}) + +(def request-icon-container + {:height 56 + :width 57 + :align-items :center + :justifyContent :center}) + +(defn request-icon-background [color] + {:height 32 + :width 32 + :border-radius 32 + :background-color color + :align-items :center + :justifyContent :center}) + +(def request-icon + {:width 12 + :height 12}) + +(def request-info-container + {:height 56 + :padding-top 10}) + +(def request-info-description + {:font-size 12 + :color color-black}) + +(def request-message-info + {:font-size 12 + :margin-top 2 + :color color-gray}) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index eee09009cf..0a8d999432 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -157,3 +157,13 @@ (reaction (if (= :command @type) @width 0))))) + +(register-sub :get-requests + (fn [db] + (let [chat-id (subscribe [:get-current-chat-id])] + (reaction (get-in @db [:chats @chat-id :requests]))))) + +(register-sub :get-response + (fn [db [_ n]] + (let [chat-id (subscribe [:get-current-chat-id])] + (reaction (get-in @db [:chats @chat-id :responses n]))))) diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 53f7f68b5c..1c91b8d89f 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -5,6 +5,7 @@ scroll-view text icon + image touchable-highlight list-view list-item @@ -15,13 +16,30 @@ [reagent.core :as r] [status-im.components.animation :as anim] [status-im.components.drag-drop :as drag] - [status-im.components.react :as react] [status-im.chat.suggestions-responder :as resp] [status-im.chat.constants :as c])) (defn set-command-input [command] (dispatch [:set-chat-command command])) +(defview request-item [{:keys [type message-id]}] + [{:keys [color icon description] :as response} [:get-response type]] + [touchable-highlight + {:on-press #(dispatch [:set-response-chat-command message-id type])} + [view st/request-container + [view st/request-icon-container + [view (st/request-icon-background color) + [image {:source {:uri icon} + :style st/request-icon}]]] + [view st/request-info-container + [text {:style st/request-info-description} description] + ;; todo stub + [text {:style st/request-message-info} + "By console, today at 14:50"]]]]) + +(defn render-request-row [row _ _] + (list-item [request-item row])) + (defn suggestion-list-item [[command {:keys [description] name :name @@ -29,16 +47,13 @@ (let [label (str "!" name)] [touchable-highlight {:onPress #(set-command-input command) - :style st/suggestion-highlight} + :style st/suggestion-highlight} [view st/suggestion-container [view st/suggestion-sub-container - [view {:flex 0.6} + [view st/command-description-container [text {:style st/value-text} label] [text {:style st/description-text} description]] - [view {:flex 0.4 - :flex-direction :column - :align-items :flex-end - :margin-right 16} + [view st/command-label-container [view (st/suggestion-background suggestion) [text {:style st/suggestion-text} label]]]]]])) @@ -46,18 +61,21 @@ (list-item [suggestion-list-item row])) (defn title [s] - [view {:margin-left 57 - :margin-bottom 16} - [text {:style {:font-size 13 - :color :#8f838c93}} s]]) + [view st/title-container + [text {:style st/title-text} s]]) (defview suggestions-view [] [suggestions [:get-suggestions] - requests [:get :chat-requests]] + requests [:get-requests]] [scroll-view (when requests [title "Requests"]) + (when requests + [view + [list-view {:dataSource (to-datasource requests) + :keyboardShouldPersistTaps true + :renderRow render-request-row}]]) [title "Commands"] - [view (st/suggestions-container (count suggestions)) + [view [list-view {:dataSource (to-datasource suggestions) :keyboardShouldPersistTaps true :renderRow render-row}]]]) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index fa6e3a7632..d01788d834 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -16,4 +16,4 @@ (def response-input-hiding-duration 100) (def response-suggesstion-resize-duration 100) -(def default-number-of-messages 10) +(def default-number-of-messages 20) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 7829563fe5..1c656f5514 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -19,7 +19,8 @@ status-im.commands.handlers.loading status-im.commands.handlers.jail status-im.qr-scanner.handlers - status-im.protocol.handlers)) + status-im.protocol.handlers + status-im.chat.handlers.requests)) ;; -- Middleware ------------------------------------------------------------ ;; diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index 8ed342537a..277da95dc3 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -2,7 +2,8 @@ (:require [cljs.reader :refer [read-string]] [status-im.components.styles :refer [default-chat-color]] [status-im.utils.types :refer [to-string]] - [status-im.utils.utils :as u]) + [status-im.utils.utils :as u] + [clojure.string :as str]) (:refer-clojure :exclude [exists?])) (def opts {:schema [{:name :contacts @@ -14,6 +15,13 @@ :optional true} :photo-path {:type "string" :optinal true}}} + {:name :requests + :properties {:message-id :string + :chat-id :string + :type :string + :status {:type :string + :default "open"} + :added :date}} {:name :kv-store :primaryKey :key :properties {:key "string" @@ -107,12 +115,16 @@ [schema-name obj] (write (fn [] (create schema-name obj true)))) +(defn and-q [queries] + (str/join " and " queries)) + (defmulti to-query (fn [schema-name operator field value] operator)) (defmethod to-query :eq [schema-name operator field value] (let [value (to-string value) - query (str (name field) "=" (if (= "string" (field-type schema-name field)) + query (str (name field) "=" (if (= "string" (name (field-type + schema-name field))) (str "\"" value "\"") value))] query)) @@ -125,6 +137,12 @@ (let [q (to-query schema-name :eq field value)] (.filtered (.objects realm (name schema-name)) q))) +(defn get-by-fieds [schema-name fields] + (let [queries (map (fn [[k v]] + (to-query schema-name :eq k v)) + fields)] + (.filtered (.objects realm (name schema-name)) (and-q queries)))) + (defn get-all [schema-name] (.objects realm (to-string schema-name))) From 0ce1e185810d211aa2d5a32c066841f3a85da7c0 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 11:12:10 +0300 Subject: [PATCH 45/53] rendering of a new request in list Former-commit-id: 952d3736c8ef4218769d7cd0d2f500281f416892 --- src/status_im/chat/handlers/requests.cljs | 4 +--- src/status_im/chat/views/suggestions.cljs | 7 +++++-- src/status_im/commands/handlers/loading.cljs | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/status_im/chat/handlers/requests.cljs b/src/status_im/chat/handlers/requests.cljs index 828e952b81..534a84cf6c 100644 --- a/src/status_im/chat/handlers/requests.cljs +++ b/src/status_im/chat/handlers/requests.cljs @@ -29,9 +29,7 @@ :status "open"}) (realm/sorted :added :desc) (realm/collection->map)) - requests' (->> requests - (map #(update % :type keyword)) - (into '()))] + requests' (map #(update % :type keyword) requests)] (assoc-in db [:chats chat-id' :requests] requests'))) (register-handler :add-request diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 1c91b8d89f..4438fe5865 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -37,8 +37,11 @@ [text {:style st/request-message-info} "By console, today at 14:50"]]]]) -(defn render-request-row [row _ _] - (list-item [request-item row])) +(defn render-request-row + [{:keys [chat-id message-id] :as row} _ _] + (list-item + ^{:key [chat-id message-id]} + [request-item row])) (defn suggestion-list-item [[command {:keys [description] diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index 2291ade0fc..b7b26589fe 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -91,13 +91,13 @@ (reg-handler ::fetch-commands! (u/side-effect! fetch-commands!)) (reg-handler ::validate-hash - (after dispatch-loaded!) - validate-hash) + (after dispatch-loaded!) + validate-hash) (reg-handler ::parse-commands! (u/side-effect! parse-commands!)) (reg-handler ::add-commands - (after save-commands-js!) - add-commands) + (after save-commands-js!) + add-commands) (reg-handler ::loading-failed! (u/side-effect! loading-failed!)) From b763d5d9c907a0a87ddd8f8a3b8602eab1958fd7 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 11:48:56 +0300 Subject: [PATCH 46/53] commands button Former-commit-id: e728c155a12139daf977397fb0ea7a6de5339b57 --- .../res/drawable-hdpi/icon_input_list.png | Bin 0 -> 469 bytes .../res/drawable-mdpi/icon_input_list.png | Bin 0 -> 247 bytes .../res/drawable-xhdpi/icon_input_list.png | Bin 0 -> 333 bytes .../res/drawable-xxhdpi/icon_input_list.png | Bin 0 -> 651 bytes .../res/drawable-xxxhdpi/icon_input_list.png | Bin 0 -> 823 bytes src/status_im/chat/styles/plain_message.cljs | 19 +++++++-- src/status_im/chat/views/plain_message.cljs | 40 +++++++++++------- 7 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 android/app/src/main/res/drawable-hdpi/icon_input_list.png create mode 100644 android/app/src/main/res/drawable-mdpi/icon_input_list.png create mode 100644 android/app/src/main/res/drawable-xhdpi/icon_input_list.png create mode 100644 android/app/src/main/res/drawable-xxhdpi/icon_input_list.png create mode 100644 android/app/src/main/res/drawable-xxxhdpi/icon_input_list.png diff --git a/android/app/src/main/res/drawable-hdpi/icon_input_list.png b/android/app/src/main/res/drawable-hdpi/icon_input_list.png new file mode 100644 index 0000000000000000000000000000000000000000..033344a21f021a20db58e5af74c97984f30c8fec GIT binary patch literal 469 zcmV;`0V@89P)Px$k4Z#9R5%gs6g^8qQS_X9uR=p04J{2i*qTH%H}nVcCkR0#MJNs>H5p2vMkqRo zKf&5v+6`)Mv3`M5p}y5-gUs~0ze!LbZ-jhdBWXO zxo;;(o^Tlf5Cv*@l{+2sQ!LdQuVgr7^(4r2v5U6I&YcRKpoF#t)+3jz`F zopt#w@>Q<3jyQ4|iS{lpPCl8pIyM8LrwB{cMxDI5MUJRw%GTko(^;R6zUv0ewvEUO zDZ()zwyyJMPhJ_*iprd!PFfrTF+H86iFjZJ8P8D59WR9bH>;w7eF7VPFL(|R@v%nCe-x6Ni!OhiJXp4ZE3NCJ+NTbnOl{)!Hq z0SseZvv*sYP}a5m9(6@Olyz+#(1h%TvaZ86w4sQ&Ybov;*ef~9ZRs?1{39t zjVF#A`0`&~_;O;v0Y&SXFC6|H|G+O%@c$rVdmh6zhm>F6&x@_-6kI0pj7g&Y!vz<1 vr7(5oVC9RA9ak9=vQ+F{uACuL|d!n>e8f=y(QCS3j3^P6Px$2T4RhR7eeDT(xQy+s((Xniv`W$1woGe+I@y>at>WVPRpvKzv#Q7Ler(|Noc& zhuieO94H3jRltRSjMn~Xp8x*-odsmdAd8d1e!|Sim|j(!vkjz|3FdQTgRqHF$#Rf2 zGJpU7p9!;%3C0*Gnh6x==$2y>0|gsU-4k@RWbmIbF*B#Z^f3-}B7`|)lpeVuFyM)h zq>}Lezkf6T|Nk#bWPE|MTXkX9c6{ndDhWxj9Au{qwDiPhKf}-|38AGI(Ip`xBjaP_ z5)W4}40s~M<*-rlkrM&~o(PF93EO(7ctM*|l(q?B(F<-H5?vBf*>aF0z-_~!Qxa0K fO^6Z&1D*&0^;fc{?`V4|00000NkvXXu0mjf5;uyo literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xxhdpi/icon_input_list.png b/android/app/src/main/res/drawable-xxhdpi/icon_input_list.png new file mode 100644 index 0000000000000000000000000000000000000000..9e4fd528b3052cec72c432a4092e9f297d4b997f GIT binary patch literal 651 zcmV;60(AX}P)Px%MM*?KR9Fe^SiLVqK@gwWcS1))f<#G0N3D=(XzyPTL2^ezg3?DwxJwZ6FI-DQ z6k19uO2rYHQ#$YMnmsld&pFH9yWC6OHoH4JyYsPcXMS%Gs1*tY@9zG2L4isG!T>0^ zMZiLTU*}Fboenflvo`!t{^^{Q9}O!>MqKpwb&b_BVm)`%4Z+)_MAZ}CU(dNvSWLC5 zlcl-2B0o3v>G@GkG-GX)UZ?rCq49og_i#kY@+r|e=++`_k_5cH;>$*Ue|$MJdufD; z%4cI{Rr;FiD#+2f9aXkPLLyz-10Qnya8dc@IVC*SZ{mkWP9OSVDLOL3AU|B_2g?cH z#2W9{&|58WDxS zYdK!YPCa}vKu_YF2e>iGIPpN@fy4ui_W&ifc!yEvM5f`il>P*O?ER1b1qdYpibAAL z!b!^JJSRB4nLilzgYuaRB9%buQzKYjB6vQ&IzN47qqyO5g402u@-E67B`Up!E ztH`U<+yGvwc7oGN2K9r}TtkbosZ=|`X##RzD#aFZ>&rs&n+i_<)jAEoo#1rCtJB;< l4dcN_Fh>z&pIia(Xk^e@_4a002ovPDHLkV1h)hEa3nE literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xxxhdpi/icon_input_list.png b/android/app/src/main/res/drawable-xxxhdpi/icon_input_list.png new file mode 100644 index 0000000000000000000000000000000000000000..d136f96ef87a84076a4bf075d92ad4491c369a98 GIT binary patch literal 823 zcmV-71IYY|P)Px%@kvBMRA>e5TFq+{Q4pV5n{5s%=s{?!7q2SqMXwe`6!hfTLqY4ofP$s*QctD_ zD~%vT(Y7Zg)w58cSgoEsh)}`5K&`!4!Bb33o-<35w&P1TOE=x!zPAvv^TEEE-@cF8 zAA?Z8lv0?>KfD4;T?T|Bo?5{dK%5!7d2JdIRl|2D{Uawce*bZgs#Ts62&Z+)QSu9J z8ZTutnH8Nq$+|9n^W*tK%j7vZ2ButsXY_xjotbd=!PLQW`OiI?G$)mUo@fEW6^i2> zfHOKalKCoQ+10i8z%XTaLmD*l;rAatet$bZ_eo=Gs=VYYr6p1vr{A8YA-bF0H1tuL z>O-f_o-e+cpZmQ&6vtch>ouF*^Zwv-RVt+kP_W;}ZQIQX)IOTQ6LMgux#3BRPHt?D zI@_9VaP2l;cf2HJM2=LLCesq2qpsbn4PV+*X~T)_wJ0N_C4e(h*-~!9mrjW+0{&|G zjHnC0QJ+#(W`+i-$nFhy zLE$oUeEemn`?v`@R!2C&YPI~Cl0QMgbb=G)XCAB8{tlhHaIyIM)yoYWUr+#&%Lx+i z$jo!lgr$F?IYAxAClmCOEhm_8PH@rh4g1+c=LB81dz7g5Rlk9^YA4?Dr;g(b`rObt zK|Y$8e&(=!o^DYttdjAPLFLdf`1*nh@Z4~u|Bz#?D~un1TLb}9nK z7edCD!kys+CkuzTBZ~=(==%ia;@#Lch<7Fn)F)VbBHgqyI#+LxWTv#Xx-v(}Q?tPm zx20|77q!i66O3D*;D347`vwu50gl!9Ldf`1_#gZjvG^HO7#siq002ovPDHLkV1fbj Bg_r;U literal 0 HcmV?d00001 diff --git a/src/status_im/chat/styles/plain_message.cljs b/src/status_im/chat/styles/plain_message.cljs index b85dea9a97..fa639b39fa 100644 --- a/src/status_im/chat/styles/plain_message.cljs +++ b/src/status_im/chat/styles/plain_message.cljs @@ -9,11 +9,24 @@ :justifyContent :center}) (defn message-input-button [scale] - {:transform [{:scale scale}]}) + {:transform [{:scale scale}] + :width 24 + :height 24 + :alignItems :center + :justifyContent :center}) (def list-icon - {:width 13 - :height 12}) + {:width 16 + :height 16}) + +(def requests-icon + {:background-color :#7099e6 + :width 8 + :height 8 + :border-radius 8 + :left 0 + :top 0 + :position :absolute}) (def close-icon {:width 12 diff --git a/src/status_im/chat/views/plain_message.cljs b/src/status_im/chat/views/plain_message.cljs index 86f06a7e6a..f1dc3a0cde 100644 --- a/src/status_im/chat/views/plain_message.cljs +++ b/src/status_im/chat/views/plain_message.cljs @@ -5,6 +5,7 @@ [status-im.components.react :refer [view animated-view icon + text touchable-highlight]] [status-im.components.animation :as anim] [status-im.chat.styles.plain-message :as st] @@ -30,22 +31,24 @@ (defn list-container [min] (fn [{:keys [command? width]}] (let [n-width (if @command? min 56) - delay (if @command? 100 0)] + delay (if @command? 100 0)] (anim/start (anim/timing width {:toValue n-width :duration response-input-hiding-duration :delay delay}) #(dispatch [:set :disable-input false]))))) (defn commands-button [] - (let [command? (subscribe [:command?]) - buttons-scale (anim/create-value (if @command? 1 0)) + (let [command? (subscribe [:command?]) + requests (subscribe [:get-requests]) + suggestions (subscribe [:get-suggestions]) + buttons-scale (anim/create-value (if @command? 1 0)) container-width (anim/create-value (if @command? 20 56)) - context {:command? command? - :val buttons-scale - :width container-width} - on-update (fn [_] - ((button-animation-logic context)) - ((list-container 20) context))] + context {:command? command? + :val buttons-scale + :width container-width} + on-update (fn [_] + ((button-animation-logic context)) + ((list-container 20) context))] (r/create-class {:component-did-mount on-update @@ -58,7 +61,12 @@ [animated-view {:style (st/message-input-button-touchable container-width)} [animated-view {:style (st/message-input-button buttons-scale)} - [icon :list st/list-icon]]]])}))) + (if (seq @suggestions) + [icon :close_gray st/close-icon] + [icon :input_list st/list-icon]) + (when (and (seq @requests) + (not (seq @suggestions))) + [view st/requests-icon])]]])}))) (defn smile-animation-logic [{:keys [command? val width]}] (fn [_] @@ -71,13 +79,13 @@ (anim/set-value width 0.1))))))) (defn smile-button [] - (let [command? (subscribe [:command?]) - buttons-scale (anim/create-value (if @command? 1 0)) + (let [command? (subscribe [:command?]) + buttons-scale (anim/create-value (if @command? 1 0)) container-width (anim/create-value (if @command? 0.1 56)) - context {:command? command? - :val buttons-scale - :width container-width} - on-update (smile-animation-logic context)] + context {:command? command? + :val buttons-scale + :width container-width} + on-update (smile-animation-logic context)] (r/create-class {:component-did-mount on-update From d0e9eb04eab91668654e5e419ffa640086189b28 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 13:52:04 +0300 Subject: [PATCH 47/53] remove request after answering & request icon animation Former-commit-id: b7426f7eba106f10115b7beb909bd308a18b0efa --- src/status_im/chat/handlers.cljs | 28 ++++++++++----- src/status_im/chat/handlers/requests.cljs | 26 +++++++++++--- src/status_im/chat/subs.cljs | 5 +++ src/status_im/chat/views/request_message.cljs | 36 ++++++++++++------- src/status_im/chat/views/suggestions.cljs | 4 +-- src/status_im/persistence/realm.cljs | 2 +- 6 files changed, 73 insertions(+), 28 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 7015df6723..68b8a79eac 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -108,11 +108,14 @@ (after invoke-command-preview!) (fn [{:keys [current-chat-id] :as db} _] (let [db (update-input-text db nil) - {:keys [command content]} (get-in db [:chats current-chat-id :command-input]) + {:keys [command content to-msg-id]} + (get-in db [:chats current-chat-id :command-input]) content' (if (= :command (:type command)) - (subs content 2) - content) - command-info {:command command :content content'}] + (subs content 2) + content) + command-info {:command command + :content content' + :to-message to-msg-id}] (-> db (commands/stage-command command-info) (assoc :staged-command command-info))))) @@ -222,7 +225,7 @@ (assoc db :new-message (when-not (str/blank? text) message))))) (defn prepare-command - [identity chat-id {:keys [preview preview-string content command]}] + [identity chat-id {:keys [preview preview-string content command to-message]}] (let [content {:command (command :name) :content content}] {:msg-id (random/id) @@ -232,7 +235,8 @@ :content-type content-type-command :outgoing true :preview preview-string - :rendered-preview preview})) + :rendered-preview preview + :to-message to-message})) (defn prepare-staged-commans [{:keys [current-chat-id identity] :as db} _] @@ -285,8 +289,15 @@ (defn save-commands-to-realm! [{:keys [new-commands current-chat-id]} _] (doseq [new-command new-commands] - (messages/save-message current-chat-id - (dissoc new-command :rendered-preview)))) + (messages/save-message + current-chat-id + (dissoc new-command :rendered-preview :to-message)))) + +(defn dispatch-responded-requests! + [{:keys [new-commands current-chat-id]} _] + (doseq [{:keys [to-message]} new-commands] + (when to-message + (dispatch [:request-answered! current-chat-id to-message])))) (defn invoke-commands-handlers! [{:keys [new-commands current-chat-id]}] @@ -319,6 +330,7 @@ ((after send-message!)) ((after save-message-to-realm!)) ((after save-commands-to-realm!)) + ((after dispatch-responded-requests!)) ;; todo maybe it is better to track if it was handled or not ((after invoke-commands-handlers!)) ((after handle-commands)))) diff --git a/src/status_im/chat/handlers/requests.cljs b/src/status_im/chat/handlers/requests.cljs index 534a84cf6c..d229b0dc94 100644 --- a/src/status_im/chat/handlers/requests.cljs +++ b/src/status_im/chat/handlers/requests.cljs @@ -1,7 +1,8 @@ (ns status-im.chat.handlers.requests - (:require [re-frame.core :refer [after]] + (:require [re-frame.core :refer [after dispatch enrich]] [status-im.utils.handlers :refer [register-handler]] - [status-im.persistence.realm :as realm])) + [status-im.persistence.realm :as realm] + [status-im.utils.handlers :as u])) (defn store-request! [{:keys [new-request]}] @@ -25,15 +26,32 @@ (let [chat-id' (or chat-id current-chat-id) requests (-> :requests ;; todo maybe limit is needed - (realm/get-by-fieds {:chat-id chat-id' - :status "open"}) + (realm/get-by-fields {:chat-id chat-id' + :status "open"}) (realm/sorted :added :desc) (realm/collection->map)) requests' (map #(update % :type keyword) requests)] (assoc-in db [:chats chat-id' :requests] requests'))) +(defn mark-request-as-answered! + [_ [_ chat-id message-id]] + (realm/write + (fn [] + (-> :requests + (realm/get-by-fields + {:chat-id chat-id + :message-id message-id}) + (realm/single) + (.-status) + (set! "answered"))))) + (register-handler :add-request (after store-request!) add-request) (register-handler :load-requests! load-requests!) + +(register-handler :request-answered! + (after (fn [_ [_ chat-id]] + (dispatch [:load-requests! chat-id]))) + (u/side-effect! mark-request-as-answered!)) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 0a8d999432..ae90e45bc0 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -167,3 +167,8 @@ (fn [db [_ n]] (let [chat-id (subscribe [:get-current-chat-id])] (reaction (get-in @db [:chats @chat-id :responses n]))))) + +(register-sub :is-request-answered? + (fn [_ [_ message-id]] + (let [requests (subscribe [:get-requests])] + (reaction (not (some #(= message-id (:message-id %)) @requests)))))) diff --git a/src/status_im/chat/views/request_message.cljs b/src/status_im/chat/views/request_message.cljs index 77e5834327..38b9237137 100644 --- a/src/status_im/chat/views/request_message.cljs +++ b/src/status_im/chat/views/request_message.cljs @@ -22,23 +22,33 @@ (def min-scale 1) (def max-scale 1.3) +(defn button-animation [val to-value loop? answered?] + (anim/anim-sequence + [(anim/anim-delay + (if (and @loop? (not @answered?)) + request-message-icon-scale-delay + 0)) + (anim/spring val {:toValue to-value})])) + (defn request-button-animation-logic - [{:keys [to-value val loop?] :as context}] + [{:keys [to-value val loop? answered?] :as context}] (anim/start - (anim/anim-sequence - [(anim/anim-delay (if @loop? request-message-icon-scale-delay 0)) - (anim/spring val {:toValue to-value})]) - #(when @loop? + (button-animation val to-value loop? answered?) + #(if (and @loop? (not @answered?)) (let [new-value (if (= to-value min-scale) max-scale min-scale) context' (assoc context :to-value new-value)] - (request-button-animation-logic context'))))) + (request-button-animation-logic context')) + (anim/start + (button-animation val min-scale loop? answered?))))) (defn request-button [msg-id command] (let [scale-anim-val (anim/create-value min-scale) + answered? (subscribe [:is-request-answered? msg-id]) loop? (r/atom true) - context {:to-value max-scale - :val scale-anim-val - :loop? loop?}] + context {:to-value max-scale + :val scale-anim-val + :answered? answered? + :loop? loop?}] (r/create-class {:component-did-mount #(request-button-animation-logic context) @@ -46,10 +56,10 @@ #(reset! loop? false) :reagent-render (fn [msg-id command] - [touchable-highlight {:on-press (fn [] - (reset! loop? false) - (set-chat-command msg-id command)) - :style st/command-request-image-touchable} + [touchable-highlight + {:on-press (when-not @answered? + #(set-chat-command msg-id command)) + :style st/command-request-image-touchable} [animated-view {:style (st/command-request-image-view command scale-anim-val)} [image {:source {:uri (:icon command)} :style st/command-request-image}]]])}))) diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 4438fe5865..d946c5fa8d 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -71,8 +71,8 @@ [suggestions [:get-suggestions] requests [:get-requests]] [scroll-view - (when requests [title "Requests"]) - (when requests + (when (seq requests) [title "Requests"]) + (when (seq requests) [view [list-view {:dataSource (to-datasource requests) :keyboardShouldPersistTaps true diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index 277da95dc3..e0ee29a606 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -137,7 +137,7 @@ (let [q (to-query schema-name :eq field value)] (.filtered (.objects realm (name schema-name)) q))) -(defn get-by-fieds [schema-name fields] +(defn get-by-fields [schema-name fields] (let [queries (map (fn [[k v]] (to-query schema-name :eq k v)) fields)] From e830ecdb394386b6e863f3d701c76a8eebde79a7 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 14:06:00 +0300 Subject: [PATCH 48/53] commands suggestions header icon Former-commit-id: ac80ae632f1097082769a362df86d67787ec9009 --- src/status_im/chat/styles/suggestions.cljs | 6 ++++++ src/status_im/chat/views/request_message.cljs | 2 +- src/status_im/chat/views/suggestions.cljs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/status_im/chat/styles/suggestions.cljs b/src/status_im/chat/styles/suggestions.cljs index e21cd4c620..2985922cd7 100644 --- a/src/status_im/chat/styles/suggestions.cljs +++ b/src/status_im/chat/styles/suggestions.cljs @@ -114,3 +114,9 @@ {:font-size 12 :margin-top 2 :color color-gray}) + +(def header-icon + {:background-color :#838c93 + :width 14 + :border-radius 1 + :height 3}) diff --git a/src/status_im/chat/views/request_message.cljs b/src/status_im/chat/views/request_message.cljs index 38b9237137..2bbd4e11df 100644 --- a/src/status_im/chat/views/request_message.cljs +++ b/src/status_im/chat/views/request_message.cljs @@ -51,7 +51,7 @@ :loop? loop?}] (r/create-class {:component-did-mount - #(request-button-animation-logic context) + (when-not @answered? #(request-button-animation-logic context)) :component-will-unmount #(reset! loop? false) :reagent-render diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index d946c5fa8d..c9a7615317 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -94,7 +94,7 @@ [view (merge (drag/pan-handlers pan-responder) {:style ddst/drag-down-touchable}) - [icon :drag_down ddst/drag-down-icon]]))) + [view st/header-icon]]))) (defn container-animation-logic [{:keys [to-value val]}] (when-let [to-value @to-value] From cbca3803c18758d0de003a8d87076e981111785f Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 15:23:31 +0300 Subject: [PATCH 49/53] persist tap Former-commit-id: aa22c975c811f6cd64371657322fb02455b7b531 --- src/status_im/chat/views/suggestions.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index c9a7615317..98f3e9e3e5 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -70,7 +70,7 @@ (defview suggestions-view [] [suggestions [:get-suggestions] requests [:get-requests]] - [scroll-view + [scroll-view {:keyboardShouldPersistTaps true} (when (seq requests) [title "Requests"]) (when (seq requests) [view From 2280fd71243de2ff777f28e6d9c8a25e3011a739 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 15:54:44 +0300 Subject: [PATCH 50/53] improve animation Former-commit-id: b4a1e9afd63105ceb59aece1dd1c1a13367ae29b --- src/status_im/android/core.cljs | 9 +++++--- src/status_im/chat/handlers.cljs | 21 ++++++++++++++++-- src/status_im/chat/handlers/animation.cljs | 25 ++++++++++++++++++---- src/status_im/chat/screen.cljs | 2 +- src/status_im/chat/views/suggestions.cljs | 2 +- 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index e69e22cc2f..5405f58393 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -39,7 +39,8 @@ (defn app-root [] (let [signed-up (subscribe [:get :signed-up]) - view-id (subscribe [:get :view-id])] + view-id (subscribe [:get :view-id]) + keyboard-height (subscribe [:get :keyboard-height])] (r/create-class {:component-will-mount (fn [] @@ -53,10 +54,12 @@ "keyboardDidShow" (fn [e] (let [h (.. e -endCoordinates -height)] - (dispatch [:set :keyboard-height h])))) + (when-not (= h keyboard-height) + (dispatch [:set :keyboard-height h]))))) (.addListener device-event-emitter "keyboardDidHide" - #(dispatch [:set :keyboard-height 0]))) + (when-not (= 0 keyboard-height) + #(dispatch [:set :keyboard-height 0])))) :render (fn [] (case (if @signed-up @view-id :chat) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 68b8a79eac..248520ca44 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -132,7 +132,8 @@ (register-handler :set-response-chat-command [(after invoke-suggestions-handler!) - (after #(dispatch [:command-edit-mode]))] + (after #(dispatch [:command-edit-mode])) + (after #(dispatch [:set-chat-input-text ""]))] (fn [db [_ to-msg-id command-key]] (-> db (commands/set-response-chat-command to-msg-id command-key) @@ -143,7 +144,7 @@ (let [suggestions (get-in db [:command-suggestions current-chat-id])] (if-not (= 1 (count suggestions)) (update-input-text db text) - db))) + (assoc db :disable-input true)))) (defn update-command [db [_ text]] (if-not (commands/get-chat-command db) @@ -545,3 +546,19 @@ (register-handler :text-edit-mode (after #(dispatch [:set-chat-input-text ""])) (edit-mode-handler :text)) + +(register-handler :set-layout-height + [(after + (fn [{:keys [current-chat-id] :as db}] + (let [suggestions (get-in db [:suggestions current-chat-id]) + mode (get-in db [:edit-mode current-chat-id])] + (when (and (= :command mode) (seq suggestions)) + (dispatch [:fix-response-height]))))) + (after + (fn [{:keys [current-chat-id] :as db}] + (let [suggestions (get-in db [:command-suggestions current-chat-id]) + mode (get-in db [:edit-mode current-chat-id])] + (when (and (= :text mode)) (seq suggestions) + (dispatch [:fix-commands-suggestions-height])))))] + (fn [db [_ h]] + (assoc db :layout-height h))) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index dd5218ac0a..571297542b 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -29,10 +29,10 @@ (fn [{:keys [current-chat-id] :as db} _] (let [suggestions? (seq (get-in db [:command-suggestions current-chat-id])) current (get-in db [:animations :command-suggestions-height]) - height (if suggestions? middle-height 10) + height (if suggestions? middle-height 30) changed? (if (and suggestions? (not (nil? current)) - (not= 10 current)) + (not= 30 current)) identity inc)] (-> db (update :animations assoc :command-suggestions-height height) @@ -44,7 +44,7 @@ type (get-in db path)] (if (= :response type) minimum-suggestion-height - 10))) + 30))) (register-handler :animate-show-response [(after #(dispatch [:command-edit-mode]))] @@ -64,9 +64,19 @@ under-middle-position? (<= current middle-height) over-middle-position? (not under-middle-position?) suggestions (get-in db [suggestions-key current-chat-id]) + old-fixed (get-in db [:animations height-key]) + new-fixed (cond (not suggestions) (minimum db) + (and (nil? vy) (nil? current) + (> old-fixed middle-height)) + max-height + + (and (nil? vy) (nil? current) + (< old-fixed middle-height)) + (minimum db) + (and under-middle-position? moving-up?) middle-height @@ -82,11 +92,18 @@ (assoc-in [:animations height-key] new-fixed) (update-in [:animations height-signal-key] inc))))) +(defn commands-min-height + [{:keys [current-chat-id] :as db}] + (let [suggestions (get-in db [:command-suggestions current-chat-id])] + (if (seq suggestions) + minimum-command-suggestions-height + 0.1))) + (register-handler :fix-commands-suggestions-height (fix-height :command-suggestions-height :commands-height-changed :command-suggestions - (constantly minimum-command-suggestions-height))) + commands-min-height)) (register-handler :fix-response-height (fix-height :to-response-height diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 0652d5109d..d2b7126cbb 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -262,7 +262,7 @@ :onLayout (fn [event] (let [height (.. event -nativeEvent -layout -height)] (when (not= height layout-height) - (dispatch [:set :layout-height height]))))} + (dispatch [:set-layout-height height]))))} [chat-toolbar] [messages-container [messages-view group-chat]] diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index 98f3e9e3e5..c28b8770ec 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -119,7 +119,7 @@ (into [animated-view {:style (st/container h)}] elements))}))) (defn suggestion-container [] - (let [h (anim/create-value 10)] + (let [h (anim/create-value 0.1)] [container h [header h] [suggestions-view] From b746bcef4f1d543ca7dd13ec204fbcdb4fe61a0b Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 17:23:38 +0300 Subject: [PATCH 51/53] attempt to fix performance issues Former-commit-id: 3a93e0890bfea4b167b934c26f2c5096ea73421a --- src/status_im/chat/handlers.cljs | 18 ++++++++++++------ src/status_im/commands/handlers/loading.cljs | 3 +-- src/status_im/commands/utils.cljs | 2 +- src/status_im/constants.cljs | 2 +- src/status_im/contacts/handlers.cljs | 3 ++- src/status_im/discovery/handlers.cljs | 3 ++- src/status_im/group_settings/handlers.cljs | 4 ++-- src/status_im/models/messages.cljs | 2 +- src/status_im/navigation/handlers.cljs | 3 ++- src/status_im/new_group/handlers.cljs | 3 ++- src/status_im/participants/handlers.cljs | 3 ++- src/status_im/protocol/handlers.cljs | 3 ++- src/status_im/qr_scanner/handlers.cljs | 3 ++- 13 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 248520ca44..05ab26564f 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -8,7 +8,8 @@ [status-im.models.messages :as messages] [status-im.constants :refer [text-content-type content-type-command - content-type-command-request]] + content-type-command-request + default-number-of-messages]] [status-im.utils.random :as random] [status-im.chat.sign-up :as sign-up-service] [status-im.models.chats :as chats] @@ -28,12 +29,17 @@ (assoc db :show-actions show-actions))) (register-handler :load-more-messages - debug (fn [{:keys [current-chat-id] :as db} _] - (let [messages-path [:chats current-chat-id :messages] - messages (get-in db messages-path) - new-messages (messages/get-messages current-chat-id (count messages))] - (update-in db messages-path concat new-messages)))) + (let [all-loaded? (get-in db [:chats current-chat-id :all-loaded?])] + (if all-loaded? + db + (let [messages-path [:chats current-chat-id :messages] + messages (get-in db messages-path) + new-messages (messages/get-messages current-chat-id (count messages)) + all-loaded? (> default-number-of-messages (count new-messages))] + (-> db + (update-in messages-path concat new-messages) + (assoc-in [:chats current-chat-id :all-loaded?] all-loaded?))))))) (defn safe-trim [s] (when (string? s) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index b7b26589fe..ccecdc86e5 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -1,7 +1,6 @@ (ns status-im.commands.handlers.loading (:require-macros [status-im.utils.slurp :refer [slurp]]) - (:require [re-frame.core :refer [register-handler after dispatch subscribe - trim-v debug]] + (:require [re-frame.core :refer [after dispatch subscribe trim-v debug]] [status-im.utils.handlers :as u] [status-im.utils.utils :refer [http-get toast]] [clojure.string :as s] diff --git a/src/status_im/commands/utils.cljs b/src/status_im/commands/utils.cljs index ca03a910cf..af728dabad 100644 --- a/src/status_im/commands/utils.cljs +++ b/src/status_im/commands/utils.cljs @@ -3,7 +3,7 @@ [clojure.walk :as w] [status-im.components.react :refer [text scroll-view view image touchable-highlight]] - [re-frame.core :refer [register-handler dispatch trim-v debug]] + [re-frame.core :refer [dispatch trim-v debug]] [status-im.utils.handlers :refer [register-handler]])) (defn json->clj [json] diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index d01788d834..41460b6cc9 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -16,4 +16,4 @@ (def response-input-hiding-duration 100) (def response-suggesstion-resize-duration 100) -(def default-number-of-messages 20) +(def default-number-of-messages 5) diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index 2e0cdc73a6..f61bed64d5 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.contacts.handlers - (:require [re-frame.core :refer [register-handler after dispatch]] + (:require [re-frame.core :refer [after dispatch]] + [status-im.utils.handlers :refer [register-handler]] [status-im.models.contacts :as contacts] [status-im.utils.crypt :refer [encrypt]] [clojure.string :as s] diff --git a/src/status_im/discovery/handlers.cljs b/src/status_im/discovery/handlers.cljs index 2b227acefa..2f062260bc 100644 --- a/src/status_im/discovery/handlers.cljs +++ b/src/status_im/discovery/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.discovery.handlers - (:require [re-frame.core :refer [register-handler after dispatch enrich]] + (:require [re-frame.core :refer [after dispatch enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.protocol.api :as api] [status-im.navigation.handlers :as nav] [status-im.discovery.model :as discoveries] diff --git a/src/status_im/group_settings/handlers.cljs b/src/status_im/group_settings/handlers.cljs index 82eab18d7b..6f5e94d558 100644 --- a/src/status_im/group_settings/handlers.cljs +++ b/src/status_im/group_settings/handlers.cljs @@ -1,6 +1,6 @@ (ns status-im.group-settings.handlers - (:require [re-frame.core :refer [register-handler debug dispatch after - enrich]] + (:require [re-frame.core :refer [debug dispatch after enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.persistence.realm :as r] [status-im.chat.handlers :refer [delete-messages!]] [status-im.protocol.api :as api] diff --git a/src/status_im/models/messages.cljs b/src/status_im/models/messages.cljs index c010719ab1..38d7342ae3 100644 --- a/src/status_im/models/messages.cljs +++ b/src/status_im/models/messages.cljs @@ -56,7 +56,7 @@ (r/collection->map)) (into '()) reverse - (map (fn [{:keys [content-type] :as message}] + (keep (fn [{:keys [content-type] :as message}] (if (command-type? content-type) (update message :content str-to-map) message)))))) diff --git a/src/status_im/navigation/handlers.cljs b/src/status_im/navigation/handlers.cljs index cf73ae6434..db33411902 100644 --- a/src/status_im/navigation/handlers.cljs +++ b/src/status_im/navigation/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.navigation.handlers - (:require [re-frame.core :refer [register-handler dispatch debug enrich after]])) + (:require [re-frame.core :refer [dispatch debug enrich after]] + [status-im.utils.handlers :refer [register-handler]])) (defn push-view [db view-id] (-> db diff --git a/src/status_im/new_group/handlers.cljs b/src/status_im/new_group/handlers.cljs index 0c34111405..3cba0c3db0 100644 --- a/src/status_im/new_group/handlers.cljs +++ b/src/status_im/new_group/handlers.cljs @@ -1,6 +1,7 @@ (ns status-im.new-group.handlers (:require [status-im.protocol.api :as api] - [re-frame.core :refer [register-handler after dispatch debug enrich]] + [re-frame.core :refer [after dispatch debug enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.components.styles :refer [default-chat-color]] [status-im.models.chats :as chats] [clojure.string :as s])) diff --git a/src/status_im/participants/handlers.cljs b/src/status_im/participants/handlers.cljs index fe0e5581c0..a6fb532355 100644 --- a/src/status_im/participants/handlers.cljs +++ b/src/status_im/participants/handlers.cljs @@ -1,6 +1,7 @@ (ns status-im.participants.handlers (:require [status-im.navigation.handlers :as nav] - [re-frame.core :refer [register-handler debug]])) + [re-frame.core :refer [debug]] + [status-im.utils.handlers :refer [register-handler]])) (defmethod nav/preload-data! :add-participants [db _] diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index a9b94e5541..e6e8c8699c 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -4,7 +4,8 @@ (:require [status-im.utils.handlers :as u] [status-im.utils.logging :as log] [status-im.protocol.api :as api] - [re-frame.core :refer [register-handler dispatch debug]] + [re-frame.core :refer [dispatch debug]] + [status-im.utils.handlers :refer [register-handler]] [status-im.models.contacts :as contacts] [status-im.protocol.api :refer [init-protocol]] [status-im.protocol.protocol-handler :refer [make-handler]] diff --git a/src/status_im/qr_scanner/handlers.cljs b/src/status_im/qr_scanner/handlers.cljs index be05d7fb65..8827ea847a 100644 --- a/src/status_im/qr_scanner/handlers.cljs +++ b/src/status_im/qr_scanner/handlers.cljs @@ -1,5 +1,6 @@ (ns status-im.qr-scanner.handlers - (:require [re-frame.core :refer [register-handler after dispatch debug enrich]] + (:require [re-frame.core :refer [after dispatch debug enrich]] + [status-im.utils.handlers :refer [register-handler]] [status-im.navigation.handlers :as nav] [status-im.utils.handlers :as u])) From 7e13ef021066cf002889a088b0ed18e3d9dff57c Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 17:24:07 +0300 Subject: [PATCH 52/53] comment debug Former-commit-id: c97fdbe8c5bcf0fb319af0a7ceec984b58c9a347 --- src/status_im/utils/handlers.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status_im/utils/handlers.cljs b/src/status_im/utils/handlers.cljs index 4d2777e335..083196375e 100644 --- a/src/status_im/utils/handlers.cljs +++ b/src/status_im/utils/handlers.cljs @@ -11,4 +11,4 @@ (defn register-handler ([name handler] (register-handler name nil handler)) ([name middleware handler] - (re-core/register-handler name [debug middleware] handler))) + (re-core/register-handler name [#_debug middleware] handler))) From f833fd12c31f19d54f8b185065e2ee7dbb30bd0c Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 30 Jun 2016 17:47:12 +0300 Subject: [PATCH 53/53] fix suggestions flickering Former-commit-id: 3e7bd39ed3856b95312ef9268bf7d022ae30b03a --- src/status_im/chat/views/suggestions.cljs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/status_im/chat/views/suggestions.cljs b/src/status_im/chat/views/suggestions.cljs index c28b8770ec..457c441083 100644 --- a/src/status_im/chat/views/suggestions.cljs +++ b/src/status_im/chat/views/suggestions.cljs @@ -119,8 +119,10 @@ (into [animated-view {:style (st/container h)}] elements))}))) (defn suggestion-container [] - (let [h (anim/create-value 0.1)] - [container h - [header h] - [suggestions-view] - [view {:height c/input-height}]])) + (let [h (anim/create-value 0.1) + command? (subscribe [:command?])] + (when-not @command? + [container h + [header h] + [suggestions-view] + [view {:height c/input-height}]])))