From ee5a169c8ef025cffb6cad7abb7cc8cccab53616 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 13 May 2016 17:34:04 +0300 Subject: [PATCH] move discoveries model Former-commit-id: c27fddfe18a86a596887a2524b2b5b1656428f8c --- src/syng_im/discovery/handlers.cljs | 10 +++++----- .../discoveries.cljs => discovery/model.cljs} | 14 ++++---------- src/syng_im/discovery/views/recent.cljs | 1 + src/syng_im/handlers.cljs | 4 +--- src/syng_im/models/messages.cljs | 3 --- 5 files changed, 11 insertions(+), 21 deletions(-) rename src/syng_im/{models/discoveries.cljs => discovery/model.cljs} (89%) diff --git a/src/syng_im/discovery/handlers.cljs b/src/syng_im/discovery/handlers.cljs index 0b00f15cd9..2efd7543ed 100644 --- a/src/syng_im/discovery/handlers.cljs +++ b/src/syng_im/discovery/handlers.cljs @@ -1,10 +1,8 @@ (ns syng-im.discovery.handlers - (:require [re-frame.core :refer [register-handler after dispatch enrich - log-ex debug]] + (:require [re-frame.core :refer [register-handler after dispatch enrich]] [syng-im.protocol.api :as api] - [syng-im.models.discoveries :refer [save-discoveries]] [syng-im.navigation.handlers :as nav] - [syng-im.models.discoveries :as discoveries] + [syng-im.discovery.model :as discoveries] [syng-im.utils.handlers :as u])) (defmethod nav/preload-data! :discovery @@ -12,6 +10,9 @@ (if-not (seq discoveries) (-> db (assoc :tags (discoveries/all-tags)) + ;; todo add limit + ;; todo hash-map with whisper-id as key and sorted by last-update + ;; may be more efficient here (assoc :discoveries (discoveries/discovery-list))) db)) @@ -71,6 +72,5 @@ (register-handler :add-discovery (-> add-discovery - debug ((after save-discovery!)) ((enrich reload-tags!)))) diff --git a/src/syng_im/models/discoveries.cljs b/src/syng_im/discovery/model.cljs similarity index 89% rename from src/syng_im/models/discoveries.cljs rename to src/syng_im/discovery/model.cljs index 6e8ea4cf0d..40d92407b2 100644 --- a/src/syng_im/models/discoveries.cljs +++ b/src/syng_im/discovery/model.cljs @@ -1,9 +1,8 @@ -(ns syng-im.models.discoveries - (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] - [syng-im.utils.logging :as log] +(ns syng-im.discovery.model + ;syng-im.models.discoveries + (:require [syng-im.utils.logging :as log] [syng-im.persistence.realm :as realm] - [syng-im.persistence.realm :as r] - [syng-im.db :as db])) + [syng-im.persistence.realm :as r])) (defn get-tag [tag] (log/debug "Getting tag: " tag) @@ -88,8 +87,3 @@ (r/sorted :count :desc) r/collection->map)) -(defn get-tag-popular [limit] - (-> (r/get-all :tag) - (r/sorted :count :desc) - (r/page 0 limit))) - diff --git a/src/syng_im/discovery/views/recent.cljs b/src/syng_im/discovery/views/recent.cljs index 598bcd66f8..b1bebc2d0a 100644 --- a/src/syng_im/discovery/views/recent.cljs +++ b/src/syng_im/discovery/views/recent.cljs @@ -17,6 +17,7 @@ (defn discovery-recent [] (let [discoveries (subscribe [:get :discoveries])] (fn [] + ;; todo fetch more on :onEndReached [list-view {:dataSource (to-datasource2 @discoveries) :renderRow render-row :renderSeparator render-separator diff --git a/src/syng_im/handlers.cljs b/src/syng_im/handlers.cljs index 021b072111..ac8ce2f21e 100644 --- a/src/syng_im/handlers.cljs +++ b/src/syng_im/handlers.cljs @@ -8,9 +8,7 @@ [syng-im.models.protocol :refer [update-identity set-initialized]] [syng-im.models.contacts :as contacts] - [syng-im.models.messages :refer [save-message - update-message! - message-by-id]] + [syng-im.models.messages :refer [save-message update-message!]] [syng-im.models.commands :refer [set-commands]] [syng-im.handlers.server :as server] [syng-im.chat.suggestions :refer [get-command diff --git a/src/syng_im/models/messages.cljs b/src/syng_im/models/messages.cljs index bf58efd2cd..b4c6d3b834 100644 --- a/src/syng_im/models/messages.cljs +++ b/src/syng_im/models/messages.cljs @@ -51,9 +51,6 @@ (update message :content str-to-map) message))))) -(defn message-by-id [msg-id] - (r/single-cljs (r/get-by-field :msgs :msg-id msg-id))) - (defn update-message! [{:keys [msg-id] :as msg}] (log/debug "update-message!" msg) (r/write