From 8d3883c709fae089b75e509ee16bd33fb7909790 Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Mon, 15 Jan 2024 20:16:42 +0000 Subject: [PATCH] feat(communities) enable user to share community channel (#18516) Co-authored-by: Paul Fitzgerald --- src/legacy/status_im/data_store/chats.cljs | 7 +++++ .../status_im/data_store/chats_test.cljs | 8 +++++ src/status_im/constants.cljs | 2 ++ .../communities/actions/chat/view.cljs | 10 +++---- .../contexts/communities/events.cljs | 29 +++++++++++++++++++ translations/en.json | 1 + 6 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/legacy/status_im/data_store/chats.cljs b/src/legacy/status_im/data_store/chats.cljs index 2a42a8dd3c..b422c4c249 100644 --- a/src/legacy/status_im/data_store/chats.cljs +++ b/src/legacy/status_im/data_store/chats.cljs @@ -36,6 +36,13 @@ :always (update :contacts conj (:id member)))) +(defn decode-chat-id + [chat-id] + (let [community-id (subs chat-id 0 constants/community-id-length) + channel-id (subs chat-id constants/community-id-length)] + {:community-id community-id + :channel-id channel-id})) + (defn- unmarshal-members [{:keys [members chat-type] :as chat}] (cond diff --git a/src/legacy/status_im/data_store/chats_test.cljs b/src/legacy/status_im/data_store/chats_test.cljs index d555efa5e6..75d6813869 100644 --- a/src/legacy/status_im/data_store/chats_test.cljs +++ b/src/legacy/status_im/data_store/chats_test.cljs @@ -41,3 +41,11 @@ :timestamp 2}] (testing "from-rpc" (is (= expected-chat (chats/<-rpc chat)))))) + +(deftest decode-chat-id-test + (let [community-id "0x0322b9b84acb1631d6a31d41d9cf8e1938d352a624bc130de92869e025c7ca79c4" + channel-id "02081bc7-20e4-4362-99e2-37669c28cc08" + chat-id (str community-id channel-id)] + (is (= {:community-id community-id + :channel-id channel-id} + (chats/decode-chat-id chat-id))))) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index b899d11083..db6630a451 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -166,6 +166,8 @@ (def ^:const community-request-to-join-state-accepted 3) (def ^:const community-request-to-join-state-cancelled 4) +(def ^:const community-id-length 68) + ; BIP44 Wallet Root Key, the extended key from which any wallet can be derived (def ^:const path-wallet-root "m/44'/60'/0'/0") ; EIP1581 Root Key, the extended key from which any whisper key/encryption key can be derived diff --git a/src/status_im/contexts/communities/actions/chat/view.cljs b/src/status_im/contexts/communities/actions/chat/view.cljs index ed57bb631f..2a171d1a07 100644 --- a/src/status_im/contexts/communities/actions/chat/view.cljs +++ b/src/status_im/contexts/communities/actions/chat/view.cljs @@ -101,10 +101,10 @@ :label (i18n/label :t/show-qr)}) (defn- action-share - [] + [chat-id] {:icon :i/share :accessibility-label :chat-share - :on-press not-implemented/alert + :on-press #(rf/dispatch [:communities/share-community-channel-url-with-data chat-id]) :label (i18n/label :t/share-channel)}) (defn actions @@ -116,7 +116,7 @@ [[(action-invite-people) (action-token-requirements) (action-qr-code) - (action-share)]]] + (action-share chat-id)]]] (and (not inside-chat?) (not locked?)) [quo/action-drawer @@ -127,7 +127,7 @@ (action-pinned-messages) (action-invite-people) (action-qr-code) - (action-share)]]] + (action-share chat-id)]]] (and inside-chat? (not locked?)) [quo/action-drawer @@ -140,6 +140,6 @@ (chat-actions/fetch-messages chat-id)) (action-invite-people) (action-qr-code) - (action-share)]]] + (action-share chat-id)]]] :else nil))) diff --git a/src/status_im/contexts/communities/events.cljs b/src/status_im/contexts/communities/events.cljs index 8aa7defea4..18335fafdf 100644 --- a/src/status_im/contexts/communities/events.cljs +++ b/src/status_im/contexts/communities/events.cljs @@ -1,6 +1,9 @@ (ns status-im.contexts.communities.events (:require [clojure.set :as set] [clojure.walk :as walk] + [legacy.status-im.data-store.chats :as data-store.chats] + [react-native.platform :as platform] + [react-native.share :as share] [status-im.constants :as constants] status-im.contexts.communities.actions.community-options.events status-im.contexts.communities.actions.leave.events @@ -219,3 +222,29 @@ {:db (assoc db :communities/selected-permission-addresses (get-in db [:communities/previous-permission-addresses]))})) + +(rf/reg-event-fx :communities/share-community-channel-url-with-data + (fn [_ [chat-id]] + (let [{:keys [community-id channel-id]} (data-store.chats/decode-chat-id chat-id) + title (i18n/label :t/channel-on-status)] + {:json-rpc/call + [{:method "wakuext_shareCommunityChannelURLWithData" + :params [{:CommunityID community-id :ChannelID channel-id}] + :on-success (fn [url] + (share/open + (if platform/ios? + {:activityItemSources [{:placeholderItem {:type "text" + :content title} + :item {:default {:type "url" + :content url}} + :linkMetadata {:title title}}]} + {:title title + :subject title + :message url + :url url + :isNewTask true}))) + :on-error (fn [err] + (log/error "failed to retrieve community channel url with data" + {:error err + :chat-id chat-id + :event "share-community-channel-url-with-data"}))}]}))) diff --git a/translations/en.json b/translations/en.json index 8038213161..b398d63d39 100644 --- a/translations/en.json +++ b/translations/en.json @@ -147,6 +147,7 @@ "change-pairing-description": "Changing the pairing code does not affect the current pairings. However, any new pairing will require the new code.", "changed-amount-warning": "Amount was changed from {{old}} to {{new}}", "changed-asset-warning": "Asset was changed from {{old}} to {{new}}", + "channel-on-status": "Channel on Status", "chaos-mode": "Chaos mode", "chaos-unicorn-day": "Chaos Unicorn Day", "chaos-unicorn-day-details": "🦄🦄🦄🦄🦄🦄🦄🚀!",