Add collapsing of categories (#15306)

290579f7...44a0f5b7

Fixes: #15290

This commit adds collapsing of categories.
It also adds ordering of chats/categories as it was previously ignored.

It also removes the communities/enabled? flag as it's not used anymore,
and communities should always be enabled.
This commit is contained in:
Andrea Maria Piana 2023-03-16 10:17:50 +00:00 committed by GitHub
parent a0697d9242
commit b44e4c6d59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 384 additions and 249 deletions

View File

@ -11,10 +11,21 @@
(defn divider-label (defn divider-label
"label -> string "label -> string
chevron-position -> :left, :right chevron-position -> :left, :right
chevron-icon -> keyword
on-press -> function
padding-bottom -> number
counter-value -> number counter-value -> number
increase-padding-top? -> boolean increase-padding-top? -> boolean
blur? -> boolean" blur? -> boolean"
[{:keys [label chevron-position counter-value increase-padding-top? blur? container-style]}] [{:keys [label
chevron-position
chevron-icon
counter-value
increase-padding-top?
padding-bottom
blur?
container-style
on-press]}]
(let [dark? (colors/dark?) (let [dark? (colors/dark?)
border-and-counter-bg-color (if dark? border-and-counter-bg-color (if dark?
(if blur? colors/white-opa-5 colors/neutral-70) (if blur? colors/white-opa-5 colors/neutral-70)
@ -22,12 +33,15 @@
padding-top (if increase-padding-top? 16 8) padding-top (if increase-padding-top? 16 8)
text-and-icon-color (if dark? colors/neutral-40 colors/neutral-50) text-and-icon-color (if dark? colors/neutral-40 colors/neutral-50)
counter-text-color (if dark? colors/white colors/neutral-100)] counter-text-color (if dark? colors/white colors/neutral-100)]
[rn/touchable-without-feedback
{:on-press on-press}
[rn/view [rn/view
{:accessible true {:accessible true
:accessibility-label :divider-label :accessibility-label :divider-label
:style (merge {:border-top-width 1 :style (merge {:border-top-width 1
:border-top-color border-and-counter-bg-color :border-top-color border-and-counter-bg-color
:padding-top padding-top :padding-top padding-top
:padding-bottom padding-bottom
:padding-horizontal 16 :padding-horizontal 16
:align-items :center :align-items :center
:flex-direction :row} :flex-direction :row}
@ -37,7 +51,7 @@
{:test-ID :divider-label-icon-left {:test-ID :divider-label-icon-left
:style {:margin-right 4}} :style {:margin-right 4}}
[icons/icon [icons/icon
:main-icons/chevron-down (or chevron-icon :i/chevron-down)
{:color text-and-icon-color {:color text-and-icon-color
:width chevron-icon-container-width :width chevron-icon-container-width
:height chevron-icon-container-height}]]) :height chevron-icon-container-height}]])
@ -50,7 +64,7 @@
(when (= chevron-position :right) (when (= chevron-position :right)
[rn/view {:test-ID :divider-label-icon-right} [rn/view {:test-ID :divider-label-icon-right}
[icons/icon [icons/icon
:main-icons/chevron-down (or chevron-icon :i/chevron-down)
{:color text-and-icon-color {:color text-and-icon-color
:size chevron-icon-container-width}]]) :size chevron-icon-container-width}]])
(when (pos? counter-value) (when (pos? counter-value)
@ -68,4 +82,4 @@
{:size :label {:size :label
:weight :medium :weight :medium
:style {:color counter-text-color}} :style {:color counter-text-color}}
counter-value]])])) counter-value]])]]))

View File

