[#19132] feat: block contact with remove contact checkbox (#19213)

This commit is contained in:
Mohsen 2024-03-13 18:33:19 +03:00 committed by GitHub
parent eb379791c9
commit 98cdf00276
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 199 additions and 75 deletions

View File

@ -3,7 +3,7 @@
[quo.foundations.colors :as colors])) [quo.foundations.colors :as colors]))
(def ^:private themes (def ^:private themes
{:light {:default {:bg colors/white {:light {:default {:bg colors/neutral-5
:border colors/neutral-20 :border colors/neutral-20
:icon colors/neutral-50 :icon colors/neutral-50
:text colors/neutral-100} :text colors/neutral-100}

View File

@ -5,21 +5,28 @@
[status-im.common.not-implemented :as not-implemented] [status-im.common.not-implemented :as not-implemented]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.contexts.profile.contact.add-nickname.view :as add-nickname] [status-im.contexts.profile.contact.add-nickname.view :as add-nickname]
[status-im.contexts.profile.contact.block-contact.view :as block-contact]
[status-im.contexts.profile.utils :as profile.utils] [status-im.contexts.profile.utils :as profile.utils]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn on-add-nickname
[]
(rf/dispatch [:show-bottom-sheet
{:content
(fn [] [add-nickname/view])}]))
(defn on-block-contact
[]
(rf/dispatch [:show-bottom-sheet
{:content
(fn [] [block-contact/view])}]))
(defn view (defn view
[] []
(let [{:keys [nickname (let [{:keys [nickname public-key contact-request-state blocked?]
public-key
contact-request-state]
:as contact} (rf/sub [:contacts/current-contact]) :as contact} (rf/sub [:contacts/current-contact])
full-name (profile.utils/displayed-name contact) full-name (profile.utils/displayed-name contact)
on-add-nickname (rn/use-callback #(rf/dispatch [:show-bottom-sheet
{:content
(fn [] [add-nickname/view])}]))
on-remove-nickname (rn/use-callback on-remove-nickname (rn/use-callback
(fn [] (fn []
(rf/dispatch [:hide-bottom-sheet]) (rf/dispatch [:hide-bottom-sheet])
@ -55,41 +62,43 @@
(rf/dispatch [:contact.ui/remove-contact-pressed contact])) (rf/dispatch [:contact.ui/remove-contact-pressed contact]))
[public-key full-name])] [public-key full-name])]
[quo/action-drawer [quo/action-drawer
[[{:icon :i/edit [(concat
:label (if has-nickname? [{:icon :i/edit
(i18n/label :t/edit-nickname) :label (if has-nickname?
(i18n/label :t/add-nickname-title)) (i18n/label :t/edit-nickname)
:on-press on-add-nickname (i18n/label :t/add-nickname-title))
:accessibility-label (if nickname :edit-nickname :add-nickname)} :on-press on-add-nickname
{:icon :i/qr-code :accessibility-label (if nickname :edit-nickname :add-nickname)}
:label (i18n/label :t/show-qr) {:icon :i/qr-code
:on-press on-show-qr :label (i18n/label :t/show-qr)
:accessibility-label :show-qr-code} :on-press on-show-qr
{:icon :i/share :accessibility-label :show-qr-code}
:label (i18n/label :t/share-profile) {:icon :i/share
:on-press on-share-profile :label (i18n/label :t/share-profile)
:accessibility-label :share-profile} :on-press on-share-profile
(when has-nickname? :accessibility-label :share-profile}
{:icon :i/delete (when has-nickname?
:label (i18n/label :t/remove-nickname) {:icon :i/delete
:on-press on-remove-nickname :label (i18n/label :t/remove-nickname)
:add-divider? true :on-press on-remove-nickname
:accessibility-label :remove-nickname :add-divider? true
:danger? true}) :accessibility-label :remove-nickname
{:icon :i/untrustworthy :danger? true})]
:label (i18n/label :t/mark-untrustworthy) (when-not blocked?
:on-press not-implemented/alert [{:icon :i/untrustworthy
:accessibility-label :mark-untrustworthy :label (i18n/label :t/mark-untrustworthy)
:add-divider? (when-not has-nickname? true) :on-press not-implemented/alert
:danger? true} :accessibility-label :mark-untrustworthy
(when (= constants/contact-request-state-mutual contact-request-state) :add-divider? (when-not has-nickname? true)
{:icon :i/remove-user :danger? true}
:label (i18n/label :t/remove-contact) (when (= constants/contact-request-state-mutual contact-request-state)
:on-press on-remove-contact {:icon :i/remove-user
:accessibility-label :remove-contact :label (i18n/label :t/remove-contact)
:danger? true}) :on-press on-remove-contact
{:icon :i/block :accessibility-label :remove-contact
:label (i18n/label :t/block-user) :danger? true})
:on-press not-implemented/alert {:icon :i/block
:accessibility-label :block-user :label (i18n/label :t/block-user)
:danger? true}]]])) :on-press on-block-contact
:accessibility-label :block-user
:danger? true}]))]]))

View File

@ -14,8 +14,8 @@
[] []
(let [{:keys [public-key primary-name nickname customization-color] (let [{:keys [public-key primary-name nickname customization-color]
:as profile} (rf/sub [:contacts/current-contact]) :as profile} (rf/sub [:contacts/current-contact])
;; TODO(@mohsen): remove :blue, https://github.com/status-im/status-mobile/issues/18733 ;; TODO(@mohsen): remove default color, https://github.com/status-im/status-mobile/issues/18733
customization-color (or customization-color :blue) customization-color (or customization-color constants/profile-default-color)
full-name (profile.utils/displayed-name profile) full-name (profile.utils/displayed-name profile)
profile-picture (profile.utils/photo profile) profile-picture (profile.utils/photo profile)
[unsaved-nickname set-unsaved-nickname] (rn/use-state nickname) [unsaved-nickname set-unsaved-nickname] (rn/use-state nickname)
@ -54,15 +54,15 @@
:customization-color customization-color}] :customization-color customization-color}]
[rn/view {:style style/input-wrapper} [rn/view {:style style/input-wrapper}
[quo/input [quo/input
{:type :text {:type :text
:char-limit constants/profile-name-max-length :char-limit constants/profile-name-max-length
:max-length constants/profile-name-max-length :max-length constants/profile-name-max-length
:auto-focus true :auto-focus true
:default-value unsaved-nickname :default-value unsaved-nickname
:error? (not (string/blank? error-msg)) :error? (not (string/blank? error-msg))
:label (i18n/label :t/nickname) :label (i18n/label :t/nickname)
:on-change-text on-nickname-change} :on-change-text on-nickname-change
:on-submit-editing on-nickname-submit] :on-submit-editing on-nickname-submit}]
[quo/info-message [quo/info-message
{:icon :i/info {:icon :i/info
:size :default :size :default

View File

@ -0,0 +1,11 @@
(ns status-im.contexts.profile.contact.block-contact.style)
(def content-wrapper
{:padding-vertical 8
:padding-horizontal 20
:gap 12})
(def checkbox-wrapper
{:flex-direction :row
:align-items :center
:gap 8})

View File

@ -0,0 +1,70 @@
(ns status-im.contexts.profile.contact.block-contact.view
(:require [quo.core :as quo]
[react-native.core :as rn]
[status-im.constants :as constants]
[status-im.contexts.profile.contact.block-contact.style :as style]
[status-im.contexts.profile.utils :as profile.utils]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn on-close [] (rf/dispatch [:hide-bottom-sheet]))
(defn view
[]
(let [{:keys [customization-color contact-request-state public-key]
:as contact} (rf/sub [:contacts/current-contact])
;; TODO(@mohsen): remove default color, https://github.com/status-im/status-mobile/issues/18733
customization-color (or customization-color constants/profile-default-color)
full-name (profile.utils/displayed-name contact)
profile-picture (profile.utils/photo contact)
[remove-contact? set-remove-contact?] (rn/use-state false)
on-remove-toggle (rn/use-callback #(set-remove-contact? not) [])
on-block-press (rn/use-callback
(fn []
(rf/dispatch [:toasts/upsert
{:id :user-blocked
:type :positive
:text (i18n/label :t/user-blocked
{:username
full-name})}])
(rf/dispatch [:contact.ui/block-contact-confirmed
public-key])
(when remove-contact?
(rf/dispatch [:contact.ui/remove-contact-pressed
{:public-key public-key}]))
(on-close))
[remove-contact? public-key full-name])]
[:<>
[quo/drawer-top
{:type :context-tag
:context-tag-type :default
:title (i18n/label :t/block)
:full-name full-name
:profile-picture profile-picture
:customization-color customization-color}]
[rn/view {:style style/content-wrapper}
[quo/text
{:weight :medium
:size :paragraph-1}
(i18n/label :t/block-user-title-message {:username full-name})]
[quo/information-box
{:icon :i/info
:type :default}
(i18n/label :t/blocking-a-user-message {:username full-name})]
(when (= constants/contact-request-state-mutual contact-request-state)
[rn/pressable
{:style style/checkbox-wrapper
:on-press on-remove-toggle}
[quo/selectors
{:type :checkbox
:checked? remove-contact?
:on-change on-remove-toggle}]
[quo/text (i18n/label :t/remove-contact)]])]
[quo/bottom-actions
{:actions :two-actions
:button-one-label (i18n/label :t/block)
:button-one-props {:type :danger
:on-press on-block-press}
:button-two-label (i18n/label :t/cancel)
:button-two-props {:type :grey
:on-press on-close}}]]))

View File

@ -2,6 +2,7 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[quo.core :as quo] [quo.core :as quo]
[react-native.core :as rn] [react-native.core :as rn]
[status-im.constants :as constants]
[status-im.contexts.profile.contact.contact-request.style :as style] [status-im.contexts.profile.contact.contact-request.style :as style]
[status-im.contexts.profile.utils :as profile.utils] [status-im.contexts.profile.utils :as profile.utils]
[utils.i18n :as i18n] [utils.i18n :as i18n]
@ -11,8 +12,8 @@
[] []
(let [{:keys [public-key customization-color] (let [{:keys [public-key customization-color]
:as profile} (rf/sub [:contacts/current-contact]) :as profile} (rf/sub [:contacts/current-contact])
;; TODO: remove :blue when #18733 merged. ;; TODO: remove default color when #18733 merged.
customization-color (or customization-color :blue) customization-color (or customization-color constants/profile-default-color)
full-name (profile.utils/displayed-name profile) full-name (profile.utils/displayed-name profile)
profile-picture (profile.utils/photo profile) profile-picture (profile.utils/photo profile)
[message set-message] (rn/use-state "") [message set-message] (rn/use-state "")

View File

@ -1,6 +1,7 @@
(ns status-im.contexts.profile.contact.contact-review.view (ns status-im.contexts.profile.contact.contact-review.view
(:require [quo.core :as quo] (:require [quo.core :as quo]
[react-native.core :as rn] [react-native.core :as rn]
[status-im.constants :as constants]
[status-im.contexts.profile.contact.contact-review.style :as style] [status-im.contexts.profile.contact.contact-review.style :as style]
[status-im.contexts.profile.utils :as profile.utils] [status-im.contexts.profile.utils :as profile.utils]
[utils.i18n :as i18n] [utils.i18n :as i18n]
@ -14,7 +15,7 @@
:keys [message]} (rf/sub [:activity-center/pending-contact-request-from-contact-id :keys [message]} (rf/sub [:activity-center/pending-contact-request-from-contact-id
public-key]) public-key])
;; TODO(@seanstrom): https://github.com/status-im/status-mobile/issues/18733 ;; TODO(@seanstrom): https://github.com/status-im/status-mobile/issues/18733
customization-color (or customization-color :blue) customization-color (or customization-color constants/profile-default-color)
full-name (profile.utils/displayed-name profile) full-name (profile.utils/displayed-name profile)
profile-picture (profile.utils/photo profile) profile-picture (profile.utils/photo profile)
on-contact-accept (rn/use-callback on-contact-accept (rn/use-callback

View File

@ -13,24 +13,41 @@
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn on-contact-request
[]
(rf/dispatch [:show-bottom-sheet
{:content (fn [] [contact-request/view])}]))
(defn on-contact-review
[]
(rf/dispatch [:show-bottom-sheet
{:content (fn [] [contact-review/view])}]))
(defn view (defn view
[{:keys [scroll-y]}] [{:keys [scroll-y]}]
(let [{:keys [public-key customization-color ens-name (let [{:keys [public-key customization-color ens-name
emoji-hash bio contact-request-state] emoji-hash bio blocked? contact-request-state]
:as profile} (rf/sub [:contacts/current-contact]) :as contact} (rf/sub [:contacts/current-contact])
customization-color (or customization-color :blue) ;; TODO(@mohsen): remove default color, https://github.com/status-im/status-mobile/issues/18733
full-name (profile.utils/displayed-name profile) customization-color (or customization-color constants/profile-default-color)
profile-picture (profile.utils/photo profile) full-name (profile.utils/displayed-name contact)
profile-picture (profile.utils/photo contact)
online? (rf/sub [:visibility-status-updates/online? public-key]) online? (rf/sub [:visibility-status-updates/online? public-key])
theme (quo.theme/use-theme-value) theme (quo.theme/use-theme-value)
on-contact-request (rn/use-callback #(rf/dispatch [:show-bottom-sheet
{:content (fn [] [contact-request/view])}]))
on-contact-review (rn/use-callback #(rf/dispatch [:show-bottom-sheet
{:content (fn [] [contact-review/view])}]))
on-start-chat (rn/use-callback #(rf/dispatch [:chat.ui/start-chat on-start-chat (rn/use-callback #(rf/dispatch [:chat.ui/start-chat
public-key public-key
ens-name]) ens-name])
[ens-name public-key])] [ens-name public-key])
on-unblock-press (rn/use-callback (fn []
(rf/dispatch [:contact.ui/unblock-contact-pressed
public-key])
(rf/dispatch [:toasts/upsert
{:id :user-unblocked
:type :positive
:text (i18n/label :t/user-unblocked
{:username
full-name})}]))
[public-key full-name])]
[rn/view {:style style/header-container} [rn/view {:style style/header-container}
[rn/view {:style style/header-top-wrapper} [rn/view {:style style/header-top-wrapper}
[rn/view {:style style/avatar-wrapper} [rn/view {:style style/avatar-wrapper}
@ -53,10 +70,20 @@
:description-text bio :description-text bio
:emoji-dash emoji-hash}] :emoji-dash emoji-hash}]
(when blocked?
[quo/button
{:container-style style/button-wrapper
:on-press on-unblock-press
:icon-left :i/block}
(i18n/label :t/unblock)])
(cond (cond
(or (not contact-request-state) (and (not blocked?)
(= contact-request-state constants/contact-request-state-none) (or
(= contact-request-state constants/contact-request-state-dismissed)) (not contact-request-state)
(= contact-request-state constants/contact-request-state-none)
(= contact-request-state constants/contact-request-state-dismissed)))
[quo/button [quo/button
{:container-style style/button-wrapper {:container-style style/button-wrapper
:on-press on-contact-request :on-press on-contact-request

View File

@ -4,6 +4,7 @@
[react-native.core :as rn] [react-native.core :as rn]
[react-native.reanimated :as reanimated] [react-native.reanimated :as reanimated]
[status-im.common.scroll-page.view :as scroll-page] [status-im.common.scroll-page.view :as scroll-page]
[status-im.constants :as constants]
[status-im.contexts.profile.contact.actions.view :as actions] [status-im.contexts.profile.contact.actions.view :as actions]
[status-im.contexts.profile.contact.header.view :as contact-header] [status-im.contexts.profile.contact.header.view :as contact-header]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -21,8 +22,8 @@
{:navigate-back? true {:navigate-back? true
:height 148 :height 148
:on-scroll #(reanimated/set-shared-value scroll-y %) :on-scroll #(reanimated/set-shared-value scroll-y %)
;; TODO(@mohsen): remove colors/primary-50, https://github.com/status-im/status-mobile/issues/18733 ;; TODO(@mohsen): remove default color, https://github.com/status-im/status-mobile/issues/18733
:cover-color (or customization-color colors/primary-50) :cover-color (or customization-color constants/profile-default-color)
:background-color (colors/theme-colors colors/white colors/neutral-95 theme) :background-color (colors/theme-colors colors/white colors/neutral-95 theme)
:page-nav-props {:right-side [{:icon-name :i/options :page-nav-props {:right-side [{:icon-name :i/options
:on-press on-action-press}]}} :on-press on-action-press}]}}

View File

@ -94,6 +94,8 @@
"blank-keycard-text": "You can proceed with your keycard once you've generated your keys and name", "blank-keycard-text": "You can proceed with your keycard once you've generated your keys and name",
"blank-keycard-title": "Looks like youve tapped \na blank keycard", "blank-keycard-title": "Looks like youve tapped \na blank keycard",
"block": "Block", "block": "Block",
"user-blocked": "{{username}} blocked",
"user-unblocked": "{{username}} unblocked",
"unblock": "Unblock", "unblock": "Unblock",
"block-contact": "Block this user", "block-contact": "Block this user",
"block-contact-details": "Blocking will delete this user's previous messages and stop new ones from reaching you", "block-contact-details": "Blocking will delete this user's previous messages and stop new ones from reaching you",
@ -2065,6 +2067,8 @@
"rename": "Rename", "rename": "Rename",
"mark-untrustworthy": "Mark as Untrustworthy", "mark-untrustworthy": "Mark as Untrustworthy",
"block-user": "Block user", "block-user": "Block user",
"block-user-title-message": "You will not see {{username}}'s messages, but {{username}} still can see your messages in mutual group chats and communities. {{username}} will be unable to message you.",
"blocking-a-user-message": "Blocking a user purges the database of all messages that youve previously received from {{username}} in all contexts.",
"group-details": "Group details", "group-details": "Group details",
"edit-name-and-image": "Edit name and image", "edit-name-and-image": "Edit name and image",
"change-group-privacy": "Change group privacy", "change-group-privacy": "Change group privacy",