From 1009b719082b55d1761b93ee32f5b5fe29959c4e Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Thu, 17 Sep 2020 15:00:46 +0300 Subject: [PATCH] [#11160] Hide blocked users from mention suggestions --- src/status_im/chat/models/loading.cljs | 8 ++--- src/status_im/chat/models/message.cljs | 2 +- src/status_im/chat/models/message_test.cljs | 16 ++++----- src/status_im/subs.cljs | 36 +++++++++++++-------- 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/status_im/chat/models/loading.cljs b/src/status_im/chat/models/loading.cljs index 2531bc3def..97ffc9b7b6 100644 --- a/src/status_im/chat/models/loading.cljs +++ b/src/status_im/chat/models/loading.cljs @@ -94,10 +94,10 @@ :as message}] (cond-> acc (and alias (not= alias "")) - (update :users assoc alias {:alias alias - :name (or name alias) - :identicon identicon - :public-key from}) + (update :users assoc from {:alias alias + :name (or name alias) + :identicon identicon + :public-key from}) (or (nil? last-clock-value) (> last-clock-value clock-value)) (assoc :last-clock-value clock-value) diff --git a/src/status_im/chat/models/message.cljs b/src/status_im/chat/models/message.cljs index c7bc13bad5..45bb8e96e2 100644 --- a/src/status_im/chat/models/message.cljs +++ b/src/status_im/chat/models/message.cljs @@ -72,7 +72,7 @@ [{:keys [db]} {:keys [chat-id alias name identicon from]}] (when (and alias (not= alias "")) {:db (update-in db [:chats chat-id :users] assoc - alias + from {:alias alias :name (or name alias) :identicon identicon diff --git a/src/status_im/chat/models/message_test.cljs b/src/status_im/chat/models/message_test.cljs index a24da579f5..6c7fbef49c 100644 --- a/src/status_im/chat/models/message_test.cljs +++ b/src/status_im/chat/models/message_test.cljs @@ -45,10 +45,10 @@ "00000000000000000000000000000000000000000000000000090x0000000000000000000000000000000000000000000000000000000000000000", :cursor-clock-value 9, :users - {"alias" {:alias "alias", - :name "name", - :identicon "identicon", - :public-key "from"}}}}}} + {"from" {:alias "alias", + :name "name", + :identicon "identicon", + :public-key "from"}}}}}} (message/add-received-message cofx message))))) @@ -67,10 +67,10 @@ "00000000000000000000000000000000000000000000000000090x0000000000000000000000000000000000000000000000000000000000000000", :cursor-clock-value 9, :users - {"alias" {:alias "alias", - :name "name", - :identicon "identicon", - :public-key "from"}}}}}} + {"from" {:alias "alias", + :name "name", + :identicon "identicon", + :public-key "from"}}}}}} (message/add-received-message cofx message))))) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 850cdc1dcd..c60b72c32a 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -150,6 +150,8 @@ (reg-root-key-sub :contacts/current-contact-identity :contacts/identity) (reg-root-key-sub :contacts/new-identity :contacts/new-identity) (reg-root-key-sub :group/selected-contacts :group/selected-contacts) +(reg-root-key-sub :contacts/blocked-set :contacts/blocked) + ;;wallet (reg-root-key-sub :wallet :wallet) (reg-root-key-sub :prices :prices) @@ -161,6 +163,7 @@ (reg-root-key-sub :wallet/prepare-transaction :wallet/prepare-transaction) (reg-root-key-sub :wallet-service/manual-setting :wallet-service/manual-setting) (reg-root-key-sub :wallet-service/state :wallet-service/state) + ;;commands (reg-root-key-sub :commands/select-account :commands/select-account) @@ -856,13 +859,17 @@ :<- [:contacts/contacts] (fn [contacts] (reduce - (fn [acc [key {:keys [alias name identicon]}]] - (if (and alias (not= alias "")) + (fn [acc [key {:keys [alias name identicon public-key] :as contact}]] + (println :foo alias (contact.db/blocked? contact)) + (if (and alias + (not= alias "") + (not (contact.db/blocked? contact))) (let [name (utils/safe-replace name ".stateofus.eth" "")] - (assoc acc alias {:alias alias - :name (or name alias) - :identicon identicon - :public-key key})) + (assoc acc public-key + {:alias alias + :name (or name alias) + :identicon identicon + :public-key key})) acc)) {} contacts))) @@ -871,14 +878,17 @@ :chats/mentionable-users :<- [:chats/current-chat] :<- [:chats/mentionable-contacts] + :<- [:contacts/blocked-set] :<- [:multiaccount] - (fn [[{:keys [users]} contacts {:keys [name preferred-name photo-path public-key]}]] - (-> users - (merge contacts) - (assoc public-key {:alias name - :name (or preferred-name name) - :identicon photo-path - :public-key public-key})))) + (fn [[{:keys [users]} contacts blocked {:keys [name preferred-name photo-path public-key]}]] + (apply dissoc + (-> users + (merge contacts) + (assoc public-key {:alias name + :name (or preferred-name name) + :identicon photo-path + :public-key public-key})) + blocked))) (re-frame/reg-sub :chat/mention-suggestions