From 666ec73959279e7e7e6c18465cc1a8f33630f756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Thor=C3=A9n?= Date: Fri, 27 Oct 2017 15:36:51 +0200 Subject: [PATCH] Overwrite default contacts with default.json Also cleanup migration for changed whisper-identities --- .../data_store/realm/schemas/account/v17/core.cljs | 13 ++++++++++++- src/status_im/ui/screens/contacts/events.cljs | 11 ++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/status_im/data_store/realm/schemas/account/v17/core.cljs b/src/status_im/data_store/realm/schemas/account/v17/core.cljs index 0da96be8d0..67f26c9881 100644 --- a/src/status_im/data_store/realm/schemas/account/v17/core.cljs +++ b/src/status_im/data_store/realm/schemas/account/v17/core.cljs @@ -37,5 +37,16 @@ local-storage/schema handler-data/schema]) +(defn remove-contact! [new-realm whisper-identity] + (when-let [contact (some-> new-realm + (.objects "contact") + (.filtered (str "whisper-identity = \"" whisper-identity "\"")) + (aget 0))] + (log/debug "v17 Removing contact" (pr-str contact)) + (.delete new-realm contact))) + +;; NOTE(oskarth): Resets Realm for some dApps to be loaded by default_contacts.json instead. (defn migration [old-realm new-realm] - (log/debug "migrating v17 account database: " old-realm new-realm)) + (log/debug "migrating v17 account database: " old-realm new-realm) + (doseq [contact ["oaken-water-meter" "gnosis" "Commiteth" "melonport"]] + (remove-contact! new-realm contact))) diff --git a/src/status_im/ui/screens/contacts/events.cljs b/src/status_im/ui/screens/contacts/events.cljs index 8757d03aea..6f523529e5 100644 --- a/src/status_im/ui/screens/contacts/events.cljs +++ b/src/status_im/ui/screens/contacts/events.cljs @@ -211,15 +211,12 @@ :timestamp (random/timestamp) :contacts (mapv #(hash-map :identity %) contacts)})]]) -;; TODO(oskarth): Consider getting rid of the :when so we can overwrite default -;; contacts with default_contacts.json This requires changing semantics of -;; update-pending-status (from :add-contacts handler) too. +;; NOTE(oskarth): We now overwrite default contacts upon upgrade with default_contacts.json data. (defn- prepare-default-contacts-events [contacts default-contacts] [[:add-contacts (for [[id {:keys [name photo-path public-key add-chat? pending? description dapp? dapp-url dapp-hash bot-url unremovable? mixable?]}] default-contacts - :let [id' (clojure.core/name id)] - :when (not (get contacts id'))] + :let [id' (clojure.core/name id)]] {:whisper-identity id' :address (public-key->address id') :name (:en name) @@ -283,10 +280,10 @@ :add-contacts (fn [{:keys [db]} [_ new-contacts]] (let [{:contacts/keys [contacts]} db - identities (set (keys contacts)) new-contacts' (->> new-contacts (map #(update-pending-status contacts %)) - (remove #(identities (:whisper-identity %))) + ;; NOTE(oskarth): Overwriting default contacts here + ;;(remove #(identities (:whisper-identity %))) (map #(vector (:whisper-identity %) %)) (into {}))] {:db (update db :contacts/contacts merge new-contacts')