From 36f9436e12532364f652c19c17259e370099bee7 Mon Sep 17 00:00:00 2001 From: Gheorghe Pinzaru Date: Fri, 16 Oct 2020 12:10:37 +0300 Subject: [PATCH] Fix group chat invitation actions based on state Fix decline button color and Check if user was removed from group invite Signed-off-by: Gheorghe Pinzaru --- src/status_im/constants.cljs | 2 ++ src/status_im/group_chats/core.cljs | 8 ++++++++ src/status_im/subs.cljs | 8 ++++++++ src/status_im/ui/screens/chat/group.cljs | 14 +++++++------- src/status_im/ui/screens/chat/styles/main.cljs | 5 +---- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index f464455be7..3ef4c4ecb0 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -35,6 +35,8 @@ (def invitation-state-requested 1) (def invitation-state-rejected 2) (def invitation-state-approved 3) +(def invitation-state-granted 4) +(def invitation-state-removed 5) (def message-type-one-to-one 1) (def message-type-public-group 2) diff --git a/src/status_im/group_chats/core.cljs b/src/status_im/group_chats/core.cljs index 22627d28dd..5b30d37450 100644 --- a/src/status_im/group_chats/core.cljs +++ b/src/status_im/group_chats/core.cljs @@ -168,3 +168,11 @@ (assoc acc id inv)) % invitations))}) + +(defn member-removed? [{:keys [membership-update-events]} pk] + (->> membership-update-events + (filter #(contains? (set (:members %)) pk)) + (sort-by :clockValue >) + first + :type + (= constants/invitation-state-removed))) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 7efec67827..819dc0b4d3 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -15,6 +15,7 @@ [status-im.ethereum.transactions.core :as transactions] [status-im.fleet.core :as fleet] [status-im.group-chats.db :as group-chats.db] + [status-im.group-chats.core :as group-chat] [status-im.i18n :as i18n] [status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.db :as multiaccounts.db] @@ -867,6 +868,13 @@ (fn [[invitations]] (filter #(= constants/invitation-state-requested (:state %)) invitations))) +(re-frame/reg-sub + :group-chat/removed-from-current-chat? + :<- [:chats/current-raw-chat] + :<- [:multiaccount/public-key] + (fn [[current-chat pk]] + (group-chat/member-removed? current-chat pk))) + (re-frame/reg-sub :chats/transaction-status ;;TODO address here for transactions diff --git a/src/status_im/ui/screens/chat/group.cljs b/src/status_im/ui/screens/chat/group.cljs index a947ae64d1..e16df3ac2d 100644 --- a/src/status_im/ui/screens/chat/group.cljs +++ b/src/status_im/ui/screens/chat/group.cljs @@ -19,12 +19,11 @@ (i18n/label :t/join-group-chat)]) (defn decline-chat [chat-id] - [react/touchable-highlight - {:on-press - #(debounce/dispatch-and-chill [:group-chats.ui/leave-chat-confirmed chat-id] 2000) - :accessibility-label :decline-chat-button} - [react/text {:style style/decline-chat} - (i18n/label :t/group-chat-decline-invitation)]]) + [quo/button + {:type :secondary + :accessibility-label :decline-chat-button + :on-press #(debounce/dispatch-and-chill [:group-chats.ui/leave-chat-confirmed chat-id] 2000)} + (i18n/label :t/group-chat-decline-invitation)]) (defn request-membership [{:keys [state introduction-message] :as invitation}] (let [{:keys [message retry?]} @(re-frame/subscribe [:chats/current-chat-membership])] @@ -64,10 +63,11 @@ (defview group-chat-footer [chat-id invitation-admin] (letsubs [{:keys [joined?]} [:group-chat/inviter-info chat-id] + removed? [:group-chat/removed-from-current-chat?] invitations [:group-chat/invitations-by-chat-id chat-id]] (if invitation-admin [request-membership (first invitations)] - (when-not joined? + (when (and (not joined?) (not removed?)) [react/view {:style style/group-chat-join-footer} [react/view {:style style/group-chat-join-container} [join-chat-button chat-id] diff --git a/src/status_im/ui/screens/chat/styles/main.cljs b/src/status_im/ui/screens/chat/styles/main.cljs index 6a51452a91..2ad5fb3a87 100644 --- a/src/status_im/ui/screens/chat/styles/main.cljs +++ b/src/status_im/ui/screens/chat/styles/main.cljs @@ -104,13 +104,10 @@ (def group-chat-join-container {:flex 1 + :padding-bottom 40 :align-items :center :justify-content :center}) -(def decline-chat - {:color colors/blue - :margin-bottom 40}) - (def are-you-friends-bubble {:border-radius 8 :border-width 1