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:
parent
a0697d9242
commit
b44e4c6d59
|
@ -11,10 +11,21 @@
|
|||
(defn divider-label
|
||||
"label -> string
|
||||
chevron-position -> :left, :right
|
||||
chevron-icon -> keyword
|
||||
on-press -> function
|
||||
padding-bottom -> number
|
||||
counter-value -> number
|
||||
increase-padding-top? -> 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?)
|
||||
border-and-counter-bg-color (if dark?
|
||||
(if blur? colors/white-opa-5 colors/neutral-70)
|
||||
|
@ -22,50 +33,53 @@
|
|||
padding-top (if increase-padding-top? 16 8)
|
||||
text-and-icon-color (if dark? colors/neutral-40 colors/neutral-50)
|
||||
counter-text-color (if dark? colors/white colors/neutral-100)]
|
||||
[rn/view
|
||||
{:accessible true
|
||||
:accessibility-label :divider-label
|
||||
:style (merge {:border-top-width 1
|
||||
:border-top-color border-and-counter-bg-color
|
||||
:padding-top padding-top
|
||||
:padding-horizontal 16
|
||||
:align-items :center
|
||||
:flex-direction :row}
|
||||
container-style)}
|
||||
(when (= chevron-position :left)
|
||||
[rn/view
|
||||
{:test-ID :divider-label-icon-left
|
||||
:style {:margin-right 4}}
|
||||
[icons/icon
|
||||
:main-icons/chevron-down
|
||||
{:color text-and-icon-color
|
||||
:width chevron-icon-container-width
|
||||
:height chevron-icon-container-height}]])
|
||||
[markdown.text/text
|
||||
{:size :paragraph-2
|
||||
:weight :medium
|
||||
:style {:color text-and-icon-color
|
||||
:flex 1}}
|
||||
label]
|
||||
(when (= chevron-position :right)
|
||||
[rn/view {:test-ID :divider-label-icon-right}
|
||||
[icons/icon
|
||||
:main-icons/chevron-down
|
||||
{:color text-and-icon-color
|
||||
:size chevron-icon-container-width}]])
|
||||
(when (pos? counter-value)
|
||||
[rn/view
|
||||
{:style {:border-radius 6
|
||||
:height 16
|
||||
:width (case (count counter-value)
|
||||
1 16
|
||||
2 20
|
||||
28)
|
||||
:background-color border-and-counter-bg-color
|
||||
:align-items :center
|
||||
:justify-content :center}}
|
||||
[markdown.text/text
|
||||
{:size :label
|
||||
:weight :medium
|
||||
:style {:color counter-text-color}}
|
||||
counter-value]])]))
|
||||
[rn/touchable-without-feedback
|
||||
{:on-press on-press}
|
||||
[rn/view
|
||||
{:accessible true
|
||||
:accessibility-label :divider-label
|
||||
:style (merge {:border-top-width 1
|
||||
:border-top-color border-and-counter-bg-color
|
||||
:padding-top padding-top
|
||||
:padding-bottom padding-bottom
|
||||
:padding-horizontal 16
|
||||
:align-items :center
|
||||
:flex-direction :row}
|
||||
container-style)}
|
||||
(when (= chevron-position :left)
|
||||
[rn/view
|
||||
{:test-ID :divider-label-icon-left
|
||||
:style {:margin-right 4}}
|
||||
[icons/icon
|
||||
(or chevron-icon :i/chevron-down)
|
||||
{:color text-and-icon-color
|
||||
:width chevron-icon-container-width
|
||||
:height chevron-icon-container-height}]])
|
||||
[markdown.text/text
|
||||
{:size :paragraph-2
|
||||
:weight :medium
|
||||
:style {:color text-and-icon-color
|
||||
:flex 1}}
|
||||
label]
|
||||
(when (= chevron-position :right)
|
||||
[rn/view {:test-ID :divider-label-icon-right}
|
||||
[icons/icon
|
||||
(or chevron-icon :i/chevron-down)
|
||||
{:color text-and-icon-color
|
||||
:size chevron-icon-container-width}]])
|
||||
(when (pos? counter-value)
|
||||
[rn/view
|
||||
{:style {:border-radius 6
|
||||
:height 16
|
||||
:width (case (count counter-value)
|
||||
1 16
|
||||
2 20
|
||||
28)
|
||||
:background-color border-and-counter-bg-color
|
||||
:align-items :center
|
||||
:justify-content :center}}
|
||||
[markdown.text/text
|
||||
{:size :label
|
||||
:weight :medium
|
||||
:style {:color counter-text-color}}
|
||||
counter-value]])]]))
|
||||
|
|
|
@ -678,12 +678,6 @@
|
|||
community-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
|
||||
{:events [::create-category-confirmation-pressed]}
|
||||
[_ community-id category-title chat-ids]
|
||||
|
@ -860,3 +854,47 @@
|
|||
:community-id community-id
|
||||
:public-key public-key
|
||||
: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?})}]})
|
||||
|
|
|
@ -46,16 +46,6 @@
|
|||
[taoensso.timbre :as log]
|
||||
[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
|
||||
::initialize-transactions-management-enabled
|
||||
(fn []
|
||||
|
@ -358,10 +348,6 @@
|
|||
[{:method "wakuext_getGroupChatInvitations"
|
||||
:on-success #(re-frame/dispatch [::initialize-invitations %])}]})
|
||||
|
||||
(rf/defn initialize-communities-enabled
|
||||
[cofx]
|
||||
{::initialize-communities-enabled nil})
|
||||
|
||||
(rf/defn initialize-transactions-management-enabled
|
||||
[cofx]
|
||||
{::initialize-transactions-management-enabled nil})
|
||||
|
@ -408,10 +394,10 @@
|
|||
(rf/dispatch [:communities/get-user-requests-to-join])
|
||||
(re-frame/dispatch [::get-chats-callback]))})
|
||||
(initialize-appearance)
|
||||
(initialize-communities-enabled)
|
||||
(initialize-wallet-connect)
|
||||
(get-node-config)
|
||||
(communities/fetch)
|
||||
(communities/fetch-collapsed-community-categories)
|
||||
(logging/set-log-level (:log-level multiaccount))
|
||||
(activity-center/notifications-fetch-pending-contact-requests)
|
||||
(activity-center/update-seen-state)
|
||||
|
@ -539,7 +525,6 @@
|
|||
(communities/fetch)
|
||||
(data-store.chats/fetch-chats-rpc
|
||||
{:on-success #(re-frame/dispatch [:chats-list/load-success %])})
|
||||
(initialize-communities-enabled)
|
||||
(multiaccounts/switch-preview-privacy-mode-flag)
|
||||
(link-preview/request-link-preview-whitelist)
|
||||
(logging/set-log-level (:log-level multiaccount))
|
||||
|
|
|
@ -2,15 +2,13 @@
|
|||
(:require [quo.core :as quo]
|
||||
[re-frame.core :as re-frame]
|
||||
[utils.i18n :as i18n]
|
||||
[status-im.ui.components.list.views :as list]
|
||||
[status-im2.config :as config])
|
||||
[status-im.ui.components.list.views :as list])
|
||||
(:require-macros [status-im.utils.views :as views]))
|
||||
|
||||
(defn- normal-mode-settings-data
|
||||
[{:keys [network-name
|
||||
current-log-level
|
||||
waku-bloom-filter-mode
|
||||
communities-enabled?
|
||||
transactions-management-enabled?
|
||||
wakuv2-flag
|
||||
current-fleet
|
||||
|
@ -76,17 +74,6 @@
|
|||
:on-press
|
||||
#(re-frame/dispatch [:navigate-to :peers-stats])
|
||||
: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
|
||||
:title (i18n/label :t/transactions-management-enabled)
|
||||
:accessibility-label :transactions-management-enabled
|
||||
|
@ -132,7 +119,6 @@
|
|||
network-name [:network-name]
|
||||
waku-bloom-filter-mode [:waku/bloom-filter-mode]
|
||||
wakuv2-flag [:waku/v2-flag]
|
||||
communities-enabled? [:communities/enabled?]
|
||||
transactions-management-enabled? [:wallet/transactions-management-enabled?]
|
||||
current-log-level [:log-level/current-log-level]
|
||||
current-fleet [:fleets/current-fleet]]
|
||||
|
@ -140,7 +126,6 @@
|
|||
{:data (flat-list-data
|
||||
{:network-name network-name
|
||||
:current-log-level current-log-level
|
||||
:communities-enabled? communities-enabled?
|
||||
:transactions-management-enabled? transactions-management-enabled?
|
||||
:current-fleet current-fleet
|
||||
:dev-mode? false
|
||||
|
|
|
@ -142,28 +142,25 @@
|
|||
|
||||
(defn communities
|
||||
[]
|
||||
(let [communities (rf/sub [:communities/section-list])
|
||||
communities-enabled? (rf/sub [:communities/enabled?])]
|
||||
(let [communities (rf/sub [:communities/section-list])]
|
||||
[:<>
|
||||
[topbar/topbar
|
||||
(cond-> {:title (i18n/label :t/communities)}
|
||||
communities-enabled?
|
||||
(assoc :right-accessories
|
||||
[{:icon :main-icons/more
|
||||
:accessibility-label :chat-menu-button
|
||||
:on-press
|
||||
#(rf/dispatch [:bottom-sheet/show-sheet
|
||||
{:content (fn []
|
||||
[communities-actions])
|
||||
:height 256}])}]))]
|
||||
{:title (i18n/label :t/communities)
|
||||
:right-accessories
|
||||
[{:icon :main-icons/more
|
||||
:accessibility-label :chat-menu-button
|
||||
:on-press
|
||||
#(rf/dispatch [:bottom-sheet/show-sheet
|
||||
{:content (fn []
|
||||
[communities-actions])
|
||||
:height 256}])}]}]
|
||||
[communities-list communities]
|
||||
(when communities-enabled?
|
||||
[toolbar/toolbar
|
||||
{:show-border? true
|
||||
:center [quo/button
|
||||
{:on-press #(rf/dispatch [::communities/open-create-community])
|
||||
:type :secondary}
|
||||
(i18n/label :t/create-community)]}])]))
|
||||
[toolbar/toolbar
|
||||
{:show-border? true
|
||||
:center [quo/button
|
||||
{:on-press #(rf/dispatch [::communities/open-create-community])
|
||||
:type :secondary}
|
||||
(i18n/label :t/create-community)]}]]))
|
||||
|
||||
(defn export-community
|
||||
[]
|
||||
|
|
|
@ -51,13 +51,12 @@
|
|||
:accessibility-label :join-public-chat-button
|
||||
:icon :main-icons/public-chat
|
||||
:on-press #(hide-sheet-and-dispatch [:open-modal :new-public-chat])}]
|
||||
(when (rf/sub [:communities/enabled?])
|
||||
[quo/list-item
|
||||
{:theme :accent
|
||||
:title (i18n/label :t/communities-alpha)
|
||||
:accessibility-label :communities-button
|
||||
:icon :main-icons/communities
|
||||
:on-press #(hide-sheet-and-dispatch [:navigate-to :communities])}])
|
||||
[quo/list-item
|
||||
{:theme :accent
|
||||
:title (i18n/label :t/communities-alpha)
|
||||
:accessibility-label :communities-button
|
||||
:icon :main-icons/communities
|
||||
:on-press #(hide-sheet-and-dispatch [:navigate-to :communities])}]
|
||||
[invite/list-item
|
||||
{:accessibility-label :chats-menu-invite-friends-button}]])
|
||||
|
||||
|
|
|
@ -354,9 +354,8 @@
|
|||
|
||||
(defview community-content
|
||||
[{:keys [community-id] :as message}]
|
||||
(letsubs [{:keys [name description verified] :as community} [:communities/community community-id]
|
||||
communities-enabled? [:communities/enabled?]]
|
||||
(when (and communities-enabled? community)
|
||||
(letsubs [{:keys [name description verified] :as community} [:communities/community community-id]]
|
||||
(when community
|
||||
[rn/view
|
||||
{:style (assoc (style/message-wrapper message)
|
||||
:margin-vertical 10
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
(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 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 debug-webview? (enabled? (get-config :DEBUG_WEBVIEW "0")))
|
||||
(def collectibles-enabled? (enabled? (get-config :COLLECTIBLES_ENABLED "1")))
|
||||
|
|
|
@ -290,3 +290,5 @@
|
|||
(def ^:const local-pair-action-sync-device 3)
|
||||
|
||||
(def ^:const everyone-mention-id "0x00001")
|
||||
|
||||
(def ^:const empty-category-id :communities/not-categorized)
|
||||
|
|
|
@ -60,35 +60,45 @@
|
|||
(defn add-category-height
|
||||
[categories-heights category height]
|
||||
(swap! categories-heights
|
||||
(fn []
|
||||
(sort-by :height
|
||||
(conj @categories-heights
|
||||
{:height height
|
||||
:label category})))))
|
||||
(fn [heights]
|
||||
(assoc heights category height))))
|
||||
|
||||
(defn collapse-category
|
||||
[community-id category-id collapsed?]
|
||||
(rf/dispatch [:communities/toggle-collapsed-category community-id category-id (not collapsed?)]))
|
||||
|
||||
(defn channel-list-component
|
||||
[{:keys [on-categories-heights-changed
|
||||
[{:keys [on-category-layout
|
||||
community-id
|
||||
on-first-channel-height-changed]}
|
||||
channels-list]
|
||||
(let [categories-heights (reagent/atom [])]
|
||||
[rn/view
|
||||
{:on-layout #(on-first-channel-height-changed (+ (if platform/ios?
|
||||
0
|
||||
38)
|
||||
(int (Math/ceil (layout-y %)))))
|
||||
:style {:margin-top 20 :flex 1}}
|
||||
(map-indexed
|
||||
(fn [index [category channels-for-category]]
|
||||
[rn/view
|
||||
{:flex 1
|
||||
:key (str index category)
|
||||
:on-layout #(do
|
||||
(add-category-height categories-heights category (int (layout-y %)))
|
||||
(on-categories-heights-changed @categories-heights))}
|
||||
[rn/view
|
||||
{:on-layout #(on-first-channel-height-changed (+ (if platform/ios?
|
||||
0
|
||||
38)
|
||||
(int (Math/ceil (layout-y %))))
|
||||
(into #{} (map (comp :name second) channels-list)))
|
||||
:style {:margin-top 20 :flex 1}}
|
||||
(map
|
||||
(fn [[category-id {:keys [chats name collapsed?]}]]
|
||||
[rn/view
|
||||
{:flex 1
|
||||
:key category-id
|
||||
;; on-layout fires only when the component re-renders, so
|
||||
;; in case the category hasn't changed, it will not be fired
|
||||
:on-layout #(on-category-layout name (int (layout-y %)))}
|
||||
|
||||
(when-not (= constants/empty-category-id category-id)
|
||||
[quo/divider-label
|
||||
{:label category
|
||||
:chevron-position :left}]
|
||||
{:label name
|
||||
: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
|
||||
{:margin-left 8
|
||||
:margin-top 10
|
||||
|
@ -98,8 +108,8 @@
|
|||
{:key (:id channel)
|
||||
:margin-top 4}
|
||||
[quo/channel-list-item channel]])
|
||||
channels-for-category)]])
|
||||
channels-list)]))
|
||||
chats)])])
|
||||
channels-list)])
|
||||
|
||||
(defn request-to-join-text
|
||||
[is-open?]
|
||||
|
@ -192,10 +202,10 @@
|
|||
|
||||
(defn add-on-press-handler-to-categorized-chats
|
||||
[community-id categorized-chats]
|
||||
(reduce-kv (fn [acc category chats]
|
||||
(assoc acc category (add-on-press-handler-to-chats community-id chats)))
|
||||
{}
|
||||
categorized-chats))
|
||||
(let [add-on-press (partial add-on-press-handler-to-chats community-id)]
|
||||
(map (fn [[category v]]
|
||||
[category (update v :chats add-on-press)])
|
||||
categorized-chats)))
|
||||
|
||||
(defn community-header
|
||||
[name]
|
||||
|
@ -221,8 +231,9 @@
|
|||
(defn community-content
|
||||
[{:keys [name description locked joined images
|
||||
status tokens tags id]
|
||||
:as community} pending?
|
||||
{:keys [on-categories-heights-changed
|
||||
:as community}
|
||||
pending?
|
||||
{:keys [on-category-layout
|
||||
on-first-channel-height-changed]}]
|
||||
(let [thumbnail-image (:thumbnail images)
|
||||
chats-by-category (rf/sub [:communities/categorized-channels id])
|
||||
|
@ -264,13 +275,14 @@
|
|||
[preview-user-list users]
|
||||
[join-community community pending?]]
|
||||
[channel-list-component
|
||||
{:on-categories-heights-changed #(on-categories-heights-changed %)
|
||||
:on-first-channel-height-changed #(on-first-channel-height-changed %)}
|
||||
{:on-category-layout on-category-layout
|
||||
:community-id id
|
||||
:on-first-channel-height-changed on-first-channel-height-changed}
|
||||
(add-on-press-handler-to-categorized-chats id chats-by-category)]]))
|
||||
|
||||
(defn sticky-category-header
|
||||
[_]
|
||||
(fn [{:keys [:enabled :label]}]
|
||||
(fn [{:keys [enabled label]}]
|
||||
(when enabled
|
||||
[blur/view
|
||||
{:style style/blur-channel-header
|
||||
|
@ -278,7 +290,7 @@
|
|||
:blur-type :transparent
|
||||
:overlay-color :transparent}
|
||||
[quo/divider-label
|
||||
{:label (:label label)
|
||||
{:label label
|
||||
:chevron-position :left}]])))
|
||||
|
||||
(defn page-nav-right-section-buttons
|
||||
|
@ -292,9 +304,18 @@
|
|||
[options/community-options-bottom-sheet
|
||||
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
|
||||
[{:keys [name images id]}]
|
||||
(let [categories-heights (reagent/atom [])
|
||||
(let [categories-heights (reagent/atom {})
|
||||
first-channel-height (reagent/atom 0)
|
||||
scroll-height (reagent/atom 0)
|
||||
cover {:uri (get-in images [:banner :uri])}
|
||||
|
@ -316,14 +337,21 @@
|
|||
|
||||
[sticky-category-header
|
||||
{:enabled (> @scroll-height @first-channel-height)
|
||||
:label (last (filter (fn [{:keys [height]}]
|
||||
(>= @scroll-height (+ height @first-channel-height)))
|
||||
@categories-heights))}]
|
||||
:label (pick-first-category-by-height
|
||||
@scroll-height
|
||||
@first-channel-height
|
||||
@categories-heights)}]
|
||||
|
||||
[community-content
|
||||
community
|
||||
pending?
|
||||
{:on-categories-heights-changed #(reset! categories-heights %)
|
||||
:on-first-channel-height-changed #(reset! first-channel-height %)}]])))
|
||||
{:on-category-layout (partial add-category-height categories-heights)
|
||||
: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
|
||||
[]
|
||||
|
|
|
@ -6,15 +6,6 @@
|
|||
[status-im2.constants :as constants]
|
||||
[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
|
||||
:communities/fetching-community
|
||||
:<- [:communities/resolve-community-info]
|
||||
|
@ -81,16 +72,13 @@
|
|||
|
||||
(re-frame/reg-sub
|
||||
:communities/featured-communities
|
||||
:<- [:communities/enabled?]
|
||||
:<- [:search/home-filter]
|
||||
:<- [:communities]
|
||||
(fn [[communities-enabled? search-filter communities]]
|
||||
(fn [[search-filter communities]]
|
||||
(filterv
|
||||
(fn [{:keys [name id]}]
|
||||
(and (or communities-enabled?
|
||||
(= id constants/status-community-id))
|
||||
(or (empty? search-filter)
|
||||
(string/includes? (string/lower-case (str name)) search-filter))))
|
||||
(fn [{:keys [name]}]
|
||||
(or (empty? search-filter)
|
||||
(string/includes? (string/lower-case (str name)) search-filter)))
|
||||
(vals communities))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
|
@ -101,17 +89,13 @@
|
|||
|
||||
(re-frame/reg-sub
|
||||
:communities/communities
|
||||
:<- [:communities/enabled?]
|
||||
:<- [:search/home-filter]
|
||||
:<- [:communities]
|
||||
(fn [[communities-enabled? search-filter communities]]
|
||||
(fn [[search-filter communities]]
|
||||
(filterv
|
||||
(fn [{:keys [name id]}]
|
||||
(and
|
||||
(or communities-enabled?
|
||||
(= id constants/status-community-id))
|
||||
(or (empty? search-filter)
|
||||
(string/includes? (string/lower-case (str name)) search-filter))))
|
||||
(fn [{:keys [name]}]
|
||||
(or (empty? search-filter)
|
||||
(string/includes? (string/lower-case (str name)) search-filter)))
|
||||
(vals communities))))
|
||||
|
||||
(re-frame/reg-sub
|
||||
|
@ -151,7 +135,7 @@
|
|||
(re-frame/reg-sub
|
||||
:communities/home-item
|
||||
(fn [[_ community-id]]
|
||||
[(re-frame/subscribe [:raw-communities])
|
||||
[(re-frame/subscribe [:communities])
|
||||
(re-frame/subscribe [:communities/unviewed-counts community-id])])
|
||||
(fn [[communities counts] [_ identity]]
|
||||
(community->home-item
|
||||
|
@ -230,31 +214,62 @@
|
|||
(sort-by :position)
|
||||
(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
|
||||
:communities/categorized-channels
|
||||
(fn [[_ community-id]]
|
||||
[(re-frame/subscribe [:communities/community community-id])
|
||||
(re-frame/subscribe [:chats/chats])])
|
||||
(fn [[{:keys [joined categories chats]} full-chats-data] [_ community-id]]
|
||||
(reduce
|
||||
(fn [acc [_ {:keys [name categoryID id emoji can-post?]}]]
|
||||
(let [category (keyword
|
||||
(get-in categories
|
||||
[categoryID :name]
|
||||
(i18n/label :t/none)))
|
||||
{:keys [unviewed-messages-count unviewed-mentions-count]} (get full-chats-data
|
||||
(str community-id id))]
|
||||
(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/subscribe [:chats/chats])
|
||||
(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
|
||||
{})
|
||||
(sort-by (comp :position second))
|
||||
(map (fn [[k v]]
|
||||
[k (update v :chats #(sort-by :position %))])))]
|
||||
|
||||
categories-and-chats)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:communities/users
|
||||
|
@ -264,3 +279,9 @@
|
|||
{:full-name "Marcus C"}
|
||||
{:full-name "MNO PQR"}
|
||||
{: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)))
|
||||
|
|
|
@ -3,25 +3,22 @@
|
|||
[re-frame.db :as rf-db]
|
||||
[test-helpers.unit :as h]
|
||||
status-im2.subs.communities
|
||||
[status-im2.constants :as constants]
|
||||
[utils.re-frame :as rf]
|
||||
[utils.i18n :as i18n]))
|
||||
|
||||
(use-fixtures :each
|
||||
{:before #(reset! rf-db/app-db {:communities/enabled? true})})
|
||||
{:before #(reset! rf-db/app-db {})})
|
||||
|
||||
(def community-id "0x1")
|
||||
|
||||
(h/deftest-sub :communities
|
||||
[sub-name]
|
||||
(testing "returns empty vector if flag is disabled"
|
||||
(swap! rf-db/app-db assoc :communities/enabled? false)
|
||||
(is (= [] (rf/sub [sub-name]))))
|
||||
|
||||
(testing "returns raw communities if flag is enabled"
|
||||
(testing "returns raw communities"
|
||||
(let [raw-communities {"0x1" {:id "0x1"}}]
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities/enabled? true
|
||||
:communities raw-communities)
|
||||
:communities
|
||||
raw-communities)
|
||||
(is (= raw-communities (rf/sub [sub-name]))))))
|
||||
|
||||
(h/deftest-sub :communities/section-list
|
||||
|
@ -85,13 +82,12 @@
|
|||
[sub-name]
|
||||
(testing "Empty communities list"
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities/enabled? true
|
||||
:communities {})
|
||||
:communities
|
||||
{})
|
||||
(is (= []
|
||||
(rf/sub [sub-name]))))
|
||||
(testing "communities sorted by name"
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities/enabled? true
|
||||
:communities
|
||||
{"0x1" {:id "0x1" :name "Civilized monkeys"}
|
||||
"0x2" {:id "0x2" :name "Civilized rats"}
|
||||
|
@ -105,56 +101,127 @@
|
|||
[sub-name]
|
||||
(testing "Channels with categories"
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities/enabled? true
|
||||
:communities
|
||||
{"0x1" {:id "0x1"
|
||||
:chats {"0x1" {:id "0x1" :name "chat1" :categoryID 1 :can-post? true}
|
||||
"0x2" {:id "0x2" :name "chat2" :categoryID 1 :can-post? false}
|
||||
"0x3" {:id "0x3" :name "chat3" :categoryID 2 :can-post? true}}
|
||||
:categories {1 {:id 1 :name "category1"}
|
||||
2 {:id 2 :name "category2"}}
|
||||
:chats {"0x1" {:id "0x1" :position 1 :name "chat1" :categoryID "1" :can-post? true}
|
||||
"0x2" {:id "0x2" :position 2 :name "chat2" :categoryID "1" :can-post? false}
|
||||
"0x3" {:id "0x3" :position 3 :name "chat3" :categoryID "2" :can-post? true}}
|
||||
:categories {"1" {:id "1"
|
||||
:position 2
|
||||
:name "category1"}
|
||||
"2" {:id "2"
|
||||
:position 1
|
||||
:name "category2"}}
|
||||
:joined true}})
|
||||
(is
|
||||
(= {:category1
|
||||
[{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false :mentions-count 0}
|
||||
{:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false :mentions-count 0}]
|
||||
:category2
|
||||
[{:name "chat3" :emoji nil :locked? false :id "0x3" :unread-messages? false :mentions-count 0}]}
|
||||
(= [["2"
|
||||
{:id "2"
|
||||
:name "category2"
|
||||
:collapsed? nil
|
||||
: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"]))))
|
||||
(testing "Channels without categories"
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities/enabled? true
|
||||
:communities
|
||||
{"0x1" {:id "0x1"
|
||||
:chats {"0x1" {:id "0x1" :name "chat1" :categoryID 1 :can-post? true}
|
||||
"0x2" {:id "0x2" :name "chat2" :categoryID 1 :can-post? false}
|
||||
"0x3" {:id "0x3" :name "chat3" :can-post? true}}
|
||||
:categories {1 {:id 1 :name "category1"}
|
||||
2 {:id 2 :name "category2"}}
|
||||
:chats {"0x1" {:id "0x1" :position 1 :name "chat1" :categoryID "1" :can-post? true}
|
||||
"0x2" {:id "0x2" :position 2 :name "chat2" :categoryID "1" :can-post? false}
|
||||
"0x3" {:id "0x3" :position 3 :name "chat3" :can-post? true}}
|
||||
:categories {"1" {:id "1"
|
||||
:position 1
|
||||
:name "category1"}
|
||||
"2" {:id "2"
|
||||
:position 2
|
||||
:name "category2"}}
|
||||
:joined true}})
|
||||
(is
|
||||
(= {:category1
|
||||
[{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? false :mentions-count 0}
|
||||
{:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false :mentions-count 0}]
|
||||
(keyword (i18n/label :t/none))
|
||||
[{:name "chat3" :emoji nil :locked? false :id "0x3" :unread-messages? false :mentions-count 0}]}
|
||||
(rf/sub [sub-name "0x1"]))))
|
||||
(=
|
||||
[[constants/empty-category-id
|
||||
{:name (i18n/label :t/none)
|
||||
:collapsed? nil
|
||||
: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"]))))
|
||||
(testing "Unread messages"
|
||||
(swap! rf-db/app-db assoc
|
||||
:communities/enabled? true
|
||||
:communities
|
||||
{"0x1" {:id "0x1"
|
||||
:chats {"0x1" {:id "0x1" :name "chat1" :categoryID 1 :can-post? true}
|
||||
"0x2" {:id "0x2" :name "chat2" :categoryID 1 :can-post? false}}
|
||||
:categories {1 {:id 1 :name "category1"}}
|
||||
:chats {"0x1" {:id "0x1" :position 1 :name "chat1" :categoryID "1" :can-post? true}
|
||||
"0x2" {:id "0x2" :position 2 :name "chat2" :categoryID "1" :can-post? false}}
|
||||
:categories {"1" {:id "1" :name "category1"}}
|
||||
:joined true}}
|
||||
:chats
|
||||
{"0x10x1" {:unviewed-messages-count 1 :unviewed-mentions-count 2}
|
||||
"0x10x2" {:unviewed-messages-count 0 :unviewed-mentions-count 0}})
|
||||
(is
|
||||
(= {:category1
|
||||
[{:name "chat1" :emoji nil :locked? false :id "0x1" :unread-messages? true :mentions-count 2}
|
||||
{:name "chat2" :emoji nil :locked? true :id "0x2" :unread-messages? false :mentions-count 0}]}
|
||||
(= [["1"
|
||||
{:name "category1"
|
||||
: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"])))))
|
||||
|
||||
(h/deftest-sub :communities/my-pending-requests-to-join
|
||||
|
|
|
@ -238,14 +238,14 @@
|
|||
|
||||
;; 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-channel :communities/create-channel)
|
||||
(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/enabled? :communities/enabled?)
|
||||
(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/collapsed-categories :communities/collapsed-categories)
|
||||
|
||||
(reg-root-key-sub :activity-center :activity-center)
|
||||
|
||||
|
@ -254,6 +254,7 @@
|
|||
|
||||
(reg-root-key-sub :backup/performing-backup :backup/performing-backup)
|
||||
|
||||
|
||||
;; wallet connect
|
||||
(reg-root-key-sub :wallet-connect/proposal-metadata :wallet-connect/proposal-metadata)
|
||||
(reg-root-key-sub :wallet-connect/enabled? :wallet-connect/enabled?)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
|
||||
"owner": "status-im",
|
||||
"repo": "status-go",
|
||||
"version": "v0.138.3",
|
||||
"commit-sha1": "290579f74f10a374ffb8c37abc47dbe2c1e90f5d",
|
||||
"src-sha256": "0vgs3m1fbyri9r1wqxfanzxlx24yzx9zaabflk26qc9d4pclmi7i"
|
||||
"version": "v0.138.4",
|
||||
"commit-sha1": "44a0f5b74d31fe31bd77b565ae679f839ea40e94",
|
||||
"src-sha256": "05j9y1fg23xgqj4348cjpn7xm6jmhzj9xz2zwhvhagnq1c28800c"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue