From c9774dbfe86276352d9af25997e4d11e1caf5015 Mon Sep 17 00:00:00 2001 From: janherich Date: Tue, 12 Jun 2018 18:39:46 +0200 Subject: [PATCH] Mark seen when loading more --- src/status_im/chat/events.cljs | 51 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/status_im/chat/events.cljs b/src/status_im/chat/events.cljs index 6dab7e98b5..3acc7fd331 100644 --- a/src/status_im/chat/events.cljs +++ b/src/status_im/chat/events.cljs @@ -64,32 +64,6 @@ (def index-messages (partial into {} (map (juxt :message-id identity)))) -(handlers/register-handler-fx - :load-more-messages - [(re-frame/inject-cofx :data-store/get-messages) - (re-frame/inject-cofx :data-store/get-user-statuses)] - (fn [{{:keys [current-chat-id] :as db} :db - get-stored-messages :get-stored-messages - get-stored-user-statuses :get-stored-user-statuses :as cofx} _] - (when-not (get-in db [:chats current-chat-id :all-loaded?]) - (let [loaded-count (count (get-in db [:chats current-chat-id :messages])) - new-messages (get-stored-messages current-chat-id loaded-count) - indexed-messages (index-messages new-messages) - new-message-ids (keys indexed-messages) - new-statuses (get-stored-user-statuses current-chat-id new-message-ids)] - (handlers-macro/merge-fx - cofx - {:db (-> db - (update-in [:chats current-chat-id :messages] merge indexed-messages) - (update-in [:chats current-chat-id :message-statuses] merge new-statuses) - (update-in [:chats current-chat-id :not-loaded-message-ids] - #(apply disj % new-message-ids)) - (update-in [:chats current-chat-id :unviewed-messages] - #(apply disj % new-message-ids)) - (assoc-in [:chats current-chat-id :all-loaded?] - (> constants/default-number-of-messages (count new-messages))))} - (models.message/group-messages current-chat-id new-messages)))))) - (handlers/register-handler-db :message-appeared [re-frame/trim-v] @@ -298,6 +272,31 @@ (fn [cofx [chat-id opts]] (navigate-to-chat chat-id opts cofx))) +(handlers/register-handler-fx + :load-more-messages + [(re-frame/inject-cofx :data-store/get-messages) + (re-frame/inject-cofx :data-store/get-user-statuses)] + (fn [{{:keys [current-chat-id] :as db} :db + get-stored-messages :get-stored-messages + get-stored-user-statuses :get-stored-user-statuses :as cofx} _] + (when-not (get-in db [:chats current-chat-id :all-loaded?]) + (let [loaded-count (count (get-in db [:chats current-chat-id :messages])) + new-messages (get-stored-messages current-chat-id loaded-count) + indexed-messages (index-messages new-messages) + new-message-ids (keys indexed-messages) + new-statuses (get-stored-user-statuses current-chat-id new-message-ids)] + (handlers-macro/merge-fx + cofx + {:db (-> db + (update-in [:chats current-chat-id :messages] merge indexed-messages) + (update-in [:chats current-chat-id :message-statuses] merge new-statuses) + (update-in [:chats current-chat-id :not-loaded-message-ids] + #(apply disj % new-message-ids)) + (assoc-in [:chats current-chat-id :all-loaded?] + (> constants/default-number-of-messages (count new-messages))))} + (models.message/group-messages current-chat-id new-messages) + (mark-messages-seen current-chat-id)))))) + (handlers/register-handler-fx :execute-stored-command-and-return-to-chat (fn [cofx [_ chat-id]]