[Fixes: #14623] Enable mutual contacts by default and show banner

This commit is contained in:
Andrea Maria Piana 2023-01-10 16:01:05 +00:00
parent 5c0bd33697
commit 7a5871a03f
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
15 changed files with 239 additions and 136 deletions

View File

@ -0,0 +1,13 @@
(ns quo2.components.drawers.permission-context.--tests--.permission-context-component-spec
(:require [quo2.components.drawers.permission-context.view :as permission-context]
[react-native.core :as rn]
[test-helpers.component :as h]))
(h/describe "permission context"
(h/test
(h/render [permission-context/view
[rn/text
{:accessibility-label :accessibility-id}
"a sample label"]])
(-> (js/expect (h/get-by-label-text :accessibility-id))
(.toBeTruthy))))

View File

@ -0,0 +1,16 @@
(ns quo2.components.drawers.permission-context.style
(:require [quo2.foundations.colors :as colors]))
(def radius 20)
(def container
{:padding-top 16
:padding-bottom 48
:padding-horizontal 20
:shadow-offset {:width 0
:height 2}
:shadow-radius radius
:border-top-left-radius radius
:border-top-right-radius radius
:elevation 2
:shadow-opacity 1
:shadow-color colors/shadow})

View File

@ -0,0 +1,8 @@
(ns quo2.components.drawers.permission-context.view
(:require [react-native.core :as rn]
[quo2.components.drawers.permission-context.style :as style]))
(defn view
[children]
[rn/view {:style style/container}
children])

View File

@ -4,6 +4,7 @@
[quo2.components.counter.--tests--.counter-component-spec] [quo2.components.counter.--tests--.counter-component-spec]
[quo2.components.dividers.--tests--.divider-label-component-spec] [quo2.components.dividers.--tests--.divider-label-component-spec]
[quo2.components.drawers.--tests--.action-drawers-component-spec] [quo2.components.drawers.--tests--.action-drawers-component-spec]
[quo2.components.drawers.permission-context.--tests--.permission-context-component-spec]
[quo2.components.markdown.--tests--.text-component-spec] [quo2.components.markdown.--tests--.text-component-spec]
[quo2.components.selectors.--tests--.selectors-component-spec] [quo2.components.selectors.--tests--.selectors-component-spec]
[quo2.components.selectors.filter.component-spec])) [quo2.components.selectors.filter.component-spec]))

View File

