From bfb074eca3281e5e3af3ea7fb41291daa7f7efed Mon Sep 17 00:00:00 2001 From: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com> Date: Fri, 21 Apr 2023 17:36:58 +0800 Subject: [PATCH] Community request to join changes (#15627) Resolves #15322 #15082 #15694 --- src/status_im/communities/core.cljs | 46 +++++++++---- src/status_im/multiaccounts/login/core.cljs | 1 + src/status_im/transport/message/core.cljs | 7 +- .../notification/common/view.cljs | 7 ++ .../notification/community_request/view.cljs | 64 +++++++++++++++++++ .../activity_center/notification_types.cljs | 5 +- .../contexts/activity_center/view.cljs | 9 ++- status-go-version.json | 6 +- translations/en.json | 9 ++- 9 files changed, 132 insertions(+), 22 deletions(-) create mode 100644 src/status_im2/contexts/activity_center/notification/community_request/view.cljs diff --git a/src/status_im/communities/core.cljs b/src/status_im/communities/core.cljs index b27c42fdc5..8fee62bc53 100644 --- a/src/status_im/communities/core.cljs +++ b/src/status_im/communities/core.cljs @@ -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})}]}) diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index 7d6c586cfd..207e2fcf9b 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -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) diff --git a/src/status_im/transport/message/core.cljs b/src/status_im/transport/message/core.cljs index 91f91528d4..d781417c96 100644 --- a/src/status_im/transport/message/core.cljs +++ b/src/status_im/transport/message/core.cljs @@ -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)] diff --git a/src/status_im2/contexts/activity_center/notification/common/view.cljs b/src/status_im2/contexts/activity_center/notification/common/view.cljs index 7924e21a75..76a5d78e08 100644 --- a/src/status_im2/contexts/activity_center/notification/common/view.cljs +++ b/src/status_im2/contexts/activity_center/notification/common/view.cljs @@ -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])] diff --git a/src/status_im2/contexts/activity_center/notification/community_request/view.cljs b/src/status_im2/contexts/activity_center/notification/community_request/view.cljs new file mode 100644 index 0000000000..8d73da6685 --- /dev/null +++ b/src/status_im2/contexts/activity_center/notification/community_request/view.cljs @@ -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}]])) diff --git a/src/status_im2/contexts/activity_center/notification_types.cljs b/src/status_im2/contexts/activity_center/notification_types.cljs index a598f65cd7..af36ac25fe 100644 --- a/src/status_im2/contexts/activity_center/notification_types.cljs +++ b/src/status_im2/contexts/activity_center/notification_types.cljs @@ -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}) diff --git a/src/status_im2/contexts/activity_center/view.cljs b/src/status_im2/contexts/activity_center/view.cljs index bee39e37c4..e41a414940 100644 --- a/src/status_im2/contexts/activity_center/view.cljs +++ b/src/status_im2/contexts/activity_center/view.cljs @@ -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)])))) diff --git a/status-go-version.json b/status-go-version.json index 6f0957fb8b..543815f69e 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "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" } diff --git a/translations/en.json b/translations/en.json index 908ae31a84..58c851a47b 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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" }