mirror of
https://github.com/status-im/status-mobile.git
synced 2025-01-24 15:38:56 +00:00
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:
parent
23af624305
commit
28a2bca012
@ -133,12 +133,15 @@
|
||||
:always
|
||||
(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]}]
|
||||
(let [{:keys [cursor-clock-value deleted-at-clock-value messages]}
|
||||
(let [{:keys [deleted-at-clock-value]}
|
||||
(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]
|
||||
(let [old-messages (get-in db [:chats chat-id :messages])]
|
||||
@ -185,16 +188,21 @@
|
||||
:unviewed-messages-count (inc current-count))}))))
|
||||
|
||||
(fx/defn receive-one
|
||||
[cofx message]
|
||||
[{:keys [db] :as cofx} {:keys [message-id] :as message}]
|
||||
(when-let [chat-id (extract-chat-id cofx message)]
|
||||
(let [message-with-chat-id (assoc message :chat-id chat-id)]
|
||||
(when (add-to-chat? cofx message-with-chat-id)
|
||||
(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)))))))
|
||||
(when-not (earlier-than-deleted-at? cofx message-with-chat-id)
|
||||
(if (message-loaded? cofx message-with-chat-id)
|
||||
;; If the message is already loaded, it means it's an update, that
|
||||
;; happens when a message that was missing a reply had the reply
|
||||
;; coming through, in which case we just insert the new message
|
||||
{:db (assoc-in db [:chats chat-id :messages message-id] message-with-chat-id)}
|
||||
(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
|
||||
|
||||
@ -225,13 +233,6 @@
|
||||
(data-store.messages/delete-message message-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
|
||||
[{:keys [db now] :as cofx} {:keys [chat-id] :as message}]
|
||||
(protocol/send-chat-message cofx message))
|
||||
|
@ -39,19 +39,19 @@
|
||||
|
||||
(defview quoted-message
|
||||
[message-id {:keys [from text]} outgoing current-public-key]
|
||||
(letsubs [{:keys [quote ens-name alias]}
|
||||
[:messages/quote-info message-id]]
|
||||
(when (or quote text)
|
||||
[react/view {:style (style/quoted-message-container outgoing)}
|
||||
[react/view {:style style/quoted-message-author-container}
|
||||
[chat.utils/format-reply-author
|
||||
(or from (:from quote))
|
||||
alias ens-name current-public-key
|
||||
(partial style/quoted-message-author outgoing)]]
|
||||
(letsubs [{:keys [ens-name alias]} [:contacts/contact-name-by-identity from]]
|
||||
[react/view {:style (style/quoted-message-container outgoing)}
|
||||
[react/view {:style style/quoted-message-author-container}
|
||||
[chat.utils/format-reply-author
|
||||
from
|
||||
alias
|
||||
ens-name
|
||||
current-public-key
|
||||
(partial style/quoted-message-author outgoing)]]
|
||||
|
||||
[react/text {:style (style/quoted-message-text outgoing)
|
||||
:number-of-lines 5}
|
||||
(or text (:text quote))]])))
|
||||
[react/text {:style (style/quoted-message-text outgoing)
|
||||
:number-of-lines 5}
|
||||
text]]))
|
||||
|
||||
(defn render-inline [message-text outgoing content-type acc {:keys [type literal destination]}]
|
||||
(case type
|
||||
@ -154,7 +154,7 @@
|
||||
[message-bubble-wrapper message
|
||||
(let [response-to (:response-to content)]
|
||||
[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])
|
||||
[render-parsed-text-with-timestamp message (:parsed-text content)]])
|
||||
[message-timestamp message true]])
|
||||
|
@ -2,7 +2,7 @@
|
||||
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
|
||||
"owner": "status-im",
|
||||
"repo": "status-go",
|
||||
"version": "v0.52.1",
|
||||
"commit-sha1": "4d2fb67add28875699ac6c8e3d942446e71e3fa1",
|
||||
"src-sha256": "0s8y1dbri6hzi1vig0d7mm0cx7dh9q3z9pbcr1xc30m1zjasx0iq"
|
||||
"version": "v0.52.2",
|
||||
"commit-sha1": "3a84afd0f19e294580406d9567eda3bb32ea8506",
|
||||
"src-sha256": "0p3mkyln7pr0qkd0j7bm3xqqd4i2jl3f5zsfqrwa1xky0rvzydw1"
|
||||
}
|
||||
|
@ -88,37 +88,38 @@
|
||||
(is (= cursor-clock-value (get-in result [:db :chats chat-id :cursor-clock-value])))
|
||||
(is (= cursor (get-in result [:db :chats chat-id :cursor]))))))))))
|
||||
|
||||
(deftest add-to-chat?
|
||||
(testing "it returns true when it's not in loaded message"
|
||||
(is (message/add-to-chat? {:db {:chats {"a" {}}}}
|
||||
{:message-id "message-id"
|
||||
:from "a"
|
||||
:clock-value 1
|
||||
:chat-id "a"})))
|
||||
(testing "it returns false when it's already in the loaded message"
|
||||
(is (not (message/add-to-chat? {:db {:chats {"a" {:messages {"message-id" {}}}}}}
|
||||
{:message-id "message-id"
|
||||
:from "a"
|
||||
:clock-value 1
|
||||
:chat-id "a"}))))
|
||||
(testing "it returns false when the clock-value is the same as the deleted-clock-value in chat"
|
||||
(is (not (message/add-to-chat? {:db {:chats {"a" {:deleted-at-clock-value 1}}}}
|
||||
{:message-id "message-id"
|
||||
:from "a"
|
||||
:clock-value 1
|
||||
:chat-id "a"}))))
|
||||
(testing "it returns true when the clock-value is greater than the deleted-clock-value in chat"
|
||||
(is (message/add-to-chat? {:db {:chats {"a" {:deleted-at-clock-value 1}}}}
|
||||
{:message-id "message-id"
|
||||
:from "a"
|
||||
:clock-value 2
|
||||
:chat-id "a"})))
|
||||
(testing "it returns false when the clock-value is less than the deleted-clock-value in chat"
|
||||
(is (not (message/add-to-chat? {:db {:chats {"a" {:deleted-at-clock-value 1}}}}
|
||||
{:message-id "message-id"
|
||||
:from "a"
|
||||
:clock-value 0
|
||||
:chat-id "a"})))))
|
||||
(deftest message-loaded?
|
||||
(testing "it returns false when it's not in loaded message"
|
||||
(is (not (message/message-loaded? {:db {:chats {"a" {}}}}
|
||||
{:message-id "message-id"
|
||||
:from "a"
|
||||
:clock-value 1
|
||||
:chat-id "a"}))))
|
||||
(testing "it returns true when it's already in the loaded message"
|
||||
(is (message/message-loaded? {:db {:chats {"a" {:messages {"message-id" {}}}}}}
|
||||
{:message-id "message-id"
|
||||
:from "a"
|
||||
:clock-value 1
|
||||
:chat-id "a"}))))
|
||||
(deftest earlier-than-deleted-at?
|
||||
(testing "it returns true when the clock-value is the same as the deleted-clock-value in chat"
|
||||
(is (message/earlier-than-deleted-at? {:db {:chats {"a" {:deleted-at-clock-value 1}}}}
|
||||
{:message-id "message-id"
|
||||
:from "a"
|
||||
:clock-value 1
|
||||
:chat-id "a"})))
|
||||
(testing "it returns false when the clock-value is greater than the deleted-clock-value in chat"
|
||||
(is (not (message/earlier-than-deleted-at? {:db {:chats {"a" {:deleted-at-clock-value 1}}}}
|
||||
{:message-id "message-id"
|
||||
:from "a"
|
||||
:clock-value 2
|
||||
:chat-id "a"}))))
|
||||
(testing "it returns true when the clock-value is less than the deleted-clock-value in chat"
|
||||
(is (message/earlier-than-deleted-at? {:db {:chats {"a" {:deleted-at-clock-value 1}}}}
|
||||
{:message-id "message-id"
|
||||
:from "a"
|
||||
:clock-value 0
|
||||
:chat-id "a"}))))
|
||||
|
||||
(deftest add-own-received-message
|
||||
(let [db {:multiaccount {:public-key "me"}
|
||||
|
Loading…
x
Reference in New Issue
Block a user