Skip to content

Commit

Permalink
Mute community
Browse files Browse the repository at this point in the history
* mute and unmute community

status-im/status-go@dfdaa72...e6187ae

* mute and unmute community and all community chats

status-im/status-go@dfdaa72...3abc86e

* updated statu-go

status-im/status-go@dfdaa72...919123e

* refactored mute chat drawer

status-im/status-go@d3e650d...3af0b17

* refactored mute chat drawer

status-im/status-go@dfdaa72...3af0b17

* fixing mute channels

* fixed mute community channels

* update community chats mute status

status-im/status-go@dfdaa72...dc50ac2

* added mute and unmute community toast

status-im/status-go@dfdaa72...c06f7a6

* unmute community when atleast one community channel is unmuted

status-im/status-go@dfdaa72...e691c47

* updated status-go

status-im/status-go@b2e56f5...c52718c

* updated status-go version v0.162.5
  • Loading branch information
jo-mut authored Jul 19, 2023
1 parent 32f18c3 commit 2317e85
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 123 deletions.
65 changes: 59 additions & 6 deletions src/quo2/components/community/community_list_view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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-list-view-item
[props
{:keys [name
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?
muted
unviewed-messages-count
unviewed-mentions-count
status
Expand All @@ -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)}])]]])
60 changes: 59 additions & 1 deletion src/status_im/communities/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand Down Expand Up @@ -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?})
Expand Down Expand Up @@ -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? %])}]}))
14 changes: 9 additions & 5 deletions src/status_im2/common/home/actions/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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?)})))
Expand Down
76 changes: 0 additions & 76 deletions src/status_im2/common/mute_chat_drawer/view.cljs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading

0 comments on commit 2317e85

Please sign in to comment.