Fix replies, clear-history, logout bug
Fixes #9433 : this was due to the fact that `.-response-to` was returning nil, because of the dash in the name, instead in this cases `(aget .. "response-to")` should be used. Fixes #9431 : This was a left-over from the move from message-groups to message-list, and the code was not updated. Fixes #9430 #9429 Both of these were due to the same issue, cofx were wrongly passed to the function resulting in the db being updated but the fxs being discarded. There's still a separate issue that might result in messages not being saved on logout, because of a race condition (if you logout while is fetching messages, some of the message might not be saved). I will address that separately as we might be able to just save messages as they come in status-go, rather then having to pass them to status-react and back to status-go for saving. Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
a39ae15d99
commit
13b01ce879
|
@ -151,7 +151,7 @@
|
|||
cofx
|
||||
{:db (update-in db [:chats chat-id] merge
|
||||
{:messages {}
|
||||
:message-groups {}
|
||||
:message-list nil
|
||||
:last-message-content nil
|
||||
:last-message-content-type nil
|
||||
:last-message-timestamp nil
|
||||
|
|
|
@ -292,27 +292,18 @@
|
|||
(send chat-id message wrapped-record)
|
||||
(update-message-status chat-id message-id :sending))))
|
||||
|
||||
(fx/defn remove-message-from-group
|
||||
[{:keys [db]} chat-id {:keys [timestamp message-id]}]
|
||||
(let [datemark (time/day-relative timestamp)]
|
||||
{:db (update-in db [:chats chat-id :message-groups]
|
||||
(fn [groups]
|
||||
(let [message-references (get groups datemark)]
|
||||
(if (= 1 (count message-references))
|
||||
;; message removed is the only one in group, remove whole group
|
||||
(dissoc groups datemark)
|
||||
;; remove message from `message-references` list
|
||||
(assoc groups datemark
|
||||
(remove (comp (partial = message-id) :message-id)
|
||||
message-references))))))}))
|
||||
(fx/defn rebuild-message-list
|
||||
[{:keys [db]} chat-id]
|
||||
{:db (assoc-in db [:chats chat-id :message-list]
|
||||
(message-list/add-many nil (vals (get-in db [:chats chat-id :messages]))))})
|
||||
|
||||
(fx/defn delete-message
|
||||
"Deletes chat message, along its occurence in all references, like `:message-groups`"
|
||||
"Deletes chat message, rebuild message-list"
|
||||
[{:keys [db] :as cofx} chat-id message-id]
|
||||
(fx/merge cofx
|
||||
{:db (update-in db [:chats chat-id :messages] dissoc message-id)}
|
||||
(messages-store/delete-message message-id)
|
||||
(remove-message-from-group chat-id (get-in db [:chats chat-id :messages message-id]))))
|
||||
(rebuild-message-list chat-id)))
|
||||
|
||||
(fx/defn add-system-messages [cofx messages]
|
||||
(let [messages-fx (map #(add-message
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
(s/def :chat/public-group-topic (s/nilable string?))
|
||||
(s/def :chat/public-group-topic-error (s/nilable string?))
|
||||
(s/def :chat/messages (s/nilable map?)) ; messages indexed by message-id
|
||||
(s/def :chat/message-groups (s/nilable map?)) ; grouped/sorted messages
|
||||
(s/def :chat/referenced-messages (s/nilable map?)) ; map of messages indexed by message-id which are not displayed directly, but referenced by other messages
|
||||
(s/def :chat/last-clock-value (s/nilable number?)) ; last logical clock value of messages in chat
|
||||
(s/def :chat/loaded-chats (s/nilable seq?))
|
||||
(s/def :chat/bot-db (s/nilable map?))
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
:deleted-at-clock-value :deletedAtClockValue
|
||||
:is-active :active
|
||||
:last-clock-value :lastClockValue})
|
||||
(dissoc :referenced-messages :message-groups :gaps-loaded? :pagination-info
|
||||
(dissoc :message-list :gaps-loaded? :pagination-info
|
||||
:public? :group-chat :messages
|
||||
:might-have-join-time-messages?
|
||||
:loaded-unviewed-messages-ids
|
||||
|
|
|
@ -711,12 +711,6 @@
|
|||
(fn [{:keys [messages]}]
|
||||
(or messages {})))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:chats/current-chat-message-groups
|
||||
:<- [:chats/current-chat]
|
||||
(fn [{:keys [message-groups]}]
|
||||
(or message-groups {})))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:chats/messages-gaps
|
||||
:<- [:mailserver/gaps]
|
||||
|
|
|
@ -64,6 +64,6 @@
|
|||
:identicon (get-in cofx [:metadata :author :identicon])
|
||||
:from signature
|
||||
:metadata (:metadata cofx))]
|
||||
(fx/merge
|
||||
(chat.message/receive-one cofx message)
|
||||
(ens/verify-names-from-message this signature)))))
|
||||
(fx/merge cofx
|
||||
(chat.message/receive-one message)
|
||||
(ens/verify-names-from-message this signature)))))
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
built-message
|
||||
(protocol/Message.
|
||||
{:text (.-text content)
|
||||
:response-to (.-response-to content)
|
||||
:response-to (aget content "response-to")
|
||||
:name (.-name content)
|
||||
:chat-id (.-chat_id content)}
|
||||
(.-content_type parsed-message-js)
|
||||
|
|
|
@ -300,9 +300,7 @@
|
|||
:chat/public-group-topic
|
||||
:chat/public-group-topic-error
|
||||
:chat/messages
|
||||
:chat/message-groups
|
||||
:chat/message-statuses
|
||||
:chat/referenced-messages
|
||||
:chat/last-clock-value
|
||||
:chat/loaded-chats
|
||||
:chat/bot-db
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
|
||||
(deftest clear-history-test
|
||||
(let [chat-id "1"
|
||||
cofx {:db {:chats {chat-id {:message-groups {:something "a"}
|
||||
cofx {:db {:chats {chat-id {:message-list [{:something "a"}]
|
||||
:messages {"1" {:clock-value 1}
|
||||
"2" {:clock-value 10}
|
||||
"3" {:clock-value 2}}
|
||||
|
@ -74,7 +74,7 @@
|
|||
(is (= {} (get-in actual [:db :chats chat-id :messages])))))
|
||||
(testing "it deletes all the message groups"
|
||||
(let [actual (chat/clear-history cofx chat-id)]
|
||||
(is (= {} (get-in actual [:db :chats chat-id :message-groups])))))
|
||||
(is (= nil (get-in actual [:db :chats chat-id :message-list])))))
|
||||
(testing "it deletes unviewed messages set"
|
||||
(let [actual (chat/clear-history cofx chat-id)]
|
||||
(is (= 0 (get-in actual [:db :chats chat-id :unviewed-messages-count])))))
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
(:require [cljs.test :refer-macros [deftest is testing]]
|
||||
[status-im.utils.gfycat.core :as gfycat]
|
||||
[status-im.utils.identicon :as identicon]
|
||||
[status-im.utils.datetime :as time]
|
||||
[status-im.transport.message.protocol :as protocol]
|
||||
[status-im.chat.models.message-list :as models.message-list]
|
||||
|
||||
[status-im.chat.models.message :as message]
|
||||
[status-im.utils.datetime :as time]))
|
||||
|
||||
|
@ -191,36 +194,53 @@
|
|||
(is (get-in (message/receive-one cofx bad-chat-id-message) [:db :chats "not-matching" :messages "1"]))))))
|
||||
|
||||
(deftest delete-message
|
||||
(let [timestamp (time/now)
|
||||
cofx1 {:db {:chats {"chat-id" {:messages {0 {:message-id 0
|
||||
:content "a"
|
||||
:clock-value 0
|
||||
:whisper-timestamp (- timestamp 1)
|
||||
:timestamp (- timestamp 1)}
|
||||
1 {:message-id 1
|
||||
:content "b"
|
||||
:clock-value 1
|
||||
:whisper-timestamp timestamp
|
||||
:timestamp timestamp}}
|
||||
:message-groups {"datetime-today" '({:message-id 1}
|
||||
{:message-id 0})}}}}}
|
||||
cofx2 {:db {:chats {"chat-id" {:messages {0 {:message-id 0
|
||||
:content "a"
|
||||
:clock-value 0
|
||||
:whisper-timestamp timestamp
|
||||
:timestamp timestamp}}
|
||||
:message-groups {"datetime-today" '({:message-id 0})}}}}}
|
||||
fx1 (message/delete-message cofx1 "chat-id" 1)
|
||||
fx2 (message/delete-message cofx2 "chat-id" 0)]
|
||||
(testing "Deleting message deletes it along with all references"
|
||||
(is (= '(0)
|
||||
(keys (get-in fx1 [:db :chats "chat-id" :messages]))))
|
||||
(is (= {"datetime-today" '({:message-id 0})}
|
||||
(get-in fx1 [:db :chats "chat-id" :message-groups])))
|
||||
(is (= {}
|
||||
(get-in fx2 [:db :chats "chat-id" :messages])))
|
||||
(is (= {}
|
||||
(get-in fx2 [:db :chats "chat-id" :message-groups]))))))
|
||||
(with-redefs [time/day-relative (constantly "day-relative")
|
||||
time/timestamp->time (constantly "timestamp")]
|
||||
(let [cofx1 {:db {:chats {"chat-id" {:messages {0 {:message-id 0
|
||||
:content "a"
|
||||
:clock-value 0
|
||||
:whisper-timestamp 0
|
||||
:timestamp 0}
|
||||
1 {:message-id 1
|
||||
:content "b"
|
||||
:clock-value 1
|
||||
:whisper-timestamp 1
|
||||
:timestamp 1}}
|
||||
:message-list [{:something :something}]}}}}
|
||||
cofx2 {:db {:chats {"chat-id" {:messages {0 {:message-id 0
|
||||
:content "a"
|
||||
:clock-value 0
|
||||
:whisper-timestamp 1
|
||||
:timestamp 1}}
|
||||
:message-list [{:something :something}]}}}}
|
||||
fx1 (message/delete-message cofx1 "chat-id" 1)
|
||||
fx2 (message/delete-message cofx2 "chat-id" 0)]
|
||||
(testing "Deleting message deletes it along with all references"
|
||||
(is (= '(0)
|
||||
(keys (get-in fx1 [:db :chats "chat-id" :messages]))))
|
||||
(is (= [{:one-to-one? false
|
||||
:message-id 0
|
||||
:whisper-timestamp 0
|
||||
:type :message
|
||||
:display-photo? true
|
||||
:system-message? false
|
||||
:last-in-group? true
|
||||
:datemark "day-relative"
|
||||
:clock-value 0
|
||||
:first-in-group? true
|
||||
:from nil
|
||||
:first-outgoing? nil
|
||||
:outgoing-seen? nil
|
||||
:timestamp-str "timestamp"
|
||||
:first? true
|
||||
:display-username? true
|
||||
:outgoing nil}]
|
||||
(models.message-list/->seq
|
||||
(get-in fx1 [:db :chats "chat-id" :message-list]))))
|
||||
(is (= {}
|
||||
(get-in fx2 [:db :chats "chat-id" :messages])))
|
||||
(is (= nil
|
||||
(get-in fx2 [:db :chats "chat-id" :message-list])))))))
|
||||
|
||||
(deftest add-outgoing-status
|
||||
(testing "coming from us"
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
[status-im.data-store.chats :as chats]))
|
||||
|
||||
(deftest ->to-rpc
|
||||
(let [chat {:referenced-messages []
|
||||
:public? false
|
||||
(let [chat {:public? false
|
||||
:group-chat true
|
||||
:message-groups {}
|
||||
:message-list []
|
||||
:color "color"
|
||||
:contacts #{"a" "b" "c" "d"}
|
||||
:last-clock-value 10
|
||||
|
|
Loading…
Reference in New Issue