pending/sent/failed statuses for messages

This commit is contained in:
Roman Volosovskyi 2016-07-05 19:07:34 +03:00
parent 7413352563
commit 0f7143e5bf
6 changed files with 35 additions and 33 deletions

View File

@ -10,7 +10,7 @@
[prismatic/schema "1.0.4"] [prismatic/schema "1.0.4"]
^{:voom {:repo "git@github.com:status-im/status-lib.git" ^{:voom {:repo "git@github.com:status-im/status-lib.git"
:branch "master"}} :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"] [natal-shell "0.1.6"]
[com.andrewmcveigh/cljs-time "0.4.0"]] [com.andrewmcveigh/cljs-time "0.4.0"]]
:plugins [[lein-cljsbuild "1.1.1"] :plugins [[lein-cljsbuild "1.1.1"]

View File

@ -283,12 +283,10 @@
[{:keys [new-message current-chat-id] :as db} _] [{:keys [new-message current-chat-id] :as db} _]
(when (and new-message (not-console? current-chat-id)) (when (and new-message (not-console? current-chat-id))
(let [{:keys [group-chat]} (get-in db [:chats 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 (if group-chat
(api/send-group-user-msg {:group-id current-chat-id (api/send-group-user-msg (assoc message :group-id current-chat-id))
:content content}) (api/send-user-msg (assoc message :to current-chat-id))))))
(api/send-user-msg {:to current-chat-id
:content content})))))
(defn save-message-to-realm! (defn save-message-to-realm!
[{:keys [new-message current-chat-id]} _] [{:keys [new-message current-chat-id]} _]

View File

@ -120,20 +120,23 @@
[message-content-audio {:content content [message-content-audio {:content content
:content-type content-type}]]]) :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 [view st/delivery-view
[image {:source (case delivery-status [image {:source (case delivery-status
:delivered {:uri :icon_ok_small}
:seen {:uri :icon_ok_small} :seen {:uri :icon_ok_small}
:seen-by-everyone {: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}] :style st/delivery-image}]
[text {:style st/delivery-text} [text {:style st/delivery-text}
(case delivery-status (case (or status delivery-status)
:delivered "Delivered" :delivered "Sent"
:seen "Seen" :seen "Seen"
:seen-by-everyone "Seen by everyone" :seen-by-everyone "Seen by everyone"
:failed "Failed")]]) :failed "Failed"
"Pending")]])
(defn member-photo [{:keys [photo-path]}] (defn member-photo [{:keys [photo-path]}]
[view st/photo-view [view st/photo-view
@ -159,12 +162,11 @@
[message-delivery-status {:delivery-status delivery-status}])]]])) [message-delivery-status {:delivery-status delivery-status}])]]]))
(defn message-body (defn message-body
[{:keys [outgoing] :as message} content] [{:keys [outgoing delivery-status] :as message} content]
(let [delivery-status :seen]
[view (st/message-body message) [view (st/message-body message)
content content
(when (and outgoing delivery-status) (when outgoing
[message-delivery-status {:delivery-status delivery-status}])])) [message-delivery-status message])])
(defn message-container-animation-logic [{:keys [to-value val callback]}] (defn message-container-animation-logic [{:keys [to-value val callback]}]
(fn [_] (fn [_]

View File

@ -3,7 +3,6 @@
[status-im.persistence.realm :as realm])) [status-im.persistence.realm :as realm]))
(defn unique-identity? [identity] (defn unique-identity? [identity]
(println identity)
(not (realm/exists? :contacts :whisper-identity identity))) (not (realm/exists? :contacts :whisper-identity identity)))
(defn valid-length? [identity] (defn valid-length? [identity]

View File

@ -4,7 +4,7 @@
(:require [status-im.utils.handlers :as u] (:require [status-im.utils.handlers :as u]
[status-im.utils.logging :as log] [status-im.utils.logging :as log]
[status-im.protocol.api :as api] [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.utils.handlers :refer [register-handler]]
[status-im.models.contacts :as contacts] [status-im.models.contacts :as contacts]
[status-im.protocol.api :refer [init-protocol]] [status-im.protocol.api :refer [init-protocol]]
@ -102,16 +102,19 @@
(log/debug action msg-id from group-id identity) (log/debug action msg-id from group-id identity)
(participant-invited-to-group-msg group-id identity from msg-id)))) (participant-invited-to-group-msg group-id identity from msg-id))))
(register-handler :acked-msg (defn update-message! [status]
(u/side-effect! (fn [_ [_ _ msg-id]]
(fn [_ [action from msg-id]]
(log/debug action from msg-id)
(messages/update-message! {:msg-id msg-id (messages/update-message! {:msg-id msg-id
:delivery-status :delivered})))) :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
(after (update-message! :delivered))
(update-message-status :delivered))
(register-handler :msg-delivery-failed (register-handler :msg-delivery-failed
(u/side-effect! (after (update-message! :failed))
(fn [_ [action msg-id]] (update-message-status :failed))
(log/debug action msg-id)
(messages/update-message! {:msg-id msg-id
:delivery-status :failed}))))

View File

@ -22,8 +22,8 @@
(dispatch [:received-msg (assoc payload :from from :to to)])) (dispatch [:received-msg (assoc payload :from from :to to)]))
:msg-acked (let [{:keys [msg-id from]} event] :msg-acked (let [{:keys [msg-id from]} event]
(dispatch [:acked-msg from msg-id])) (dispatch [:acked-msg from msg-id]))
:delivery-failed (let [{:keys [msg-id]} event] :delivery-failed (let [{:keys [msg-id from]} event]
(dispatch [:msg-delivery-failed msg-id])) (dispatch [:msg-delivery-failed from msg-id]))
:new-group-chat (let [{:keys [from group-id identities group-name]} event] :new-group-chat (let [{:keys [from group-id identities group-name]} event]
(dispatch [:group-chat-invite-received from group-id identities group-name])) (dispatch [:group-chat-invite-received from group-id identities group-name]))
:new-group-msg (let [{from :from :new-group-msg (let [{from :from