Community request to join changes (#15627)

Resolves  #15322 #15082 #15694
This commit is contained in:
Mohamed Javid 2023-04-21 17:36:58 +08:00 committed by GitHub
parent b87b3083a3
commit bfb074eca3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 132 additions and 22 deletions

View File

@ -87,23 +87,27 @@
(:communities/community-id-input db))
(defn- handle-my-request
[db {:keys [community-id state] :as request}]
{:db (if (= constants/community-request-to-join-state-pending state)
(assoc-in db [:communities/my-pending-requests-to-join community-id] request)
(update-in db [:communities/my-pending-requests-to-join] dissoc community-id))})
[db {:keys [community-id state deleted] :as request}]
(if (and (= constants/community-request-to-join-state-pending state) (not deleted))
(assoc-in db [:communities/my-pending-requests-to-join community-id] request)
(update-in db [:communities/my-pending-requests-to-join] dissoc community-id)))
(defn handle-admin-request
[db {:keys [id community-id] :as request}]
{:db (assoc-in db [:communities/requests-to-join community-id id] request)})
[db {:keys [id community-id deleted] :as request}]
(if deleted
(update-in db [:communities/requests-to-join community-id] dissoc id)
(assoc-in db [:communities/requests-to-join community-id id] request)))
(rf/defn handle-request-to-join
[{:keys [db]} r]
(let [my-public-key (get-in db [:multiaccount :public-key])
{:keys [id community-id public-key] :as request} (<-request-to-join-community-rpc r)
my-request? (= my-public-key public-key)]
(if my-request?
(handle-my-request db request)
(handle-admin-request db request))))
(rf/defn handle-requests-to-join
[{:keys [db]} requests]
(let [my-public-key (get-in db [:multiaccount :public-key])]
{:db (reduce (fn [db {:keys [public-key] :as request}]
(let [my-request? (= my-public-key public-key)]
(if my-request?
(handle-my-request db request)
(handle-admin-request db request))))
db
requests)}))
(rf/defn handle-removed-chats
[{:keys [db]} chat-ids]
@ -317,6 +321,7 @@
:on-error #(do
(log/error "failed to invite-user community" %)
(re-frame/dispatch [::failed-to-invite-people %]))}]})))
(rf/defn share-community
{:events [::share-community-confirmation-pressed]}
[cofx user-pk contacts]
@ -898,3 +903,16 @@
:event :communities/toggle-collapsed-category
:category-id category-id
:collapse? collapse?})}]})
(rf/defn check-and-delete-pending-request-to-join
{:events [:communities/check-and-delete-pending-request-to-join]}
[_]
{:json-rpc/call [{:method "wakuext_checkAndDeletePendingRequestToJoinCommunity"
:params []
:js-response true
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/info
"failed to fetch communities"
{:error %
:event
:communities/check-and-delete-pending-request-to-join-community})}]})

View File

@ -410,6 +410,7 @@
(get-node-config)
(communities/fetch)
(communities/fetch-collapsed-community-categories)
(communities/check-and-delete-pending-request-to-join)
(logging/set-log-level (:log-level multiaccount))
(activity-center/notifications-fetch-pending-contact-requests)
(activity-center/update-seen-state)

View File

