Remove support for cancelling outgoing contact requests (#15415)

Removes the feature that allows users to cancel outgoing contact requests (possible spam vector). From now on, the user who sent the contact request will only be able to see the notification in the pending state. It seems this feature will be revisited in the future, but for now the agreement is to do the simplest thing and remove it.

Fixes https://github.com/status-im/status-mobile/issues/15357

Steps to test:

- Send CR from A to B.
- A should see a new notification in the pending state.
- B should receive a notification. If B accepts the CR, then A's pending CR disappears. If B declines the CR, then A's notification stays pending forever.

Note: As expected, A can swipe left->right to mark the outgoing pending notification as read or swipe right->left to delete it.
This commit is contained in:
Icaro Motta 2023-03-22 08:59:32 -03:00 committed by GitHub
parent 8c358d4ae4
commit 554476ede9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 91 deletions

View File

@ -1,6 +1,5 @@
(ns status-im2.contexts.activity-center.notification.contact-requests.events
(:require [status-im2.contexts.activity-center.events :as ac-events]
[taoensso.timbre :as log]
(:require [taoensso.timbre :as log]
[utils.re-frame :as rf]))
(rf/defn accept-contact-request
@ -19,8 +18,7 @@
(log/error "Failed to accept contact-request"
{:error error
:event :activity-center.contact-requests/accept
:contact-id contact-id})
nil)
:contact-id contact-id}))
(rf/defn decline-contact-request
{:events [:activity-center.contact-requests/decline]}
@ -38,32 +36,4 @@
(log/error "Failed to decline contact-request"
{:error error
:event :activity-center.contact-requests/decline
:contact-id contact-id})
nil)
(rf/defn cancel-outgoing-contact-request
{:events [:activity-center.contact-requests/cancel-outgoing]}
[{:keys [db]} {:keys [contact-id notification-id]}]
(when-let [notification (ac-events/get-notification db notification-id)]
{:json-rpc/call
[{:method "wakuext_cancelOutgoingContactRequest"
:params [{:id contact-id}]
:on-success #(rf/dispatch [:activity-center.contact-requests/cancel-outgoing-success
notification])
:on-error #(rf/dispatch [:activity-center.contact-requests/cancel-outgoing-error contact-id
%])}]}))
(rf/defn cancel-outgoing-contact-request-success
{:events [:activity-center.contact-requests/cancel-outgoing-success]}
[_ notification]
{:dispatch [:activity-center.notifications/reconcile
[(assoc notification :deleted true)]]})
(rf/defn cancel-outgoing-contact-request-error
{:events [:activity-center.contact-requests/cancel-outgoing-error]}
[_ contact-id error]
(log/error "Failed to cancel outgoing contact-request"
{:error error
:event :activity-center.contact-requests/cancel-outgoing
:contact-id contact-id})
nil)
:contact-id contact-id}))

View File

@ -1,12 +1,13 @@
(ns status-im2.contexts.activity-center.notification.contact-requests.view
(:require [quo2.core :as quo]
[react-native.gesture :as gesture]
[status-im2.constants :as constants]
[status-im2.contexts.activity-center.notification.common.style :as common-style]
[status-im2.contexts.activity-center.notification.common.view :as common]
[utils.datetime :as datetime]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(:require
[quo2.core :as quo]
[react-native.gesture :as gesture]
[status-im2.constants :as constants]
[status-im2.contexts.activity-center.notification.common.style :as common-style]
[status-im2.contexts.activity-center.notification.common.view :as common]
[utils.datetime :as datetime]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn- swipe-button-accept
[{:keys [style]} _]
@ -22,24 +23,17 @@
:icon :i/placeholder
:text (i18n/label :t/decline)}])
(defn- swipe-button-cancel-pending
[{:keys [style]} _]
[common/swipe-button-container
{:style (common-style/swipe-danger-container style)
:icon :i/placeholder
:text (i18n/label :t/cancel)}])
(defn- swipeable
[{:keys [active-swipeable extra-fn notification]} child]
(let [{:keys [id author message last-message]} notification
{:keys [contact-request-state]} (or (:message notification)
(:last-message notification))
{:keys [public-key]} (rf/sub [:multiaccount/contact])
message (or message last-message)]
(let [{:keys [id author message]} notification
{:keys [contact-request-state]} message
{:keys [public-key]} (rf/sub [:multiaccount/contact])
outgoing? (= public-key author)]
(cond
(#{constants/contact-request-message-state-accepted
constants/contact-request-message-state-declined}
contact-request-state)
(or (#{constants/contact-request-message-state-accepted
constants/contact-request-message-state-declined}
contact-request-state)
(and outgoing? (= contact-request-state constants/contact-request-message-state-pending)))
[common/swipeable
{:left-button common/swipe-button-read-or-unread
:left-on-press common/swipe-on-press-toggle-read
@ -49,33 +43,23 @@
:extra-fn extra-fn}
child]
(= contact-request-state constants/contact-request-message-state-pending)
(if (= public-key author)
[common/swipeable
{:right-button swipe-button-cancel-pending
:right-on-press (fn []
(rf/dispatch
[:activity-center.contact-requests/cancel-outgoing
{:contact-id (:from message)
:notification-id id}]))
:active-swipeable active-swipeable
:extra-fn extra-fn}
child]
[common/swipeable
{:left-button swipe-button-accept
:left-on-press #(rf/dispatch [:activity-center.contact-requests/accept id])
:right-button swipe-button-decline
:right-on-press #(rf/dispatch [:activity-center.contact-requests/decline id])
:active-swipeable active-swipeable
:extra-fn extra-fn}
child])
(and (= contact-request-state constants/contact-request-message-state-pending)
(not outgoing?))
[common/swipeable
{:left-button swipe-button-accept
:left-on-press #(rf/dispatch [:activity-center.contact-requests/accept id])
:right-button swipe-button-decline
:right-on-press #(rf/dispatch [:activity-center.contact-requests/decline id])
:active-swipeable active-swipeable
:extra-fn extra-fn}
child]
:else
child)))
(defn- outgoing-contact-request-view
[{:keys [notification set-swipeable-height]}]
(let [{:keys [id chat-id message last-message]} notification
(let [{:keys [chat-id message last-message]} notification
{:keys [contact-request-state] :as message} (or message last-message)]
(if (= contact-request-state constants/contact-request-message-state-accepted)
[quo/activity-log
@ -99,17 +83,7 @@
:message {:body (get-in message [:content :text])}
:items (case contact-request-state
constants/contact-request-message-state-pending
[{:type :button
:subtype :danger
:key :button-cancel
:label (i18n/label :t/cancel)
:accessibility-label :cancel-contact-request
:on-press (fn []
(rf/dispatch
[:activity-center.contact-requests/cancel-outgoing
{:contact-id (:from message)
:notification-id id}]))}
{:type :status
[{:type :status
:subtype :pending
:key :status-pending
:blur? true

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "94cd1ec",
"commit-sha1": "94cd1ec",
"src-sha256": "1inm5x6wwfm2v45aq0jyaq52lw6hpgkyy82h3v1bh2bs7bl1yd26"
"version": "v0.139.0",
"commit-sha1": "9c1c01c66f652ad6ce6fd4bbfbc613cc7a292878",
"src-sha256": "15cbbzir3bddgdbrrc9pnwdrsahn7a2ihaab7mfz93r0dg3q110i"
}