Merge pull request #512 from status-im/bug/#484

Chat list order
This commit is contained in:
Roman Volosovskyi 2016-11-30 12:23:38 +02:00 committed by GitHub
commit 04f040dd48
3 changed files with 18 additions and 11 deletions

View File

@ -54,7 +54,7 @@
:optimizations :none :optimizations :none
:target :nodejs}}]} :target :nodejs}}]}
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl] :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]
:timeout 120000}} :timeout 240000}}
:prod {:cljsbuild {:builds [{:id "ios" :prod {:cljsbuild {:builds [{:id "ios"
:source-paths ["src" "env/prod"] :source-paths ["src" "env/prod"]
:compiler {:output-to "index.ios.js" :compiler {:output-to "index.ios.js"

View File

@ -38,7 +38,8 @@
status-im.chat.handlers.webview-bridge status-im.chat.handlers.webview-bridge
status-im.chat.handlers.wallet-chat status-im.chat.handlers.wallet-chat
status-im.chat.handlers.console status-im.chat.handlers.console
[taoensso.timbre :as log])) [taoensso.timbre :as log]
[tailrecursion.priority-map :refer [priority-map-by]]))
(register-handler :set-chat-ui-props (register-handler :set-chat-ui-props
(fn [db [_ ui-element value]] (fn [db [_ ui-element value]]
@ -285,6 +286,10 @@
((enrich init-chat)) ((enrich init-chat))
((after load-commands!)))) ((after load-commands!))))
(defn compare-chats
[{timesatmp1 :timestamp} {timestamp2 :timestamp}]
(compare timestamp2 timesatmp1))
(defn initialize-chats (defn initialize-chats
[{:keys [loaded-chats account-creation? chats] :as db} _] [{:keys [loaded-chats account-creation? chats] :as db} _]
(let [chats' (if account-creation? (let [chats' (if account-creation?
@ -293,7 +298,7 @@
(map (fn [{:keys [chat-id] :as chat}] (map (fn [{:keys [chat-id] :as chat}]
(let [last-message (messages/get-last-message db chat-id)] (let [last-message (messages/get-last-message db chat-id)]
[chat-id (assoc chat :last-message last-message)]))) [chat-id (assoc chat :last-message last-message)])))
(into {}))) (into (priority-map-by compare-chats))))
ids (set (keys chats'))] ids (set (keys chats'))]
(-> db (-> db
@ -432,7 +437,8 @@
(fn [db [_ {:keys [chat-id clock-value] :as opts}]] (fn [db [_ {:keys [chat-id clock-value] :as opts}]]
(let [chat (if (chats/exists? chat-id) (let [chat (if (chats/exists? chat-id)
(let [{old-clock-value :clock-value :as chat} (chats/get-by-id chat-id)] (let [{old-clock-value :clock-value :as chat} (chats/get-by-id chat-id)]
(assoc chat :clock-value (max old-clock-value clock-value))) (assoc chat :clock-value (max old-clock-value clock-value)
:timestamp (random/timestamp)))
(prepare-chat db chat-id opts))] (prepare-chat db chat-id opts))]
(chats/save chat) (chats/save chat)
(update-in db [:chats chat-id] merge chat)))) (update-in db [:chats chat-id] merge chat))))
@ -570,5 +576,6 @@
(u/side-effect! (u/side-effect!
(fn [_ [_ chat-id]] (fn [_ [_ chat-id]]
(let [chat (-> (chats/get-by-id chat-id) (let [chat (-> (chats/get-by-id chat-id)
(update :clock-value inc))] (update :clock-value inc)
(assoc :timestamp (random/timestamp)))]
(dispatch [:update-chat! chat]))))) (dispatch [:update-chat! chat])))))

View File

@ -77,8 +77,8 @@
[view st/chats-container [view st/chats-container
[chats-list-toolbar] [chats-list-toolbar]
[list-view {:dataSource (to-datasource chats) [list-view {:dataSource (to-datasource chats)
:renderRow (fn [row _ _] :renderRow (fn [[id :as row] _ _]
(list-item [chat-list-item row])) (list-item ^{:key id} [chat-list-item row]))
:renderFooter #(list-item [chat-shadow-item]) :renderFooter #(list-item [chat-shadow-item])
:renderSeparator #(list-item :renderSeparator #(list-item
(when (< %2 (- (count chats) 1)) (when (< %2 (- (count chats) 1))