feat(communities) enable user to share community channel (#18516)

Co-authored-by: Paul Fitzgerald <paulfitz99@gmail.com>
This commit is contained in:
Jamie Caprani 2024-01-15 20:16:42 +00:00 committed by GitHub
parent 8a16017859
commit 8d3883c709
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 5 deletions

View File

@ -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

View File

@ -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)))))

View File

@ -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

View File

@ -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)))

View File

@ -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"}))}]})))

View File

@ -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": "🦄🦄🦄🦄🦄🦄🦄🚀!",