Allow toggling communities

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2021-05-20 10:02:41 +02:00
parent dd5c30b7a0
commit a71468f425
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
16 changed files with 77 additions and 45 deletions

1
.env
View File

@ -27,5 +27,4 @@ ENABLE_QUO_PREVIEW=1
MAX_IMAGES_BATCH=5 MAX_IMAGES_BATCH=5
APN_TOPIC=im.status.ethereum.pr APN_TOPIC=im.status.ethereum.pr
COMMUNITIES_ENABLED=1 COMMUNITIES_ENABLED=1
COMMUNITIES_MANAGEMENT_ENABLED=1
DATABASE_MANAGEMENT_ENABLED=1 DATABASE_MANAGEMENT_ENABLED=1

View File

@ -27,5 +27,4 @@ MAX_IMAGES_BATCH=5
APN_TOPIC=im.status.ethereum.pr APN_TOPIC=im.status.ethereum.pr
VERIFY_TRANSACTION_CHAIN_ID=3 VERIFY_TRANSACTION_CHAIN_ID=3
COMMUNITIES_ENABLED=1 COMMUNITIES_ENABLED=1
DATABASE_MANAGEMENT_ENABLED=1
COMMUNITIES_MANAGEMENT_ENABLED=1 COMMUNITIES_MANAGEMENT_ENABLED=1

View File

@ -27,5 +27,4 @@ BLANK_PREVIEW=0
MAX_IMAGES_BATCH=5 MAX_IMAGES_BATCH=5
GOOGLE_FREE=0 GOOGLE_FREE=0
COMMUNITIES_ENABLED=1 COMMUNITIES_ENABLED=1
DATABASE_MANAGEMENT_ENABLED=1
COMMUNITIES_MANAGEMENT_ENABLED=1 COMMUNITIES_MANAGEMENT_ENABLED=1

View File

@ -22,4 +22,3 @@ MAX_IMAGES_BATCH=5
BLANK_PREVIEW=0 BLANK_PREVIEW=0
COMMUNITIES_ENABLED=1 COMMUNITIES_ENABLED=1
DATABASE_MANAGEMENT_ENABLED=1 DATABASE_MANAGEMENT_ENABLED=1
COMMUNITIES_MANAGEMENT_ENABLED=1

View File

