From 0f7143e5bf8e7e2c5e19570d207268e001098108 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Tue, 5 Jul 2016 19:07:34 +0300 Subject: [PATCH] pending/sent/failed statuses for messages --- project.clj | 2 +- src/status_im/chat/handlers.cljs | 8 +++--- src/status_im/chat/views/message.cljs | 26 ++++++++++--------- src/status_im/contacts/validations.cljs | 1 - src/status_im/protocol/handlers.cljs | 27 +++++++++++--------- src/status_im/protocol/protocol_handler.cljs | 4 +-- 6 files changed, 35 insertions(+), 33 deletions(-) diff --git a/project.clj b/project.clj index af80bbed96..958a23e8bf 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-20160630_153846-gbf92f5f"] + [status-im/protocol "0.1.1-20160705_154931-g96b5c92"] [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 97df9c4281..a21d0f3c63 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -283,12 +283,10 @@ [{:keys [new-message current-chat-id] :as db} _] (when (and new-message (not-console? current-chat-id)) (let [{:keys [group-chat]} (get-in db [:chats current-chat-id]) - content (:content new-message)] + message (select-keys new-message [:content :msg-id])] (if group-chat - (api/send-group-user-msg {:group-id current-chat-id - :content content}) - (api/send-user-msg {:to current-chat-id - :content content}))))) + (api/send-group-user-msg (assoc message :group-id current-chat-id)) + (api/send-user-msg (assoc message :to current-chat-id)))))) (defn save-message-to-realm! [{:keys [new-message current-chat-id]} _] diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index c7f910e799..28daa5af59 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -120,20 +120,23 @@ [message-content-audio {:content content :content-type content-type}]]]) -(defn message-delivery-status [{:keys [delivery-status]}] +(defview message-delivery-status + [{: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 - :delivered {:uri :icon_ok_small} :seen {:uri :icon_ok_small} :seen-by-everyone {:uri :icon_ok_small} - :failed res/delivery-failed-icon) + :failed res/delivery-failed-icon + nil) :style st/delivery-image}] [text {:style st/delivery-text} - (case delivery-status - :delivered "Delivered" + (case (or status delivery-status) + :delivered "Sent" :seen "Seen" :seen-by-everyone "Seen by everyone" - :failed "Failed")]]) + :failed "Failed" + "Pending")]]) (defn member-photo [{:keys [photo-path]}] [view st/photo-view @@ -159,12 +162,11 @@ [message-delivery-status {:delivery-status delivery-status}])]]])) (defn message-body - [{:keys [outgoing] :as message} content] - (let [delivery-status :seen] - [view (st/message-body message) - content - (when (and outgoing delivery-status) - [message-delivery-status {:delivery-status delivery-status}])])) + [{:keys [outgoing delivery-status] :as message} content] + [view (st/message-body message) + content + (when outgoing + [message-delivery-status message])]) (defn message-container-animation-logic [{:keys [to-value val callback]}] (fn [_] diff --git a/src/status_im/contacts/validations.cljs b/src/status_im/contacts/validations.cljs index 1e4d517682..5c930a8b3c 100644 --- a/src/status_im/contacts/validations.cljs +++ b/src/status_im/contacts/validations.cljs @@ -3,7 +3,6 @@ [status-im.persistence.realm :as realm])) (defn unique-identity? [identity] - (println identity) (not (realm/exists? :contacts :whisper-identity identity))) (defn valid-length? [identity] diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index 9bb41936e0..55a7530f54 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -4,13 +4,13 @@ (:require [status-im.utils.handlers :as u] [status-im.utils.logging :as log] [status-im.protocol.api :as api] - [re-frame.core :refer [dispatch debug]] + [re-frame.core :refer [dispatch after]] [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]] [status-im.models.protocol :refer [update-identity - set-initialized]] + set-initialized]] [status-im.constants :refer [text-content-type]] [status-im.models.messages :as messages] [status-im.models.chats :as chats] @@ -102,16 +102,19 @@ (log/debug action msg-id from group-id identity) (participant-invited-to-group-msg group-id identity from msg-id)))) +(defn update-message! [status] + (fn [_ [_ _ msg-id]] + (messages/update-message! {:msg-id msg-id + :delivery-status status}))) + +(defn update-message-status [status] + (fn [db [_ from msg-id]] + (assoc-in db [:message-status from msg-id] status))) + (register-handler :acked-msg - (u/side-effect! - (fn [_ [action from msg-id]] - (log/debug action from msg-id) - (messages/update-message! {:msg-id msg-id - :delivery-status :delivered})))) + (after (update-message! :delivered)) + (update-message-status :delivered)) (register-handler :msg-delivery-failed - (u/side-effect! - (fn [_ [action msg-id]] - (log/debug action msg-id) - (messages/update-message! {:msg-id msg-id - :delivery-status :failed})))) + (after (update-message! :failed)) + (update-message-status :failed)) diff --git a/src/status_im/protocol/protocol_handler.cljs b/src/status_im/protocol/protocol_handler.cljs index cd0d44c812..f684baca87 100644 --- a/src/status_im/protocol/protocol_handler.cljs +++ b/src/status_im/protocol/protocol_handler.cljs @@ -22,8 +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])) - :delivery-failed (let [{:keys [msg-id]} event] - (dispatch [:msg-delivery-failed 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] (dispatch [:group-chat-invite-received from group-id identities group-name])) :new-group-msg (let [{from :from