Use first-not-visible message instead of last-visible
Using last visible message ignores an edge case: If we are on top of the list (i.e oldest message), any received message should be appended (it must be visible). When using last-visible message for this, a newer message will have < clock-value, therefore it will be offloaded to the database, which is not correct. Instead if we use the first-not-visible message, this should not be a problem. If we are on top of the list, this will be nil, and therefore the message will be appended. Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
9594bb49e2
commit
c2e195979c
|
@ -116,7 +116,6 @@
|
||||||
(when (and current-chat?
|
(when (and current-chat?
|
||||||
(or (not cursor-clock-value)
|
(or (not cursor-clock-value)
|
||||||
(<= cursor-clock-value clock-value)))
|
(<= cursor-clock-value clock-value)))
|
||||||
;; Not in the current view, offload to db and update cursor if necessary
|
|
||||||
(if (or (not @view.state/viewable-item)
|
(if (or (not @view.state/viewable-item)
|
||||||
(not= current-chat-id
|
(not= current-chat-id
|
||||||
(:chat-id @view.state/viewable-item))
|
(:chat-id @view.state/viewable-item))
|
||||||
|
@ -124,10 +123,11 @@
|
||||||
clock-value))
|
clock-value))
|
||||||
(add-message cofx {:message message
|
(add-message cofx {:message message
|
||||||
:current-chat? current-chat?})
|
:current-chat? current-chat?})
|
||||||
|
;; Not in the current view, offload to db and update cursor if necessary
|
||||||
(when (and (< clock-value
|
(when (and (< clock-value
|
||||||
cursor-clock-value)
|
cursor-clock-value)
|
||||||
(= current-chat-id
|
(= current-chat-id
|
||||||
(:chat-id (.-item view.state/viewable-item))))
|
(:chat-id @view.state/viewable-item)))
|
||||||
{:db (assoc-in db [:chats chat-id :cursor] (chat-loading/clock-value->cursor clock-value))})))))
|
{:db (assoc-in db [:chats chat-id :cursor] (chat-loading/clock-value->cursor clock-value))})))))
|
||||||
|
|
||||||
(defn- add-to-chat?
|
(defn- add-to-chat?
|
||||||
|
|
|
@ -305,13 +305,18 @@
|
||||||
(defonce messages-list-ref (atom nil))
|
(defonce messages-list-ref (atom nil))
|
||||||
|
|
||||||
(defn on-viewable-items-changed [e]
|
(defn on-viewable-items-changed [e]
|
||||||
|
(when @messages-list-ref
|
||||||
(reset! state/viewable-item
|
(reset! state/viewable-item
|
||||||
(let [element (->> (.-viewableItems e)
|
(when-let [last-visible-element (aget (.-viewableItems e) (dec (.-length (.-viewableItems e))))]
|
||||||
reverse
|
(let [index (.-index last-visible-element)
|
||||||
(filter (fn [e]
|
;; Get first not visible element, if it's a datemark/gap
|
||||||
(= :message (:type (.-item e)))))
|
;; we might unnecessarely add messages on receiving as
|
||||||
first)]
|
;; they do not have a clock value, but most of the times
|
||||||
(when element (.-item element))))
|
;; it will be a message
|
||||||
|
first-not-visible (aget (.-data (.-props @messages-list-ref)) (inc index))]
|
||||||
|
(when (and first-not-visible
|
||||||
|
(= :message (:type first-not-visible)))
|
||||||
|
first-not-visible)))))
|
||||||
(debounce/debounce-and-dispatch [:chat.ui/message-visibility-changed e] 5000))
|
(debounce/debounce-and-dispatch [:chat.ui/message-visibility-changed e] 5000))
|
||||||
|
|
||||||
(defview messages-view
|
(defview messages-view
|
||||||
|
|
Loading…
Reference in New Issue