pending/sent/failed statuses for messages

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

View File

@ -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"]

View File

@ -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]} _]

View File

@ -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 [_]

View File

@ -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]

View File

@ -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))

View File

@ -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