@ -4,7 +4,6 @@
[status-im.contact.block :as contact.block] [status-im.contact.block :as contact.block]
[status-im.contact.db :as contact.db] [status-im.contact.db :as contact.db]
[status-im.data-store.contacts :as contacts-store] [status-im.data-store.contacts :as contacts-store]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[status-im2.navigation.events :as navigation] [status-im2.navigation.events :as navigation]
[taoensso.timbre :as log])) [taoensso.timbre :as log]))
@ -151,15 +150,6 @@
#(re-frame/dispatch [:sanitize-messages-and-process-response %])) #(re-frame/dispatch [:sanitize-messages-and-process-response %]))
(navigation/navigate-back))) (navigation/navigate-back)))
(rf/defn switch-mutual-contact-requests-enabled
{:events [:multiaccounts.ui/switch-mutual-contact-requests-enabled]}
[cofx enabled?]
(multiaccounts.update/multiaccount-update
cofx
:mutual-contact-enabled?
enabled?
nil))
(rf/defn set-search-query (rf/defn set-search-query
{:events [:contacts/set-search-query]} {:events [:contacts/set-search-query]}
[{:keys [db] :as cofx} value] [{:keys [db] :as cofx} value]

View File

@ -86,8 +86,9 @@
(get-in db [:contacts/contacts public-key])) (get-in db [:contacts/contacts public-key]))
(defn added? (defn added?
([contact] ([{:keys [contact-request-state]}]
(:added contact)) (or (= constants/contact-request-state-mutual contact-request-state)
(= constants/contact-request-state-sent contact-request-state)))
([db public-key] ([db public-key]
(added? (get-in db [:contacts/contacts public-key])))) (added? (get-in db [:contacts/contacts public-key]))))
@ -98,27 +99,28 @@
(blocked? (get-in db [:contacts/contacts public-key])))) (blocked? (get-in db [:contacts/contacts public-key]))))
(defn active? (defn active?
"Checks that the user is added to the contact and not blocked" "Checks that we are mutual contacts"
([contact] ([contact]
(and (:added contact) (and (= constants/contact-request-state-mutual
(:contact-request-state contact))
(not (:blocked contact)))) (not (:blocked contact))))
([db public-key] ([db public-key]
(active? (get-in db [:contacts/contacts public-key])))) (active? (get-in db [:contacts/contacts public-key]))))
(defn enrich-contact (defn enrich-contact
([contact] (enrich-contact contact nil nil)) ([contact] (enrich-contact contact nil nil))
([{:keys [added public-key] :as contact} setting own-public-key] ([{:keys [public-key] :as contact} setting own-public-key]
(cond-> (-> contact (cond-> (-> contact
(dissoc :ens-verified-at :ens-verification-retries) (dissoc :ens-verified-at :ens-verification-retries)
(assoc :blocked? (:blocked contact) (assoc :blocked? (:blocked contact)
:active? (active? contact) :active? (active? contact)
:added? added) :added? (added? contact))
(multiaccounts/contact-with-names)) (multiaccounts/contact-with-names))
(and setting (and setting
(not= public-key own-public-key) (not= public-key own-public-key)
(or (= setting constants/profile-pictures-visibility-none) (or (= setting constants/profile-pictures-visibility-none)
(and (= setting constants/profile-pictures-visibility-contacts-only) (and (= setting constants/profile-pictures-visibility-contacts-only)
(not added)))) (not (added? contact)))))
(dissoc :images)))) (dissoc :images))))
(defn enrich-contacts (defn enrich-contacts

View File

@ -14,8 +14,7 @@
transactions-management-enabled? transactions-management-enabled?
wakuv2-flag wakuv2-flag
current-fleet current-fleet
webview-debug webview-debug]}]
mutual-contact-requests-enabled?]}]
(keep (keep
identity identity
[{:size :small [{:size :small
@ -115,17 +114,7 @@
#(re-frame/dispatch #(re-frame/dispatch
[:multiaccounts.ui/waku-bloom-filter-mode-switched (not waku-bloom-filter-mode)]) [:multiaccounts.ui/waku-bloom-filter-mode-switched (not waku-bloom-filter-mode)])
:accessory :switch :accessory :switch
:active waku-bloom-filter-mode} :active waku-bloom-filter-mode}]))
{:size :small
:title (i18n/label :t/mutual-contact-requests)
:accessibility-label :mutual-contact-requests-switch
:container-margin-bottom 8
:on-press
#(re-frame/dispatch
[:multiaccounts.ui/switch-mutual-contact-requests-enabled
(not mutual-contact-requests-enabled?)])
:accessory :switch
:active mutual-contact-requests-enabled?}]))
(defn- flat-list-data (defn- flat-list-data
[options] [options]
@ -146,8 +135,7 @@
communities-enabled? [:communities/enabled?] communities-enabled? [:communities/enabled?]
transactions-management-enabled? [:wallet/transactions-management-enabled?] transactions-management-enabled? [:wallet/transactions-management-enabled?]
current-log-level [:log-level/current-log-level] current-log-level [:log-level/current-log-level]
current-fleet [:fleets/current-fleet] current-fleet [:fleets/current-fleet]]
mutual-contact-requests-enabled? [:mutual-contact-requests/enabled?]]
[list/flat-list [list/flat-list
{:data (flat-list-data {:data (flat-list-data
{:network-name network-name {:network-name network-name
@ -158,7 +146,6 @@
:dev-mode? false :dev-mode? false
:wakuv2-flag wakuv2-flag :wakuv2-flag wakuv2-flag
:waku-bloom-filter-mode waku-bloom-filter-mode :waku-bloom-filter-mode waku-bloom-filter-mode
:webview-debug webview-debug :webview-debug webview-debug})
:mutual-contact-requests-enabled? mutual-contact-requests-enabled?})
:key-fn (fn [_ i] (str i)) :key-fn (fn [_ i] (str i))
:render-fn render-item}])) :render-fn render-item}]))

View File

