Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15128] Introduce muting for a specific duration #15253

Merged
merged 25 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/quo2/components/list_items/menu_item.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@
(when on-press
{:on-press on-press}))
[rn/view
{:style {:flex-direction :row
:flex-grow 0
:flex-shrink 1
:padding-horizontal 20
:align-items :center}}
{:style (cond-> {:flex-direction :row
:flex-grow 0
:flex-shrink 1
:align-items :center}
icon (assoc :padding-horizontal 20))}
[rn/view
{:style {:width 20
:height 20
:align-items :center
:justify-content :center
:margin-right 12}}
[icons/icon icon {:color icon-color}]]
{:style (cond-> {:width 20
:height 20
:align-items :center
:justify-content :center}
icon (assoc :margin-right 12))}
(when icon [icons/icon icon {:color icon-color}])]
[rn/view
[text/text
{:weight :medium
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/data_store/chats.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
:identicon (.-identicon chat)
:muted (.-muted chat)
:joined (.-joined chat)

:muted-till (.-mutetill chat)
:chat-id (.-id chat)
:community-id (.-communityId chat)
:synced-from (.-syncedFrom chat)
Expand Down
5 changes: 3 additions & 2 deletions src/status_im/integration_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
status-im2.navigation.core
status-im2.subs.root ; so integration tests can run independently
[taoensso.timbre :as log]
[utils.security.core :as security]))
[utils.security.core :as security]
[status-im2.constants :as constants]))

(def password "testabc")

Expand Down Expand Up @@ -295,7 +296,7 @@
(rf/dispatch-sync [:chat/navigate-to-chat chat-id])
(is (= chat-id @(rf/subscribe [:chats/current-chat-id])))
(is @(rf/subscribe [:chats/chat chat-id]))
(rf/dispatch-sync [:chat.ui/mute chat-id true])
(rf/dispatch-sync [:chat.ui/mute chat-id true constants/mute-till-unmuted])
(rf-test/wait-for
[:chat/mute-successfully]
(is @(rf/subscribe [:chats/muted chat-id]))
Expand Down
7 changes: 5 additions & 2 deletions src/status_im/ui/screens/profile/contact/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
[status-im.ui.components.toolbar :as toolbar]
[status-im.ui.components.topbar :as topbar]
[status-im.ui.screens.profile.components.sheets :as sheets]
[utils.re-frame :as rf]))
[utils.re-frame :as rf]
[status-im2.constants :as constants]))

(defn actions
[{:keys [public-key added? blocked? ens-name mutual?] :as contact} muted?]
Expand Down Expand Up @@ -43,7 +44,9 @@
:selected muted?
:disabled blocked?
:action (when-not blocked?
#(re-frame/dispatch [:chat.ui/mute public-key (not muted?)]))}]
#(re-frame/dispatch [:chat.ui/mute public-key (not muted?)
(when-not muted?
constants/mute-till-unmuted)]))}]
[{:label (i18n/label (if blocked? :t/unblock :t/block))
:negative true
:selected blocked?
Expand Down
2 changes: 1 addition & 1 deletion src/status_im2/common/home/actions/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

(defn mute-chat-action
[chat-id]
(hide-sheet-and-dispatch [:chat.ui/mute chat-id true]))
(hide-sheet-and-dispatch [:chat.ui/mute chat-id true constants/mute-till-unmuted]))

(defn unmute-chat-action
[chat-id]
Expand Down
8 changes: 8 additions & 0 deletions src/status_im2/common/mute_chat_drawer/style.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns status-im2.common.mute-chat-drawer.style
(:require [quo2.foundations.colors :as colors]))

(defn header-text
[]
{:margin-left 20
:margin-bottom 10
:color (colors/theme-colors colors/neutral-50 colors/neutral-40)})
65 changes: 65 additions & 0 deletions src/status_im2/common/mute_chat_drawer/view.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
(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 hide-sheet-and-dispatch
[event]
(rf/dispatch [:bottom-sheet/hide])
(rf/dispatch event))

(defn mute-chat-drawer
[chat-id accessibility-label]
[rn/view {:accessibility-label accessibility-label}
[quo/text
{:weight :medium
:size :paragraph-2
:style (style/header-text)} (i18n/label :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]))}]])
6 changes: 6 additions & 0 deletions src/status_im2/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
(def ^:const activity-center-membership-status-accepted 2)
(def ^:const activity-center-membership-status-declined 3)

(def ^:const mute-for-15-mins-type 1)
(def ^:const mute-for-1-hour-type 2)
(def ^:const mute-for-8-hours-type 3)
(def ^:const mute-for-1-week 4)
(def ^:const mute-till-unmuted 5)

(def ^:const activity-center-mark-all-as-read-undo-time-limit-ms 4000)
(def ^:const activity-center-max-unread-count 99)

Expand Down
30 changes: 17 additions & 13 deletions src/status_im2/contexts/chat/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@
(defn map-chats
[{:keys [db] :as cofx}]
(fn [val]
(assoc
(merge
(or (get (:chats db) (:chat-id val))
(create-new-chat (:chat-id val) cofx))
val)
:invitation-admin
(:invitation-admin val))))
(let [chat (or (get (:chats db) (:chat-id val))
(create-new-chat (:chat-id val) cofx))]
(assoc
(merge
(cond-> chat
(comp not :muted) (dissoc chat :muted-till))
val)
:invitation-admin
(:invitation-admin val)))))

