From 9d4387cefa1e360d116467b0b9ad4f0a805096fe Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Thu, 23 Jun 2016 15:52:54 +0300 Subject: [PATCH 1/4] changed server url Former-commit-id: 17497b53596f537f094233820b8bf2959191b655 --- src/status_im/constants.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 7faee32d1b..64be21f5b5 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -2,7 +2,7 @@ (def ethereum-rpc-url "http://localhost:8545") -(def server-address "http://rpc0.status.im:20000/") +(def server-address "http://api.status.im/") ;; (def server-address "http://10.0.3.2:3000/") ;; (def server-address "http://localhost:3000/") From b044b3917eea4e59e692f97a9f0867697f0440c5 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Fri, 24 Jun 2016 13:40:18 +0300 Subject: [PATCH 2/4] added stub function for geth communication Former-commit-id: a99778031b77525521d68018c6abe66b6d9ffea4 --- android/app/src/main/java/com/statusim/GethService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android/app/src/main/java/com/statusim/GethService.java b/android/app/src/main/java/com/statusim/GethService.java index 7967807cbd..84ec5daaa2 100644 --- a/android/app/src/main/java/com/statusim/GethService.java +++ b/android/app/src/main/java/com/statusim/GethService.java @@ -94,6 +94,10 @@ public class GethService extends Service { handler.postDelayed(addPeer, 5000); } + public void signalEvent(String jsonEvent) { + + } + @Nullable @Override public IBinder onBind(Intent intent) { From 721af7a283b67e39a173b1bdb49cac65dfd33ccd Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 15:54:06 +0300 Subject: [PATCH 3/4] lock to portrait orientation Former-commit-id: dc079cc2175e03f1ad1a0ade1fbdeb49a36c27a3 --- src/status_im/android/core.cljs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 0e1e22c930..38b60a5b77 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -48,6 +48,7 @@ (.addOrientationListener orientation #(dispatch [:set :orientation (orientation->keyword %)])) + (.lockToPortrait orientation) (.addListener device-event-emitter "keyboardDidShow" (fn [e] From ca2e5681db6b26c0db02bbddb68cdbff1cce5491 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Mon, 27 Jun 2016 15:57:40 +0300 Subject: [PATCH 4/4] load messages on scroll Former-commit-id: ff1291dac0598a61ed82e3d9fb3d6299dab82b83 --- src/status_im/chat/handlers.cljs | 43 ++++++++++++++---------------- src/status_im/constants.cljs | 2 ++ src/status_im/models/messages.cljs | 24 +++++++++-------- 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index ae8cdd5dc0..ef8ae2d24f 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -27,13 +27,12 @@ (assoc db :show-actions show-actions))) (register-handler :load-more-messages - (fn [db _] - db - ;; TODO implement - #_(let [chat-id (get-in db [:chat :current-chat-id]) - messages [:chats chat-id :messages] - new-messages (gen-messages 10)] - (update-in db messages concat new-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)))) (defn safe-trim [s] (when (string? s) @@ -144,26 +143,26 @@ (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]) {:keys [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)}] + content {:command (name command-key) + :content (:content staged-command)}] {:msg-id (random/id) :from identity :to chat-id @@ -287,10 +286,8 @@ (defn load-messages! ([db] (load-messages! db nil)) - ([db _] - (->> (:current-chat-id db) - messages/get-messages - (assoc db :messages)))) + ([{:keys [current-chat-id] :as db} _] + (assoc db :messages (messages/get-messages current-chat-id)))) (defn init-chat ([db] (init-chat db nil)) @@ -308,7 +305,7 @@ (map (fn [{:keys [chat-id] :as chat}] [chat-id chat])) (into {})) - ids (set (keys chats))] + ids (set (keys chats))] (-> db (assoc :chats chats) (assoc :chats-ids ids) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 64be21f5b5..fa6e3a7632 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -15,3 +15,5 @@ (def response-input-hiding-duration 100) (def response-suggesstion-resize-duration 100) + +(def default-number-of-messages 10) diff --git a/src/status_im/models/messages.cljs b/src/status_im/models/messages.cljs index 65de1d2476..50a0c4f895 100644 --- a/src/status_im/models/messages.cljs +++ b/src/status_im/models/messages.cljs @@ -3,7 +3,6 @@ [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]] @@ -46,16 +45,19 @@ #{c/content-type-command c/content-type-command-request} type)) -(defn get-messages [chat-id] - (->> (-> (r/get-by-field :msgs :chat-id chat-id) - (r/sorted :timestamp :desc) - (r/collection->map)) - (into '()) - reverse - (map (fn [{:keys [content-type] :as message}] - (if (command-type? content-type) - (update message :content str-to-map) - message))))) +(defn get-messages + ([chat-id] (get-messages chat-id 0)) + ([chat-id from] + (->> (-> (r/get-by-field :msgs :chat-id chat-id) + (r/sorted :timestamp :desc) + (r/page from (+ from c/default-number-of-messages)) + (r/collection->map)) + (into '()) + reverse + (map (fn [{:keys [content-type] :as message}] + (if (command-type? content-type) + (update message :content str-to-map) + message)))))) (defn update-message! [{:keys [msg-id] :as msg}] (log/debug "update-message!" msg)