Get replies directly from status-go

Fixes: #10297
Fixes: #10274

Before if a reply was missing (for example if it the message replied to
arrived after the reply) status-react would subscribe to it dynamically
and use that. This caused some flickering issues when offloading the
messages from the database, as the message being replied to would be
offloaded and later loaded back again, triggering scroll and ending up
in a loop.

This commit changes the behavior so that status-go always adds the
reply to the message. In case the message being replied to arrives after
the reply, this will be included in the message update, and status-react
will replace it in the local storage.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2020-04-08 18:01:11 +02:00
parent 23af624305
commit 28a2bca012
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
4 changed files with 68 additions and 66 deletions

View File

@ -133,12 +133,15 @@
:always :always
(assoc-in [:chats chat-id :all-loaded?] false))})))) (assoc-in [:chats chat-id :all-loaded?] false))}))))
(defn- add-to-chat? (defn- message-loaded?
[{:keys [db]} {:keys [chat-id message-id]}]
(get-in db [:chats chat-id :messages message-id]))
(defn- earlier-than-deleted-at?
[{:keys [db]} {:keys [chat-id clock-value message-id from]}] [{:keys [db]} {:keys [chat-id clock-value message-id from]}]
(let [{:keys [cursor-clock-value deleted-at-clock-value messages]} (let [{:keys [deleted-at-clock-value]}
(get-in db [:chats chat-id])] (get-in db [:chats chat-id])]
(not (or (get messages message-id) (>= deleted-at-clock-value clock-value)))
(>= deleted-at-clock-value clock-value)))))
(fx/defn offload-message-from [{:keys [db] :as cofx} chat-id message-id] (fx/defn offload-message-from [{:keys [db] :as cofx} chat-id message-id]
(let [old-messages (get-in db [:chats chat-id :messages])] (let [old-messages (get-in db [:chats chat-id :messages])]
@ -185,16 +188,21 @@
:unviewed-messages-count (inc current-count))})))) :unviewed-messages-count (inc current-count))}))))
(fx/defn receive-one (fx/defn receive-one
[cofx message] [{:keys [db] :as cofx} {:keys [message-id] :as message}]
(when-let [chat-id (extract-chat-id cofx message)] (when-let [chat-id (extract-chat-id cofx message)]
(let [message-with-chat-id (assoc message :chat-id chat-id)] (let [message-with-chat-id (assoc message :chat-id chat-id)]
(when (add-to-chat? cofx message-with-chat-id) (when-not (earlier-than-deleted-at? cofx message-with-chat-id)
(fx/merge cofx (if (message-loaded? cofx message-with-chat-id)
(add-received-message message-with-chat-id) ;; If the message is already loaded, it means it's an update, that
(update-unviewed-count message-with-chat-id) ;; happens when a message that was missing a reply had the reply
(chat-model/join-time-messages-checked chat-id) ;; coming through, in which case we just insert the new message
(when platform/desktop? {:db (assoc-in db [:chats chat-id :messages message-id] message-with-chat-id)}
(chat-model/update-dock-badge-label))))))) (fx/merge cofx
(add-received-message message-with-chat-id)
(update-unviewed-count message-with-chat-id)
(chat-model/join-time-messages-checked chat-id)
(when platform/desktop?
(chat-model/update-dock-badge-label))))))))
;;;; Send message ;;;; Send message
@ -225,13 +233,6 @@
(data-store.messages/delete-message message-id) (data-store.messages/delete-message message-id)
(rebuild-message-list chat-id))) (rebuild-message-list chat-id)))
(fx/defn handle-saved-system-messages
{:events [:messages/system-messages-saved]}
[cofx messages]
(apply fx/merge cofx (map #(add-message {:message %
:seen-by-user? true})
messages)))
(fx/defn send-message (fx/defn send-message
[{:keys [db now] :as cofx} {:keys [chat-id] :as message}] [{:keys [db now] :as cofx} {:keys [chat-id] :as message}]
(protocol/send-chat-message cofx message)) (protocol/send-chat-message cofx message))

View File

