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

import of https://github.com/status-im/status-mobile/pull/18271 #18516

Merged
merged 1 commit into from
Jan 15, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/legacy/status_im/data_store/chats.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/legacy/status_im/data_store/chats_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))
2 changes: 2 additions & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/status_im/contexts/communities/actions/chat/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -140,6 +140,6 @@
(chat-actions/fetch-messages chat-id))
(action-invite-people)
(action-qr-code)
(action-share)]]]
(action-share chat-id)]]]

:else nil)))
29 changes: 29 additions & 0 deletions src/status_im/contexts/communities/events.cljs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"}))}]})))
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "🦄🦄🦄🦄🦄🦄🦄🚀!",
Expand Down