Fix seen statuses

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
janherich 2018-05-24 13:25:38 +02:00 committed by Igor Mandrigin
parent 638b30c443
commit 874e88fc38
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
6 changed files with 32 additions and 29 deletions

View File

@ -1,20 +1,26 @@
(ns status-im.chat.core)
(ns status-im.chat.core
(:require [status-im.data-store.messages :as messages-store]))
;; Seen messages
(defn receive-seen
[chat-id sender {:keys [message-ids js-obj]} {:keys [db]}]
[chat-id sender {:keys [message-ids]} {:keys [db js-obj]}]
(merge
{:confirm-message-processed [{:web3 (:web3 db)
:js-obj js-obj}]}
{:confirm-messages-processed [{:web3 (:web3 db)
:js-obj js-obj}]}
(when-let [seen-messages-ids (-> (get-in db [:chats chat-id :messages])
(select-keys message-ids)
keys)]
{:db (reduce
(fn [new-db message-id]
(assoc-in new-db
[:chats chat-id
:messages message-id
:user-statuses sender]
:seen))
db
seen-messages-ids)})))
(let [new-db (reduce
(fn [new-db message-id]
(assoc-in new-db
[:chats chat-id
:messages message-id
:user-statuses sender]
:seen))
db
seen-messages-ids)]
{:db new-db
:data-store/tx [(messages-store/update-messages-tx
(map #(select-keys (get-in db [:chats chat-id :messages %])
[:message-id :user-statuses])
seen-messages-ids))]}))))

View File

@ -128,8 +128,8 @@
request-command)
add-message-fn (if batch? add-batch-message add-single-message)]
(handlers-macro/merge-fx cofx
{:confirm-message-processed [{:web3 web3
:js-obj js-obj}]}
{:confirm-messages-processed [{:web3 web3
:js-obj js-obj}]}
(add-message-fn (cond-> message
public-key
(assoc :user-statuses {public-key (if current-chat? :seen :received)})

View File

@ -21,9 +21,7 @@
(data-source/change-account address new-account? encryption-key handler))
(defn- perform-transactions [raw-transactions realm]
(let [success-events (->> raw-transactions
(map :success-event)
(filter identity))
(let [success-events (keep :success-event raw-transactions)
transactions (map (fn [{:keys [transaction] :as f}]
(or transaction f)) raw-transactions)]
(data-source/write realm #(doseq [transaction transactions]

View File

@ -29,15 +29,14 @@
(let [{:keys [payload sig timestamp ttl]} (js->clj js-message :keywordize-keys true)
status-message (-> payload
transport.utils/to-utf8
transit/deserialize
(assoc :js-obj js-message))]
transit/deserialize)]
(when (and sig status-message)
(handlers-macro/merge-fx
cofx
(assoc cofx :js-obj js-message)
(message/receive status-message (or chat-id sig) sig)
(update-last-received-from-inbox now-in-s timestamp ttl)))))
(defn- js-array->list [array]
(defn- js-array->seq [array]
(for [i (range (.-length array))]
(aget array i)))
@ -47,7 +46,7 @@
cofx
(fn [message temp-cofx]
(receive-message temp-cofx now-in-s chat-id message))
(js-array->list js-messages))))
(js-array->seq js-messages))))
(handlers/register-handler-fx
:protocol/receive-whisper-message
@ -173,9 +172,8 @@
fx))))
(re-frame/reg-fx
;; TODO(rasom): confirmMessagesProcessed should be called after :data-store/tx
;; effect, so this effect should be rewritten/removed
:confirm-message-processed
;; TODO(janherich): this should be called after `:data-store/tx` actually
:confirm-messages-processed
(fn [messages]
(let [{:keys [web3]} (first messages)
js-messages (->> messages
@ -186,4 +184,4 @@
js-messages
(fn [err resp]
(when err
(log/info "Confirming message processed failed"))))))))
(log/info "Confirming messages processed failed"))))))))

View File

@ -101,7 +101,8 @@
:message-id (transport.utils/message-id this)
:show? true
:chat-id chat-id
:from signature)]}))
:from signature
:js-obj (:js-obj cofx))]}))
(defrecord MessagesSeen [message-ids]
message/StatusMessage

View File

@ -10,7 +10,7 @@
(def ^:private mergable-keys
#{:data-store/tx :data-store/base-tx :chat-received-message/add-fx
:shh/add-new-sym-keys :shh/get-new-sym-keys :shh/post
:confirm-message-processed :call-jail})
:confirm-messages-processed :call-jail})
(defn safe-merge [fx new-fx]
(if (:merging-fx-with-common-keys fx)