Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for mutual contact requests #13054

Merged
merged 1 commit into from May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added resources/images/ui/hand-wave.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/ui/hand-wave@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/ui/hand-wave@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/quo/components/text.cljs
Expand Up @@ -28,6 +28,7 @@
:inherit nil)
(case (or size :base)
:tiny typography/tiny
:x-small typography/x-small
:small typography/small
:base typography/base
:large typography/large
Expand Down
3 changes: 3 additions & 0 deletions src/quo/design_system/typography.cljs
Expand Up @@ -3,6 +3,9 @@
(def tiny {:font-size 10
:line-height 14})

(def x-small {:font-size 12
:line-height 16})

(def small {:font-size 13
:line-height 18})

Expand Down
43 changes: 43 additions & 0 deletions src/status_im/chat/models/input.cljs
Expand Up @@ -143,6 +143,20 @@
:on-error #(log/error "failed to delete message message " %)
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]})

(fx/defn show-contact-request-input
"Sets reference to previous chat message and focuses on input"
{:events [:chat.ui/send-contact-request]}
[{:keys [db] :as cofx}]
(let [current-chat-id (:current-chat-id db)]
{:db (-> db
(assoc-in [:chat/inputs current-chat-id :metadata :sending-contact-request]
current-chat-id)
(assoc-in [:chat/inputs current-chat-id :metadata :responding-to-message]
nil)
(assoc-in [:chat/inputs current-chat-id :metadata :editing-message] nil)
(update-in [:chat/inputs current-chat-id :metadata]
dissoc :sending-image))}))

(fx/defn cancel-message-reply
"Cancels stage message reply"
{:events [:chat.ui/cancel-message-reply]}
Expand Down Expand Up @@ -179,6 +193,7 @@
(fx/defn clean-input [{:keys [db] :as cofx} current-chat-id]
(fx/merge cofx
{:db (-> db
(assoc-in [:chat/inputs current-chat-id :metadata :sending-contact-request] nil)
(assoc-in [:chat/inputs current-chat-id :metadata :sending-image] nil)
(assoc-in [:chat/inputs current-chat-id :metadata :editing-message] nil)
(assoc-in [:chat/inputs current-chat-id :metadata :responding-to-message] nil))}
Expand Down Expand Up @@ -262,6 +277,34 @@
(mentions/clear-mentions)
(mentions/clear-cursor))))