@ -27,7 +27,7 @@
(swap! tmp-storage merge items) (swap! tmp-storage merge items)
(debounced)))) (debounced))))
(defn- get-items [keys cb] (defn get-items [keys cb]
(-> ^js async-storage (-> ^js async-storage
(.multiGet (to-array (map key->string keys))) (.multiGet (to-array (map key->string keys)))
(.then (fn [^js data] (.then (fn [^js data]
@ -38,6 +38,14 @@
(cb nil) (cb nil)
(log/error "[async-storage]" error))))) (log/error "[async-storage]" error)))))
(defn get-item [k cb]
(-> ^js async-storage
(.getItem (key->string k))
(.then cb)
(.catch (fn [error]
(cb nil)
(log/error "[async-storage]" error)))))
(re-frame/reg-fx ::set! (set-item-factory)) (re-frame/reg-fx ::set! (set-item-factory))
(re-frame/reg-fx (re-frame/reg-fx

View File

@ -5,6 +5,7 @@
[clojure.string :as string] [clojure.string :as string]
[clojure.set :as clojure.set] [clojure.set :as clojure.set]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[status-im.async-storage.core :as async-storage]
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.bottom-sheet.core :as bottom-sheet] [status-im.bottom-sheet.core :as bottom-sheet]
@ -435,3 +436,9 @@
:js-response true :js-response true
:on-success #(re-frame/dispatch [::request-to-join-declined community-id request-id %]) :on-success #(re-frame/dispatch [::request-to-join-declined community-id request-id %])
:on-error #(log/error "failed to decline requests-to-join" community-id request-id)}]}) :on-error #(log/error "failed to decline requests-to-join" community-id request-id)}]})
(fx/defn switch-communities-enabled
{:events [:multiaccounts.ui/switch-communities-enabled]}
[{:keys [db]} enabled?]
{::async-storage/set! {:communities-enabled? enabled?}
:db (assoc db :communities/enabled? enabled?)})

View File

@ -3,6 +3,7 @@
[status-im.anon-metrics.core :as anon-metrics] [status-im.anon-metrics.core :as anon-metrics]
[status-im.chat.models.loading :as chat.loading] [status-im.chat.models.loading :as chat.loading]
[status-im.contact.core :as contact] [status-im.contact.core :as contact]
[status-im.utils.config :as config]
[status-im.data-store.settings :as data-store.settings] [status-im.data-store.settings :as data-store.settings]
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.ethereum.transactions.core :as transactions] [status-im.ethereum.transactions.core :as transactions]
@ -37,6 +38,16 @@
[status-im.async-storage.core :as async-storage] [status-im.async-storage.core :as async-storage]
[status-im.notifications-center.core :as notifications-center])) [status-im.notifications-center.core :as notifications-center]))
(re-frame/reg-fx
::initialize-communities-enabled
(fn []
(let [callback #(re-frame/dispatch [:multiaccounts.ui/switch-communities-enabled %])]
(if config/communities-enabled?
(callback true)
(async-storage/get-item
:communities-enabled?
callback)))))
(re-frame/reg-fx (re-frame/reg-fx
::login ::login
(fn [[key-uid account-data hashed-password]] (fn [[key-uid account-data hashed-password]]
@ -238,6 +249,10 @@
[{:method (json-rpc/call-ext-method "getGroupChatInvitations") [{:method (json-rpc/call-ext-method "getGroupChatInvitations")
:on-success #(re-frame/dispatch [::initialize-invitations %])}]}) :on-success #(re-frame/dispatch [::initialize-invitations %])}]})
(fx/defn initialize-communities-enabled
[cofx]
{::initialize-communities-enabled nil})
(fx/defn get-settings-callback (fx/defn get-settings-callback
{:events [::get-settings-callback]} {:events [::get-settings-callback]}
[{:keys [db] :as cofx} settings] [{:keys [db] :as cofx} settings]
@ -262,6 +277,7 @@
(acquisition/login) (acquisition/login)
(initialize-appearance) (initialize-appearance)
(transport/start-messenger) (transport/start-messenger)
(initialize-communities-enabled)
(check-network-version network-id) (check-network-version network-id)
(chat.loading/initialize-chats) (chat.loading/initialize-chats)
(communities/fetch) (communities/fetch)

View File

@ -211,23 +211,22 @@
;; communities ;; communities
(reg-root-key-sub :raw-communities :communities)
(reg-root-key-sub :communities/create :communities/create) (reg-root-key-sub :communities/create :communities/create)
(reg-root-key-sub :communities/requests-to-join :communities/requests-to-join) (reg-root-key-sub :communities/requests-to-join :communities/requests-to-join)
(reg-root-key-sub :communities/community-id-input :communities/community-id-input) (reg-root-key-sub :communities/community-id-input :communities/community-id-input)
(reg-root-key-sub :communities/enabled? :communities/enabled?)
(reg-root-key-sub :activity.center/notifications :activity.center/notifications) (reg-root-key-sub :activity.center/notifications :activity.center/notifications)
(reg-root-key-sub :activity.center/notifications-count :activity.center/notifications-count) (reg-root-key-sub :activity.center/notifications-count :activity.center/notifications-count)
(re-frame/reg-sub (re-frame/reg-sub
:communities :communities
(fn [db] :<- [:raw-communities]
(cond :<- [:communities/enabled?]
config/communities-management-enabled? (fn [[raw-communities communities-enabled?]]
(:communities db) (if communities-enabled?
config/communities-enabled? raw-communities
;; If no management enabled, only return status-community
(select-keys (:communities db) [constants/status-community-id])
:else
[]))) [])))
(re-frame/reg-sub (re-frame/reg-sub
@ -249,13 +248,14 @@
(re-frame/reg-sub (re-frame/reg-sub
:communities/communities :communities/communities
:<- [:communities/enabled?]
:<- [:search/home-filter] :<- [:search/home-filter]
:<- [:communities] :<- [:communities]
(fn [[search-filter communities]] (fn [[communities-enabled? search-filter communities]]
(filterv (filterv
(fn [{:keys [name joined id]}] (fn [{:keys [name joined id]}]
(and joined (and joined
(or config/communities-management-enabled? (or communities-enabled?
(= id constants/status-community-id)) (= id constants/status-community-id))
(or (empty? search-filter) (or (empty? search-filter)
(string/includes? (string/lower-case (str name)) search-filter)))) (string/includes? (string/lower-case (str name)) search-filter))))

View File

@ -11,6 +11,7 @@
(defn- normal-mode-settings-data [{:keys [network-name (defn- normal-mode-settings-data [{:keys [network-name
current-log-level current-log-level
waku-bloom-filter-mode waku-bloom-filter-mode
communities-enabled?
current-fleet current-fleet
webview-debug]}] webview-debug]}]
[{:size :small [{:size :small
@ -65,6 +66,15 @@
:on-press :on-press
#(re-frame/dispatch [:navigate-to :notifications-advanced-settings]) #(re-frame/dispatch [:navigate-to :notifications-advanced-settings])
:chevron true}) :chevron true})
{:size :small
:title (i18n/label :t/communities-enabled)
:accessibility-label :communities-enabled
:container-margin-bottom 8
:on-press
#(re-frame/dispatch
[:multiaccounts.ui/switch-communities-enabled (not communities-enabled?)])
:accessory :switch
:active communities-enabled?}
{:size :small {:size :small
:title "Webview debug" :title "Webview debug"
:accessibility-label :webview-debug-switch :accessibility-label :webview-debug-switch
@ -96,6 +106,7 @@
(views/letsubs [{:keys [webview-debug]} [:multiaccount] (views/letsubs [{:keys [webview-debug]} [:multiaccount]
network-name [:network-name] network-name [:network-name]
waku-bloom-filter-mode [:waku/bloom-filter-mode] waku-bloom-filter-mode [:waku/bloom-filter-mode]
communities-enabled? [:communities/enabled?]
current-log-level [:log-level/current-log-level] current-log-level [:log-level/current-log-level]
current-fleet [:fleets/current-fleet]] current-fleet [:fleets/current-fleet]]
[react/view {:flex 1} [react/view {:flex 1}
@ -104,6 +115,7 @@
{:data (flat-list-data {:data (flat-list-data
{:network-name network-name {:network-name network-name
:current-log-level current-log-level :current-log-level current-log-level
:communities-enabled? communities-enabled?
:current-fleet current-fleet :current-fleet current-fleet
:dev-mode? false :dev-mode? false
:waku-bloom-filter-mode waku-bloom-filter-mode :waku-bloom-filter-mode waku-bloom-filter-mode

View File

@ -2,7 +2,6 @@
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.utils.config :as config]
[status-im.react-native.resources :as resources] [status-im.react-native.resources :as resources]
[status-im.ui.components.colors :as colors] [status-im.ui.components.colors :as colors]
[status-im.ui.components.icons.icons :as icons] [status-im.ui.components.icons.icons :as icons]
@ -216,8 +215,9 @@
(chat.utils/format-author contact-with-names opts))) (chat.utils/format-author contact-with-names opts)))
(defview community-content [{:keys [community-id] :as message}] (defview community-content [{:keys [community-id] :as message}]
(letsubs [{:keys [name description verified] :as community} [:communities/community community-id]] (letsubs [{:keys [name description verified] :as community} [:communities/community community-id]
(when (and config/communities-enabled? community) communities-enabled? [:communities/enabled?]]
(when (and communities-enabled? community)
[react/view {:style (assoc (style/message-wrapper message) [react/view {:style (assoc (style/message-wrapper message)
:margin-vertical 10 :margin-vertical 10
:margin-left 8 :margin-left 8

View File

@ -17,7 +17,6 @@
[status-im.ui.components.icons.icons :as icons] [status-im.ui.components.icons.icons :as icons]
[status-im.utils.core :as utils] [status-im.utils.core :as utils]
[status-im.ui.components.plus-button :as components.plus-button] [status-im.ui.components.plus-button :as components.plus-button]
[status-im.utils.config :as config]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.ui.screens.chat.sheets :as sheets])) [status-im.ui.screens.chat.sheets :as sheets]))
@ -109,7 +108,7 @@
true true
name name
(or color (rand-nth colors/chat-colors))])}] (or color (rand-nth colors/chat-colors))])}]
(when (and config/communities-management-enabled? can-manage-users?) (when can-manage-users?
[quo/list-item [quo/list-item
{:theme :accent {:theme :accent
:title (i18n/label :t/export-key) :title (i18n/label :t/export-key)

View File

@ -3,7 +3,6 @@
[quo.core :as quo] [quo.core :as quo]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.utils.core :as utils] [status-im.utils.core :as utils]
[status-im.utils.config :as config]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.communities.core :as communities] [status-im.communities.core :as communities]
[status-im.utils.handlers :refer [>evt <sub]] [status-im.utils.handlers :refer [>evt <sub]]
@ -114,11 +113,12 @@
:render-fn community-list-item}]) :render-fn community-list-item}])
(defn communities [] (defn communities []
(let [communities (<sub [:communities/section-list])] (let [communities (<sub [:communities/section-list])
communities-enabled? (<sub [:communities/enabled?])]
[react/view {:flex 1} [react/view {:flex 1}
[topbar/topbar (cond-> {:title (i18n/label :t/communities) [topbar/topbar (cond-> {:title (i18n/label :t/communities)
:modal? true} :modal? true}
config/communities-management-enabled? communities-enabled?
(assoc :right-accessories [{:icon :main-icons/more (assoc :right-accessories [{:icon :main-icons/more
:accessibility-label :chat-menu-button :accessibility-label :chat-menu-button
:on-press :on-press
@ -127,7 +127,7 @@
[communities-actions]) [communities-actions])
:height 256}])}]))] :height 256}])}]))]
[communities-list communities] [communities-list communities]
(when config/communities-management-enabled? (when communities-enabled?
[toolbar/toolbar [toolbar/toolbar
{:show-border? true {:show-border? true
:center [quo/button {:on-press #(>evt [::communities/open-create-community]) :center [quo/button {:on-press #(>evt [::communities/open-create-community])
@ -162,4 +162,3 @@
:padding-horizontal 8 :padding-horizontal 8
:padding-vertical 5} :padding-vertical 5}
[quo/text {:color :link} name]]]]) [quo/text {:color :link} name]]]])

View File

@ -47,7 +47,7 @@
:accessibility-label :join-public-chat-button :accessibility-label :join-public-chat-button
:icon :main-icons/public-chat :icon :main-icons/public-chat
:on-press #(hide-sheet-and-dispatch [:navigate-to :new-public-chat])}] :on-press #(hide-sheet-and-dispatch [:navigate-to :new-public-chat])}]
(when config/communities-enabled? (when @(re-frame/subscribe [:communities/enabled?])
[quo/list-item [quo/list-item
{:theme :accent {:theme :accent
:title (i18n/label :t/communities-alpha) :title (i18n/label :t/communities-alpha)

View File

@ -20,7 +20,6 @@
[status-im.add-new.db :as db] [status-im.add-new.db :as db]
[status-im.utils.debounce :as debounce] [status-im.utils.debounce :as debounce]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.utils.config :as config]
[cljs-bean.core :as bean] [cljs-bean.core :as bean]
[status-im.multiaccounts.login.core :as multiaccounts.login] [status-im.multiaccounts.login.core :as multiaccounts.login]
[status-im.ui.components.invite.views :as invite] [status-im.ui.components.invite.views :as invite]
@ -85,7 +84,7 @@
[react/view {:flex-direction :row :flex-wrap :wrap :justify-content :center} [react/view {:flex-direction :row :flex-wrap :wrap :justify-content :center}
(for [chat (new-public-chat/featured-public-chats)] (for [chat (new-public-chat/featured-public-chats)]
(new-public-chat/render-topic chat))]] (new-public-chat/render-topic chat))]]
(when config/communities-enabled? (when @(re-frame/subscribe [:communities/enabled?])
[react/view [react/view
[react/i18n-text {:style {:margin-horizontal 16 [react/i18n-text {:style {:margin-horizontal 16
:text-align :center} :text-align :center}

View File

@ -17,8 +17,7 @@
[status-im.ui.screens.profile.group-chat.views :as profile.group-chat] [status-im.ui.screens.profile.group-chat.views :as profile.group-chat]
[status-im.ui.components.tabbar.styles :as tabbar.styles] [status-im.ui.components.tabbar.styles :as tabbar.styles]
[status-im.ui.screens.stickers.views :as stickers] [status-im.ui.screens.stickers.views :as stickers]
[status-im.ui.screens.notifications-center.views :as notifications-center] [status-im.ui.screens.notifications-center.views :as notifications-center]))
[status-im.utils.config :as config]))
(defonce stack (navigation/create-stack)) (defonce stack (navigation/create-stack))
(defonce group-stack (navigation/create-stack)) (defonce group-stack (navigation/create-stack))
@ -69,19 +68,18 @@
:insets {:bottom true :insets {:bottom true
:top false} :top false}
:component communities.import/view}] :component communities.import/view}]
(when config/communities-management-enabled? [{:name :community-edit
[{:name :community-edit :insets {:bottom true
:insets {:bottom true :top false}
:top false} :component community.edit/edit}
:component community.edit/edit} {:name :community-create
{:name :community-create :insets {:bottom true
:insets {:bottom true :top false}
:top false} :component communities.create/view}
:component communities.create/view} {:name :community-membership
{:name :community-membership :insets {:bottom true
:insets {:bottom true :top false}
:top false} :component membership/membership}])])
:component membership/membership}]))])
(defn new-group-chat [] (defn new-group-chat []
[group-stack {:header-mode :none [group-stack {:header-mode :none

View File

@ -46,8 +46,6 @@
(def quo-preview-enabled? (enabled? (get-config :ENABLE_QUO_PREVIEW "0"))) (def quo-preview-enabled? (enabled? (get-config :ENABLE_QUO_PREVIEW "0")))
(def google-free (enabled? (get-config :GOOGLE_FREE "0"))) (def google-free (enabled? (get-config :GOOGLE_FREE "0")))
(def communities-enabled? (enabled? (get-config :COMMUNITIES_ENABLED "0"))) (def communities-enabled? (enabled? (get-config :COMMUNITIES_ENABLED "0")))
(def communities-management-enabled? (and (enabled? (get-config :COMMUNITIES_MANAGEMENT_ENABLED "0"))
communities-enabled?))
(def database-management-enabled? (enabled? (get-config :DATABASE_MANAGEMENT_ENABLED "0"))) (def database-management-enabled? (enabled? (get-config :DATABASE_MANAGEMENT_ENABLED "0")))
(def debug-webview? (enabled? (get-config :DEBUG_WEBVIEW "0"))) (def debug-webview? (enabled? (get-config :DEBUG_WEBVIEW "0")))