@ -678,12 +678,6 @@
community-id community-id
request-id)}]}) request-id)}]})
(rf/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?)})
(rf/defn create-category (rf/defn create-category
{:events [::create-category-confirmation-pressed]} {:events [::create-category-confirmation-pressed]}
[_ community-id category-title chat-ids] [_ community-id category-title chat-ids]
@ -860,3 +854,47 @@
:community-id community-id :community-id community-id
:public-key public-key :public-key public-key
:role-id role-id})]}) :role-id role-id})]})
(rf/defn fetched-collapsed-community-categories
{:events [:communities/fetched-collapsed-categories-success]}
[{:keys [db]} categories]
{:db (assoc db
:communities/collapsed-categories
(reduce
(fn [acc {:keys [communityId categoryId]}]
(assoc-in acc [communityId categoryId] true))
{}
categories))})
(rf/defn fetch-collapsed-community-categories
[_]
{:json-rpc/call [{:method "wakuext_collapsedCommunityCategories"
:params []
:on-success #(re-frame/dispatch
[:communities/fetched-collapsed-categories-success %])
:on-error #(log/error "failed to fetch collapsed community categories"
{:error :%})}]})
(rf/defn toggled-collapsed-category
{:events [:communities/toggled-collapsed-category-success]}
[{:keys [db]} community-id category-id collapsed?]
{:db (assoc-in db [:communities/collapsed-categories community-id category-id] collapsed?)})
(rf/defn toggle-collapsed-category
{:events [:communities/toggle-collapsed-category]}
[{:keys [db]} community-id category-id collapse?]
{:json-rpc/call [{:method "wakuext_toggleCollapsedCommunityCategory"
:params [{:communityId community-id
:categoryId category-id
:collapsed collapse?}]
:on-success #(re-frame/dispatch
[:communities/toggled-collapsed-category-success
community-id
category-id
collapse?])
:on-error #(log/error "failed to toggle collapse category"
{:error %
:community-id community-id
:event :communities/toggle-collapsed-category
:category-id category-id
:collapse? collapse?})}]})

View File