(fx/defn send-contact-request
{:events [:contacts/send-contact-request]}
[{:keys [db] :as cofx} public-key message]
(fx/merge cofx
{::json-rpc/call [{:method "wakuext_sendContactRequest"
:js-response true
:params [{:id public-key :message message}]
:on-error #(log/warn "failed to send a contact request" %)

:on-success #(re-frame/dispatch [:transport/message-sent %])}]}

(mentions/clear-mentions)
(mentions/clear-cursor)
(clean-input (:current-chat-id db))
(process-cooldown)))

(fx/defn cancel-contact-request
"Cancels contact request"
{:events [:chat.ui/cancel-contact-request]}
[{:keys [db] :as cofx}]
(let [current-chat-id (:current-chat-id db)]
(fx/merge cofx
{:db (assoc-in db [:chat/inputs current-chat-id :metadata :sending-contact-request] nil)}
(mentions/clear-mentions)
(mentions/clear-cursor)
(clean-input (:current-chat-id db))
(process-cooldown))))

(fx/defn chat-send-sticker
{:events [:chat/send-sticker]}
[{{:keys [current-chat-id] :as db} :db :as cofx} {:keys [hash packID] :as sticker}]
Expand Down
15 changes: 14 additions & 1 deletion src/status_im/constants.cljs
Expand Up @@ -13,6 +13,13 @@
(def ^:const content-type-audio 8)
(def ^:const content-type-community 9)
(def ^:const content-type-gap 10)
(def ^:const content-type-contact-request 11) ;; TODO: temp, will be removed

(def ^:const contact-request-state-none 0)
(def ^:const contact-request-state-mutual 1)
(def ^:const contact-request-state-sent 2)
(def ^:const contact-request-state-received 3)
(def ^:const contact-request-state-dismissed 4)

(def ^:const emoji-reaction-love 1)
(def ^:const emoji-reaction-thumbs-up 2)
Expand All @@ -28,6 +35,10 @@
(def ^:const timeline-chat-type 5)
(def ^:const community-chat-type 6)

(def ^:const contact-request-message-state-pending 1)
(def ^:const contact-request-message-state-accepted 2)
(def ^:const contact-request-message-state-declined 3)

(def request-to-join-pending-state 1)

(def reactions {emoji-reaction-love (:love resources/reactions)
Expand Down Expand Up @@ -161,6 +172,8 @@
(def ^:const activity-center-notification-type-private-group-chat 2)
(def ^:const activity-center-notification-type-mention 3)
(def ^:const activity-center-notification-type-reply 4)
(def ^:const activity-center-notification-type-contact-request 5)
(def ^:const activity-center-notification-type-contact-request-retracted 6)

(def ^:const visibility-status-unknown 0)
(def ^:const visibility-status-automatic 1)
Expand All @@ -173,4 +186,4 @@

(def ^:const sticker-pack-status-installed 1)
(def ^:const sticker-pack-status-pending 2)
(def ^:const sticker-pack-status-owned 3)
(def ^:const sticker-pack-status-owned 3)
44 changes: 36 additions & 8 deletions src/status_im/contact/core.cljs
Expand Up @@ -5,6 +5,7 @@
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.navigation :as navigation]
[status-im.utils.fx :as fx]
[status-im.async-storage.core :as async-storage]
[taoensso.timbre :as log]
[status-im.constants :as constants]
[status-im.contact.block :as contact.block]))
Expand All @@ -28,13 +29,6 @@
(= public-key (:public-key multiaccount))
(assoc :name (:name multiaccount))))

(defn- own-info
[db]
(let [{:keys [name preferred-name identicon address]} (:multiaccount db)]
{:name (or preferred-name name)
:profile-image identicon
:address address}))

(fx/defn ensure-contacts
[{:keys [db]} contacts chats]
(let [events
Expand Down Expand Up @@ -66,6 +60,13 @@
(when (> (count events) 1)
{:dispatch-n events}))))

(defn- own-info
[db]
(let [{:keys [name preferred-name identicon address]} (:multiaccount db)]
{:name (or preferred-name name)
:profile-image identicon
:address address}))

(fx/defn send-contact-request
{:events [::send-contact-request]}
[{:keys [db] :as cofx} public-key]
Expand All @@ -92,12 +93,33 @@
"Remove a contact from current account's contact list"
{:events [:contact.ui/remove-contact-pressed]}
[{:keys [db]} {:keys [public-key]}]
{:db (assoc-in db [:contacts/contacts public-key :added] false)
{:db (-> db
(assoc-in [:contacts/contacts public-key :added] false)
(assoc-in [:contacts/contacts public-key :contact-request-state] constants/contact-request-state-none))
::json-rpc/call [{:method "wakuext_removeContact"
:params [public-key]
:on-success #(log/debug "contact removed successfully")}
{:method "wakuext_retractContactRequest"
:params [{:contactId public-key}]
:on-success #(log/debug "contact removed successfully")}]
:dispatch [:offload-messages constants/timeline-chat-id]})

(fx/defn accept-contact-request
{:events [:contact-requests.ui/accept-request]}
[{:keys [db]} id]
{::json-rpc/call [{:method "wakuext_acceptContactRequest"
:params [{:id id}]
:js-response true
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]})

(fx/defn decline-contact-request
{:events [:contact-requests.ui/decline-request]}
[{:keys [db]} id]
{::json-rpc/call [{:method "wakuext_dismissContactRequest"
:params [{:id id}]
:js-response true
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])}]})

(fx/defn initialize-contacts [cofx]
(contacts-store/fetch-contacts-rpc cofx #(re-frame/dispatch [::contacts-loaded %])))

Expand All @@ -119,3 +141,9 @@
nickname
#(re-frame/dispatch [:sanitize-messages-and-process-response %]))
(navigation/navigate-back)))

(fx/defn switch-mutual-contact-requests-enabled
{:events [:multiaccounts.ui/switch-mutual-contact-requests-enabled]}
[{:keys [db]} enabled?]
{::async-storage/set! {:mutual-contact-requests-enabled? enabled?}
:db (assoc db :mutual-contact-requests/enabled? enabled?)})
19 changes: 12 additions & 7 deletions src/status_im/data_store/contacts.cljs
Expand Up @@ -5,13 +5,18 @@
[taoensso.timbre :as log]))

(defn <-rpc [contact]
(clojure.set/rename-keys contact {:id :public-key
:ensVerifiedAt :ens-verified-at
:ensVerified :ens-verified
:ensVerificationRetries :ens-verification-retries
:lastENSClockValue :last-ens-clock-value
:lastUpdated :last-updated
:localNickname :nickname}))
(-> contact
(clojure.set/rename-keys {:id :public-key
:ensVerifiedAt :ens-verified-at
:ensVerified :ens-verified
:ensVerificationRetries :ens-verification-retries
:hasAddedUs :has-added-us
:contactRequestState :contact-request-state
:lastENSClockValue :last-ens-clock-value
:lastUpdated :last-updated
:localNickname :nickname})
(assoc :mutual? (and (:added contact)
(:hasAddedUs contact)))))

(fx/defn fetch-contacts-rpc
[_ on-success]
Expand Down
1 change: 1 addition & 0 deletions src/status_im/data_store/contacts_test.cljs
Expand Up @@ -10,6 +10,7 @@
:lastUpdated 1}
expected-contact {:public-key "pk"
:address "address"
:mutual? nil
:name "name"
:identicon "identicon"
:last-updated 1}]
Expand Down
1 change: 1 addition & 0 deletions src/status_im/data_store/messages.cljs
Expand Up @@ -20,6 +20,7 @@
(clojure.set/rename-keys {:id :message-id
:whisperTimestamp :whisper-timestamp
:editedAt :edited-at
:contactRequestState :contact-request-state
:commandParameters :command-parameters
:gapParameters :gap-parameters
:messageType :message-type
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/ethereum/json_rpc.cljs
Expand Up @@ -61,4 +61,4 @@
::call
(fn [params]
(doseq [param params]
(call param))))
(call param))))
12 changes: 12 additions & 0 deletions src/status_im/multiaccounts/login/core.cljs
Expand Up @@ -94,6 +94,13 @@
:wallet-connect-enabled?
#(re-frame/dispatch [:multiaccounts.ui/switch-wallet-connect-enabled %]))))

