move discoveries model

This commit is contained in:
Roman Volosovskyi 2016-05-13 17:34:04 +03:00
parent c62feb0159
commit c27fddfe18
5 changed files with 11 additions and 21 deletions

View File

@ -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!))))

View File

@ -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)))

View File

@ -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

View File

@ -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

View File

@ -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