(rf/defn leave-removed-chat
[{{:keys [view-id current-chat-id chats]} :db
Expand Down Expand Up @@ -292,18 +294,20 @@

(rf/defn mute-chat-toggled-successfully
{:events [:chat/mute-successfully]}
[_ chat-id]
(log/debug "muted chat successfully" chat-id))
[{:keys [db]} chat-id muted-till]
(log/debug "muted chat successfully" chat-id " for" muted-till)
{:db (assoc-in db [:chats chat-id :muted-till] muted-till)})

(rf/defn mute-chat
{:events [:chat.ui/mute]}
[{:keys [db]} chat-id muted?]
(let [method (if muted? "wakuext_muteChat" "wakuext_unmuteChat")]
[{:keys [db]} chat-id muted? mute-type]
(let [method (if muted? "wakuext_muteChatV2" "wakuext_unmuteChat")
Copy link
Contributor Author

@ibrkhalil ibrkhalil Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna have to go with a V2 naming to not break desktop muting functionality

params (if muted? [{:chatId chat-id :mutedType mute-type}] [chat-id])]
{:db (assoc-in db [:chats chat-id :muted] muted?)
:json-rpc/call [{:method method
:params [chat-id]
:params params
:on-error #(rf/dispatch [:chat/mute-failed chat-id muted? %])
:on-success #(rf/dispatch [:chat/mute-successfully chat-id])}]}))
:on-success #(rf/dispatch [:chat/mute-successfully chat-id %])}]}))

(rf/defn show-clear-history-confirmation
{:events [:chat.ui/show-clear-history-confirmation]}
Expand Down
6 changes: 4 additions & 2 deletions src/status_im2/contexts/chat/group_details/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[status-im2.common.contact-list-item.view :as contact-list-item]
[status-im2.common.home.actions.view :as actions]
[utils.re-frame :as rf]
[reagent.core :as reagent]))
[reagent.core :as reagent]
[status-im2.constants :as constants]))

(defn back-button
[]
Expand Down Expand Up @@ -191,7 +192,8 @@
[rn/touchable-opacity
{:style (style/action-container color)
:accessibility-label :toggle-mute
:on-press #(rf/dispatch [:chat.ui/mute chat-id (not muted)])}
:on-press #(rf/dispatch [:chat.ui/mute chat-id (not muted)
(when-not muted constants/mute-till-unmuted)])}
[quo/icon (if muted :i/muted :i/activity-center)
{:size 20 :color (colors/theme-colors colors/neutral-100 colors/white)}]
[quo/text {:style {:margin-top 16} :size :paragraph-1 :weight :medium}
Expand Down
13 changes: 7 additions & 6 deletions src/status_im2/contexts/chat/home/chat_list_item/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@

(defn chat-list-item
[{:keys [chat-id group-chat color name unviewed-messages-count unviewed-mentions-count
timestamp last-message]
timestamp last-message muted]
:as item}]
(let [display-name (if group-chat
name
Expand All @@ -143,8 +143,9 @@
:style {:color (colors/theme-colors colors/neutral-50 colors/neutral-40)}}
(get-in last-message [:content :text])]
[render-subheader (get-in last-message [:content :parsed-text])])]
(if (> unviewed-mentions-count 0)
[quo/info-count {:style {:top 16}}
unviewed-mentions-count]
(when (> unviewed-messages-count 0)
[rn/view {:style (style/count-container)}]))]))
(when-not muted
(if (> unviewed-mentions-count 0)
[quo/info-count {:style {:top 16}}
unviewed-mentions-count]
(when (> unviewed-messages-count 0)
[rn/view {:style (style/count-container)}])))]))
16 changes: 9 additions & 7 deletions src/status_im2/subs/shell.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,19 @@
(fn [chats]
(let [{:keys [chats-stack community-stack]}
(reduce
(fn [acc [_ {:keys [unviewed-messages-count unviewed-mentions-count chat-type]}]]
(fn [acc [_ {:keys [unviewed-messages-count unviewed-mentions-count chat-type muted]}]]
(case chat-type
constants/community-chat-type
(-> acc
(update-in [:community-stack :unviewed-messages-count] + unviewed-messages-count)
(update-in [:community-stack :unviewed-mentions-count] + unviewed-mentions-count))
(when-not muted
(-> acc
(update-in [:community-stack :unviewed-messages-count] + unviewed-messages-count)
(update-in [:community-stack :unviewed-mentions-count] + unviewed-mentions-count)))

(constants/private-group-chat-type constants/one-to-one-chat-type)
(-> acc
(update-in [:chats-stack :unviewed-messages-count] + unviewed-messages-count)
(update-in [:chats-stack :unviewed-mentions-count] + unviewed-mentions-count))
(when-not muted
(-> acc
(update-in [:chats-stack :unviewed-messages-count] + unviewed-messages-count)
(update-in [:chats-stack :unviewed-mentions-count] + unviewed-mentions-count)))

acc))
{:chats-stack {:unviewed-messages-count 0 :unviewed-mentions-count 0}
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.144.0",
"commit-sha1": "ba1ba1ac0203948339be5877ea6e970efb7b8ee0",
"src-sha256": "0r2gxivnx201zfnm69g2mk1izcjid4lf9s4ln721kwrnc1v288sf"
"version": "v0.145.2",
"commit-sha1": "719af90fcc077f301f50349c034938701883031e",
"src-sha256": "1p93x7ph03aq95961j4098fy2p7a4ssymf4hf3kbl5ldmvdk403p"
}
8 changes: 7 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2064,5 +2064,11 @@
"enable-biometrics": "Enable biometrics",
"use-biometrics": "Use biometrics to fill in your password",
"name-must-have-at-least-characters": "Name must have at least {{min-chars}} characters",
"name-is-not-valid": "Name is not valid"
"name-is-not-valid": "Name is not valid",
"mute-for-15-mins": "For 15 min",
"mute-for-1-hour": "For 1 hour",
"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"
}