[15128] Introduce muting for a specific duration (#15253)

This commit is contained in:
Ibrahem Khalil 2023-04-16 17:31:39 +02:00 committed by GitHub
parent f6d74df80b
commit 8af7011eb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 147 additions and 49 deletions

View File

@ -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

View File

@ -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)

View File

@ -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")
@ -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]))

View File

@ -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?]
@ -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?

View File

@ -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]

View File

@ -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)})

View File

@ -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]))}]])

View File

@ -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)

View File

@ -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
@ -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")
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]}

View File

@ -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
[]
@ -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}

View File

@ -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
@ -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)}])))]))

View File

@ -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}

View File

@ -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"
}

View File

@ -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"
}