diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index 289b195a95..a09ad984aa 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -471,7 +471,7 @@ (handlers/register-handler-fx :contact-request-received (fn [{{:contacts/keys [contacts]} :db} - [_ {:keys [from payload]}]] + [_ {:keys [from payload timestamp]}]] (when from (let [{{:keys [name profile-image address status fcm-token]} :contact {:keys [public private]} :keypair} payload @@ -486,15 +486,22 @@ :fcm-token fcm-token} chat {:name name :chat-id from - :contact-info (prn-str contact)}] + :contact-info (prn-str contact)} + prev-last-updated (get-in contacts [from :last-updated] 0) + ;; NOTE(dmitryn) Workaround for old messages not having "payload.timestamp" attribute. + ;; Get timestamp from message root level. + ;; Root level "timestamp" is a unix ts in seconds. + timestamp' (or (:payload timestamp) + (* 1000 timestamp))] + (if-not existing-contact (let [contact (assoc contact :pending? true)] {:dispatch-n [[:add-contacts [contact]] [:add-chat from chat]]}) (when-not (:pending? existing-contact) - {:dispatch-n [[:update-contact! contact] - [:update-chat! chat] - [:watch-contact contact]]})))))) + (cond-> {:dispatch-n [[:update-chat! chat] + [:watch-contact contact]]} + (<= prev-last-updated timestamp') (update :dispatch-n concat [[:update-contact! contact]])))))))) ;;GROUP diff --git a/src/status_im/ui/screens/contacts/events.cljs b/src/status_im/ui/screens/contacts/events.cljs index d88b41fcc5..752a21540c 100644 --- a/src/status_im/ui/screens/contacts/events.cljs +++ b/src/status_im/ui/screens/contacts/events.cljs @@ -19,7 +19,8 @@ [status-im.ui.screens.contacts.navigation] [status-im.chat.console :as console-chat] [status-im.commands.events.loading :as loading-events] - [cljs.spec.alpha :as spec])) + [cljs.spec.alpha :as spec] + [status-im.protocol.web3.utils :as web3.utils])) ;;;; COFX @@ -68,7 +69,8 @@ :status status :fcm-token fcm-token} :keypair {:public updates-public-key - :private updates-private-key}}}}))) + :private updates-private-key} + :timestamp (web3.utils/timestamp)}}}))) (reg-fx ::reset-pending-messages