diff --git a/src/status_im/data_store/realm/schemas/account/v16/core.cljs b/src/status_im/data_store/realm/schemas/account/v16/core.cljs index 4c3b7b0317..1ffd365d6c 100644 --- a/src/status_im/data_store/realm/schemas/account/v16/core.cljs +++ b/src/status_im/data_store/realm/schemas/account/v16/core.cljs @@ -16,7 +16,8 @@ [status-im.data-store.realm.schemas.account.v5.group-contact :as group-contact] [status-im.data-store.realm.schemas.account.v8.local-storage :as local-storage] [status-im.data-store.realm.schemas.account.v13.handler-data :as handler-data] - [taoensso.timbre :as log])) + [taoensso.timbre :as log] + [cljs.reader :as reader])) (def schema [chat/schema chat-contact/schema @@ -36,15 +37,34 @@ local-storage/schema handler-data/schema]) +(defn chat-by-id [realm chat-id] + (some-> realm + (.objects "chat") + (.filtered (str "chat-id = \"" chat-id "\"")) + (aget 0))) + +(defn migrate-commands [realm content-type] + (some-> realm + (.objects "message") + (.filtered (str "content-type = \"" content-type "\"")) + (.map (fn [object _ _] + (let [group-id (aget object "group-id") + {:keys [bot] :as content} (reader/read-string (aget object "content"))] + (when-not bot + (let [chat-id (aget object "chat-id") + chat (chat-by-id realm chat-id) + group? (aget chat "group-chat") + bot-name (if group? + "transactor-group" + "transactor-personal") + content' (assoc content :bot bot-name)] + (aset object "content" (pr-str content'))))))))) + (defn migration [old-realm new-realm] (log/debug "migrating v16 account database: " old-realm new-realm) - (when-let [wallet-chat (some-> new-realm - (.objects "chat") - (.filtered "chat-id = \"wallet\"") - (aget 0))] + (when-let [wallet-chat (chat-by-id new-realm "wallet")] (.delete new-realm wallet-chat)) - (when-let [wallet-contact (some-> new-realm - (.objects "contact") - (.filtered "whisper-identity = \"wallet\"") - (aget 0))] - (.delete new-realm wallet-contact))) \ No newline at end of file + (when-let [wallet-contact (chat-by-id new-realm "wallet")] + (.delete new-realm wallet-contact)) + (migrate-commands new-realm "command-request") + (migrate-commands new-realm "command")) diff --git a/src/status_im/native_module/impl/module.cljs b/src/status_im/native_module/impl/module.cljs index 91808cb62b..5ef716a6da 100644 --- a/src/status_im/native_module/impl/module.cljs +++ b/src/status_im/native_module/impl/module.cljs @@ -156,7 +156,7 @@ "Removes duplicates by [jail path] keys, remains the last one." [[all-keys calls] {:keys [jail-id path] :as call}] (if (and (contains? all-keys [jail-id path]) - (not= (second path) :subscription)) + (not (#{:subscription :preview} (last path)))) [all-keys calls] [(conj all-keys [jail-id path]) (conj calls call)]))