Fix seen statuses
Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
parent
638b30c443
commit
874e88fc38
|
@ -1,15 +1,16 @@
|
||||||
(ns status-im.chat.core)
|
(ns status-im.chat.core
|
||||||
|
(:require [status-im.data-store.messages :as messages-store]))
|
||||||
|
|
||||||
;; Seen messages
|
;; Seen messages
|
||||||
(defn receive-seen
|
(defn receive-seen
|
||||||
[chat-id sender {:keys [message-ids js-obj]} {:keys [db]}]
|
[chat-id sender {:keys [message-ids]} {:keys [db js-obj]}]
|
||||||
(merge
|
(merge
|
||||||
{:confirm-message-processed [{:web3 (:web3 db)
|
{:confirm-messages-processed [{:web3 (:web3 db)
|
||||||
:js-obj js-obj}]}
|
:js-obj js-obj}]}
|
||||||
(when-let [seen-messages-ids (-> (get-in db [:chats chat-id :messages])
|
(when-let [seen-messages-ids (-> (get-in db [:chats chat-id :messages])
|
||||||
(select-keys message-ids)
|
(select-keys message-ids)
|
||||||
keys)]
|
keys)]
|
||||||
{:db (reduce
|
(let [new-db (reduce
|
||||||
(fn [new-db message-id]
|
(fn [new-db message-id]
|
||||||
(assoc-in new-db
|
(assoc-in new-db
|
||||||
[:chats chat-id
|
[:chats chat-id
|
||||||
|
@ -17,4 +18,9 @@
|
||||||
:user-statuses sender]
|
:user-statuses sender]
|
||||||
:seen))
|
:seen))
|
||||||
db
|
db
|
||||||
seen-messages-ids)})))
|
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))]}))))
|
||||||
|
|
|
@ -128,7 +128,7 @@
|
||||||
request-command)
|
request-command)
|
||||||
add-message-fn (if batch? add-batch-message add-single-message)]
|
add-message-fn (if batch? add-batch-message add-single-message)]
|
||||||
(handlers-macro/merge-fx cofx
|
(handlers-macro/merge-fx cofx
|
||||||
{:confirm-message-processed [{:web3 web3
|
{:confirm-messages-processed [{:web3 web3
|
||||||
:js-obj js-obj}]}
|
:js-obj js-obj}]}
|
||||||
(add-message-fn (cond-> message
|
(add-message-fn (cond-> message
|
||||||
public-key
|
public-key
|
||||||
|
|
|
@ -21,9 +21,7 @@
|
||||||
(data-source/change-account address new-account? encryption-key handler))
|
(data-source/change-account address new-account? encryption-key handler))
|
||||||
|
|
||||||
(defn- perform-transactions [raw-transactions realm]
|
(defn- perform-transactions [raw-transactions realm]
|
||||||
(let [success-events (->> raw-transactions
|
(let [success-events (keep :success-event raw-transactions)
|
||||||
(map :success-event)
|
|
||||||
(filter identity))
|
|
||||||
transactions (map (fn [{:keys [transaction] :as f}]
|
transactions (map (fn [{:keys [transaction] :as f}]
|
||||||
(or transaction f)) raw-transactions)]
|
(or transaction f)) raw-transactions)]
|
||||||
(data-source/write realm #(doseq [transaction transactions]
|
(data-source/write realm #(doseq [transaction transactions]
|
||||||
|
|
|
@ -29,15 +29,14 @@
|
||||||
(let [{:keys [payload sig timestamp ttl]} (js->clj js-message :keywordize-keys true)
|
(let [{:keys [payload sig timestamp ttl]} (js->clj js-message :keywordize-keys true)
|
||||||
status-message (-> payload
|
status-message (-> payload
|
||||||
transport.utils/to-utf8
|
transport.utils/to-utf8
|
||||||
transit/deserialize
|
transit/deserialize)]
|
||||||
(assoc :js-obj js-message))]
|
|
||||||
(when (and sig status-message)
|
(when (and sig status-message)
|
||||||
(handlers-macro/merge-fx
|
(handlers-macro/merge-fx
|
||||||
cofx
|
(assoc cofx :js-obj js-message)
|
||||||
(message/receive status-message (or chat-id sig) sig)
|
(message/receive status-message (or chat-id sig) sig)
|
||||||
(update-last-received-from-inbox now-in-s timestamp ttl)))))
|
(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))]
|
(for [i (range (.-length array))]
|
||||||
(aget array i)))
|
(aget array i)))
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@
|
||||||
cofx
|
cofx
|
||||||
(fn [message temp-cofx]
|
(fn [message temp-cofx]
|
||||||
(receive-message temp-cofx now-in-s chat-id message))
|
(receive-message temp-cofx now-in-s chat-id message))
|
||||||
(js-array->list js-messages))))
|
(js-array->seq js-messages))))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:protocol/receive-whisper-message
|
:protocol/receive-whisper-message
|
||||||
|
@ -173,9 +172,8 @@
|
||||||
fx))))
|
fx))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
;; TODO(rasom): confirmMessagesProcessed should be called after :data-store/tx
|
;; TODO(janherich): this should be called after `:data-store/tx` actually
|
||||||
;; effect, so this effect should be rewritten/removed
|
:confirm-messages-processed
|
||||||
:confirm-message-processed
|
|
||||||
(fn [messages]
|
(fn [messages]
|
||||||
(let [{:keys [web3]} (first messages)
|
(let [{:keys [web3]} (first messages)
|
||||||
js-messages (->> messages
|
js-messages (->> messages
|
||||||
|
@ -186,4 +184,4 @@
|
||||||
js-messages
|
js-messages
|
||||||
(fn [err resp]
|
(fn [err resp]
|
||||||
(when err
|
(when err
|
||||||
(log/info "Confirming message processed failed"))))))))
|
(log/info "Confirming messages processed failed"))))))))
|
||||||
|
|
|
@ -101,7 +101,8 @@
|
||||||
:message-id (transport.utils/message-id this)
|
:message-id (transport.utils/message-id this)
|
||||||
:show? true
|
:show? true
|
||||||
:chat-id chat-id
|
:chat-id chat-id
|
||||||
:from signature)]}))
|
:from signature
|
||||||
|
:js-obj (:js-obj cofx))]}))
|
||||||
|
|
||||||
(defrecord MessagesSeen [message-ids]
|
(defrecord MessagesSeen [message-ids]
|
||||||
message/StatusMessage
|
message/StatusMessage
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
(def ^:private mergable-keys
|
(def ^:private mergable-keys
|
||||||
#{:data-store/tx :data-store/base-tx :chat-received-message/add-fx
|
#{:data-store/tx :data-store/base-tx :chat-received-message/add-fx
|
||||||
:shh/add-new-sym-keys :shh/get-new-sym-keys :shh/post
|
: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]
|
(defn safe-merge [fx new-fx]
|
||||||
(if (:merging-fx-with-common-keys fx)
|
(if (:merging-fx-with-common-keys fx)
|
||||||
|
|
Loading…
Reference in New Issue