Chats list: new messages counter for group chat (fixes #252)

Former-commit-id: 3c28b83e43
This commit is contained in:
Roman Volosovskyi 2016-09-23 16:30:30 +03:00
parent 8643a1eb2a
commit 54f76720c4
3 changed files with 26 additions and 28 deletions

View File

@ -58,9 +58,9 @@
(if all-loaded? (if all-loaded?
db db
(let [messages-path [:chats current-chat-id :messages] (let [messages-path [:chats current-chat-id :messages]
messages (get-in db messages-path) messages (get-in db messages-path)
new-messages (messages/get-messages current-chat-id (count messages)) new-messages (messages/get-messages current-chat-id (count messages))
all-loaded? (> default-number-of-messages (count new-messages))] all-loaded? (> default-number-of-messages (count new-messages))]
(-> db (-> db
(assoc :loading-allowed false) (assoc :loading-allowed false)
(update-in messages-path concat new-messages) (update-in messages-path concat new-messages)
@ -172,7 +172,7 @@
(defn init-console-chat (defn init-console-chat
[{:keys [chats] :as db} existing-account?] [{:keys [chats] :as db} existing-account?]
(let [chat-id "console" (let [chat-id "console"
new-chat sign-up-service/console-chat] new-chat sign-up-service/console-chat]
(if (chats chat-id) (if (chats chat-id)
db db
@ -249,7 +249,7 @@
(map (fn [{:keys [chat-id] :as chat}] (map (fn [{:keys [chat-id] :as chat}]
[chat-id chat])) [chat-id chat]))
(into {})) (into {}))
ids (set (keys chats))] ids (set (keys chats))]
(-> db (-> db
(assoc :chats chats) (assoc :chats chats)
@ -268,9 +268,9 @@
(defmethod nav/preload-data! :chat (defmethod nav/preload-data! :chat
[{:keys [current-chat-id] :as db} [_ _ id]] [{:keys [current-chat-id] :as db} [_ _ id]]
(let [chat-id (or id current-chat-id) (let [chat-id (or id current-chat-id)
messages (get-in db [:chats chat-id :messages]) messages (get-in db [:chats chat-id :messages])
db' (assoc db :current-chat-id chat-id)] db' (assoc db :current-chat-id chat-id)]
(dispatch [:load-requests! chat-id]) (dispatch [:load-requests! chat-id])
(dispatch [:load-commands! chat-id]) (dispatch [:load-commands! chat-id])
(if (seq messages) (if (seq messages)
@ -405,31 +405,35 @@
[(after [(after
(fn [{:keys [current-chat-id] :as db}] (fn [{:keys [current-chat-id] :as db}]
(let [suggestions (get-in db [:has-suggestions? current-chat-id]) (let [suggestions (get-in db [:has-suggestions? current-chat-id])
mode (get-in db [:edit-mode current-chat-id])] mode (get-in db [:edit-mode current-chat-id])]
(when (and (= :command mode) suggestions) (when (and (= :command mode) suggestions)
(dispatch [:fix-response-height nil nil true]))))) (dispatch [:fix-response-height nil nil true])))))
(after (after
(fn [{:keys [current-chat-id] :as db}] (fn [{:keys [current-chat-id] :as db}]
(let [suggestions (get-in db [:command-suggestions current-chat-id]) (let [suggestions (get-in db [:command-suggestions current-chat-id])
mode (get-in db [:edit-mode current-chat-id])] mode (get-in db [:edit-mode current-chat-id])]
(when (and (not= :command mode) (seq suggestions)) (when (and (not= :command mode) (seq suggestions))
(dispatch [:fix-commands-suggestions-height nil nil true])))))] (dispatch [:fix-commands-suggestions-height nil nil true])))))]
(fn [db [_ h]] (fn [db [_ h]]
(assoc db :layout-height h))) (assoc db :layout-height h)))
(defn send-seen!
[{:keys [web3 current-public-key chats]}
[_ {:keys [from chat-id message-id]}]]
(when-not (console? chat-id)
(let [{:keys [group-chat]} (chats chat-id)]
(protocol/send-seen! {:web3 web3
:message {:from current-public-key
:to from
:group-id (when group-chat chat-id)
:message-id message-id}}))))
(register-handler :send-seen! (register-handler :send-seen!
(after (fn [_ [_ options]] [(after (fn [_ [_ {:keys [message-id]}]]
(dispatch [:message-seen options]))) (messages/update-message! {:message-id message-id
(u/side-effect! :message-status :seen})))
(fn [{:keys [web3 current-public-key chats]} (after (fn [_ [_ {:keys [chat-id]}]]
[_ {:keys [from chat-id message-id]}]] (dispatch [:remove-unviewed-messages chat-id])))]
(when-not (console? chat-id) (u/side-effect! send-seen!))
(let [{:keys [group-chat]} (chats chat-id)]
(protocol/send-seen! {:web3 web3
:message {:from current-public-key
:to from
:group-id (when group-chat chat-id)
:message-id message-id}}))))))
(register-handler :set-web-view-url (register-handler :set-web-view-url
(fn [{:keys [current-chat-id] :as db} [_ url]] (fn [{:keys [current-chat-id] :as db} [_ url]]

View File

@ -41,8 +41,6 @@
(defview chats-list [] (defview chats-list []
[chats [:get :chats]] [chats [:get :chats]]
;; todo what is this?!
#_(dispatch [:set :chats-scrolled? false])
[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)

View File

@ -234,11 +234,7 @@
(update-message-status :sent)) (update-message-status :sent))
(register-handler :message-seen (register-handler :message-seen
[(after (save-message-status! :seen)) [(after (save-message-status! :seen))]
(after (fn [_ [_ {:keys [from]
{:keys [group-id]} :payload}]]
(when-not group-id
(dispatch [:remove-unviewed-messages from]))))]
(update-message-status :seen)) (update-message-status :seen))
(register-handler :pending-message-upsert (register-handler :pending-message-upsert