diff --git a/src/status_im/chat/models.cljs b/src/status_im/chat/models.cljs index 1e860088f9..fb3c37c570 100644 --- a/src/status_im/chat/models.cljs +++ b/src/status_im/chat/models.cljs @@ -187,10 +187,12 @@ (fx/defn offload-messages {:events [:offload-messages]} [{:keys [db]} chat-id] - {:db (-> db - (update :messages dissoc chat-id) - (update :message-lists dissoc chat-id) - (update :pagination-info dissoc chat-id))}) + (merge {:db (-> db + (update :messages dissoc chat-id) + (update :message-lists dissoc chat-id) + (update :pagination-info dissoc chat-id))} + (when (and (= chat-id constants/timeline-chat-id) (= (:view-id db) :status)) + {:dispatch [:init-timeline-chat]}))) (fx/defn close-chat {:events [:close-chat]} diff --git a/src/status_im/contact/core.cljs b/src/status_im/contact/core.cljs index 1d33a8772b..9aac209d73 100644 --- a/src/status_im/contact/core.cljs +++ b/src/status_im/contact/core.cljs @@ -39,27 +39,37 @@ (fx/defn ensure-contacts [{:keys [db]} contacts chats] - {:db (update db :contacts/contacts - #(reduce (fn [acc {:keys [public-key] :as contact}] - (-> acc - (update public-key merge contact) - (assoc-in [public-key :nickname] (:nickname contact)))) - % - contacts)) - :dispatch-n (mapcat (fn [{:keys [public-key] :as contact}] - (cond-> [] - (:added contact) - (conj [:start-profile-chat public-key]) + (let [events + (reduce + (fn [acc {:keys [public-key] :as contact}] + (let [added (:added contact) + was-added (contact.db/added? db public-key) + blocked (:blocked contact) + was-blocked (contact.db/blocked? db public-key)] + (cond-> acc + (and added (not was-added)) + (conj [:start-profile-chat public-key]) - (not (:added contact)) - (conj [:offload-messages constants/timeline-chat-id]) + (and was-added (not added)) + (conj nil) - (:blocked contact) - (conj [::contact.block/contact-blocked contact chats]) + (and blocked (not was-blocked)) + (conj [::contact.block/contact-blocked contact chats]) - (contact.db/blocked? db public-key) - (conj [::contact.block/contact-unblocked public-key]))) - contacts)}) + (and was-blocked (not blocked)) + (conj [::contact.block/contact-unblocked public-key])))) + [[:offload-messages constants/timeline-chat-id]] + contacts)] + (merge + {:db (update db :contacts/contacts + #(reduce (fn [acc {:keys [public-key] :as contact}] + (-> acc + (update public-key merge contact) + (assoc-in [public-key :nickname] (:nickname contact)))) + % + contacts))} + (when (> (count events) 1) + {:dispatch-n events})))) (fx/defn upsert-contact [{:keys [db] :as cofx} diff --git a/src/status_im/contact/db.cljs b/src/status_im/contact/db.cljs index 2c31c9f2f9..d6c0468fe6 100644 --- a/src/status_im/contact/db.cljs +++ b/src/status_im/contact/db.cljs @@ -73,8 +73,8 @@ (get-in db [:contacts/contacts public-key])) (defn added? - ([{:keys [system-tags]}] - (contains? system-tags :contact/added)) + ([contact] + (:added contact)) ([db public-key] (added? (get-in db [:contacts/contacts public-key])))) @@ -84,29 +84,6 @@ ([db public-key] (blocked? (get-in db [:contacts/contacts public-key])))) -(defn pending? - "Check if this is a pending? contact, meaning one side sent a contact request - but the other didn't respond to it yet" - ([{:keys [system-tags] :as contact}] - (let [request-received? (contains? system-tags :contact/request-received) - added? (added? contact)] - (and (or request-received? - added?) - (not (and request-received? added?))))) - ([db public-key] - (pending? (get-in db [:contacts/contacts public-key])))) - -(defn legacy-pending? - "Would the :pending? field be true? for contacts sync payload sent to devices - running 0.11.0 or older?" - ([{:keys [system-tags] :as contact}] - (let [request-received? (contains? system-tags :contact/request-received) - added? (added? contact)] - (and request-received? - (not added?)))) - ([db public-key] - (pending? (get-in db [:contacts/contacts public-key])))) - (defn active? "Checks that the user is added to the contact and not blocked" ([contact]