diff --git a/src/status_im/chat/events.cljs b/src/status_im/chat/events.cljs index 20e31585fa..59351d8d12 100644 --- a/src/status_im/chat/events.cljs +++ b/src/status_im/chat/events.cljs @@ -83,19 +83,14 @@ (async/go (async/>! realm-queue #(messages-store/save message))))) (re-frame/reg-fx - :delete-chat-messages - (fn [{:keys [chat-id group-chat debug?]}] - (when (or group-chat debug?) - (async/go (async/>! realm-queue #(messages-store/delete-by-chat-id chat-id)))) - (async/go (async/>! realm-queue #(pending-messages-store/delete-all-by-chat-id chat-id))))) + :delete-messages + (fn [chat-id] + (async/go (async/>! realm-queue #(messages-store/delete-by-chat-id chat-id))))) (re-frame/reg-fx - :update-message-overhead - (fn [[chat-id network-status]] - (let [update-fn (if (= network-status :offline) - chats-store/inc-message-overhead - chats-store/reset-message-overhead)] - (async/go (async/>! realm-queue #(update-fn chat-id)))))) + :delete-pending-messages + (fn [chat-id] + (async/go (async/>! realm-queue #(pending-messages-store/delete-all-by-chat-id chat-id))))) (re-frame/reg-fx :save-chat @@ -103,16 +98,14 @@ (async/go (async/>! realm-queue #(chats-store/save chat))))) (re-frame/reg-fx - :delete-chat - (fn [{:keys [chat-id debug?]}] - (if debug? - (async/go (async/>! realm-queue #(chats-store/delete chat-id))) - (async/go (async/>! realm-queue #(chats-store/set-inactive chat-id)))))) + :deactivate-chat + (fn [chat-id] + (async/go (async/>! realm-queue #(chats-store/set-inactive chat-id))))) (re-frame/reg-fx - :save-all-contacts - (fn [contacts] - (contacts-store/save-all contacts))) + :delete-chat + (fn [chat-id] + (async/go (async/>! realm-queue #(chats-store/delete chat-id))))) (re-frame/reg-fx :protocol-send-seen @@ -354,9 +347,14 @@ :remove-chat [re-frame/trim-v] (fn [{:keys [db]} [chat-id]] - (let [chat (get-in db [:chats chat-id])] - {:db (-> db - (update :chats dissoc chat-id) - (update :deleted-chats (fnil conj #{}) chat-id)) - :delete-chat chat - :delete-chat-messages chat}))) + (let [{:keys [chat-id group-chat debug?]} (get-in db [:chats chat-id])] + (cond-> {:db (-> db + (update :chats dissoc chat-id) + (update :deleted-chats (fnil conj #{}) chat-id)) + :delete-pending-messages chat-id} + (or group-chat debug?) + (assoc :delete-messages chat-id) + debug? + (assoc :delete-chat chat-id) + (not debug?) + (assoc :deactivate-chat chat-id))))) diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index 38fc7bb8fa..5e0189f2eb 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -219,9 +219,8 @@ (let [chat (get-in db [:chats chat-id]) message (prepare-message params chat) params' (assoc params :message message) - fx {:db (add-message-to-db db chat-id message true) - :update-message-overhead [chat-id network-status] - :save-message message}] + fx {:db (add-message-to-db db chat-id message true) + :save-message message}] (-> (merge fx (chat-model/upsert-chat (assoc fx :now now) {:chat-id chat-id})) (as-> fx' @@ -283,8 +282,7 @@ params' (assoc params :command command') fx {:db (-> (merge db (:db result)) - (add-message-to-db chat-id command' true)) - :update-message-overhead [chat-id network-status] + (add-message-to-db chat-id command' true)) :save-message (-> command' (assoc :chat-id chat-id) (update-in [:content :params] diff --git a/src/status_im/data_store/chats.cljs b/src/status_im/data_store/chats.cljs index d81d3863f7..90605e0a44 100644 --- a/src/status_im/data_store/chats.cljs +++ b/src/status_im/data_store/chats.cljs @@ -62,10 +62,6 @@ [chat-id] (get-property chat-id :removed-at)) -(defn get-message-overhead - [chat-id] - (get-property chat-id :message-overhead)) - (defn get-active-group-chats [] (data-store/get-active-group-chats)) @@ -74,14 +70,6 @@ [chat-id active?] (save-property chat-id :is-active active?)) -(defn inc-message-overhead - [chat-id] - (save-property chat-id :message-overhead (inc (get-message-overhead chat-id)))) - -(defn reset-message-overhead - [chat-id] - (save-property chat-id :message-overhead 0)) - (defn new-update? [timestamp chat-id] (let diff --git a/src/status_im/data_store/realm/schemas/account/v21/chat.cljs b/src/status_im/data_store/realm/schemas/account/v21/chat.cljs new file mode 100644 index 0000000000..51e2ad1c1e --- /dev/null +++ b/src/status_im/data_store/realm/schemas/account/v21/chat.cljs @@ -0,0 +1,37 @@ +(ns status-im.data-store.realm.schemas.account.v21.chat + (:require [status-im.ui.components.styles :refer [default-chat-color]])) + +(def schema {:name :chat + :primaryKey :chat-id + :properties {:chat-id :string + :name :string + :color {:type :string + :default default-chat-color} + :group-chat {:type :bool + :indexed true} + :group-admin {:type :string + :optional true} + :is-active :bool + :timestamp :int + :contacts {:type :list + :objectType :chat-contact} + :unremovable? {:type :bool + :default false} + :removed-at {:type :int + :optional true} + :removed-from-at {:type :int + :optional true} + :added-to-at {:type :int + :optional true} + :updated-at {:type :int + :optional true} + :public-key {:type :string + :optional true} + :private-key {:type :string + :optional true} + :contact-info {:type :string + :optional true} + :debug? {:type :bool + :default false} + :public? {:type :bool + :default false}}}) diff --git a/src/status_im/data_store/realm/schemas/account/v21/core.cljs b/src/status_im/data_store/realm/schemas/account/v21/core.cljs index 1ae8fa4baf..321f7d57c1 100644 --- a/src/status_im/data_store/realm/schemas/account/v21/core.cljs +++ b/src/status_im/data_store/realm/schemas/account/v21/core.cljs @@ -1,5 +1,5 @@ (ns status-im.data-store.realm.schemas.account.v21.core - (:require [status-im.data-store.realm.schemas.account.v19.chat :as chat] + (:require [status-im.data-store.realm.schemas.account.v21.chat :as chat] [status-im.data-store.realm.schemas.account.v1.chat-contact :as chat-contact] [status-im.data-store.realm.schemas.account.v19.contact :as contact] [status-im.data-store.realm.schemas.account.v20.discover :as discover] diff --git a/src/status_im/ui/screens/contacts/events.cljs b/src/status_im/ui/screens/contacts/events.cljs index f49a81a033..4a5e7569e3 100644 --- a/src/status_im/ui/screens/contacts/events.cljs +++ b/src/status_im/ui/screens/contacts/events.cljs @@ -84,7 +84,7 @@ (contacts/save contact))) (reg-fx - ::save-contacts! + :save-all-contacts (fn [new-contacts] (contacts/save-all new-contacts))) @@ -223,8 +223,8 @@ ;;(remove #(identities (:whisper-identity %))) (map #(vector (:whisper-identity %) %)) (into {})) - fx {:db (update db :contacts/contacts merge new-contacts') - ::save-contacts! (vals new-contacts')}] + fx {:db (update db :contacts/contacts merge new-contacts') + :save-all-contacts (vals new-contacts')}] (transduce (map second) (completing (partial loading-events/load-commands (assoc cofx :db (:db fx)))) fx diff --git a/src/status_im/ui/screens/group/chat_settings/events.cljs b/src/status_im/ui/screens/group/chat_settings/events.cljs index fa6d9ad9e2..569e1a02ed 100644 --- a/src/status_im/ui/screens/group/chat_settings/events.cljs +++ b/src/status_im/ui/screens/group/chat_settings/events.cljs @@ -2,8 +2,7 @@ (:require [re-frame.core :refer [dispatch reg-fx]] [status-im.utils.handlers :refer [register-handler-fx]] [status-im.protocol.core :as protocol] - [status-im.utils.random :as random] - [status-im.chat.handlers :as chat-events] + [status-im.utils.random :as random] [status-im.data-store.contacts :as contacts] [status-im.data-store.messages :as messages] [status-im.data-store.chats :as chats] @@ -173,4 +172,4 @@ :clear-history (fn [{{:keys [current-chat-id] :as db} :db} _] {:db (assoc-in db [:chats current-chat-id :messages] {}) - ::chat-events/delete-messages current-chat-id})) + :delete-messages current-chat-id})) diff --git a/test/cljs/status_im/test/contacts/events.cljs b/test/cljs/status_im/test/contacts/events.cljs index 47e8c5e1b2..fbbbcb5e69 100644 --- a/test/cljs/status_im/test/contacts/events.cljs +++ b/test/cljs/status_im/test/contacts/events.cljs @@ -64,7 +64,7 @@ (defn test-fixtures [] (rf/reg-fx ::events/init-store #()) - (rf/reg-fx ::contacts-events/save-contacts! #()) + (rf/reg-fx :save-all-contacts #()) (rf/reg-fx ::contacts-events/save-contact #()) (rf/reg-fx ::contacts-events/watch-contact #()) (rf/reg-fx ::contacts-events/stop-watching-contact #())