From 8754f72eba2b5b73b654d8adb83d721253f2e0a2 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 18 Jan 2019 13:45:54 +0200 Subject: [PATCH] Fix merging of :message/message-persisted event Previously `:message/message-persisted` was dispatched for each incoming message because its argument was not a vector. The event was renamed to `:message/messages-persisted`. --- src/status_im/chat/core.cljs | 2 +- src/status_im/chat/models/message.cljs | 3 ++- src/status_im/data_store/core.cljs | 2 +- src/status_im/events.cljs | 11 ++++++++--- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/status_im/chat/core.cljs b/src/status_im/chat/core.cljs index 5522e353e1..d887efc589 100644 --- a/src/status_im/chat/core.cljs +++ b/src/status_im/chat/core.cljs @@ -21,4 +21,4 @@ db statuses) :data-store/tx [{:transaction (user-statuses-store/save-statuses-tx statuses) - :success-event [:message/message-persisted js-obj]}]}))) + :success-event [:message/messages-persisted [js-obj]]}]}))) diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index e1f2bf605e..c50f7049a8 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -139,7 +139,8 @@ :data-store/tx [(merge {:transaction (messages-store/save-message-tx prepared-message)} (when raw-message - {:success-event [:message/message-persisted raw-message]}))]} + {:success-event + [:message/messages-persisted [raw-message]]}))]} (when (and platform/desktop? (not batch?) (not (system-message? prepared-message))) diff --git a/src/status_im/data_store/core.cljs b/src/status_im/data_store/core.cljs index 790b9e8911..9e94f226b7 100644 --- a/src/status_im/data_store/core.cljs +++ b/src/status_im/data_store/core.cljs @@ -66,7 +66,7 @@ [merged-values]))])))))) (defn- merge-persistence-events [success-events] - (merge-events-of-type success-events :message/message-persisted)) + (merge-events-of-type success-events :message/messages-persisted)) (defn- perform-transactions [raw-transactions realm] (let [success-events (keep :success-event raw-transactions) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index d7b6f4e247..f1cea296bb 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -791,9 +791,14 @@ (chat.message/update-message-status cofx chat-id message-id status))) (handlers/register-handler-fx - :message/message-persisted - (fn [cofx [_ raw-message]] - (chat.message/confirm-message-processed cofx raw-message))) + :message/messages-persisted + (fn [cofx [_ raw-messages]] + (apply fx/merge + cofx + (map + (fn [raw-message] + (chat.message/confirm-message-processed raw-message)) + raw-messages)))) ;; signal module