load messages on scroll
This commit is contained in:
parent
dc079cc217
commit
ff1291dac0
|
@ -27,13 +27,12 @@
|
|||
(assoc db :show-actions show-actions)))
|
||||
|
||||
(register-handler :load-more-messages
|
||||
(fn [db _]
|
||||
db
|
||||
;; TODO implement
|
||||
#_(let [chat-id (get-in db [:chat :current-chat-id])
|
||||
messages [:chats chat-id :messages]
|
||||
new-messages (gen-messages 10)]
|
||||
(update-in db messages concat new-messages))))
|
||||
debug
|
||||
(fn [{:keys [current-chat-id] :as db} _]
|
||||
(let [messages-path [:chats current-chat-id :messages]
|
||||
messages (get-in db messages-path)
|
||||
new-messages (messages/get-messages current-chat-id (count messages))]
|
||||
(update-in db messages-path concat new-messages))))
|
||||
|
||||
(defn safe-trim [s]
|
||||
(when (string? s)
|
||||
|
@ -287,10 +286,8 @@
|
|||
|
||||
(defn load-messages!
|
||||
([db] (load-messages! db nil))
|
||||
([db _]
|
||||
(->> (:current-chat-id db)
|
||||
messages/get-messages
|
||||
(assoc db :messages))))
|
||||
([{:keys [current-chat-id] :as db} _]
|
||||
(assoc db :messages (messages/get-messages current-chat-id))))
|
||||
|
||||
(defn init-chat
|
||||
([db] (init-chat db nil))
|
||||
|
|
|
@ -15,3 +15,5 @@
|
|||
|
||||
(def response-input-hiding-duration 100)
|
||||
(def response-suggesstion-resize-duration 100)
|
||||
|
||||
(def default-number-of-messages 10)
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
[re-frame.core :refer [dispatch]]
|
||||
[cljs.reader :refer [read-string]]
|
||||
[status-im.utils.random :refer [timestamp]]
|
||||
[status-im.db :as db]
|
||||
[status-im.utils.logging :as log]
|
||||
[clojure.string :refer [join split]]
|
||||
[clojure.walk :refer [stringify-keys keywordize-keys]]
|
||||
|
@ -46,16 +45,19 @@
|
|||
#{c/content-type-command c/content-type-command-request}
|
||||
type))
|
||||
|
||||
(defn get-messages [chat-id]
|
||||
(defn get-messages
|
||||
([chat-id] (get-messages chat-id 0))
|
||||
([chat-id from]
|
||||
(->> (-> (r/get-by-field :msgs :chat-id chat-id)
|
||||
(r/sorted :timestamp :desc)
|
||||
(r/page from (+ from c/default-number-of-messages))
|
||||
(r/collection->map))
|
||||
(into '())
|
||||
reverse
|
||||
(map (fn [{:keys [content-type] :as message}]
|
||||
(if (command-type? content-type)
|
||||
(update message :content str-to-map)
|
||||
message)))))
|
||||
message))))))
|
||||
|
||||
(defn update-message! [{:keys [msg-id] :as msg}]
|
||||
(log/debug "update-message!" msg)
|
||||
|
|
Loading…
Reference in New Issue