@ -124,10 +124,13 @@
(models.communities/handle-removed-chats removed-chats-clj)))
(seq requests-to-join-community)
(let [request-js (types/js->clj (.pop requests-to-join-community))]
(let [requests (->> requests-to-join-community
types/js->clj
(map models.communities/<-request-to-join-community-rpc))]
(js-delete response-js "requestsToJoinCommunity")
(rf/merge cofx
(process-next response-js sync-handler)
(models.communities/handle-request-to-join request-js)))
(models.communities/handle-requests-to-join requests)))
(seq emoji-reactions)
(let [reactions (types/js->clj emoji-reactions)]

View File

@ -8,6 +8,13 @@
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(def tag-params
{:size :small
:override-theme :dark
:color colors/primary-50
:style style/user-avatar-tag
:text-style style/user-avatar-tag-text})
(defn user-avatar-tag
[user-id]
(let [contact (rf/sub [:contacts/contact-by-identity user-id])]

View File

@ -0,0 +1,64 @@
(ns status-im2.contexts.activity-center.notification.community-request.view
(:require [quo2.core :as quo]
[status-im2.constants :as constants]
[status-im2.contexts.activity-center.notification.common.style :as common-style]
[status-im2.contexts.activity-center.notification.common.view :as common]
[utils.datetime :as datetime]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn- swipeable
[{:keys [active-swipeable extra-fn]} child]
[common/swipeable
{:left-button common/swipe-button-read-or-unread
:left-on-press common/swipe-on-press-toggle-read
:right-button common/swipe-button-delete
:right-on-press common/swipe-on-press-delete
:active-swipeable active-swipeable
:extra-fn extra-fn}
child])
(defn- get-header-text-and-context
[community membership-status]
(let [community-name (:name community)
community-image (get-in community [:images :thumbnail :uri])
community-context-tag [quo/context-tag common/tag-params {:uri community-image}
community-name]]
(cond
(= membership-status constants/activity-center-membership-status-idle)
{:header-text (i18n/label :t/community-request-not-accepted)
:context [[quo/text {:style common-style/user-avatar-tag-text}
(i18n/label :t/community-request-not-accepted-body-text-prefix)]
community-context-tag
[quo/text {:style common-style/user-avatar-tag-text}
(i18n/label :t/community-request-not-accepted-body-text-suffix)]]}
(= membership-status constants/activity-center-membership-status-pending)
{:header-text (i18n/label :t/community-request-pending)
:context [[quo/text {:style common-style/user-avatar-tag-text}
(i18n/label :t/community-request-pending-body-text)]
community-context-tag]}
(= membership-status constants/activity-center-membership-status-accepted)
{:header-text (i18n/label :t/community-request-accepted)
:context [[quo/text {:style common-style/user-avatar-tag-text}
(i18n/label :t/community-request-accepted-body-text)]
community-context-tag]}
:else nil)))
(defn view
[{:keys [notification set-swipeable-height] :as props}]
(let [{:keys [community-id membership-status read
timestamp]} notification
community (rf/sub [:communities/community community-id])
{:keys [header-text context]} (get-header-text-and-context community
membership-status)]
[swipeable props
[quo/activity-log
{:title header-text
:icon :i/communities
:on-layout set-swipeable-height
:timestamp (datetime/timestamp->relative timestamp)
:unread? (not read)
:context context}]]))

View File

@ -6,6 +6,7 @@
(def ^:const mention 3)
(def ^:const reply 4)
(def ^:const contact-request 5)
(def ^:const community-request 7)
(def ^:const admin 8)
(def ^:const contact-verification 10)
@ -15,6 +16,7 @@
mention
reply
contact-request
community-request
admin
contact-verification})
@ -26,4 +28,5 @@
"Membership is like a logical group of notifications with different types, i.e.
it doesn't have a corresponding type in the backend. Think of the collection
as a composite key of actual types."
#{private-group-chat})
#{private-group-chat
community-request})

View File

@ -12,6 +12,8 @@
[status-im2.contexts.activity-center.notification.membership.view :as membership]
[status-im2.contexts.activity-center.notification.mentions.view :as mentions]
[status-im2.contexts.activity-center.notification.reply.view :as reply]
[status-im2.contexts.activity-center.notification.community-request.view :as
community-request]
[status-im2.contexts.activity-center.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
@ -196,7 +198,12 @@
[admin/view props]
(some types/membership [type])
[membership/view props]
(case type
types/private-group-chat [membership/view props]
types/community-request [community-request/view props]
nil)
:else
nil)]))))

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.146.3",
"commit-sha1": "9dea0aaee3ce0ebb29c6898c771a383dfbd6bb52",
"src-sha256": "08hcl3bmy0f90b3drd2ny1gn0hs6rmbzdkv7drikvgpsnfanm8gw"
"version": "v0.146.4",
"commit-sha1": "e8ceed11125dfd470c0e0caac0755313fb85cba6",
"src-sha256": "1flwq5sfy1cfdl40fiip0q555rdcq5f5l2lpb4az8j5bwmwmi31x"
}

View File

@ -2071,5 +2071,12 @@
"mute-for-8-hours": "For 8 hours",
"mute-for-1-week": "For 7 days",
"mute-till-unmute": "Until you turn it back on",
"mute-channel": "Mute channel"
"mute-channel": "Mute channel",
"community-request-accepted": "Request accepted",
"community-request-accepted-body-text": "Now you are a member of",
"community-request-not-accepted": "Request hasn't been accepted",
"community-request-not-accepted-body-text-prefix": "Your request to join",
"community-request-not-accepted-body-text-suffix": "hasn't been accepted",
"community-request-pending": "Request pending",
"community-request-pending-body-text": "You requested to join"
}