From 34059e5c61675468de94e404b827a634d0957e69 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 6 Jul 2016 11:55:21 +0300 Subject: [PATCH] "seen" message Former-commit-id: 155626f59a8b4956bf2b5cc46f0fd3ec396214c4 --- .../statusim/geth/service/GethService.java | 2 +- project.clj | 2 +- src/status_im/chat/handlers.cljs | 10 ++++- src/status_im/chat/views/message.cljs | 39 ++++++++++++------- src/status_im/protocol/handlers.cljs | 11 +++++- src/status_im/protocol/protocol_handler.cljs | 2 + 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/android/app/src/main/java/com/statusim/geth/service/GethService.java b/android/app/src/main/java/com/statusim/geth/service/GethService.java index 9900b3ef8e..71e15636f8 100644 --- a/android/app/src/main/java/com/statusim/geth/service/GethService.java +++ b/android/app/src/main/java/com/statusim/geth/service/GethService.java @@ -213,7 +213,7 @@ public class GethService extends Service { String address = data.getString("address"); String password = data.getString("password"); // TODO: remove third argument - String result = Statusgo.Login(address, password); + String result = Statusgo.UnlockAccount(address, password, 0); Log.d(TAG, "Unlocked account: " + result); Bundle replyData = new Bundle(); diff --git a/project.clj b/project.clj index 958a23e8bf..ad95b36baa 100644 --- a/project.clj +++ b/project.clj @@ -10,7 +10,7 @@ [prismatic/schema "1.0.4"] ^{:voom {:repo "git@github.com:status-im/status-lib.git" :branch "master"}} - [status-im/protocol "0.1.1-20160705_154931-g96b5c92"] + [status-im/protocol "0.1.1-20160706_085008-ge61756a"] [natal-shell "0.1.6"] [com.andrewmcveigh/cljs-time "0.4.0"]] :plugins [[lein-cljsbuild "1.1.1"] diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index a21d0f3c63..25860a07bb 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -568,6 +568,14 @@ (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])))))] + (dispatch [:fix-commands-suggestions-height])))))] (fn [db [_ h]] (assoc db :layout-height h))) + + +(register-handler :send-seen! + #_(afetr (fn [_ [_ chat-id message-id]] + (dispatch [:msg-seen chat-id message-id]))) + (debug (u/side-effect! + (fn [_ [_ chat-id message-id]] + (api/send-seen chat-id message-id))))) diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 28daa5af59..01c50c3500 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -124,7 +124,7 @@ [{:keys [delivery-status msg-id to] :as m}] [status [:get-in [:message-status to msg-id]]] [view st/delivery-view - [image {:source (case delivery-status + [image {:source (case (or status delivery-status) :seen {:uri :icon_ok_small} :seen-by-everyone {:uri :icon_ok_small} :failed res/delivery-failed-icon @@ -205,17 +205,28 @@ (into [view] children))) (defn chat-message - [{:keys [outgoing delivery-status timestamp new-day group-chat] + [{:keys [outgoing delivery-status timestamp new-day group-chat msg-id chat-id] :as message}] - [message-container message - ;; TODO there is no new-day info in message - (when new-day - [message-date timestamp]) - [view - (let [incoming-group (and group-chat (not outgoing))] - [message-content - (if incoming-group - incoming-group-message-body - message-body) - (merge message {:delivery-status (keyword delivery-status) - :incoming-group incoming-group})])]]) + (let [status (subscribe [:get-in [:message-status chat-id msg-id]])] + (r/create-class + {:component-did-mount + (fn [] + (when (and outgoing + (not= :seen delivery-status) + (not= :seen @status)) + (dispatch [:send-seen! chat-id msg-id]))) + :reagent-render + (fn [{:keys [outgoing delivery-status timestamp new-day group-chat] + :as message}] + [message-container message + ;; TODO there is no new-day info in message + (when new-day + [message-date timestamp]) + [view + (let [incoming-group (and group-chat (not outgoing))] + [message-content + (if incoming-group + incoming-group-message-body + message-body) + (merge message {:delivery-status (keyword delivery-status) + :incoming-group incoming-group})])]])}))) diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index 55a7530f54..9221c4b8e4 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -109,7 +109,10 @@ (defn update-message-status [status] (fn [db [_ from msg-id]] - (assoc-in db [:message-status from msg-id] status))) + (let [current-status (get-in db [:message-status from msg-id])] + (if-not (= :seen current-status) + (assoc-in db [:message-status from msg-id] status) + db)))) (register-handler :acked-msg (after (update-message! :delivered)) @@ -118,3 +121,9 @@ (register-handler :msg-delivery-failed (after (update-message! :failed)) (update-message-status :failed)) + +;; todo maybe it is fine to treat as "seen" all messages that are older +;; than current +(register-handler :msg-seen + (after (update-message! :seen)) + (update-message-status :seen)) diff --git a/src/status_im/protocol/protocol_handler.cljs b/src/status_im/protocol/protocol_handler.cljs index f684baca87..8f79ed7939 100644 --- a/src/status_im/protocol/protocol_handler.cljs +++ b/src/status_im/protocol/protocol_handler.cljs @@ -22,6 +22,8 @@ (dispatch [:received-msg (assoc payload :from from :to to)])) :msg-acked (let [{:keys [msg-id from]} event] (dispatch [:acked-msg from msg-id])) + :msg-seen (let [{:keys [msg-id from]} event] + (dispatch [:msg-seen from msg-id])) :delivery-failed (let [{:keys [msg-id from]} event] (dispatch [:msg-delivery-failed from msg-id])) :new-group-chat (let [{:keys [from group-id identities group-name]} event]