diff --git a/src/status_im/chat/events.cljs b/src/status_im/chat/events.cljs index 6e1a2c3d07..55eb03bd1a 100644 --- a/src/status_im/chat/events.cljs +++ b/src/status_im/chat/events.cljs @@ -57,7 +57,7 @@ (re-frame/reg-fx :update-message (fn [message] - (msg-store/update message))) + (msg-store/update-message message))) (re-frame/reg-fx :save-message @@ -261,4 +261,4 @@ (handlers/register-handler-fx :browse-link-from-message (fn [{{:keys [global-commands]} :db} [_ link]] - {:browse [(:browse global-commands) link]})) \ No newline at end of file + {:browse [(:browse global-commands) link]})) diff --git a/src/status_im/data_store/messages.cljs b/src/status_im/data_store/messages.cljs index cedd449b90..fb1d0edf69 100644 --- a/src/status_im/data_store/messages.cljs +++ b/src/status_im/data_store/messages.cljs @@ -5,8 +5,7 @@ [status-im.utils.utils :refer [update-if-present]] [clojure.walk :refer [stringify-keys keywordize-keys]] [cljs.reader :refer [read-string]] - [status-im.constants :as c]) - (:refer-clojure :exclude [update])) + [status-im.constants :as c])) (defn- user-statuses-to-map [user-statuses] @@ -105,13 +104,17 @@ (assoc acc message-id (read-string preview))) {}))) +(defn- prepare-content [content] + (pr-str + (update content :params dissoc :password :password-confirmation))) + (defn save ;; todo remove chat-id parameter [chat-id {:keys [message-id content] :as message}] (when-not (data-store/exists? message-id) (let [content' (if (string? content) content - (pr-str content)) + (prepare-content content)) message' (merge default-values message {:chat-id chat-id @@ -119,7 +122,7 @@ :timestamp (timestamp)})] (data-store/save message')))) -(defn update +(defn update-message [{:keys [message-id] :as message}] (when (data-store/exists? message-id) (let [message (update-if-present message :user-statuses vals)] 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 67f26c9881..f817670d10 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 @@ -45,8 +45,31 @@ (log/debug "v17 Removing contact" (pr-str contact)) (.delete new-realm contact))) +(defn command-with-wrong-bot? [bot command] + (and + (#{"transactor-personal" "transactor-group"} bot) + (not (#{"send" "request"} command)))) + +(defn update-commands [new-realm content-type] + (some-> new-realm + (.objects "message") + (.filtered (str "content-type = \"" content-type "\"")) + (.map (fn [object _ _] + (let [{:keys [bot command] :as content} (reader/read-string (aget object "content")) + content' (cond-> + content + + (= "password" command) + (update :params dissoc :password :password-confirmation) + + (command-with-wrong-bot? bot command) + (assoc :bot nil))] + (aset object "content" (pr-str content'))))))) + ;; 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) (doseq [contact ["oaken-water-meter" "gnosis" "Commiteth" "melonport"]] - (remove-contact! new-realm contact))) + (remove-contact! new-realm contact)) + (update-commands new-realm "command") + (update-commands new-realm "command-request")) diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index 6eb643fe2f..10f1824d9d 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -302,7 +302,7 @@ (assoc message :message-status status)) ;; we need to dissoc preview because it has been saved before (dissoc :preview))] - (messages/update message'))))))) + (messages/update-message message'))))))) (defn update-message-status [status] (fn [db @@ -347,8 +347,8 @@ (fn [_ [_ {:keys [type id] :as pending-message}]] (pending-messages/save pending-message) (when (#{:message :group-message} type) - (messages/update {:message-id id - :delivery-status :pending})))) + (messages/update-message {:message-id id + :delivery-status :pending})))) (fn [db [_ {:keys [type id to group-id]}]] (if (#{:message :group-message} type) (let [chat-id (or group-id to)