From 6e5d54b5aa4dc9bbd1b0d79dd7dea996734fc247 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Wed, 12 Dec 2018 09:55:59 +0100 Subject: [PATCH] Fetch history action --- src/status_im/events.cljs | 5 +++++ src/status_im/mailserver/core.cljs | 15 +++++++++++++++ src/status_im/ui/components/popup_menu/views.cljs | 2 ++ src/status_im/ui/screens/chat/actions.cljs | 7 +++++++ translations/en.json | 1 + 5 files changed, 30 insertions(+) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 6ee3900ae0..ad6467e1f6 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -609,6 +609,11 @@ :confirm-button-text (i18n/label :t/clear-history-action) :on-accept #(re-frame/dispatch [:chat.ui/clear-history])}})) +(handlers/register-handler-fx + :chat.ui/fetch-history-pressed + (fn [cofx [_ chat-id]] + (mailserver/fetch-history cofx chat-id))) + (handlers/register-handler-fx :chat.ui/remove-chat-pressed (fn [_ [_ chat-id]] diff --git a/src/status_im/mailserver/core.cljs b/src/status_im/mailserver/core.cljs index c2c7dfdac8..4ace1d9489 100644 --- a/src/status_im/mailserver/core.cljs +++ b/src/status_im/mailserver/core.cljs @@ -7,6 +7,7 @@ [status-im.native-module.core :as status] [status-im.transport.utils :as transport.utils] [status-im.utils.fx :as fx] + [status-im.constants :as constants] [status-im.utils.utils :as utils] [taoensso.timbre :as log] [status-im.transport.db :as transport.db] @@ -481,6 +482,20 @@ :data-store/tx [(data-store.mailservers/save-mailserver-topic-tx {:topic topic :mailserver-topic mailserver-topic})]})))) +(fx/defn fetch-history + [{:keys [db] :as cofx} chat-id] + (let [topic (or (get-in db [:transport/chats chat-id :topic]) + (transport.utils/get-topic constants/contact-discovery)) + {:keys [chat-ids last-request] :as current-mailserver-topic} + (get-in db [:mailserver/topics topic] {:chat-ids #{}})] + (let [mailserver-topic (-> current-mailserver-topic + (assoc :last-request 1))] + (fx/merge cofx + {:db (assoc-in db [:mailserver/topics topic] mailserver-topic) + :data-store/tx [(data-store.mailservers/save-mailserver-topic-tx + {:topic topic + :mailserver-topic mailserver-topic})]} + (process-next-messages-request))))) (fx/defn resend-request [{:keys [db] :as cofx} {:keys [request-id]}] diff --git a/src/status_im/ui/components/popup_menu/views.cljs b/src/status_im/ui/components/popup_menu/views.cljs index a3c7428c5c..800269b2f1 100644 --- a/src/status_im/ui/components/popup_menu/views.cljs +++ b/src/status_im/ui/components/popup_menu/views.cljs @@ -19,6 +19,8 @@ :on-select #(re-frame/dispatch [:show-group-chat-profile])}) {:text (i18n/label :t/clear-history) :on-select #(re-frame/dispatch [:chat.ui/clear-history-pressed])} + {:text (i18n/label :t/fetch-history) + :on-select #(re-frame/dispatch [:chat.ui/fetch-history-pressed chat-id])} {:text (i18n/label :t/delete-chat) :on-select #(re-frame/dispatch [(if (and group-chat (not public?)) :group-chats.ui/remove-chat-pressed diff --git a/src/status_im/ui/screens/chat/actions.cljs b/src/status_im/ui/screens/chat/actions.cljs index a5b64de8c8..10d96383fb 100644 --- a/src/status_im/ui/screens/chat/actions.cljs +++ b/src/status_im/ui/screens/chat/actions.cljs @@ -26,6 +26,10 @@ {:label (i18n/label :t/clear-history) :action #(re-frame/dispatch [:chat.ui/clear-history-pressed])}) +(defn fetch-history [chat-id] + {:label (i18n/label :t/fetch-history) + :action #(re-frame/dispatch [:chat.ui/fetch-history-pressed chat-id])}) + (defn- delete-chat [chat-id group?] {:label (i18n/label :t/delete-chat) :action #(re-frame/dispatch [(if group? @@ -37,18 +41,21 @@ [view-my-wallet (view-profile chat-id) (clear-history) + (fetch-history chat-id) (delete-chat chat-id false)]) (defn- group-chat-actions [chat-id] [view-my-wallet (group-info chat-id) (clear-history) + (fetch-history chat-id) (delete-chat chat-id true)]) (defn- public-chat-actions [chat-id] [view-my-wallet (share-chat chat-id) (clear-history) + (fetch-history chat-id) (delete-chat chat-id false)]) (defn actions [group-chat? chat-id public?] diff --git a/translations/en.json b/translations/en.json index de77cd873c..aae50ce862 100644 --- a/translations/en.json +++ b/translations/en.json @@ -526,6 +526,7 @@ "and-you": "and you", "wallets": "Wallets", "clear-history": "Clear history", + "fetch-history": "Fetch last 24 hours", "currency-display-name-sgd": "Singapore Dollar", "wallet-manage-assets": "Manage Assets", "wallet-choose-from-contacts": "Choose from Contacts",