From 0f97f16a38557d66fd0d5125d9944603e139573c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Thor=C3=A9n?= Date: Fri, 20 Oct 2017 17:26:47 +0200 Subject: [PATCH] [BUG #2242]: Quickfix to make phone command reanswerable again --- src/status_im/chat/handlers/requests.cljs | 2 +- src/status_im/data_store/realm/requests.cljs | 16 ++++++++++++++++ src/status_im/data_store/requests.cljs | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/status_im/chat/handlers/requests.cljs b/src/status_im/chat/handlers/requests.cljs index 98a7481c24..eaa6d582c8 100644 --- a/src/status_im/chat/handlers/requests.cljs +++ b/src/status_im/chat/handlers/requests.cljs @@ -26,7 +26,7 @@ [{:keys [current-chat-id] :as db} [_ chat-id]] (let [chat-id' (or chat-id current-chat-id) ;; todo maybe limit is needed - requests (requests/get-open-by-chat-id chat-id') + requests (requests/get-available-by-chat-id chat-id') requests' (map #(update % :type keyword) requests)] (assoc-in db [:chats chat-id' :requests] requests'))) diff --git a/src/status_im/data_store/realm/requests.cljs b/src/status_im/data_store/realm/requests.cljs index 75191f4f3e..d7adffb08e 100644 --- a/src/status_im/data_store/realm/requests.cljs +++ b/src/status_im/data_store/realm/requests.cljs @@ -16,6 +16,22 @@ (realm/sorted :added :desc) (realm/realm-collection->list))) +;; NOTE(oskarth): phone command in Console can be answered again, so we want to list this +;; TODO(oskarth): Refactor this, either by extending and/or query or changing status of message +(defn- get-reanswerable-by-chat-id + [chat-id] + (-> (realm/get-by-fields @realm/account-realm :request :and [[:chat-id chat-id] + [:type "phone"] + [:status "answered"]]) + (realm/sorted :added :desc) + (realm/realm-collection->list))) + +(defn get-available-by-chat-id + [chat-id] + (-> ((juxt get-open-by-chat-id get-reanswerable-by-chat-id) chat-id) + flatten + vec)) + (defn save [request] (realm/save @realm/account-realm :request request true)) diff --git a/src/status_im/data_store/requests.cljs b/src/status_im/data_store/requests.cljs index fd6a25239f..6902385e36 100644 --- a/src/status_im/data_store/requests.cljs +++ b/src/status_im/data_store/requests.cljs @@ -9,6 +9,10 @@ [chat-id] (data-store/get-open-by-chat-id chat-id)) +(defn get-available-by-chat-id + [chat-id] + (data-store/get-available-by-chat-id chat-id)) + (defn save [request] (data-store/save request))