Community channel editing

Signed-off-by: Volodymyr Kozieiev <vkjr.sp@gmail.com>
This commit is contained in:
Volodymyr Kozieiev 2021-06-04 13:55:51 +03:00
parent aaf07911c4
commit 1900e3038b
No known key found for this signature in database
GPG Key ID: 82B04968DF4C0535
11 changed files with 224 additions and 73 deletions

View File

@ -248,13 +248,14 @@
(fx/defn create-channel
{:events [::create-channel-confirmation-pressed]}
[cofx community-channel-name community-channel-description]
(let [community-id (fetch-community-id-input cofx)]
[{:keys [db] :as cofx}]
(let [community-id (fetch-community-id-input cofx)
{:keys [name description]} (get db :communities/create-channel)]
{::json-rpc/call [{:method "wakuext_createCommunityChat"
:params [community-id
{:identity {:display_name community-channel-name
{:identity {:display_name name
:color (rand-nth colors/chat-colors)
:description community-channel-description}
:description description}
:permissions {:access constants/community-channel-access-no-membership}}]
:js-response true
:on-success #(re-frame/dispatch [::community-channel-created %])
@ -262,18 +263,42 @@
(log/error "failed to create community channel" %)
(re-frame/dispatch [::failed-to-create-community-channel %]))}]}))
(def community-chat-id-length 68)
(defn to-community-chat-id [chat-id]
(subs chat-id community-chat-id-length))
(fx/defn edit-channel
{:events [::edit-channel-confirmation-pressed]}
[{:keys [db] :as cofx}]
(let [{:keys [name description color community-id]} (get db :communities/create-channel)
chat-id (to-community-chat-id (get db :current-chat-id))]
{::json-rpc/call [{:method "wakuext_editCommunityChat"
:params [community-id
chat-id
{:identity {:display_name name
:description description
:color color}
:permissions {:access constants/community-channel-access-no-membership}}]
:js-response true
:on-success #(re-frame/dispatch [::community-channel-edited %])
:on-error #(do
(log/error "failed to edit community channel" %)
(re-frame/dispatch [::failed-to-edit-community-channel %]))}]}))
(defn require-membership? [permissions]
(not= constants/community-no-membership-access (:access permissions)))
(def community-id-length 68)
(defn can-post? [community _ local-chat-id]
(let [chat-id (subs local-chat-id community-id-length)]
(let [chat-id (to-community-chat-id local-chat-id)]
(get-in community [:chats chat-id :can-post?])))
(fx/defn reset-community-id-input [{:keys [db]} id]
{:db (assoc db :communities/community-id-input id)})
(fx/defn reset-channel-info [{:keys [db]}]
{:db (assoc db :communities/create-channel {})})
(fx/defn invite-people-pressed
{:events [::invite-people-pressed]}
[cofx id]
@ -292,10 +317,21 @@
(fx/defn create-channel-pressed
{:events [::create-channel-pressed]}
[cofx id]
[{:keys [db] :as cofx} id]
(fx/merge cofx
(reset-community-id-input id)
(navigation/navigate-to :create-community-channel nil)))
(reset-channel-info)
(navigation/navigate-to :communities {:screen :create-community-channel})))
(fx/defn edit-channel-pressed
{:events [::edit-channel-pressed]}
[{:keys [db] :as cofx} community-id chat-name description color]
(fx/merge cofx
{:db (assoc db :communities/create-channel {:name chat-name
:description description
:color color
:community-id community-id})}
(navigation/navigate-to :communities {:screen :edit-community-channel})))
(fx/defn community-created
{:events [::community-created]}
@ -354,6 +390,13 @@
(navigation/navigate-back)
(handle-response response-js)))
(fx/defn community-channel-edited
{:events [::community-channel-edited]}
[cofx response-js]
(fx/merge cofx
(navigation/navigate-back)
(handle-response response-js)))
(fx/defn create-field
{:events [::create-field]}
[{:keys [db]} field value]
@ -364,6 +407,11 @@
[{:keys [db]} field]
{:db (update-in db [:communities/create] dissoc field)})
(fx/defn create-channel-field
{:events [::create-channel-field]}
[{:keys [db]} field value]
{:db (assoc-in db [:communities/create-channel field] value)})
(fx/defn member-banned
{:events [::member-banned]}
[cofx response-js]

View File

@ -130,6 +130,7 @@
"wakuext_createCommunity" {}
"wakuext_editCommunity" {}
"wakuext_createCommunityChat" {}
"wakuext_editCommunityChat" {}
"wakuext_inviteUsersToCommunity" {}
"wakuext_shareCommunity" {}
"wakuext_removeUserFromCommunity" {}

View File

@ -213,6 +213,7 @@
(reg-root-key-sub :raw-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?)

View File

@ -83,10 +83,14 @@
(fn [{:keys [chat-id group-chat chat-name color]}]
[react/view
[quo/list-item
{:theme :accent
:title chat-name
:icon [chat-icon/chat-icon-view-chat-sheet
chat-id group-chat chat-name color]}]
{:theme :accent
:title chat-name
:icon [chat-icon/chat-icon-view-chat-sheet
chat-id group-chat chat-name color]
:subtitle (i18n/label :t/view-details)
:chevron true
:accessibility-label :view-community-channel-details
:on-press #(hide-sheet-and-dispatch [:navigate-to :community-channel-details {:chat-id chat-id}])}]
[quo/list-item
{:theme :accent
:title (i18n/label :t/mark-all-read)

View File

@ -0,0 +1,34 @@
(ns status-im.ui.screens.communities.channel-details
(:require [quo.core :as quo]
[status-im.utils.handlers :refer [>evt <sub]]
[status-im.ui.components.profile-header.view :as profile-header]
[status-im.i18n.i18n :as i18n]
[clojure.string :as string]
[status-im.communities.core :as communities]))
(defn view [route]
(let [chat-id (get-in route [:route :params :chat-id])
current-chat (<sub [:chat-by-id chat-id])
{:keys [chat-name color description community-id]} current-chat
{:keys [admin]} (<sub [:communities/community community-id])]
[:<>
[quo/animated-header {:left-accessories [{:icon :main-icons/arrow-left
:accessibility-label :back-button
:on-press #(>evt [:navigate-back])}]
:right-accessories (when admin [{:icon :edit
:accessibility-label :invite-button
:on-press #(>evt [::communities/edit-channel-pressed
community-id
chat-name
description
color])}])
:extended-header (profile-header/extended-header
{:title chat-name
:color color
:subtitle (i18n/label :t/public-channel)})
:use-insets true}
(when-not (string/blank? description)
[:<>
[quo/list-footer {:color :main}
description]
[quo/separator {:style {:margin-vertical 8}}]])]]))

View File

@ -115,7 +115,7 @@
:elevation 2}}
[icons/icon :main-icons/add {:color colors/white}]]]]]]))
(defn countable-label [{:keys [label value max-length]}]
(defn countable-label [{:keys [label text max-length]}]
[rn/view {:style {:padding-bottom 10
:justify-content :space-between
:align-items :flex-end
@ -123,10 +123,10 @@
:flex-wrap :nowrap}}
[quo/text label]
[quo/text {:size :small
:color (if (> (count value) max-length)
:color (if (> (count text) max-length)
:negative
:secondary)}
(str (count value) "/" max-length)]])
(str (count text) "/" max-length)]])
(defn form []
(let [{:keys [name description]} (<sub [:communities/create])]
@ -137,7 +137,7 @@
:padding-top 10
:padding-horizontal 16}}
[countable-label {:label (i18n/label :t/name-your-community)
:value name
:text name
:max-length max-name-length}]
[quo/text-input
{:placeholder (i18n/label :t/name-your-community-placeholder)
@ -148,7 +148,7 @@
:padding-top 10
:padding-horizontal 16}}
[countable-label {:label (i18n/label :t/give-a-short-description-community)
:value description
:text description
:max-length max-description-length}]
[quo/text-input
{:placeholder (i18n/label :t/give-a-short-description-community)

View File

@ -1,38 +1,59 @@
(ns status-im.ui.screens.communities.create-channel
(:require [clojure.string :as str]
[reagent.core :as reagent]
[quo.react-native :as rn]
[quo.core :as quo]
[status-im.i18n.i18n :as i18n]
[status-im.ui.components.toolbar :as toolbar]
[status-im.communities.core :as communities]
[status-im.ui.components.topbar :as topbar]
[status-im.utils.debounce :as debounce]))
[status-im.utils.debounce :as debounce]
[status-im.utils.handlers :refer [>evt <sub]]
[status-im.ui.screens.communities.create :as create]))
(defn valid? [community-name]
(not (str/blank? community-name)))
(defn valid? [channel-name channel-description]
(and (not (str/blank? channel-name))
(not (str/blank? channel-description))
(<= (count channel-name) create/max-name-length)
(<= (count channel-description) create/max-description-length)))
(defn create-channel []
(let [channel-name (reagent/atom "")]
(fn []
[:<>
[topbar/topbar {:title (i18n/label :t/create-channel-title)}]
[rn/scroll-view {:style {:flex 1}
:content-container-style {:padding-vertical 16}}
[rn/view {:style {:padding-bottom 16
:padding-top 10
:padding-horizontal 16}}
[quo/text-input
{:label (i18n/label :t/name-your-channel)
:placeholder (i18n/label :t/name-your-channel-placeholder)
:on-change-text #(reset! channel-name %)
:auto-focus true}]]]
[toolbar/toolbar
{:show-border? true
:center
[quo/button {:disabled (not (valid? @channel-name))
:type :secondary
:on-press #(debounce/dispatch-and-chill
[::communities/create-channel-confirmation-pressed @channel-name]
3000)}
(i18n/label :t/create)]}]])))
(defn form []
(let [{:keys [name description]} (<sub [:communities/create-channel])]
[rn/scroll-view {:style {:flex 1}
:content-container-style {:padding-vertical 16}}
[rn/view {:style {:padding-bottom 16
:padding-top 10
:padding-horizontal 16}}
[rn/view
[create/countable-label {:label (i18n/label :t/name)
:text name
:max-length create/max-name-length}]
[quo/text-input
{:placeholder (i18n/label :t/name-your-channel-placeholder)
:on-change-text #(>evt [::communities/create-channel-field :name %])
:default-value name
:auto-focus true}]]
[quo/separator {:style {:margin-vertical 10}}]
[rn/view
[create/countable-label {:label (i18n/label :t/description)
:text description
:max-length create/max-description-length}]
[quo/text-input
{:placeholder (i18n/label :t/give-a-short-description-community)
:multiline true
:default-value description
:on-change-text #(>evt [::communities/create-channel-field :description %])}]]]]))
(defn view []
(let [{:keys [name description]} (<sub [:communities/create-channel])]
[:<>
[topbar/topbar {:title (i18n/label :t/create-channel-title)}]
[form]
[toolbar/toolbar
{:show-border? true
:center
[quo/button {:disabled (not (valid? name description))
:type :secondary
:on-press #(debounce/dispatch-and-chill
[::communities/create-channel-confirmation-pressed]
3000)}
(i18n/label :t/create)]}]]))

View File

@ -0,0 +1,29 @@
(ns status-im.ui.screens.communities.edit-channel
(:require [clojure.string :as str]
[quo.core :as quo]
[status-im.i18n.i18n :as i18n]
[status-im.ui.components.toolbar :as toolbar]
[status-im.communities.core :as communities]
[status-im.ui.components.topbar :as topbar]
[status-im.utils.debounce :as debounce]
[status-im.utils.handlers :refer [<sub]]
[status-im.ui.screens.communities.create-channel :as create-channel]))
(defn valid? [community-name]
(not (str/blank? community-name)))
(defn view []
(let [{:keys [name]} (<sub [:communities/create-channel])]
(fn []
[:<>
[topbar/topbar {:title (i18n/label :t/edit-channel-title)}]
[create-channel/form]
[toolbar/toolbar
{:show-border? true
:center
[quo/button {:disabled (not (valid? name))
:type :secondary
:on-press #(debounce/dispatch-and-chill
[::communities/edit-channel-confirmation-pressed]
3000)}
(i18n/label :t/save)]}]])))

View File

@ -9,8 +9,10 @@
[status-im.ui.screens.communities.create :as communities.create]
[status-im.ui.screens.communities.import :as communities.import]
[status-im.ui.screens.communities.profile :as community.profile]
[status-im.ui.screens.communities.channel-details :as communities.channel-details]
[status-im.ui.screens.communities.edit :as community.edit]
[status-im.ui.screens.communities.create-channel :as create-channel]
[status-im.ui.screens.communities.edit-channel :as edit-channel]
[status-im.ui.screens.communities.membership :as membership]
[status-im.ui.screens.communities.members :as members]
[status-im.ui.screens.communities.requests-to-join :as requests-to-join]
@ -54,32 +56,40 @@
:component members/members-container}
{:name :community-requests-to-join
:component requests-to-join/requests-to-join-container}
{:name :create-community-channel
:component create-channel/create-channel}]])
{:name :community-channel-details
:insets {:top false}
:component communities.channel-details/view}]])
(defn communities []
[communities-stack {:header-mode :none}
(concat
[{:name :communities
:insets {:bottom true
:top false}
:component communities/communities}
{:name :community-import
:insets {:bottom true
:top false}
:component communities.import/view}]
[{:name :community-edit
:insets {:bottom true
:top false}
:component community.edit/edit}
{:name :community-create
:insets {:bottom true
:top false}
:component communities.create/view}
{:name :community-membership
:insets {:bottom true
:top false}
:component membership/membership}])])
[{:name :communities
:insets {:bottom true
:top false}
:component communities/communities}
{:name :community-import
:insets {:bottom true
:top false}
:component communities.import/view}
{:name :community-edit
:insets {:bottom true
:top false}
:component community.edit/edit}
{:name :community-create
:insets {:bottom true
:top false}
:component communities.create/view}
{:name :community-membership
:insets {:bottom true
:top false}
:component membership/membership}
{:name :create-community-channel
:insets {:bottom true
:top false}
:component create-channel/view}
{:name :edit-community-channel
:insets {:bottom true
:top false}
:component edit-channel/view}]])
(defn new-group-chat []
[group-stack {:header-mode :none

View File

@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.79.7",
"commit-sha1": "60de443e89bd6a5d4f5b71e7038528d27f26090b",
"src-sha256": "0gjgkqyvpbwg8drwi2mpcan5vxqrnrzl1j0ccmm2m8vq7j3b1332"
"version": "v0.79.10",
"commit-sha1": "d5782fffafc0acde103842f63bccc787181ed8f9",
"src-sha256": "1s4wvvf70szadwp4mqlrb658n6rvkjnfswhkq5vkfqcya3ppw4w2"
}

View File

@ -167,6 +167,7 @@
"name-your-channel": "Name your channel",
"name-your-channel-placeholder": "Channel name",
"give-a-short-description": "Give a short description",
"describe-channel": "Describe the channel",
"communities-alpha": "Communities (alpha)",
"communities-verified": "✓ Verified Status Community",
"communities-enabled": "Communities enabled",
@ -187,6 +188,7 @@
"new-community-title": "New community",
"membership-title": "Membership requirement",
"create-channel-title": "New channel",
"edit-channel-title": "Edit channel",
"community-thumbnail-image": "Thumbnail image",
"community-thumbnail-upload": "Upload",
"community-image-take": "Take a photo",
@ -1534,8 +1536,9 @@
"one-week": "One week",
"one-month": "One month",
"my-profile": "My profile",
"default-sync-period": "Sync history for",
"bip39-password-placeholder": "BIP39 password",
"public-channel": "Public channel",
"default-sync-period": "Sync history for",
"anonymous-usage-data": "Anonymous usage data",
"anonymous-usage-data-subtitle": "Share anonymous, end-to-end ecrypted data about how you use Status.",
"share-anonymous-usage-data": "Share anonymous usage data",