[#12517] Ensure that all necessary contact fields are synced

This commit is contained in:
Roman Volosovskyi 2021-09-23 13:19:02 +03:00
parent 68ffddbb51
commit 23a0ac9522
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
6 changed files with 64 additions and 26 deletions

View File

@ -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

View File

@ -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}

View File

@ -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))

View File

@ -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)]

View File

@ -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]]])

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"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"
}