Fix chat list rendering
This commit is contained in:
parent
8b6f007313
commit
2b405d4d6c
|
@ -30,17 +30,18 @@
|
||||||
(:ref (get available-commands-responses response-name))))
|
(:ref (get available-commands-responses response-name))))
|
||||||
|
|
||||||
(defn- add-message-to-db
|
(defn- add-message-to-db
|
||||||
[db {:keys [message-id] :as message} chat-id]
|
[db {:keys [message-id] :as message} chat-id current-chat?]
|
||||||
(-> db
|
(cond-> (chat-utils/add-message-to-db db chat-id chat-id message (:new? message))
|
||||||
(update-in [:chats chat-id :unviewed-messages] (fnil conj #{}) message-id)
|
(not current-chat?)
|
||||||
(chat-utils/add-message-to-db chat-id chat-id message (:new? message))))
|
(update-in [:chats chat-id :unviewed-messages] (fnil conj #{}) message-id)))
|
||||||
|
|
||||||
(defn receive
|
(defn receive
|
||||||
[{:keys [db message-exists? pop-up-chat? get-last-clock-value now] :as cofx}
|
[{:keys [db message-exists? pop-up-chat? get-last-clock-value now] :as cofx}
|
||||||
{:keys [from group-id chat-id content-type content message-id timestamp clock-value]
|
{:keys [from group-id chat-id content-type content message-id timestamp clock-value]
|
||||||
:as message
|
:as message
|
||||||
:or {clock-value 0}}]
|
:or {clock-value 0}}]
|
||||||
(let [{:keys [access-scope->commands-responses] :contacts/keys [contacts]} db
|
(let [{:keys [current-chat-id view-id
|
||||||
|
access-scope->commands-responses] :contacts/keys [contacts]} db
|
||||||
{:keys [public-key] :as current-account} (get-current-account db)
|
{:keys [public-key] :as current-account} (get-current-account db)
|
||||||
chat-identifier (or group-id chat-id from)
|
chat-identifier (or group-id chat-id from)
|
||||||
direct-message? (nil? group-id)]
|
direct-message? (nil? group-id)]
|
||||||
|
@ -51,7 +52,9 @@
|
||||||
(not= from public-key)
|
(not= from public-key)
|
||||||
(or (pop-up-chat? chat-identifier)
|
(or (pop-up-chat? chat-identifier)
|
||||||
direct-message?))
|
direct-message?))
|
||||||
(let [fx (if (get-in db [:chats chat-identifier])
|
(let [current-chat? (and (= :chat view-id)
|
||||||
|
(= current-chat-id chat-identifier))
|
||||||
|
fx (if (get-in db [:chats chat-identifier])
|
||||||
(chat-model/upsert-chat cofx {:chat-id chat-identifier
|
(chat-model/upsert-chat cofx {:chat-id chat-identifier
|
||||||
:group-chat (boolean group-id)})
|
:group-chat (boolean group-id)})
|
||||||
(chat-model/add-chat cofx chat-identifier))
|
(chat-model/add-chat cofx chat-identifier))
|
||||||
|
@ -65,7 +68,7 @@
|
||||||
clock-value
|
clock-value
|
||||||
(get-last-clock-value chat-identifier)))
|
(get-last-clock-value chat-identifier)))
|
||||||
public-key
|
public-key
|
||||||
(assoc :user-statuses {public-key :received})
|
(assoc :user-statuses {public-key (if current-chat? :seen :received)})
|
||||||
(and command command-request?)
|
(and command command-request?)
|
||||||
(assoc-in [:content :content-command-ref]
|
(assoc-in [:content :content-command-ref]
|
||||||
(lookup-response-ref access-scope->commands-responses
|
(lookup-response-ref access-scope->commands-responses
|
||||||
|
@ -74,7 +77,7 @@
|
||||||
contacts
|
contacts
|
||||||
command)))]
|
command)))]
|
||||||
(cond-> (-> fx
|
(cond-> (-> fx
|
||||||
(update :db add-message-to-db enriched-message chat-identifier)
|
(update :db add-message-to-db enriched-message chat-identifier current-chat?)
|
||||||
(assoc :save-message (dissoc enriched-message :new?)))
|
(assoc :save-message (dissoc enriched-message :new?)))
|
||||||
command-request?
|
command-request?
|
||||||
(requests-events/add-request chat-identifier enriched-message))))))
|
(requests-events/add-request chat-identifier enriched-message))))))
|
||||||
|
|
|
@ -45,7 +45,8 @@
|
||||||
[toolbar-view]
|
[toolbar-view]
|
||||||
[list/flat-list {:style styles/list-container
|
[list/flat-list {:style styles/list-container
|
||||||
:data chats
|
:data chats
|
||||||
:render-fn (fn [chat] [chat-list-item chat edit?])
|
:render-fn (fn [[chat-id :as chat]]
|
||||||
|
^{:key chat-id} [chat-list-item chat edit?])
|
||||||
:header (when-not (empty? chats) list/default-header)
|
:header (when-not (empty? chats) list/default-header)
|
||||||
:footer (when-not (empty? chats)
|
:footer (when-not (empty? chats)
|
||||||
[react/view
|
[react/view
|
||||||
|
|
Loading…
Reference in New Issue