@ -39,19 +39,19 @@
(defview quoted-message (defview quoted-message
[message-id {:keys [from text]} outgoing current-public-key] [message-id {:keys [from text]} outgoing current-public-key]
(letsubs [{:keys [quote ens-name alias]} (letsubs [{:keys [ens-name alias]} [:contacts/contact-name-by-identity from]]
[:messages/quote-info message-id]] [react/view {:style (style/quoted-message-container outgoing)}
(when (or quote text) [react/view {:style style/quoted-message-author-container}
[react/view {:style (style/quoted-message-container outgoing)} [chat.utils/format-reply-author
[react/view {:style style/quoted-message-author-container} from
[chat.utils/format-reply-author alias
(or from (:from quote)) ens-name
alias ens-name current-public-key current-public-key
(partial style/quoted-message-author outgoing)]] (partial style/quoted-message-author outgoing)]]
[react/text {:style (style/quoted-message-text outgoing) [react/text {:style (style/quoted-message-text outgoing)
:number-of-lines 5} :number-of-lines 5}
(or text (:text quote))]]))) text]]))
(defn render-inline [message-text outgoing content-type acc {:keys [type literal destination]}] (defn render-inline [message-text outgoing content-type acc {:keys [type literal destination]}]
(case type (case type
@ -154,7 +154,7 @@
[message-bubble-wrapper message [message-bubble-wrapper message
(let [response-to (:response-to content)] (let [response-to (:response-to content)]
[react/view [react/view
(when (seq response-to) (when (and (seq response-to) (:quoted-message message))
[quoted-message response-to (:quoted-message message) outgoing current-public-key]) [quoted-message response-to (:quoted-message message) outgoing current-public-key])
[render-parsed-text-with-timestamp message (:parsed-text content)]]) [render-parsed-text-with-timestamp message (:parsed-text content)]])
[message-timestamp message true]]) [message-timestamp message true]])

View File

@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead", "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.52.1", "version": "v0.52.2",
"commit-sha1": "4d2fb67add28875699ac6c8e3d942446e71e3fa1", "commit-sha1": "3a84afd0f19e294580406d9567eda3bb32ea8506",
"src-sha256": "0s8y1dbri6hzi1vig0d7mm0cx7dh9q3z9pbcr1xc30m1zjasx0iq" "src-sha256": "0p3mkyln7pr0qkd0j7bm3xqqd4i2jl3f5zsfqrwa1xky0rvzydw1"
} }

View File

@ -88,37 +88,38 @@
(is (= cursor-clock-value (get-in result [:db :chats chat-id :cursor-clock-value]))) (is (= cursor-clock-value (get-in result [:db :chats chat-id :cursor-clock-value])))
(is (= cursor (get-in result [:db :chats chat-id :cursor])))))))))) (is (= cursor (get-in result [:db :chats chat-id :cursor]))))))))))
(deftest add-to-chat? (deftest message-loaded?
(testing "it returns true when it's not in loaded message" (testing "it returns false when it's not in loaded message"
(is (message/add-to-chat? {:db {:chats {"a" {}}}} (is (not (message/message-loaded? {:db {:chats {"a" {}}}}
{:message-id "message-id" {:message-id "message-id"
:from "a" :from "a"
:clock-value 1 :clock-value 1
:chat-id "a"}))) :chat-id "a"}))))
(testing "it returns false when it's already in the loaded message" (testing "it returns true when it's already in the loaded message"
(is (not (message/add-to-chat? {:db {:chats {"a" {:messages {"message-id" {}}}}}} (is (message/message-loaded? {:db {:chats {"a" {:messages {"message-id" {}}}}}}
{:message-id "message-id" {:message-id "message-id"
:from "a" :from "a"
:clock-value 1 :clock-value 1
:chat-id "a"})))) :chat-id "a"}))))
(testing "it returns false when the clock-value is the same as the deleted-clock-value in chat" (deftest earlier-than-deleted-at?
(is (not (message/add-to-chat? {:db {:chats {"a" {:deleted-at-clock-value 1}}}} (testing "it returns true when the clock-value is the same as the deleted-clock-value in chat"
{:message-id "message-id" (is (message/earlier-than-deleted-at? {:db {:chats {"a" {:deleted-at-clock-value 1}}}}
:from "a" {:message-id "message-id"
:clock-value 1 :from "a"
:chat-id "a"})))) :clock-value 1
(testing "it returns true when the clock-value is greater than the deleted-clock-value in chat" :chat-id "a"})))
(is (message/add-to-chat? {:db {:chats {"a" {:deleted-at-clock-value 1}}}} (testing "it returns false when the clock-value is greater than the deleted-clock-value in chat"
{:message-id "message-id" (is (not (message/earlier-than-deleted-at? {:db {:chats {"a" {:deleted-at-clock-value 1}}}}
:from "a" {:message-id "message-id"
:clock-value 2 :from "a"
:chat-id "a"}))) :clock-value 2
(testing "it returns false when the clock-value is less than the deleted-clock-value in chat" :chat-id "a"}))))
(is (not (message/add-to-chat? {:db {:chats {"a" {:deleted-at-clock-value 1}}}} (testing "it returns true when the clock-value is less than the deleted-clock-value in chat"
{:message-id "message-id" (is (message/earlier-than-deleted-at? {:db {:chats {"a" {:deleted-at-clock-value 1}}}}
:from "a" {:message-id "message-id"
:clock-value 0 :from "a"
:chat-id "a"}))))) :clock-value 0
:chat-id "a"}))))
(deftest add-own-received-message (deftest add-own-received-message
(let [db {:multiaccount {:public-key "me"} (let [db {:multiaccount {:public-key "me"}