Dont choke on wrongly serialized messages
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
parent
88c06c53d4
commit
54b9ba5a2e
|
@ -3,7 +3,6 @@
|
||||||
[status-im.accounts.db :as accounts.db]
|
[status-im.accounts.db :as accounts.db]
|
||||||
[status-im.chat.commands.core :as commands]
|
[status-im.chat.commands.core :as commands]
|
||||||
[status-im.chat.models :as chat-model]
|
[status-im.chat.models :as chat-model]
|
||||||
[status-im.constants :as constants]
|
|
||||||
[status-im.data-store.user-statuses :as user-statuses-store]
|
[status-im.data-store.user-statuses :as user-statuses-store]
|
||||||
[status-im.utils.datetime :as time]
|
[status-im.utils.datetime :as time]
|
||||||
[status-im.utils.fx :as fx]
|
[status-im.utils.fx :as fx]
|
||||||
|
@ -78,7 +77,8 @@
|
||||||
db :chats
|
db :chats
|
||||||
(reduce
|
(reduce
|
||||||
(fn [chats chat-id]
|
(fn [chats chat-id]
|
||||||
(let [chat-messages (index-messages (get-stored-messages chat-id))
|
(let [{:keys [messages]} (get-stored-messages chat-id)
|
||||||
|
chat-messages (index-messages messages)
|
||||||
message-ids (keys chat-messages)
|
message-ids (keys chat-messages)
|
||||||
statuses (get-stored-user-statuses chat-id message-ids)
|
statuses (get-stored-user-statuses chat-id message-ids)
|
||||||
unviewed-messages-ids (get-unviewed-messages-ids statuses public-key)]
|
unviewed-messages-ids (get-unviewed-messages-ids statuses public-key)]
|
||||||
|
@ -139,7 +139,12 @@
|
||||||
get-referenced-messages :get-referenced-messages :as cofx}]
|
get-referenced-messages :get-referenced-messages :as cofx}]
|
||||||
(when-not (get-in db [:chats current-chat-id :all-loaded?])
|
(when-not (get-in db [:chats current-chat-id :all-loaded?])
|
||||||
(let [loaded-count (count (get-in db [:chats current-chat-id :messages]))
|
(let [loaded-count (count (get-in db [:chats current-chat-id :messages]))
|
||||||
new-messages (get-stored-messages current-chat-id loaded-count)
|
{:keys [messages
|
||||||
|
all-loaded?]} (get-stored-messages current-chat-id loaded-count)
|
||||||
|
already-loaded-messages (get-in db [:chats current-chat-id :messages])
|
||||||
|
;; We remove those messages that are already loaded, as we might get some duplicates
|
||||||
|
new-messages (remove (comp already-loaded-messages :message-id)
|
||||||
|
messages)
|
||||||
indexed-messages (index-messages new-messages)
|
indexed-messages (index-messages new-messages)
|
||||||
referenced-messages (into empty-message-map
|
referenced-messages (into empty-message-map
|
||||||
(get-referenced-messages (get-referenced-ids indexed-messages)))
|
(get-referenced-messages (get-referenced-ids indexed-messages)))
|
||||||
|
@ -154,7 +159,7 @@
|
||||||
(update-in [:chats current-chat-id :referenced-messages]
|
(update-in [:chats current-chat-id :referenced-messages]
|
||||||
#(into (apply dissoc % new-message-ids) referenced-messages))
|
#(into (apply dissoc % new-message-ids) referenced-messages))
|
||||||
(assoc-in [:chats current-chat-id :all-loaded?]
|
(assoc-in [:chats current-chat-id :all-loaded?]
|
||||||
(> constants/default-number-of-messages (count new-messages))))}
|
all-loaded?))}
|
||||||
(chat-model/update-chats-unviewed-messages-count
|
(chat-model/update-chats-unviewed-messages-count
|
||||||
{:chat-id current-chat-id
|
{:chat-id current-chat-id
|
||||||
:new-loaded-unviewed-messages-ids loaded-unviewed-messages})
|
:new-loaded-unviewed-messages-ids loaded-unviewed-messages})
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
(ns status-im.data-store.messages
|
(ns status-im.data-store.messages
|
||||||
(:require [cljs.tools.reader.edn :as edn]
|
(:require [cljs.tools.reader.edn :as edn]
|
||||||
|
[taoensso.timbre :as log]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
[status-im.data-store.realm.core :as core]
|
[status-im.data-store.realm.core :as core]
|
||||||
|
@ -7,9 +8,12 @@
|
||||||
[status-im.js-dependencies :as dependencies]))
|
[status-im.js-dependencies :as dependencies]))
|
||||||
|
|
||||||
(defn- transform-message [message]
|
(defn- transform-message [message]
|
||||||
|
(try
|
||||||
(-> message
|
(-> message
|
||||||
(update :message-type keyword)
|
(update :message-type keyword)
|
||||||
(update :content edn/read-string)))
|
(update :content edn/read-string))
|
||||||
|
(catch :default e
|
||||||
|
(log/warn "failed to transform message with " e))))
|
||||||
|
|
||||||
(defn- get-by-chat-id
|
(defn- get-by-chat-id
|
||||||
([chat-id]
|
([chat-id]
|
||||||
|
@ -19,7 +23,8 @@
|
||||||
(core/sorted :timestamp :desc)
|
(core/sorted :timestamp :desc)
|
||||||
(core/page from (+ from constants/default-number-of-messages))
|
(core/page from (+ from constants/default-number-of-messages))
|
||||||
(core/all-clj :message))]
|
(core/all-clj :message))]
|
||||||
(map transform-message messages))))
|
{:all-loaded? (> constants/default-number-of-messages (count messages))
|
||||||
|
:messages (keep transform-message messages)})))
|
||||||
|
|
||||||
(defn get-message-id-by-old [old-message-id]
|
(defn get-message-id-by-old [old-message-id]
|
||||||
(when-let
|
(when-let
|
||||||
|
@ -39,10 +44,10 @@
|
||||||
(core/single (core/get-by-field
|
(core/single (core/get-by-field
|
||||||
@core/account-realm
|
@core/account-realm
|
||||||
:message :old-message-id response-to)))]
|
:message :old-message-id response-to)))]
|
||||||
[(or response-to-v2 response-to)
|
(when-let [deserialized-message (-> js-message
|
||||||
(-> js-message
|
|
||||||
(core/realm-obj->clj :message)
|
(core/realm-obj->clj :message)
|
||||||
transform-message)]))
|
transform-message)]
|
||||||
|
[(or response-to-v2 response-to) deserialized-message])))
|
||||||
message-ids)))
|
message-ids)))
|
||||||
|
|
||||||
(def default-values
|
(def default-values
|
||||||
|
|
Loading…
Reference in New Issue