diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index 51674d0262..72396f742d 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -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)) diff --git a/src/status_im/ui/screens/chat/message/message.cljs b/src/status_im/ui/screens/chat/message/message.cljs index 9d104a4ade..aa78f4a977 100644 --- a/src/status_im/ui/screens/chat/message/message.cljs +++ b/src/status_im/ui/screens/chat/message/message.cljs @@ -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]]) diff --git a/status-go-version.json b/status-go-version.json index 59949aaa39..7b63b91242 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -2,7 +2,7 @@ "_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh ' 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" } diff --git a/test/cljs/status_im/test/chat/models/message.cljs b/test/cljs/status_im/test/chat/models/message.cljs index 84db2b0b57..fa8ebe13ad 100644 --- a/test/cljs/status_im/test/chat/models/message.cljs +++ b/test/cljs/status_im/test/chat/models/message.cljs @@ -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"}