diff --git a/src/status_im/contact/block.cljs b/src/status_im/contact/block.cljs index f81afbd490..36417c90fc 100644 --- a/src/status_im/contact/block.cljs +++ b/src/status_im/contact/block.cljs @@ -35,7 +35,10 @@ {:events [::contact-blocked]} [{:keys [db] :as cofx} {:keys [public-key]} chats] (let [fxs (map #(clean-up-chat public-key %) chats)] - (apply fx/merge cofx fxs))) + (apply fx/merge + cofx + {:db (update db :chats dissoc public-key)} + fxs))) (fx/defn block-contact {:events [:contact.ui/block-contact-confirmed]} @@ -51,9 +54,7 @@ ;; add the contact to blocked contacts (update :contacts/blocked (fnil conj #{}) public-key) ;; update the contact in contacts list - (assoc-in [:contacts/contacts public-key] contact) - ;; remove the 1-1 chat if it exists - (update-in [:chats] dissoc public-key))} + (assoc-in [:contacts/contacts public-key] contact))} (contacts-store/block contact #(do (re-frame/dispatch [::contact-blocked contact (map chats-store/<-rpc %)]) (re-frame/dispatch [:hide-popover]))) ;; reset navigation to avoid going back to non existing one to one chat diff --git a/src/status_im/contact/core.cljs b/src/status_im/contact/core.cljs index 1b393710ed..747307dd2f 100644 --- a/src/status_im/contact/core.cljs +++ b/src/status_im/contact/core.cljs @@ -8,7 +8,8 @@ [status-im.utils.fx :as fx] [taoensso.timbre :as log] [clojure.string :as string] - [status-im.constants :as constants])) + [status-im.constants :as constants] + [status-im.contact.block :as contact.block])) (fx/defn load-contacts {:events [::contacts-loaded]} @@ -37,7 +38,7 @@ :address address})) (fx/defn ensure-contacts - [{:keys [db]} contacts] + [{:keys [db]} contacts chats] {:db (update db :contacts/contacts #(reduce (fn [acc {:keys [public-key] :as contact}] (-> acc @@ -45,10 +46,17 @@ (assoc-in [public-key :nickname] (:nickname contact)))) % contacts)) - :dispatch-n (map (fn [{:keys [public-key] :as contact}] - (when (contact.db/added? contact) - [:start-profile-chat public-key])) - contacts)}) + :dispatch-n (mapcat (fn [{:keys [public-key] :as contact}] + (cond-> [] + (contact.db/added? contact) + (conj [:start-profile-chat public-key]) + + (contact.db/removed? contact) + (conj [:offload-messages constants/timeline-chat-id]) + + (contact.db/blocked? contact) + (conj [::contact.block/contact-blocked contact chats]))) + contacts)}) (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 3e496d0324..389e68e3ee 100644 --- a/src/status_im/contact/db.cljs +++ b/src/status_im/contact/db.cljs @@ -79,6 +79,8 @@ ([db public-key] (added? (get-in db [:contacts/contacts public-key])))) +(def removed? (complement added?)) + (defn blocked? ([{:keys [system-tags]}] (contains? system-tags :contact/blocked)) diff --git a/src/status_im/transport/message/core.cljs b/src/status_im/transport/message/core.cljs index d3843f5b73..8beabc6d2d 100644 --- a/src/status_im/transport/message/core.cljs +++ b/src/status_im/transport/message/core.cljs @@ -43,11 +43,25 @@ ^js pin-messages (.-pinMessages response-js) ^js removed-messages (.-removedMessages response-js) sync-handler (when-not process-async process-response)] - (cond (seq chats) (do + (when (seq contacts) + ;; Note(rasom): in case if response contains contacts entries, some + ;; of them might be blocked. That means we might need to recalculate + ;; unviewed/mentions counters in chats where blocked users sent + ;; messages. Currently we ignore unviewed/mentions values which come + ;; from go side (see code few lines below) because it (probably) + ;; breaks app-db state. But we still have to apply those values when + ;; blocked contact is received from a paired device. + ;; In order to do so, we store all affected chats separately so that + ;; process loop might continue and then we use those chats on + ;; processing contacts update. Currently it causes one bug: for some + ;; reason own messages are counted as unviewed in 1-1 chat if they are + ;; sent on paired device. Although this change reveals the bug it is + ;; not the cause and thus the bug should be fixed separately. + (set! (.-chatsForContacts response-js) chats)) (js-delete response-js "chats") (fx/merge cofx (process-next response-js sync-handler) @@ -78,11 +92,16 @@ (models.pairing/handle-installations installations-clj))) (seq contacts) - (let [contacts-clj (types/js->clj contacts)] + (let [contacts-clj (types/js->clj contacts) + ^js chats (.-chatsForContacts response-js)] (js-delete response-js "contacts") + (js-delete response-js "chatsForContacts") (fx/merge cofx (process-next response-js sync-handler) - (models.contact/ensure-contacts (map data-store.contacts/<-rpc contacts-clj)))) + (models.contact/ensure-contacts + (map data-store.contacts/<-rpc contacts-clj) + (when chats + (map data-store.chats/<-rpc (types/js->clj chats)))))) (seq communities) (let [communities-clj (types/js->clj communities)] diff --git a/src/status_im/ui/screens/profile/contact/views.cljs b/src/status_im/ui/screens/profile/contact/views.cljs index d185464387..e3512d2a99 100644 --- a/src/status_im/ui/screens/profile/contact/views.cljs +++ b/src/status_im/ui/screens/profile/contact/views.cljs @@ -40,11 +40,13 @@ :accessibility-label :add-to-contacts-button :action #(re-frame/dispatch [:contact.ui/add-to-contact-pressed public-key])}]) (when platform/ios? - [{:label (i18n/label (if muted? :t/unmute :t/mute)) + [{:label (i18n/label (if (or muted? blocked?) :t/unmute :t/mute)) :icon :main-icons/notification :accessibility-label :mute-chat :selected muted? - :action #(re-frame/dispatch [::chat.models/mute-chat-toggled public-key (not muted?)])}]) + :disabled blocked? + :action (when-not blocked? + #(re-frame/dispatch [::chat.models/mute-chat-toggled public-key (not muted?)]))}]) [{:label (i18n/label (if blocked? :t/unblock :t/block)) :negative true :selected blocked? @@ -150,19 +152,25 @@ (views/letsubs [{:keys [public-key names]} [:contacts/current-contact]] [nickname-view public-key names])) -(defn button-item [{:keys [icon label action selected negative]}] +(defn button-item [{:keys [icon label action selected disabled negative]}] [react/touchable-highlight {:on-press action :style {:flex 1} :accessibility-label (str label "-item-button")} [react/view {:flex 1 :align-items :center} [list-item/icon-column {:icon icon :size :small - :icon-bg-color (if negative - (if selected colors/red colors/red-light) - (if selected colors/blue colors/blue-light)) - :icon-color (if negative - (if selected colors/white colors/red) - (if selected colors/white colors/blue))}] - [react/text {:style {:text-align :center :color (if negative colors/red colors/blue) + :icon-bg-color (if disabled + colors/gray-lighter + (if negative + (if selected colors/red colors/red-light) + (if selected colors/blue colors/blue-light))) + :icon-color (if disabled + colors/gray + (if negative + (if selected colors/white colors/red) + (if selected colors/white colors/blue)))}] + [react/text {:style {:text-align :center :color (if disabled + colors/gray + (if negative colors/red colors/blue)) :font-size 12 :line-height 16 :margin-top 6} :number-of-lines 2} label]]]) diff --git a/status-go-version.json b/status-go-version.json index 2f529458e2..f77977de99 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v0.87.1", - "commit-sha1": "59eeed94368c1f0ee9d603e313a13f178e644514", - "src-sha256": "1pnyb4vw88nx5b8np0ajhfyjblfkxr8bl40vhilz5gpz1g1a9l3c" + "version": "v0.88.0", + "commit-sha1": "839d6b3194e93fe29c898217549590e9f507c8e9", + "src-sha256": "01yn1n7zh3pzdaahax5flx2alvip4rd9723nya89fmvp67qwiiy4" }