Mute community

* mute and unmute community

dfdaa722...e6187aec

* mute and unmute community and all community chats

dfdaa722...3abc86e4

* updated statu-go

dfdaa722...919123e1

* refactored mute chat drawer

d3e650d5...3af0b17c

* refactored mute chat drawer

dfdaa722...3af0b17c

* fixing mute channels

* fixed mute community channels

* update community chats mute status

dfdaa722...dc50ac21

* added mute and unmute community toast

dfdaa722...c06f7a6c

* unmute community when atleast one community channel is unmuted

dfdaa722...e691c475

* updated status-go

b2e56f5d...c52718cd

* updated status-go version v0.162.5
This commit is contained in:
John Ngei 2023-07-19 16:30:42 +03:00 committed by GitHub
parent 32f18c3d3c
commit 2317e856bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 293 additions and 124 deletions

View File

@ -3,6 +3,7 @@
[quo2.components.community.style :as style]
[quo2.components.counter.counter :as counter]
[quo2.components.icon :as icons]
[quo2.theme :as theme]
[quo2.components.markdown.text :as text]
[quo2.foundations.colors :as colors]
[quo2.components.community.icon :as community-icon]
@ -21,18 +22,65 @@
:resize-mode :center
:size 20
:color (colors/theme-colors
colors/neutral-40
colors/neutral-50)}]
colors/neutral-50
colors/neutral-40)}]
(pos? unread-mentions-count)
[counter/counter {:type :default} unread-mentions-count]
unread-messages?
[unread-grey-dot :unviewed-messages-public]))
(defn communities-membership-list-item
(defn communities-list-view-item
[props
{:keys [name
muted?
locked?
status
muted
unread-messages?
unread-mentions-count
community-icon
tokens]}]
[rn/view
{:style (merge (style/community-card 16)
{:margin-bottom 12})}
[rn/touchable-highlight
(merge {:style {:height 56
:border-radius 16}}
props)
[rn/view {:style style/detail-container}
[rn/view (style/list-info-container)
[community-icon/community-icon
{:images community-icon} 32]
[rn/view
{:flex 1
:margin-horizontal 12}
[text/text
{:weight :semi-bold
:size :paragraph-1
:accessibility-label :community-name-text
:number-of-lines 1
:ellipsize-mode :tail
:style {:color (when muted
(colors/theme-colors
colors/neutral-40
colors/neutral-60))}}
name]
[community-view/community-stats-column
{:type :list-view}]]
(if (= status :gated)
[community-view/permission-tag-container
{:locked? locked?
:tokens tokens}]
[notification-view
{:muted? muted
:unread-mentions-count unread-mentions-count
:unread-messages? unread-messages?}])]]]])
(defn communities-membership-list-item
[props
bottom-sheet?
{:keys [name
muted
unviewed-messages-count
unviewed-mentions-count
status
@ -59,17 +107,22 @@
:number-of-lines 1
:ellipsize-mode :tail
:weight :semi-bold
:size :paragraph-1}
:size :paragraph-1
:style (when muted
{:color (if (theme/dark?)
colors/neutral-60
colors/neutral-40)})}
name]]
[rn/view
{:justify-content :center
:margin-right 16}
:margin-right (when bottom-sheet?
16)}
(if (= status :gated)
[community-view/permission-tag-container
{:locked? locked?
:tokens tokens}]
[notification-view
{:muted? muted?
{:muted? muted
:unread-mentions-count unviewed-mentions-count
:unread-messages? (pos? unviewed-messages-count)}])]]])

View File

