From 3b4d7a6a628001835af9764929d7a7fa1252ddc0 Mon Sep 17 00:00:00 2001 From: janherich Date: Mon, 30 Apr 2018 08:35:09 +0200 Subject: [PATCH] Remove obsolete code --- src/status_im/chat/events.cljs | 3 +- src/status_im/chat/events/queue_message.cljs | 29 ------- src/status_im/utils/pre_receiver.cljs | 41 ---------- test/cljs/status_im/test/runner.cljs | 6 +- .../status_im/test/utils/pre_receiver.cljs | 80 ------------------- 5 files changed, 3 insertions(+), 156 deletions(-) delete mode 100644 src/status_im/chat/events/queue_message.cljs delete mode 100644 src/status_im/utils/pre_receiver.cljs delete mode 100644 test/cljs/status_im/test/utils/pre_receiver.cljs diff --git a/src/status_im/chat/events.cljs b/src/status_im/chat/events.cljs index 9061543564..e677f55078 100644 --- a/src/status_im/chat/events.cljs +++ b/src/status_im/chat/events.cljs @@ -22,8 +22,7 @@ [status-im.transport.message.v1.group-chat :as group-chat] status-im.chat.events.commands status-im.chat.events.requests - status-im.chat.events.send-message - status-im.chat.events.queue-message + status-im.chat.events.send-message status-im.chat.events.receive-message status-im.chat.events.console status-im.chat.events.webview-bridge)) diff --git a/src/status_im/chat/events/queue_message.cljs b/src/status_im/chat/events/queue_message.cljs deleted file mode 100644 index 40337b8f2f..0000000000 --- a/src/status_im/chat/events/queue_message.cljs +++ /dev/null @@ -1,29 +0,0 @@ -(ns status-im.chat.events.queue-message - (:require [cljs.core.async :as async] - [re-frame.core :as re-frame] - [status-im.utils.config :as config] - [status-im.utils.pre-receiver :as pre-receiver] - [status-im.utils.handlers :as handlers])) - -;; We queue messaged before receiving them to allow lagging messages to catch up. -;; This ensures proper ordering from a user's POV the vast majority of the time. - -;; XXX(oskarth): Hacky def, consider better encapsulation -(when config/queue-message-enabled? - (def in-ch (pre-receiver/start! - {:delay-ms 500 - :reorder? true - :add-fn #(re-frame/dispatch [:chat-received-message/add %])}))) - -;; NOTE(oskarth): in-ch is assumed to exist -(re-frame/reg-fx - ::queue-message - (fn [message] - (async/put! in-ch message))) - -(handlers/register-handler-fx - :pre-received-message - (fn [_ [_ message]] - (if config/queue-message-enabled? - {::queue-message message} - {:dispatch [:chat-received-message/add message]}))) diff --git a/src/status_im/utils/pre_receiver.cljs b/src/status_im/utils/pre_receiver.cljs deleted file mode 100644 index 2133dc99d6..0000000000 --- a/src/status_im/utils/pre_receiver.cljs +++ /dev/null @@ -1,41 +0,0 @@ -(ns status-im.utils.pre-receiver - (:require [cljs.core.async :as async] - [taoensso.timbre :as log] - [status-im.utils.async :as async-utils])) - -;; See status-im.test.utils.pre-receiver for justification. - -(defn- add-message-mock [{:keys [id clock-value] :as msg}] - (log/debug "add-message-mock:" id clock-value)) - -(defn- earliest-clock-value-seen? [seen id clock-value] - (->> seen - (filter (fn [[_ x]] (= x id))) - sort - ffirst - (= clock-value))) - -(defn start! - "Starts a pre-receiver that returns channel to put messages on. Once - 'delay-ms' (default 50ms) time has passed, calls add-fn on message." - [& [{:keys [delay-ms reorder? add-fn] - :or {delay-ms 50 reorder? true add-fn add-message-mock}}]] - (let [in-ch (async/chan) - mature-ch (async/chan) - seen (atom #{})] - (async/go-loop [] - (let [{:keys [message-id clock-value] :as msg} (async/> received - (filter (fn [[_ x]] (= x id))) - sort - last - first - ((fn [v] (or (nil? v) (> clock-value v)))))) - -(defn add-message-test [received invariant? {:keys [id clock-value] :as msg}] - (when (not (monotonic-increase? @received id clock-value)) - (println "add-message-test NOT earliest clock value seen!") - (println "add-message-test received:" (pr-str @received)) - (println "add-message-test new:" id clock-value) - (is (not invariant?))) - (swap! received conj [clock-value id])) - -(defn simulate! [{:keys [reorder? invariant? done]}] - (let [delay-ms 50 - received (atom #{}) - add-fn (partial add-message-test received invariant?) - in-ch (pre-receiver/start! {:delay-ms delay-ms - :reorder? reorder? - :add-fn add-fn})] - - (doseq [msg messages] - (async/put! in-ch msg)) - - (async/go (async/