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 (ns status-im2.contexts.activity-center.notification.contact-requests.events
(:require [status-im2.contexts.activity-center.events :as ac-events] (:require [taoensso.timbre :as log]
[taoensso.timbre :as log]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(rf/defn accept-contact-request (rf/defn accept-contact-request
@ -19,8 +18,7 @@
(log/error "Failed to accept contact-request" (log/error "Failed to accept contact-request"
{:error error {:error error
:event :activity-center.contact-requests/accept :event :activity-center.contact-requests/accept
:contact-id contact-id}) :contact-id contact-id}))
nil)
(rf/defn decline-contact-request (rf/defn decline-contact-request
{:events [:activity-center.contact-requests/decline]} {:events [:activity-center.contact-requests/decline]}
@ -38,32 +36,4 @@
(log/error "Failed to decline contact-request" (log/error "Failed to decline contact-request"
{:error error {:error error
:event :activity-center.contact-requests/decline :event :activity-center.contact-requests/decline
:contact-id contact-id}) :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)

View File

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

View File

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