@ -6,7 +6,7 @@
[quo.design-system.colors :as colors] [quo.design-system.colors :as colors]
[quo.react :as quo.react] [quo.react :as quo.react]
[quo.react-native :as rn] [quo.react-native :as rn]
[re-frame.core :as re-frame] [re-frame.core :as rf]
re-frame.db re-frame.db
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.constants :as constants] [status-im.constants :as constants]
@ -42,13 +42,13 @@
(defn invitation-requests (defn invitation-requests
[chat-id admins] [chat-id admins]
(let [current-pk @(re-frame/subscribe [:multiaccount/public-key]) (let [current-pk @(rf/subscribe [:multiaccount/public-key])
admin? (get admins current-pk)] admin? (get admins current-pk)]
(when admin? (when admin?
(let [invitations @(re-frame/subscribe [:group-chat/pending-invitations-by-chat-id chat-id])] (let [invitations @(rf/subscribe [:group-chat/pending-invitations-by-chat-id chat-id])]
(when (seq invitations) (when (seq invitations)
[react/touchable-highlight [react/touchable-highlight
{:on-press #(re-frame/dispatch [:navigate-to :group-chat-invite]) {:on-press #(rf/dispatch [:navigate-to :group-chat-invite])
:accessibility-label :invitation-requests-button} :accessibility-label :invitation-requests-button}
[react/view {:style (style/add-contact)} [react/view {:style (style/add-contact)}
[react/text {:style style/add-contact-text} [react/text {:style style/add-contact-text}
@ -56,11 +56,11 @@
(defn add-contact-bar (defn add-contact-bar
[public-key] [public-key]
(when-not (or @(re-frame/subscribe [:contacts/contact-added? public-key]) (when-not (or @(rf/subscribe [:contacts/contact-added? public-key])
@(re-frame/subscribe [:contacts/contact-blocked? public-key])) @(rf/subscribe [:contacts/contact-blocked? public-key]))
[react/touchable-highlight [react/touchable-highlight
{:on-press {:on-press
#(re-frame/dispatch [:contact.ui/add-to-contact-pressed public-key]) #(rf/dispatch [:contact.ui/add-to-contact-pressed public-key])
:accessibility-label :add-to-contacts-button} :accessibility-label :add-to-contacts-button}
[react/view {:style (style/add-contact)} [react/view {:style (style/add-contact)}
[icons/icon :main-icons/add [icons/icon :main-icons/add
@ -69,7 +69,7 @@
(defn contact-request (defn contact-request
[] []
(let [contact-request @(re-frame/subscribe [:chats/sending-contact-request])] (let [contact-request @(rf/subscribe [:chats/sending-contact-request])]
[react/view {:style style/contact-request} [react/view {:style style/contact-request}
[react/image [react/image
{:source (resources/get-image :hand-wave) {:source (resources/get-image :hand-wave)
@ -92,7 +92,7 @@
[quo/button [quo/button
{:style {:width "100%"} {:style {:width "100%"}
:accessibility-label :contact-request--button :accessibility-label :contact-request--button
:on-press #(re-frame/dispatch [:chat.ui/send-contact-request])} :on-press #(rf/dispatch [:chat.ui/send-contact-request])}
(i18n/label :t/contact-request)]])])) (i18n/label :t/contact-request)]])]))
(defn chat-intro (defn chat-intro
@ -101,7 +101,6 @@
chat-type chat-type
group-chat group-chat
invitation-admin invitation-admin
mutual-contact-requests-enabled?
contact-name contact-name
color color
loading-messages? loading-messages?
@ -136,22 +135,20 @@
:no-messages? no-messages?}] :no-messages? no-messages?}]
[react/text {:style (assoc style/intro-header-description :margin-bottom 32)} [react/text {:style (assoc style/intro-header-description :margin-bottom 32)}
(str (i18n/label :t/empty-chat-description-one-to-one) contact-name)]) (str (i18n/label :t/empty-chat-description-one-to-one) contact-name)])
(when (and mutual-contact-requests-enabled? (when
(= chat-type constants/one-to-one-chat-type) (= chat-type constants/one-to-one-chat-type)
(or (= contact-request-state constants/contact-request-state-none) (or (= contact-request-state constants/contact-request-state-none)
(= contact-request-state constants/contact-request-state-received) (= contact-request-state constants/contact-request-state-received)
(= contact-request-state constants/contact-request-state-dismissed))) (= contact-request-state constants/contact-request-state-dismissed)))
[contact-request])]) [contact-request]])
(defn chat-intro-one-to-one (defn chat-intro-one-to-one
[{:keys [chat-id] :as opts}] [{:keys [chat-id] :as opts}]
(let [contact @(re-frame/subscribe [:contacts/contact-by-identity chat-id]) (let [contact @(rf/subscribe [:contacts/contact-by-identity chat-id])
mutual-contact-requests-enabled? @(re-frame/subscribe [:mutual-contact-requests/enabled?]) contact-names @(rf/subscribe [:contacts/contact-two-names-by-identity
contact-names @(re-frame/subscribe [:contacts/contact-two-names-by-identity
chat-id])] chat-id])]
[chat-intro [chat-intro
(assoc opts (assoc opts
:mutual-contact-requests-enabled? mutual-contact-requests-enabled?
:contact-name (first contact-names) :contact-name (first contact-names)
:contact-request-state (or (:contact-request-state contact) :contact-request-state (or (:contact-request-state contact)
constants/contact-request-state-none))])) constants/contact-request-state-none))]))
@ -217,8 +214,8 @@
(defn invitation-bar (defn invitation-bar
[chat-id] [chat-id]
(let [{:keys [state chat-id] :as invitation} (let [{:keys [state chat-id] :as invitation}
(first @(re-frame/subscribe [:group-chat/invitations-by-chat-id chat-id])) (first @(rf/subscribe [:group-chat/invitations-by-chat-id chat-id]))
{:keys [retry? message]} @(re-frame/subscribe [:chats/current-chat-membership]) {:keys [retry? message]} @(rf/subscribe [:chats/current-chat-membership])
message-length (count message)] message-length (count message)]
[react/view {:margin-horizontal 16 :margin-top 10} [react/view {:margin-horizontal 16 :margin-top 10}
(cond (cond
@ -238,13 +235,13 @@
[quo/button [quo/button
{:type :secondary {:type :secondary
:accessibility-label :retry-button :accessibility-label :retry-button
:on-press #(re-frame/dispatch [:group-chats.ui/membership-retry])} :on-press #(rf/dispatch [:group-chats.ui/membership-retry])}
(i18n/label :t/mailserver-retry)] (i18n/label :t/mailserver-retry)]
:left :left
[quo/button [quo/button
{:type :secondary {:type :secondary
:accessibility-label :remove-group-button :accessibility-label :remove-group-button
:on-press #(re-frame/dispatch [:group-chats.ui/remove-chat-confirmed chat-id])} :on-press #(rf/dispatch [:group-chats.ui/remove-chat-confirmed chat-id])}
(i18n/label :t/remove-group)]}] (i18n/label :t/remove-group)]}]
:else :else
[toolbar/toolbar [toolbar/toolbar
@ -255,7 +252,7 @@
:accessibility-label :introduce-yourself-button :accessibility-label :introduce-yourself-button
:disabled (or (string/blank? message) :disabled (or (string/blank? message)
(> message-length chat.group/message-max-length)) (> message-length chat.group/message-max-length))
:on-press #(re-frame/dispatch [:send-group-chat-membership-request])} :on-press #(rf/dispatch [:send-group-chat-membership-request])}
(i18n/label :t/request-membership)]}])])) (i18n/label :t/request-membership)]}])]))
(defn get-space-keeper-ios (defn get-space-keeper-ios
@ -289,9 +286,9 @@
(defn list-footer (defn list-footer
[{:keys [chat-id] :as chat}] [{:keys [chat-id] :as chat}]
(let [loading-messages? @(re-frame/subscribe [:chats/loading-messages? chat-id]) (let [loading-messages? @(rf/subscribe [:chats/loading-messages? chat-id])
no-messages? @(re-frame/subscribe [:chats/chat-no-messages? chat-id]) no-messages? @(rf/subscribe [:chats/chat-no-messages? chat-id])
all-loaded? @(re-frame/subscribe [:chats/all-loaded? chat-id])] all-loaded? @(rf/subscribe [:chats/all-loaded? chat-id])]
[react/view {:style (when platform/android? {:scaleY -1})} [react/view {:style (when platform/android? {:scaleY -1})}
(if (or loading-messages? (not chat-id) (not all-loaded?)) (if (or loading-messages? (not chat-id) (not all-loaded?))
[react/view {:height 324 :align-items :center :justify-content :center} [react/view {:height 324 :align-items :center :justify-content :center}
@ -340,15 +337,15 @@
(defn list-on-end-reached (defn list-on-end-reached
[] []
(if @state/scrolling (if @state/scrolling
(re-frame/dispatch [:chat.ui/load-more-messages-for-current-chat]) (rf/dispatch [:chat.ui/load-more-messages-for-current-chat])
(utils/set-timeout #(re-frame/dispatch [:chat.ui/load-more-messages-for-current-chat]) (utils/set-timeout #(rf/dispatch [:chat.ui/load-more-messages-for-current-chat])
(if platform/low-device? 700 200)))) (if platform/low-device? 700 200))))
(defn get-render-data (defn get-render-data
[{:keys [group-chat chat-id public? community-id admins space-keeper show-input? edit-enabled [{:keys [group-chat chat-id public? community-id admins space-keeper show-input? edit-enabled
in-pinned-view?]}] in-pinned-view?]}]
(let [current-public-key @(re-frame/subscribe [:multiaccount/public-key]) (let [current-public-key @(rf/subscribe [:multiaccount/public-key])
community @(re-frame/subscribe [:communities/community community-id]) community @(rf/subscribe [:communities/community community-id])
group-admin? (get admins current-public-key) group-admin? (get admins current-public-key)
community-admin? (when community (community :admin)) community-admin? (when community (community :admin))
message-pin-enabled (and (not public?) message-pin-enabled (and (not public?)
@ -371,17 +368,15 @@
[{:keys [chat [{:keys [chat
bottom-space bottom-space
pan-responder pan-responder
mutual-contact-requests-enabled?
space-keeper space-keeper
show-input?]}] show-input?]}]
(let [{:keys [group-chat chat-type chat-id public? community-id admins]} chat (let [{:keys [group-chat chat-type chat-id public? community-id admins]} chat
messages @(re-frame/subscribe [:chats/raw-chat-messages-stream chat-id]) messages @(rf/subscribe [:chats/raw-chat-messages-stream chat-id])
one-to-one? (= chat-type constants/one-to-one-chat-type) one-to-one? (= chat-type constants/one-to-one-chat-type)
contact-added? (when one-to-one? @(re-frame/subscribe [:contacts/contact-added? chat-id])) contact-added? (when one-to-one? @(rf/subscribe [:contacts/contact-added? chat-id]))
should-send-contact-request? should-send-contact-request?
(and (and
mutual-contact-requests-enabled?
one-to-one? one-to-one?
(not contact-added?))] (not contact-added?))]
@ -423,13 +418,13 @@
[] []
(when (and (not @navigation.state/curr-modal) (= (get @re-frame.db/app-db :view-id) :chat)) (when (and (not @navigation.state/curr-modal) (= (get @re-frame.db/app-db :view-id) :chat))
(react/hw-back-remove-listener navigate-back-handler) (react/hw-back-remove-listener navigate-back-handler)
(re-frame/dispatch [:close-chat]) (rf/dispatch [:close-chat])
(re-frame/dispatch [:navigate-back]))) (rf/dispatch [:navigate-back])))
(defn topbar-content (defn topbar-content
[] []
(let [window-width @(re-frame/subscribe [:dimensions/window-width]) (let [window-width @(rf/subscribe [:dimensions/window-width])
{:keys [group-chat chat-id] :as chat-info} @(re-frame/subscribe [:chats/current-chat])] {:keys [group-chat chat-id] :as chat-info} @(rf/subscribe [:chats/current-chat])]
[react/touchable-highlight [react/touchable-highlight
{:on-press #(when-not group-chat {:on-press #(when-not group-chat
(debounce/dispatch-and-chill [:chat.ui/show-profile chat-id] 1000)) (debounce/dispatch-and-chill [:chat.ui/show-profile chat-id] 1000))
@ -452,7 +447,7 @@
[react/view {:flex 1 :left 52 :right 52 :top 0 :bottom 0 :position :absolute} [react/view {:flex 1 :left 52 :right 52 :top 0 :bottom 0 :position :absolute}
[topbar-content]] [topbar-content]]
[react/touchable-highlight [react/touchable-highlight
{:on-press-in #(re-frame/dispatch [:bottom-sheet/show-sheet {:on-press-in #(rf/dispatch [:bottom-sheet/show-sheet
{:content (fn [] [sheets/current-chat-actions]) {:content (fn [] [sheets/current-chat-actions])
:height 256}]) :height 256}])
:accessibility-label :chat-menu-button :accessibility-label :chat-menu-button
@ -481,24 +476,26 @@
set-active-panel (get-set-active-panel active-panel) set-active-panel (get-set-active-panel active-panel)
on-close #(set-active-panel nil)] on-close #(set-active-panel nil)]
(fn [] (fn []
(let [{:keys [chat-id show-input? group-chat admins invitation-admin] :as chat} (let [{:keys [chat-id
;;we want to react only on these fields, do not use full chat map here show-input?
@(re-frame/subscribe [:chats/current-chat-chat-view]) group-chat
mutual-contact-requests-enabled? @(re-frame/subscribe [:mutual-contact-requests/enabled?]) admins
max-bottom-space (max @bottom-space @panel-space)] invitation-admin]
:as chat}
@(rf/subscribe [:chats/current-chat-chat-view])
max-bottom-space (max @bottom-space
@panel-space)]
[:<> [:<>
[topbar] [topbar]
[connectivity/loading-indicator] [connectivity/loading-indicator]
(when chat-id (when chat-id
(if group-chat (when group-chat
[invitation-requests chat-id admins] [invitation-requests chat-id admins]))
(when-not mutual-contact-requests-enabled? [add-contact-bar chat-id])))
;;MESSAGES LIST ;;MESSAGES LIST
[messages-view [messages-view
{:chat chat {:chat chat
:bottom-space max-bottom-space :bottom-space max-bottom-space
:pan-responder pan-responder :pan-responder pan-responder
:mutual-contact-requests-enabled? mutual-contact-requests-enabled?
:space-keeper space-keeper :space-keeper space-keeper
:show-input? show-input?}] :show-input? show-input?}]
(when (and group-chat invitation-admin) (when (and group-chat invitation-admin)

View File

@ -0,0 +1,26 @@
(ns status-im2.contexts.chat.messages.contact-requests.bottom-drawer
(:require
[i18n.i18n :as i18n]
[utils.re-frame :as rf]
[quo2.core :as quo]
[quo2.components.drawers.permission-context.view :as permission-context]
[status-im2.common.constants :as constants]))
(defn view
[contact-id contact-request-state]
(let [names (rf/sub [:contacts/contact-two-names-by-identity contact-id])]
[permission-context/view
[quo/button
{:type :ghost
:on-press #(rf/dispatch [:chat.ui/show-profile contact-id])
:before :i/communities}
(cond
(or (= contact-request-state
constants/contact-request-state-none)
(= contact-request-state
constants/contact-request-state-received))
(i18n/label :t/contact-request-chat-add {:name (first names)})
(= contact-request-state
constants/contact-request-state-sent)
(i18n/label :t/contact-request-chat-pending))]]))

View File

@ -131,16 +131,9 @@
[{:keys [chat [{:keys [chat
pan-responder pan-responder
show-input?]}] show-input?]}]
(let [{:keys [group-chat chat-type chat-id public? community-id admins]} chat (let [{:keys [group-chat chat-id public? community-id admins]} chat
mutual-contact-requests-enabled? (rf/sub [:mutual-contact-requests/enabled?]) messages (rf/sub [:chats/raw-chat-messages-stream
messages (rf/sub [:chats/raw-chat-messages-stream chat-id]) chat-id])
one-to-one? (= chat-type constants/one-to-one-chat-type)
contact-added? (when one-to-one? (rf/sub [:contacts/contact-added? chat-id]))
should-send-contact-request?
(and
mutual-contact-requests-enabled?
one-to-one?
(not contact-added?))
bottom-space 15] bottom-space 15]
[rn/view [rn/view
{:style {:flex 1}} {:style {:flex 1}}
@ -152,7 +145,7 @@
:ref list-ref :ref list-ref
:header [list-header chat] :header [list-header chat]
:footer [list-footer chat] :footer [list-footer chat]
:data (when-not should-send-contact-request? messages) :data messages
:render-data (get-render-data {:group-chat group-chat :render-data (get-render-data {:group-chat group-chat
:chat-id chat-id :chat-id chat-id
:public? public? :public? public?

View File

@ -7,6 +7,8 @@
[status-im.ui2.screens.chat.pin-limit-popover.view :as pin-limit-popover] [status-im.ui2.screens.chat.pin-limit-popover.view :as pin-limit-popover]
[status-im2.common.constants :as constants] [status-im2.common.constants :as constants]
[status-im2.contexts.chat.messages.list.view :as messages.list] [status-im2.contexts.chat.messages.list.view :as messages.list]
[status-im2.contexts.chat.messages.contact-requests.bottom-drawer :as
contact-requests.bottom-drawer]
[status-im2.contexts.chat.messages.pin.banner.view :as pin.banner] ;;TODO move to status-im2 [status-im2.contexts.chat.messages.pin.banner.view :as pin.banner] ;;TODO move to status-im2
[status-im2.navigation.state :as navigation.state] [status-im2.navigation.state :as navigation.state]
[utils.debounce :as debounce] [utils.debounce :as debounce]
@ -62,8 +64,11 @@
(defn chat-render (defn chat-render
[] []
(let [;;NOTE: we want to react only on these fields, do not use full chat map here (let [{:keys [chat-id
{:keys [chat-id show-input?] :as chat} (rf/sub [:chats/current-chat-chat-view])] contact-request-state
show-input?]
:as chat}
(rf/sub [:chats/current-chat-chat-view])]
[rn/keyboard-avoiding-view {:style {:position :relative :flex 1}} [rn/keyboard-avoiding-view {:style {:position :relative :flex 1}}
[rn/view [rn/view
{:style {:position :absolute {:style {:position :absolute
@ -74,13 +79,14 @@
[pin.banner/banner chat-id] [pin.banner/banner chat-id]
[not-implemented/not-implemented [not-implemented/not-implemented
[pin-limit-popover/pin-limit-popover chat-id]] [pin-limit-popover/pin-limit-popover chat-id]]]
]
[page-nav] [page-nav]
[messages.list/messages-list {:chat chat :show-input? show-input?}] [messages.list/messages-list {:chat chat :show-input? show-input?}]
(when show-input? (cond (and (not show-input?)
contact-request-state)
[contact-requests.bottom-drawer/view chat-id contact-request-state]
show-input?
[composer/composer chat-id])])) [composer/composer chat-id])]))
(defn chat (defn chat

View File

@ -171,11 +171,10 @@
:<- [:multiaccount/public-key] :<- [:multiaccount/public-key]
:<- [:communities/current-community] :<- [:communities/current-community]
:<- [:contacts/blocked-set] :<- [:contacts/blocked-set]
:<- [:contacts/contacts] :<- [:contacts/contacts-raw]
:<- [:chat/inputs] :<- [:chat/inputs]
:<- [:mutual-contact-requests/enabled?]
(fn [[{:keys [group-chat chat-id] :as current-chat} my-public-key community blocked-users-set contacts (fn [[{:keys [group-chat chat-id] :as current-chat} my-public-key community blocked-users-set contacts
inputs mutual-contact-requests-enabled?]] inputs]]
(when current-chat (when current-chat
(cond-> current-chat (cond-> current-chat
(chat.models/public-chat? current-chat) (chat.models/public-chat? current-chat)
@ -191,14 +190,14 @@
(assoc :show-input? true) (assoc :show-input? true)
(not group-chat) (not group-chat)
(assoc :show-input? (assoc
:contact-request-state (get-in contacts [chat-id :contact-request-state])
:show-input?
(and (and
(or (or
(not mutual-contact-requests-enabled?)
(get-in inputs [chat-id :metadata :sending-contact-request]) (get-in inputs [chat-id :metadata :sending-contact-request])
(and mutual-contact-requests-enabled?
(= constants/contact-request-state-mutual (= constants/contact-request-state-mutual
(get-in contacts [chat-id :contact-request-state])))) (get-in contacts [chat-id :contact-request-state])))
(not (contains? blocked-users-set chat-id)))))))) (not (contains? blocked-users-set chat-id))))))))
(re-frame/reg-sub (re-frame/reg-sub
@ -206,8 +205,20 @@
:<- [:chats/current-chat] :<- [:chats/current-chat]
(fn [current-chat] (fn [current-chat]
(select-keys current-chat (select-keys current-chat
[:chat-id :show-input? :group-chat :admins :invitation-admin :public? :chat-type :color [:chat-id
:chat-name :synced-to :synced-from :community-id :emoji]))) :show-input?
:group-chat
:admins
:invitation-admin
:public?
:chat-type
:color
:contact-request-state
:chat-name
:synced-to
:synced-from
:community-id
:emoji])))
(re-frame/reg-sub (re-frame/reg-sub
:current-chat/metadata :current-chat/metadata

View File

@ -0,0 +1,57 @@
(ns status-im2.subs.chat.chats-test
(:require [cljs.test :refer [is testing]]
[re-frame.db :as rf-db]
[test-helpers.unit :as h]
[status-im2.common.constants :as constants]
[utils.re-frame :as rf]))
(def public-key "0xpk")
(def multiaccount {:public-key public-key})
(def chat-id "1")
(def chat {:chat-id chat-id})
(def private-group-chat
(assoc
chat
:members #{{:id public-key}}
:group-chat true
:chat-type constants/private-group-chat-type))
(def one-to-one-chat
(assoc
chat
:chat-type
constants/one-to-one-chat-type))
(h/deftest-sub :chats/current-chat
[sub-name]
(testing "private group chat, user is a member"
(let [chats {chat-id private-group-chat}]
(swap! rf-db/app-db assoc
:multiaccount multiaccount
:current-chat-id chat-id
:chats chats)
(is (true? (:show-input? (rf/sub [sub-name]))))))
(testing "private group chat, user is not member"
(let [chats {chat-id (dissoc private-group-chat :members)}]
(swap! rf-db/app-db assoc
:multiaccount multiaccount
:current-chat-id chat-id
:chats chats)
(is (not (:show-input? (rf/sub [sub-name]))))))
(testing "one to one chat, mutual contacts"
(let [chats {chat-id one-to-one-chat}]
(swap! rf-db/app-db assoc
:contacts/contacts {chat-id {:contact-request-state constants/contact-request-state-mutual}}
:multiaccount multiaccount
:current-chat-id chat-id
:chats chats)
(is (:show-input? (rf/sub [sub-name])))))
(testing "one to one chat, not a contact"
(let [chats {chat-id one-to-one-chat}]
(swap! rf-db/app-db assoc
:contacts/contacts {chat-id {:contact-request-state constants/contact-request-state-sent}}
:multiaccount multiaccount
:current-chat-id chat-id
:chats chats)
(is (not (:show-input? (rf/sub [sub-name])))))))

View File

@ -23,12 +23,6 @@
(fn [multiaccount] (fn [multiaccount]
(get multiaccount :profile-pictures-show-to))) (get multiaccount :profile-pictures-show-to)))
(re-frame/reg-sub
:mutual-contact-requests/enabled?
:<- [:multiaccount]
(fn [settings]
(boolean (:mutual-contact-enabled? settings))))
(re-frame/reg-sub (re-frame/reg-sub
::profile-pictures-visibility ::profile-pictures-visibility
:<- [:multiaccount] :<- [:multiaccount]

View File

@ -1935,5 +1935,7 @@
"who-are-you-looking-for": "Who are you looking for ?", "who-are-you-looking-for": "Who are you looking for ?",
"close-contact-search": "Close contact search", "close-contact-search": "Close contact search",
"selected-count-from-max": "{{selected}}/{{max}}", "selected-count-from-max": "{{selected}}/{{max}}",
"online": "Online" "online": "Online",
"contact-request-chat-pending": "Your contact request is pending",
"contact-request-chat-add": "Add {{name}} to send a message"
} }