@ -3,6 +3,7 @@
[clojure.string :as string]
[clojure.walk :as walk]
[quo.design-system.colors :as colors]
[quo2.foundations.colors :as quo2.colors]
[re-frame.core :as re-frame]
[status-im.utils.types :as types]
[status-im.async-storage.core :as async-storage]
@ -16,6 +17,7 @@
[taoensso.timbre :as log]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[status-im2.common.muting.helpers :refer [format-mute-till]]
[status-im2.contexts.chat.events :as chat.events]))
(def crop-size 1000)
@ -72,7 +74,8 @@
:isMember :is-member?
:adminSettings :admin-settings
:tokenPermissions :token-permissions
:communityTokensMetadata :tokens-metadata})
:communityTokensMetadata :tokens-metadata
:muteTill :muted-till})
(update :admin-settings
set/rename-keys
{:pinMessageAllMembersEnabled :pin-message-all-members-enabled?})
@ -938,3 +941,58 @@
{:error %
:event
:communities/check-and-delete-pending-request-to-join-community})}]})
(rf/defn mute-community-chats
{:events [:community/mute-community-chats]}
[{:keys [db]} chat-id muted? muted-till]
(log/debug "muted community chat successfully" chat-id muted?)
{:db (update-in db [:chats chat-id] merge {:muted muted? :muted-till muted-till})})
(rf/defn mute-and-unmute-community-chats
{:events [:community/update-community-chats-mute-status]}
[{:keys [db]} community-id muted? mute-till]
(let [channels (get-in db [:communities community-id :chats])
chats (mapv vector (keys channels) (vals channels))]
(doseq [x chats]
(doseq [{:keys [id]} x]
(let [chat-id (str community-id id)]
(rf/dispatch [:community/mute-community-chats chat-id muted? mute-till]))))))
(rf/defn mute-chat-failed
{:events [:community/mute-community-failed]}
[{:keys [db]} community-id muted? error]
(log/error "mute community failed" community-id error)
{:db (update-in db [:communities community-id :muted] (not muted?))}
(rf/dispatch [:community/update-community-chats-mute-status community-id muted? error]))
(rf/defn mute-community-successfully
{:events [:community/mute-community-successful]}
[{:keys [db]} community-id muted? muted-till]
(log/debug "muted community successfully" community-id muted-till)
(rf/dispatch [:community/update-community-chats-mute-status community-id muted? muted-till])
(let [time-string (fn [mute-title mute-duration]
(i18n/label mute-title {:duration mute-duration}))]
{:db (assoc-in db [:communities community-id :muted-till] muted-till)
:dispatch [:toasts/upsert
{:icon :correct
:icon-color (quo2.colors/theme-colors
quo2.colors/success-60
quo2.colors/success-50)
:text (if muted?
(when (some? muted-till)
(time-string :t/muted-until (format-mute-till muted-till)))
(i18n/label :t/community-unmuted))}]}))
(rf/defn set-community-muted
{:events [:community/set-muted]}
[{:keys [db]} community-id muted? muted-type]
(let [params (if muted? [{:communityId community-id :mutedType muted-type}] [community-id])
method (if muted? "wakuext_muteCommunityChats" "wakuext_unMuteCommunityChats")]
{:db (assoc-in db [:communities community-id :muted] muted?)
:json-rpc/call [{:method method
:params params
:on-error #(rf/dispatch [:community/mute-community-failed community-id
muted? %])
:on-success #(rf/dispatch [:community/mute-community-successful
community-id muted? %])}]}))

View File

@ -8,7 +8,7 @@
[status-im2.contexts.contacts.drawers.nickname-drawer.view :as nickname-drawer]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[status-im2.common.mute-chat-drawer.view :as mute-chat-drawer]
[status-im2.common.mute-drawer.view :as mute-drawer]
[status-im2.common.muting.helpers :refer [format-mute-till]]))
(defn- entry
@ -53,11 +53,15 @@
:accessibility-label :edit-nickname}])}]))
(defn mute-chat-action
[chat-id chat-type]
[chat-id chat-type muted?]
(hide-sheet-and-dispatch [:show-bottom-sheet
{:content (fn []
[mute-chat-drawer/mute-chat-drawer chat-id
:mute-chat-for-duration chat-type])}]))
[mute-drawer/mute-drawer
{:id chat-id
:community? false
:muted? (not muted?)
:chat-type chat-type
:accessibility-label :mute-community-title}])}]))
(defn unmute-chat-action
[chat-id]
@ -136,7 +140,7 @@
(format-mute-till muted-till)))
:on-press (if muted?
#(unmute-chat-action chat-id)
#(mute-chat-action chat-id chat-type))
#(mute-chat-action chat-id chat-type muted?))
:danger? false
:accessibility-label :mute-chat
:chevron? (not muted?)})))