@ -46,16 +46,6 @@
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.security.core :as security])) [utils.security.core :as security]))
(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
::initialize-transactions-management-enabled ::initialize-transactions-management-enabled
(fn [] (fn []
@ -358,10 +348,6 @@
[{:method "wakuext_getGroupChatInvitations" [{:method "wakuext_getGroupChatInvitations"
:on-success #(re-frame/dispatch [::initialize-invitations %])}]}) :on-success #(re-frame/dispatch [::initialize-invitations %])}]})
(rf/defn initialize-communities-enabled
[cofx]
{::initialize-communities-enabled nil})
(rf/defn initialize-transactions-management-enabled (rf/defn initialize-transactions-management-enabled
[cofx] [cofx]
{::initialize-transactions-management-enabled nil}) {::initialize-transactions-management-enabled nil})
@ -408,10 +394,10 @@
(rf/dispatch [:communities/get-user-requests-to-join]) (rf/dispatch [:communities/get-user-requests-to-join])
(re-frame/dispatch [::get-chats-callback]))}) (re-frame/dispatch [::get-chats-callback]))})
(initialize-appearance) (initialize-appearance)
(initialize-communities-enabled)
(initialize-wallet-connect) (initialize-wallet-connect)
(get-node-config) (get-node-config)
(communities/fetch) (communities/fetch)
(communities/fetch-collapsed-community-categories)
(logging/set-log-level (:log-level multiaccount)) (logging/set-log-level (:log-level multiaccount))
(activity-center/notifications-fetch-pending-contact-requests) (activity-center/notifications-fetch-pending-contact-requests)
(activity-center/update-seen-state) (activity-center/update-seen-state)
@ -539,7 +525,6 @@
(communities/fetch) (communities/fetch)
(data-store.chats/fetch-chats-rpc (data-store.chats/fetch-chats-rpc
{:on-success #(re-frame/dispatch [:chats-list/load-success %])}) {:on-success #(re-frame/dispatch [:chats-list/load-success %])})
(initialize-communities-enabled)
(multiaccounts/switch-preview-privacy-mode-flag) (multiaccounts/switch-preview-privacy-mode-flag)
(link-preview/request-link-preview-whitelist) (link-preview/request-link-preview-whitelist)
(logging/set-log-level (:log-level multiaccount)) (logging/set-log-level (:log-level multiaccount))

View File

@ -2,15 +2,13 @@
(:require [quo.core :as quo] (:require [quo.core :as quo]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[status-im.ui.components.list.views :as list] [status-im.ui.components.list.views :as list])
[status-im2.config :as config])
(:require-macros [status-im.utils.views :as views])) (:require-macros [status-im.utils.views :as views]))
(defn- normal-mode-settings-data (defn- normal-mode-settings-data
[{:keys [network-name [{:keys [network-name
current-log-level current-log-level
waku-bloom-filter-mode waku-bloom-filter-mode
communities-enabled?
transactions-management-enabled? transactions-management-enabled?
wakuv2-flag wakuv2-flag
current-fleet current-fleet
@ -76,17 +74,6 @@
:on-press :on-press
#(re-frame/dispatch [:navigate-to :peers-stats]) #(re-frame/dispatch [:navigate-to :peers-stats])
:chevron true} :chevron true}
;; If it's enabled in the config, we don't show the option
(when (not config/communities-enabled?)
{: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 (i18n/label :t/transactions-management-enabled) :title (i18n/label :t/transactions-management-enabled)
:accessibility-label :transactions-management-enabled :accessibility-label :transactions-management-enabled
@ -132,7 +119,6 @@
network-name [:network-name] network-name [:network-name]
waku-bloom-filter-mode [:waku/bloom-filter-mode] waku-bloom-filter-mode [:waku/bloom-filter-mode]
wakuv2-flag [:waku/v2-flag] wakuv2-flag [:waku/v2-flag]
communities-enabled? [:communities/enabled?]
transactions-management-enabled? [:wallet/transactions-management-enabled?] transactions-management-enabled? [:wallet/transactions-management-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]]
@ -140,7 +126,6 @@
{: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?
:transactions-management-enabled? transactions-management-enabled? :transactions-management-enabled? transactions-management-enabled?
:current-fleet current-fleet :current-fleet current-fleet
:dev-mode? false :dev-mode? false

View File

@ -142,28 +142,25 @@
(defn communities (defn communities
[] []
(let [communities (rf/sub [:communities/section-list]) (let [communities (rf/sub [:communities/section-list])]
communities-enabled? (rf/sub [:communities/enabled?])]
[:<> [:<>
[topbar/topbar [topbar/topbar
(cond-> {:title (i18n/label :t/communities)} {:title (i18n/label :t/communities)
communities-enabled? :right-accessories
(assoc :right-accessories
[{:icon :main-icons/more [{:icon :main-icons/more
:accessibility-label :chat-menu-button :accessibility-label :chat-menu-button
:on-press :on-press
#(rf/dispatch [:bottom-sheet/show-sheet #(rf/dispatch [:bottom-sheet/show-sheet
{:content (fn [] {:content (fn []
[communities-actions]) [communities-actions])
:height 256}])}]))] :height 256}])}]}]
[communities-list communities] [communities-list communities]
(when communities-enabled?
[toolbar/toolbar [toolbar/toolbar
{:show-border? true {:show-border? true
:center [quo/button :center [quo/button
{:on-press #(rf/dispatch [::communities/open-create-community]) {:on-press #(rf/dispatch [::communities/open-create-community])
:type :secondary} :type :secondary}
(i18n/label :t/create-community)]}])])) (i18n/label :t/create-community)]}]]))
(defn export-community (defn export-community
[] []

View File

@ -51,13 +51,12 @@
: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 [:open-modal :new-public-chat])}] :on-press #(hide-sheet-and-dispatch [:open-modal :new-public-chat])}]
(when (rf/sub [:communities/enabled?])
[quo/list-item [quo/list-item
{:theme :accent {:theme :accent
:title (i18n/label :t/communities-alpha) :title (i18n/label :t/communities-alpha)
:accessibility-label :communities-button :accessibility-label :communities-button
:icon :main-icons/communities :icon :main-icons/communities
:on-press #(hide-sheet-and-dispatch [:navigate-to :communities])}]) :on-press #(hide-sheet-and-dispatch [:navigate-to :communities])}]
[invite/list-item [invite/list-item
{:accessibility-label :chats-menu-invite-friends-button}]]) {:accessibility-label :chats-menu-invite-friends-button}]])

View File

@ -354,9 +354,8 @@
(defview community-content (defview community-content
[{:keys [community-id] :as message}] [{: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]]
communities-enabled? [:communities/enabled?]] (when community
(when (and communities-enabled? community)
[rn/view [rn/view
{:style (assoc (style/message-wrapper message) {:style (assoc (style/message-wrapper message)
:margin-vertical 10 :margin-vertical 10

View File

@ -31,7 +31,6 @@
(def keycard-test-menu-enabled? (enabled? (get-config :KEYCARD_TEST_MENU "1"))) (def keycard-test-menu-enabled? (enabled? (get-config :KEYCARD_TEST_MENU "1")))
(def qr-test-menu-enabled? (enabled? (get-config :QR_READ_TEST_MENU "0"))) (def qr-test-menu-enabled? (enabled? (get-config :QR_READ_TEST_MENU "0")))
(def quo-preview-enabled? (enabled? (get-config :ENABLE_QUO_PREVIEW "0"))) (def quo-preview-enabled? (enabled? (get-config :ENABLE_QUO_PREVIEW "0")))
(def communities-enabled? (enabled? (get-config :COMMUNITIES_ENABLED "0")))
(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")))
(def collectibles-enabled? (enabled? (get-config :COLLECTIBLES_ENABLED "1"))) (def collectibles-enabled? (enabled? (get-config :COLLECTIBLES_ENABLED "1")))

View File

@ -290,3 +290,5 @@
(def ^:const local-pair-action-sync-device 3) (def ^:const local-pair-action-sync-device 3)
(def ^:const everyone-mention-id "0x00001") (def ^:const everyone-mention-id "0x00001")
(def ^:const empty-category-id :communities/not-categorized)

View File

@ -60,35 +60,45 @@
(defn add-category-height (defn add-category-height
[categories-heights category height] [categories-heights category height]
(swap! categories-heights (swap! categories-heights
(fn [] (fn [heights]
(sort-by :height (assoc heights category height))))
(conj @categories-heights
{:height height (defn collapse-category
:label category}))))) [community-id category-id collapsed?]
(rf/dispatch [:communities/toggle-collapsed-category community-id category-id (not collapsed?)]))
(defn channel-list-component (defn channel-list-component
[{:keys [on-categories-heights-changed [{:keys [on-category-layout
community-id
on-first-channel-height-changed]} on-first-channel-height-changed]}
channels-list] channels-list]
(let [categories-heights (reagent/atom [])]
[rn/view [rn/view
{:on-layout #(on-first-channel-height-changed (+ (if platform/ios? {:on-layout #(on-first-channel-height-changed (+ (if platform/ios?
0 0
38) 38)
(int (Math/ceil (layout-y %))))) (int (Math/ceil (layout-y %))))
(into #{} (map (comp :name second) channels-list)))
:style {:margin-top 20 :flex 1}} :style {:margin-top 20 :flex 1}}
(map-indexed (map
(fn [index [category channels-for-category]] (fn [[category-id {:keys [chats name collapsed?]}]]
[rn/view [rn/view
{:flex 1 {:flex 1
:key (str index category) :key category-id
:on-layout #(do ;; on-layout fires only when the component re-renders, so
(add-category-height categories-heights category (int (layout-y %))) ;; in case the category hasn't changed, it will not be fired
(on-categories-heights-changed @categories-heights))} :on-layout #(on-category-layout name (int (layout-y %)))}
(when-not (= constants/empty-category-id category-id)
[quo/divider-label [quo/divider-label
{:label category {:label name
:chevron-position :left}] :on-press #(collapse-category
community-id
category-id
collapsed?)
:chevron-icon (if collapsed? :main-icons/chevron-right :main-icons/chevron-down)
:padding-bottom (if collapsed? 7 0)
:chevron-position :left}])
(when-not collapsed?
[rn/view [rn/view
{:margin-left 8 {:margin-left 8
:margin-top 10 :margin-top 10
@ -98,8 +108,8 @@
{:key (:id channel) {:key (:id channel)
:margin-top 4} :margin-top 4}
[quo/channel-list-item channel]]) [quo/channel-list-item channel]])
channels-for-category)]]) chats)])])
channels-list)])) channels-list)])
(defn request-to-join-text (defn request-to-join-text
[is-open?] [is-open?]
@ -192,10 +202,10 @@
(defn add-on-press-handler-to-categorized-chats (defn add-on-press-handler-to-categorized-chats
[community-id categorized-chats] [community-id categorized-chats]
(reduce-kv (fn [acc category chats] (let [add-on-press (partial add-on-press-handler-to-chats community-id)]
(assoc acc category (add-on-press-handler-to-chats community-id chats))) (map (fn [[category v]]
{} [category (update v :chats add-on-press)])
categorized-chats)) categorized-chats)))
(defn community-header (defn community-header
[name] [name]
@ -221,8 +231,9 @@
(defn community-content (defn community-content
[{:keys [name description locked joined images [{:keys [name description locked joined images
status tokens tags id] status tokens tags id]
:as community} pending? :as community}
{:keys [on-categories-heights-changed pending?
{:keys [on-category-layout
on-first-channel-height-changed]}] on-first-channel-height-changed]}]
(let [thumbnail-image (:thumbnail images) (let [thumbnail-image (:thumbnail images)
chats-by-category (rf/sub [:communities/categorized-channels id]) chats-by-category (rf/sub [:communities/categorized-channels id])
@ -264,13 +275,14 @@
[preview-user-list users] [preview-user-list users]
[join-community community pending?]] [join-community community pending?]]
[channel-list-component [channel-list-component
{:on-categories-heights-changed #(on-categories-heights-changed %) {:on-category-layout on-category-layout
:on-first-channel-height-changed #(on-first-channel-height-changed %)} :community-id id
:on-first-channel-height-changed on-first-channel-height-changed}
(add-on-press-handler-to-categorized-chats id chats-by-category)]])) (add-on-press-handler-to-categorized-chats id chats-by-category)]]))
(defn sticky-category-header (defn sticky-category-header
[_] [_]
(fn [{:keys [:enabled :label]}] (fn [{:keys [enabled label]}]
(when enabled (when enabled
[blur/view [blur/view
{:style style/blur-channel-header {:style style/blur-channel-header
@ -278,7 +290,7 @@
:blur-type :transparent :blur-type :transparent
:overlay-color :transparent} :overlay-color :transparent}
[quo/divider-label [quo/divider-label
{:label (:label label) {:label label
:chevron-position :left}]]))) :chevron-position :left}]])))
(defn page-nav-right-section-buttons (defn page-nav-right-section-buttons
@ -292,9 +304,18 @@
[options/community-options-bottom-sheet [options/community-options-bottom-sheet
id])}])}]) id])}])}])
(defn pick-first-category-by-height
[scroll-height first-channel-height categories-heights]
(->> categories-heights
(sort-by (comp - second))
(some (fn [[category height]]
(and
(>= scroll-height (+ height first-channel-height))
category)))))
(defn community-card-page-view (defn community-card-page-view
[{:keys [name images id]}] [{:keys [name images id]}]
(let [categories-heights (reagent/atom []) (let [categories-heights (reagent/atom {})
first-channel-height (reagent/atom 0) first-channel-height (reagent/atom 0)
scroll-height (reagent/atom 0) scroll-height (reagent/atom 0)
cover {:uri (get-in images [:banner :uri])} cover {:uri (get-in images [:banner :uri])}
@ -316,14 +337,21 @@
[sticky-category-header [sticky-category-header
{:enabled (> @scroll-height @first-channel-height) {:enabled (> @scroll-height @first-channel-height)
:label (last (filter (fn [{:keys [height]}] :label (pick-first-category-by-height
(>= @scroll-height (+ height @first-channel-height))) @scroll-height
@categories-heights))}] @first-channel-height
@categories-heights)}]
[community-content [community-content
community community
pending? pending?
{:on-categories-heights-changed #(reset! categories-heights %) {:on-category-layout (partial add-category-height categories-heights)
:on-first-channel-height-changed #(reset! first-channel-height %)}]]))) :on-first-channel-height-changed
;; Here we set the height of the component
;; and we filter out the categories, as some might have been removed
(fn [height categories]
(swap! categories-heights select-keys categories)
(reset! first-channel-height height))}]])))
(defn overview (defn overview
[] []

View File

@ -6,15 +6,6 @@
[status-im2.constants :as constants] [status-im2.constants :as constants]
[utils.i18n :as i18n])) [utils.i18n :as i18n]))
(re-frame/reg-sub
:communities
:<- [:raw-communities]
:<- [:communities/enabled?]
(fn [[raw-communities communities-enabled?]]
(if communities-enabled?
raw-communities
[])))
(re-frame/reg-sub (re-frame/reg-sub
:communities/fetching-community :communities/fetching-community
:<- [:communities/resolve-community-info] :<- [:communities/resolve-community-info]
@ -81,16 +72,13 @@
(re-frame/reg-sub (re-frame/reg-sub
:communities/featured-communities :communities/featured-communities
:<- [:communities/enabled?]
:<- [:search/home-filter] :<- [:search/home-filter]
:<- [:communities] :<- [:communities]
(fn [[communities-enabled? search-filter communities]] (fn [[search-filter communities]]
(filterv (filterv
(fn [{:keys [name id]}] (fn [{:keys [name]}]
(and (or communities-enabled?
(= 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)))
(vals communities)))) (vals communities))))
(re-frame/reg-sub (re-frame/reg-sub
@ -101,17 +89,13 @@
(re-frame/reg-sub (re-frame/reg-sub
:communities/communities :communities/communities
:<- [:communities/enabled?]
:<- [:search/home-filter] :<- [:search/home-filter]
:<- [:communities] :<- [:communities]
(fn [[communities-enabled? search-filter communities]] (fn [[search-filter communities]]
(filterv (filterv
(fn [{:keys [name id]}] (fn [{:keys [name]}]
(and
(or communities-enabled?
(= 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)))
(vals communities)))) (vals communities))))
(re-frame/reg-sub (re-frame/reg-sub
@ -151,7 +135,7 @@
(re-frame/reg-sub (re-frame/reg-sub
:communities/home-item :communities/home-item
(fn [[_ community-id]] (fn [[_ community-id]]
[(re-frame/subscribe [:raw-communities]) [(re-frame/subscribe [:communities])
(re-frame/subscribe [:communities/unviewed-counts community-id])]) (re-frame/subscribe [:communities/unviewed-counts community-id])])
(fn [[communities counts] [_ identity]] (fn [[communities counts] [_ identity]]
(community->home-item (community->home-item
@ -230,31 +214,62 @@
(sort-by :position) (sort-by :position)
(into [])))) (into []))))
(defn reduce-over-categories
[community-id
joined
categories
collapsed-categories
full-chats-data]
(fn [acc
[_ {:keys [name categoryID position id emoji can-post?]}]]
(let [category-id (if (seq categoryID) categoryID constants/empty-category-id)
{:keys [unviewed-messages-count
unviewed-mentions-count]} (get full-chats-data
(str community-id id))
acc-with-category (if (get acc category-id)
acc
(assoc acc
category-id
(assoc
(or (get categories category-id)
{:name (i18n/label :t/none)})
:collapsed? (get collapsed-categories
category-id)
:chats [])))
chat {:name name
:emoji emoji
:unread-messages? (pos? unviewed-messages-count)
:position position
:mentions-count (or unviewed-mentions-count 0)
:locked? (or (not joined)
(not can-post?))
:id id}]
(update-in acc-with-category [category-id :chats] conj chat))))
(re-frame/reg-sub (re-frame/reg-sub
:communities/categorized-channels :communities/categorized-channels
(fn [[_ community-id]] (fn [[_ community-id]]
[(re-frame/subscribe [:communities/community community-id]) [(re-frame/subscribe [:communities/community community-id])
(re-frame/subscribe [:chats/chats])]) (re-frame/subscribe [:chats/chats])
(fn [[{:keys [joined categories chats]} full-chats-data] [_ community-id]] (re-frame/subscribe [:communities/collapsed-categories-for-community community-id])])
(fn [[{:keys [joined categories chats]} full-chats-data collapsed-categories] [_ community-id]]
(let [reduce-fn (reduce-over-categories
community-id
joined
categories
collapsed-categories
full-chats-data)
categories-and-chats
(->>
chats
(reduce (reduce
(fn [acc [_ {:keys [name categoryID id emoji can-post?]}]] reduce-fn
(let [category (keyword {})
(get-in categories (sort-by (comp :position second))
[categoryID :name] (map (fn [[k v]]
(i18n/label :t/none))) [k (update v :chats #(sort-by :position %))])))]
{:keys [unviewed-messages-count unviewed-mentions-count]} (get full-chats-data
(str community-id id))] categories-and-chats)))
(update acc
category
#(vec (conj %1 %2))
{:name name
:emoji emoji
:unread-messages? (pos? unviewed-messages-count)
:mentions-count (or unviewed-mentions-count 0)
:locked? (or (not joined) (not can-post?))
:id id})))
{}
chats)))
(re-frame/reg-sub (re-frame/reg-sub
:communities/users :communities/users
@ -264,3 +279,9 @@
{:full-name "Marcus C"} {:full-name "Marcus C"}
{:full-name "MNO PQR"} {:full-name "MNO PQR"}
{:full-name "STU VWX"}])) {:full-name "STU VWX"}]))
(re-frame/reg-sub
:communities/collapsed-categories-for-community
:<- [:communities/collapsed-categories]
(fn [collapsed-categories [_ community-id]]
(get collapsed-categories community-id)))

View File

@ -3,25 +3,22 @@
[re-frame.db :as rf-db] [re-frame.db :as rf-db]
[test-helpers.unit :as h] [test-helpers.unit :as h]
status-im2.subs.communities status-im2.subs.communities
[status-im2.constants :as constants]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[utils.i18n :as i18n])) [utils.i18n :as i18n]))
(use-fixtures :each (use-fixtures :each
{:before #(reset! rf-db/app-db {:communities/enabled? true})}) {:before #(reset! rf-db/app-db {})})
(def community-id "0x1") (def community-id "0x1")
(h/deftest-sub :communities (h/deftest-sub :communities
[sub-name] [sub-name]
(testing "returns empty vector if flag is disabled" (testing "returns raw communities"
(swap! rf-db/app-db assoc :communities/enabled? false)
(is (= [] (rf/sub [sub-name]))))
(testing "returns raw communities if flag is enabled"
(let [raw-communities {"0x1" {:id "0x1"}}] (let [raw-communities {"0x1" {:id "0x1"}}]
(swap! rf-db/app-db assoc (swap! rf-db/app-db assoc
:communities/enabled? true :communities
:communities raw-communities) raw-communities)
(is (= raw-communities (rf/sub [sub-name])))))) (is (= raw-communities (rf/sub [sub-name]))))))
(h/deftest-sub :communities/section-list (h/deftest-sub :communities/section-list
@ -85,13 +82,12 @@
[sub-name] [sub-name]
(testing "Empty communities list" (testing "Empty communities list"
(swap! rf-db/app-db assoc (swap! rf-db/app-db assoc
:communities/enabled? true :communities
:communities {}) {})
(is (= [] (is (= []
(rf/sub [sub-name])))) (rf/sub [sub-name]))))
(testing "communities sorted by name" (testing "communities sorted by name"
(swap! rf-db/app-db assoc (swap! rf-db/app-db assoc
:communities/enabled? true
:communities :communities
{"0x1" {:id "0x1" :name "Civilized monkeys"} {"0x1" {:id "0x1" :name "Civilized monkeys"}
"0x2" {:id "0x2" :name "Civilized rats"} "0x2" {:id "0x2" :name "Civilized rats"}
@ -105,56 +101,127 @@
[sub-name] [sub-name]
(testing "Channels with categories" (testing "Channels with categories"
(swap! rf-db/app-db assoc (swap! rf-db/app-db assoc
:communities/enabled? true
:communities :communities
{"0x1" {:id "0x1" {"0x1" {:id "0x1"
:chats {"0x1" {:id "0x1" :name "chat1" :categoryID 1 :can-post? true} :chats {"0x1" {:id "0x1" :position 1 :name "chat1" :categoryID "1" :can-post? true}
"0x2" {:id "0x2" :name "chat2" :categoryID 1 :can-post? false} "0x2" {:id "0x2" :position 2 :name "chat2" :categoryID "1" :can-post? false}
"0x3" {:id "0x3" :name "chat3" :categoryID 2 :can-post? true}} "0x3" {:id "0x3" :position 3 :name "chat3" :categoryID "2" :can-post? true}}
:categories {1 {:id 1 :name "category1"} :categories {"1" {:id "1"
2 {:id 2 :name "category2"}} :position 2
:name "category1"}
"2" {:id "2"
:position 1
:name "category2"}}
:joined true}}) :joined true}})
(is (is
(= {:category1 (= [["2"
[{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false :mentions-count 0} {:id "2"
{:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false :mentions-count 0}] :name "category2"
:category2 :collapsed? nil
[{:name "chat3" :emoji nil :locked? false :id "0x3" :unread-messages? false :mentions-count 0}]} :position 1
:chats [{:name "chat3"
:position 3
:emoji nil
:locked? false
:id "0x3"
:unread-messages? false
:mentions-count 0}]}]
["1"
{:id "1"
:name "category1"
:collapsed? nil
:position 2
:chats [{:name "chat1"
:emoji nil
:position 1
:locked? false
:id "0x1"
:unread-messages? false
:mentions-count 0}
{:name "chat2"
:emoji nil
:position 2
:locked? true
:id "0x2"
:unread-messages? false
:mentions-count 0}]}]]
(rf/sub [sub-name "0x1"])))) (rf/sub [sub-name "0x1"]))))
(testing "Channels without categories" (testing "Channels without categories"
(swap! rf-db/app-db assoc (swap! rf-db/app-db assoc
:communities/enabled? true
:communities :communities
{"0x1" {:id "0x1" {"0x1" {:id "0x1"
:chats {"0x1" {:id "0x1" :name "chat1" :categoryID 1 :can-post? true} :chats {"0x1" {:id "0x1" :position 1 :name "chat1" :categoryID "1" :can-post? true}
"0x2" {:id "0x2" :name "chat2" :categoryID 1 :can-post? false} "0x2" {:id "0x2" :position 2 :name "chat2" :categoryID "1" :can-post? false}
"0x3" {:id "0x3" :name "chat3" :can-post? true}} "0x3" {:id "0x3" :position 3 :name "chat3" :can-post? true}}
:categories {1 {:id 1 :name "category1"} :categories {"1" {:id "1"
2 {:id 2 :name "category2"}} :position 1
:name "category1"}
"2" {:id "2"
:position 2
:name "category2"}}
:joined true}}) :joined true}})
(is (is
(= {:category1 (=
[{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false :mentions-count 0} [[constants/empty-category-id
{:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false :mentions-count 0}] {:name (i18n/label :t/none)
(keyword (i18n/label :t/none)) :collapsed? nil
[{:name "chat3" :emoji nil :locked? false :id "0x3" :unread-messages? false :mentions-count 0}]} :chats [{:name "chat3"
:emoji nil
:position 3
:locked? false
:id "0x3"
:unread-messages? false
:mentions-count 0}]}]
["1"
{:name "category1"
:id "1"
:position 1
:collapsed? nil
:chats [{:name "chat1"
:emoji nil
:position 1
:locked? false
:id "0x1"
:unread-messages? false
:mentions-count 0}
{:name "chat2"
:emoji nil
:position 2
:locked? true
:id "0x2"
:unread-messages? false
:mentions-count 0}]}]]
(rf/sub [sub-name "0x1"])))) (rf/sub [sub-name "0x1"]))))
(testing "Unread messages" (testing "Unread messages"
(swap! rf-db/app-db assoc (swap! rf-db/app-db assoc
:communities/enabled? true
:communities :communities
{"0x1" {:id "0x1" {"0x1" {:id "0x1"
:chats {"0x1" {:id "0x1" :name "chat1" :categoryID 1 :can-post? true} :chats {"0x1" {:id "0x1" :position 1 :name "chat1" :categoryID "1" :can-post? true}
"0x2" {:id "0x2" :name "chat2" :categoryID 1 :can-post? false}} "0x2" {:id "0x2" :position 2 :name "chat2" :categoryID "1" :can-post? false}}
:categories {1 {:id 1 :name "category1"}} :categories {"1" {:id "1" :name "category1"}}
:joined true}} :joined true}}
:chats :chats
{"0x10x1" {:unviewed-messages-count 1 :unviewed-mentions-count 2} {"0x10x1" {:unviewed-messages-count 1 :unviewed-mentions-count 2}
"0x10x2" {:unviewed-messages-count 0 :unviewed-mentions-count 0}}) "0x10x2" {:unviewed-messages-count 0 :unviewed-mentions-count 0}})
(is (is
(= {:category1 (= [["1"
[{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? true :mentions-count 2} {:name "category1"
{:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false :mentions-count 0}]} :id "1"
:collapsed? nil
:chats [{:name "chat1"
:emoji nil
:position 1
:locked? false
:id "0x1"
:unread-messages? true
:mentions-count 2}
{:name "chat2"
:emoji nil
:position 2
:locked? true
:id "0x2"
:unread-messages? false
:mentions-count 0}]}]]
(rf/sub [sub-name "0x1"]))))) (rf/sub [sub-name "0x1"])))))
(h/deftest-sub :communities/my-pending-requests-to-join (h/deftest-sub :communities/my-pending-requests-to-join

View File

@ -238,14 +238,14 @@
;; communities ;; communities
(reg-root-key-sub :raw-communities :communities) (reg-root-key-sub :communities :communities)
(reg-root-key-sub :communities/create :communities/create) (reg-root-key-sub :communities/create :communities/create)
(reg-root-key-sub :communities/create-channel :communities/create-channel) (reg-root-key-sub :communities/create-channel :communities/create-channel)
(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 :communities/resolve-community-info :communities/resolve-community-info) (reg-root-key-sub :communities/resolve-community-info :communities/resolve-community-info)
(reg-root-key-sub :communities/my-pending-requests-to-join :communities/my-pending-requests-to-join) (reg-root-key-sub :communities/my-pending-requests-to-join :communities/my-pending-requests-to-join)
(reg-root-key-sub :communities/collapsed-categories :communities/collapsed-categories)
(reg-root-key-sub :activity-center :activity-center) (reg-root-key-sub :activity-center :activity-center)
@ -254,6 +254,7 @@
(reg-root-key-sub :backup/performing-backup :backup/performing-backup) (reg-root-key-sub :backup/performing-backup :backup/performing-backup)
;; wallet connect ;; wallet connect
(reg-root-key-sub :wallet-connect/proposal-metadata :wallet-connect/proposal-metadata) (reg-root-key-sub :wallet-connect/proposal-metadata :wallet-connect/proposal-metadata)
(reg-root-key-sub :wallet-connect/enabled? :wallet-connect/enabled?) (reg-root-key-sub :wallet-connect/enabled? :wallet-connect/enabled?)

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.138.3", "version": "v0.138.4",
"commit-sha1": "290579f74f10a374ffb8c37abc47dbe2c1e90f5d", "commit-sha1": "44a0f5b74d31fe31bd77b565ae679f839ea40e94",
"src-sha256": "0vgs3m1fbyri9r1wqxfanzxlx24yzx9zaabflk26qc9d4pclmi7i" "src-sha256": "05j9y1fg23xgqj4348cjpn7xm6jmhzj9xz2zwhvhagnq1c28800c"
} }