(re-frame/reg-fx
::initialize-mutual-contact-requests
(fn []
(async-storage/get-item
:mutual-contact-requests-enabled?
#(re-frame/dispatch [:multiaccounts.ui/switch-mutual-contact-requests-enabled %]))))

(defn rpc->accounts [accounts]
(reduce (fn [acc {:keys [chat type wallet] :as account}]
(if chat
Expand Down Expand Up @@ -359,6 +366,10 @@
[cofx]
{::initialize-wallet-connect nil})

(fx/defn initialize-mutual-contact-requests
[cofx]
{::initialize-mutual-contact-requests nil})

(fx/defn get-node-config-callback
{:events [::get-node-config-callback]}
[{:keys [db] :as cofx} node-config-json]
Expand Down Expand Up @@ -393,6 +404,7 @@
(initialize-appearance)
(initialize-communities-enabled)
(initialize-wallet-connect)
(initialize-mutual-contact-requests)
(get-node-config)
(communities/fetch)
(logging/set-log-level (:log-level multiaccount))
Expand Down
49 changes: 35 additions & 14 deletions src/status_im/notifications_center/core.cljs
@@ -1,23 +1,38 @@
(ns status-im.notifications-center.core
(:require [status-im.utils.fx :as fx]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.constants :as constants]
[taoensso.timbre :as log]
[re-frame.core :as re-frame]
[status-im.data-store.activities :as data-store.activities]))

(def non-dismissable-notifications
#{constants/activity-center-notification-type-contact-request
constants/activity-center-notification-type-contact-request-retracted})

(fx/defn handle-activities [{:keys [db]} activities]
(let [{:keys [unread-count notifications]}
(reduce (fn [acc {:keys [read dismissed accepted] :as notification}]
(as-> acc a
(if read
(update a :unread-count dec)
(update a :unread-count inc))

(if (or dismissed accepted)
(update a :notifications (fn [items] (remove #(= (:id notification) (:id %)) items)))
(update a :notifications conj notification))))
(let [index-existing (->> (map-indexed vector (:notifications acc))
(filter (fn [[idx {:keys [id]}]] (= id (:id notification))))
first
first)]
(as-> acc a
(if read
(update a :unread-count dec)
(update a :unread-count inc))

(if index-existing
(if (or dismissed accepted)
;; Remove at specific location
(assoc a :notifications
(into (subvec (:notifications a) 0 index-existing) (subvec (:notifications a) (inc index-existing))))
;; Replace element
(do
(assoc-in a [:notifications index-existing] notification)))
(update a :notifications conj notification)))))
{:unread-count (get db :activity.center/notifications-count 0)
:notifications (get-in db [:activity.center/notifications :notifications])}
:notifications (into [] (get-in db [:activity.center/notifications :notifications]))}
activities)]
(merge
{:db (-> db
Expand Down Expand Up @@ -69,14 +84,21 @@
{:events [:accept-all-activity-center-notifications-from-chat]}
[{:keys [db]} chat-id]
(let [notifications (get-in db [:activity.center/notifications :notifications])
notifications-from-chat (filter #(= chat-id (:chat-id %)) notifications)
notifications-from-chat (filter #(and
(= chat-id (:chat-id %))
(not (contains? non-dismissable-notifications (:type %))))
notifications)
notifications-from-chat-not-read (filter #(and (= chat-id (:chat-id %))
(not (:read %))) notifications)
ids (map :id notifications-from-chat)]
(not (:read %)))
notifications)
ids (into #{} (map :id notifications-from-chat))]
(when (seq ids)
{:db (-> db
(update-in [:activity.center/notifications :notifications]
(fn [items] (filter #(not (= chat-id (:chat-id %))) items)))
(fn [items]
(filter
#(not (contains? ids (:id %)))
items)))
(update :activity.center/notifications-count - (min (db :activity.center/notifications-count) (count notifications-from-chat-not-read))))
::json-rpc/call [{:method "wakuext_acceptActivityCenterNotifications"
:params [ids]
Expand Down Expand Up @@ -170,4 +192,3 @@
(update-in [:activity.center/notifications :notifications]
concat
(map data-store.activities/<-rpc notifications)))})

1 change: 1 addition & 0 deletions src/status_im/react_native/resources.cljs
Expand Up @@ -45,6 +45,7 @@
:notifications (js/require "../resources/images/ui/notifications.png")
:collectible (js/require "../resources/images/ui/collectible.png")
:collectible-dark (js/require "../resources/images/ui/collectible-dark.png")
:hand-wave (js/require "../resources/images/ui/hand-wave.png")
:graph (js/require "../resources/images/ui/graph.png")})

(defn get-theme-image [k]
Expand Down