View File

@ -1,76 +0,0 @@
(ns status-im2.common.mute-chat-drawer.view
(:require [utils.i18n :as i18n]
[quo2.core :as quo]
[react-native.core :as rn]
[status-im2.constants :as constants]
[utils.re-frame :as rf]
[status-im2.common.mute-chat-drawer.style :as style]))
(defn not-community-chat?
[chat-type]
(contains? #{constants/public-chat-type
constants/private-group-chat-type
constants/one-to-one-chat-type}
chat-type))
(defn hide-sheet-and-dispatch
[event]
(rf/dispatch [:hide-bottom-sheet])
(rf/dispatch event))
(defn mute-chat-drawer
[chat-id accessibility-label chat-type]
[rn/view {:accessibility-label accessibility-label}
[quo/text
{:weight :medium
:size :paragraph-2
:style (style/header-text)}
(i18n/label
(if (not-community-chat? chat-type)
:t/mute-chat-capitialized
:t/mute-channel))]
[quo/menu-item
{:type :transparent
:title (i18n/label :t/mute-for-15-mins)
:icon-bg-color :transparent
:container-padding-vertical 12
:title-column-style {:margin-left 2}
:on-press (fn []
(hide-sheet-and-dispatch [:chat.ui/mute chat-id true
constants/mute-for-15-mins-type]))}]
[quo/menu-item
{:type :transparent
:title (i18n/label :t/mute-for-1-hour)
:icon-bg-color :transparent
:container-padding-vertical 12
:title-column-style {:margin-left 2}
:on-press (fn []
(hide-sheet-and-dispatch [:chat.ui/mute chat-id true
constants/mute-for-1-hour-type]))}]
[quo/menu-item
{:type :transparent
:title (i18n/label :t/mute-for-8-hours)
:icon-bg-color :transparent
:container-padding-vertical 12
:title-column-style {:margin-left 2}
:on-press (fn []
(hide-sheet-and-dispatch [:chat.ui/mute chat-id true
constants/mute-for-8-hours-type]))}]
[quo/menu-item
{:type :transparent
:title (i18n/label :t/mute-for-1-week)
:icon-bg-color :transparent
:container-padding-vertical 12
:title-column-style {:margin-left 2}
:on-press (fn []
(hide-sheet-and-dispatch [:chat.ui/mute chat-id true
constants/mute-for-1-week]))}]
[quo/menu-item
{:type :transparent
:title (i18n/label :t/mute-till-unmute)
:icon-bg-color :transparent
:container-padding-vertical 12
:title-column-style {:margin-left 2}
:on-press (fn []
(hide-sheet-and-dispatch [:chat.ui/mute chat-id true
constants/mute-till-unmuted]))}]])

View File

@ -1,4 +1,4 @@
(ns status-im2.common.mute-chat-drawer.style
(ns status-im2.common.mute-drawer.style
(:require [quo2.foundations.colors :as colors]))
(defn header-text

View File

@ -0,0 +1,100 @@
(ns status-im2.common.mute-drawer.view
(:require [utils.i18n :as i18n]
[quo2.core :as quo]
[react-native.core :as rn]
[status-im2.constants :as constants]
[utils.re-frame :as rf]
[status-im2.common.mute-drawer.style :as style]))
(defn not-community-chat?
[chat-type]
(contains? #{constants/public-chat-type
constants/private-group-chat-type
constants/one-to-one-chat-type}
chat-type))
(defn hide-sheet-and-dispatch
[{:keys [id community? muted? muted-type]}]
(rf/dispatch [:hide-bottom-sheet])
(if community?
(rf/dispatch [:community/set-muted id muted? muted-type])
(rf/dispatch [:chat.ui/mute id muted? muted-type])))
(defn mute-drawer
[{:keys [id accessibility-label muted? chat-type community?]}]
[rn/view {:accessibility-label accessibility-label}
[quo/text
{:weight :medium
:size :paragraph-2
:style (style/header-text)}
(i18n/label
(if community?
:t/mute-community
(if (not-community-chat? chat-type)
:t/mute-chat-capitialized
:t/mute-channel)))]
[quo/menu-item
{:type :transparent
:title (i18n/label :t/mute-for-15-mins)
:icon-bg-color :transparent
:container-padding-vertical 12
:title-column-style {:margin-left 2}
:on-press (fn []
(hide-sheet-and-dispatch
{:id id
:chat-type chat-type
:muted? muted?
:community? community?
:muted-type constants/mute-for-15-mins-type}))}]
[quo/menu-item
{:type :transparent
:title (i18n/label :t/mute-for-1-hour)
:icon-bg-color :transparent
:container-padding-vertical 12
:title-column-style {:margin-left 2}
:on-press (fn []
(hide-sheet-and-dispatch
{:id id
:chat-type chat-type
:muted? muted?
:community? community?
:muted-type constants/mute-for-1-hour-type}))}]
[quo/menu-item
{:type :transparent
:title (i18n/label :t/mute-for-8-hours)
:icon-bg-color :transparent
:container-padding-vertical 12
:title-column-style {:margin-left 2}
:on-press (fn []
(hide-sheet-and-dispatch
{:id id
:chat-type chat-type
:muted? muted?
:community? community?
:muted-type constants/mute-for-8-hours-type}))}]
[quo/menu-item
{:type :transparent
:title (i18n/label :t/mute-for-1-week)
:icon-bg-color :transparent
:container-padding-vertical 12
:title-column-style {:margin-left 2}
:on-press (fn []
(hide-sheet-and-dispatch
{:id id
:chat-type chat-type
:muted? muted?
:community? community?
:muted-type constants/mute-for-1-week}))}]
[quo/menu-item
{:type :transparent
:title (i18n/label :t/mute-till-unmute)
:icon-bg-color :transparent
:container-padding-vertical 12
:title-column-style {:margin-left 2}
:on-press (fn []
(hide-sheet-and-dispatch
{:id id
:chat-type chat-type
:muted? muted?
:community? community?
:muted-type constants/mute-till-unmuted}))}]])

View File

@ -48,6 +48,7 @@
(def ^:const mute-for-8-hours-type 3)
(def ^:const mute-for-1-week 4)
(def ^:const mute-till-unmuted 5)
(def ^:const un-muted 0)
(def ^:const activity-center-mark-all-as-read-undo-time-limit-ms 4000)
(def ^:const activity-center-max-unread-count 99)

View File

@ -293,6 +293,12 @@
(deactivate-chat chat-id)
(offload-messages chat-id)))
(rf/defn unmute-chat-community
{:events [:chat/unmute-chat-community]}
[{:keys [db]} chat-id muted?]
(let [{:keys [community-id]} (get-in db [:chats chat-id])]
{:db (assoc-in db [:communities community-id :muted] muted?)}))
(rf/defn mute-chat-failed
{:events [:chat/mute-failed]}
[{:keys [db]} chat-id muted? error]
@ -303,6 +309,8 @@
{:events [:chat/mute-successfully]}
[{:keys [db]} chat-id muted-till mute-type muted? chat-type]
(log/debug "muted chat successfully" chat-id " for" muted-till)
(when-not muted?
(rf/dispatch [:chat/unmute-chat-community chat-id muted?]))
(let [time-string (fn [duration-kw unmute-time]
(i18n/label duration-kw {:duration unmute-time}))
not-community-chat? #(contains? #{constants/public-chat-type
@ -361,7 +369,7 @@
:params params
:on-error #(rf/dispatch [:chat/mute-failed chat-id muted? %])
:on-success #(rf/dispatch [:chat/mute-successfully chat-id % mute-type
(not muted?) chat-type])}]}))
muted? chat-type])}]}))
(rf/defn show-clear-history-confirmation
{:events [:chat.ui/show-clear-history-confirmation]}

View File

@ -4,7 +4,7 @@
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[status-im2.common.muting.helpers :refer [format-mute-till]]
[status-im2.common.mute-chat-drawer.view :as mute-chat-drawer]))
[status-im2.common.mute-drawer.view :as mute-drawer]))
(defn hide-sheet-and-dispatch
[event]
@ -12,11 +12,15 @@
(rf/dispatch event))
(defn- mute-channel-action
[chat-id chat-type]
[chat-id chat-type muted?]
(hide-sheet-and-dispatch [:show-bottom-sheet
{:content (fn []
[mute-chat-drawer/mute-chat-drawer chat-id
:mute-chat-for-duration chat-type])}]))
[mute-drawer/mute-drawer
{:id chat-id
:community? false
:muted? (not muted?)
:chat-type chat-type
:accessibility-label :mute-community-title}])}]))
(defn- unmute-channel-action
[chat-id]
@ -46,16 +50,16 @@
(defn- action-toggle-muted
[id muted? muted-till chat-type]
(let [muted (and muted? (some? muted-till))]
(let [muted (and muted? (some? muted-till))
time-string (fn [mute-title mute-duration]
(i18n/label mute-title {:duration mute-duration}))]
(cond-> {:icon :i/muted
:accessibility-label :chat-toggle-muted
:sub-label (when muted
(str (i18n/label :t/muted-until)
" "
(format-mute-till muted-till)))
:sub-label (when (and muted? (some? muted-till))
(time-string :t/muted-until (format-mute-till muted-till)))
:on-press (if muted?
#(unmute-channel-action id)
#(mute-channel-action id chat-type))
#(mute-channel-action id chat-type muted?))
:label (i18n/label (if muted
:t/unmute-channel
:t/mute-channel))}

View File

@ -4,6 +4,9 @@
[quo2.core :as quo]
[status-im2.contexts.communities.actions.see-rules.view :as see-rules]
[status-im2.contexts.communities.actions.leave.view :as leave-menu]
[status-im2.common.mute-drawer.view :as mute-options]
[status-im2.constants :as constants]
[status-im2.common.muting.helpers :refer [format-mute-till]]
[status-im2.contexts.communities.actions.token-gating.view :as token-gating]))
(defn hide-sheet-and-dispatch
@ -45,12 +48,26 @@
:on-press #(hide-sheet-and-dispatch [:chat.ui/mark-all-read-in-community-pressed id])})
(defn mute-community
[_ muted?]
{:icon (if muted? :i/muted :i/activity-center)
:accessibility-label (if muted? :unmute-community :mute-community)
:label (i18n/label (if muted? :t/unmute-community :t/mute-community))
:sub-label (when muted? (str "muted for 15 minutes"))
:right-icon :i/chevron-right})
[id muted? muted-till]
(let [time-string (fn [mute-title mute-duration]
(i18n/label mute-title {:duration mute-duration}))]
{:icon (if muted? :i/muted :i/activity-center)
:accessibility-label (if muted? :unmute-community :mute-community)
:label (i18n/label (if muted? :t/unmute-community :t/mute-community))
:sub-label (when (and muted? (some? muted-till))
(time-string :t/muted-until (format-mute-till muted-till)))
:right-icon :i/chevron-right
:on-press (if muted?
#(hide-sheet-and-dispatch [:community/set-muted id (not muted?)
constants/un-muted])
#(hide-sheet-and-dispatch
[:show-bottom-sheet
{:content (fn []
[mute-options/mute-drawer
{:id id
:community? true
:muted? (not muted?)
:accessibility-label :mute-community-title}])}]))}))
(defn community-notification-settings
[id]
@ -119,12 +136,12 @@
(not-joined-options id token-gated?))
(defn joined-options
[id token-gated? muted?]
[id token-gated? muted? muted-till]
[[(view-members id)
(view-rules id)
(when token-gated? (view-token-gating id))
(mark-as-read id)
(mute-community id muted?)
(mute-community id muted? muted-till)
(community-notification-settings id)
(invite-contacts id)
(show-qr id)
@ -132,12 +149,12 @@
[(assoc (leave-community id) :add-divider? true)]])
(defn owner-options
[id token-gated? muted?]
[id token-gated? muted? muted-till]
[[(view-members id)
(view-rules id)
(when token-gated? (view-token-gating id))
(mark-as-read id)
(mute-community id muted?)
(mute-community id muted? muted-till)
(community-notification-settings id)
(invite-contacts id)
(show-qr id)
@ -146,11 +163,11 @@
(defn get-context-drawers
[{:keys [id]}]
(let [{:keys [token-permissions admin joined
muted banList]} (rf/sub [:communities/community id])
request-id (rf/sub [:communities/my-pending-request-to-join id])]
muted banList muted-till]} (rf/sub [:communities/community id])
request-id (rf/sub [:communities/my-pending-request-to-join id])]
(cond
admin (owner-options id token-permissions muted)
joined (joined-options id token-permissions muted)
admin (owner-options id token-permissions muted muted-till)
joined (joined-options id token-permissions muted muted-till)
request-id (join-request-sent-options id token-permissions request-id)
banList (banned-options id token-permissions)
:else (not-joined-options id token-permissions))))

View File

@ -27,7 +27,8 @@
{:content (fn []
[options/community-options-bottom-sheet id])
:selected-item (fn []
[quo/communities-membership-list-item {} item])}])}
[quo/communities-membership-list-item {} true item])}])}
false
item]))
(def tabs-data

View File

@ -46,6 +46,7 @@
{:padding-vertical 60
:justify-content :center}
[community-list-view/communities-membership-list-item {}
false
(cond-> (merge @state data/community)
(= :muted (:notifications @state))
(assoc :muted? true)

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.162.3",
"commit-sha1": "b2e56f5d2d22d7299a049f70127b415fae4da75a",
"src-sha256": "0pz8ins5gz3f19syhi5rxz4j7115lakvw90yci85ci1k7rrhjxjk"
"version": "v0.162.5",
"commit-sha1": "cf2d72bfa83f094719a93b7b7fd5a68e3a68ab47",
"src-sha256": "0x79nm1n6gbgz2lzsky29laap7m0r0hggrb2fsn07bf0xw0364qn"
}

View File

@ -1041,7 +1041,6 @@
"remote-notifications": "Remote notifications",
"remote-notifications-subtitle": "Enable google push notifications",
"show-notifications": "Show notifications",
"notification-settings": "Notifications",
"notification-settings": "Notification settings",
"notifications-servers": "Notification servers",
"notifications-preferences": "Notification preferences",
@ -2209,11 +2208,9 @@
"read-more": "Read more",
"token-gated-communities-info": "Here will be something relevant about this topic. This will help the user get more context and therefore have a better understanding of it.",
"dont-yell-at-me": "Dont yell at me",
"view-channel-members-and-details": "View channel members and details",
"unmute-channel": "Unmute channel",
"share-channel": "Share channel",
"all-messages": "All messages",
"muted-until": "Muted until",
"muted-until": "Muted until {{duration}}",
"until-you-turn-it-back-on": "you turn it back on",
"mon": "Mon",
"tue": "Tue",
@ -2247,5 +2244,6 @@
"until": "until",
"chat-unmuted-successfully": "Chat unmuted successfully! ",
"channel-unmuted-successfully": "Channel unmuted successfully! ",
"photo-saved": "Photo saved to your device"
"photo-saved": "Photo saved to your device",
"community-unmuted": "Community unmuted"
}