Allow to undo muting the chat/channel from toast (#19074)
* feat: added undo action to mute chat toast * fix: removed trailing spaces from toast text * test: integration test for mute-chat undo * fix: added space before newline to toast messages text * feat: add undo to community mute toast * fix: integration tests * fix: integration tests --------- Co-authored-by: Volodymyr <52490791+VolodLytvynenko@users.noreply.github.com>
This commit is contained in:
parent
41763689e0
commit
76bf8d365c
|
@ -52,6 +52,8 @@
|
||||||
(def ^:const mute-till-unmuted 5)
|
(def ^:const mute-till-unmuted 5)
|
||||||
(def ^:const un-muted 0)
|
(def ^:const un-muted 0)
|
||||||
|
|
||||||
|
(def ^:const mute-undo-time-limit-ms 4000)
|
||||||
|
|
||||||
(def ^:const activity-center-mark-all-as-read-undo-time-limit-ms 4000)
|
(def ^:const activity-center-mark-all-as-read-undo-time-limit-ms 4000)
|
||||||
(def ^:const activity-center-max-unread-count 99)
|
(def ^:const activity-center-max-unread-count 99)
|
||||||
|
|
||||||
|
|
|
@ -275,9 +275,9 @@
|
||||||
|
|
||||||
(rf/defn unmute-chat-community
|
(rf/defn unmute-chat-community
|
||||||
{:events [:chat/unmute-chat-community]}
|
{:events [:chat/unmute-chat-community]}
|
||||||
[{:keys [db]} chat-id muted?]
|
[{:keys [db]} chat-id]
|
||||||
(let [{:keys [community-id]} (get-in db [:chats chat-id])]
|
(let [{:keys [community-id]} (get-in db [:chats chat-id])]
|
||||||
{:db (assoc-in db [:communities community-id :muted] muted?)}))
|
{:db (assoc-in db [:communities community-id :muted] false)}))
|
||||||
|
|
||||||
(rf/defn mute-chat-failed
|
(rf/defn mute-chat-failed
|
||||||
{:events [:chat/mute-failed]}
|
{:events [:chat/mute-failed]}
|
||||||
|
@ -290,7 +290,7 @@
|
||||||
[{:keys [db]} chat-id muted-till mute-type muted? chat-type]
|
[{:keys [db]} chat-id muted-till mute-type muted? chat-type]
|
||||||
(log/debug "muted chat successfully" chat-id " for" muted-till)
|
(log/debug "muted chat successfully" chat-id " for" muted-till)
|
||||||
(when-not muted?
|
(when-not muted?
|
||||||
(rf/dispatch [:chat/unmute-chat-community chat-id muted?]))
|
(rf/dispatch [:chat/unmute-chat-community chat-id]))
|
||||||
(let [time-string (fn [duration-kw unmute-time]
|
(let [time-string (fn [duration-kw unmute-time]
|
||||||
(i18n/label duration-kw {:duration unmute-time}))
|
(i18n/label duration-kw {:duration unmute-time}))
|
||||||
not-community-chat? #(contains? #{constants/public-chat-type
|
not-community-chat? #(contains? #{constants/public-chat-type
|
||||||
|
@ -332,9 +332,13 @@
|
||||||
:t/channel-unmuted-successfully))))]
|
:t/channel-unmuted-successfully))))]
|
||||||
{:db (assoc-in db [:chats chat-id :muted-till] muted-till)
|
{:db (assoc-in db [:chats chat-id :muted-till] muted-till)
|
||||||
:dispatch [:toasts/upsert
|
:dispatch [:toasts/upsert
|
||||||
{:type :positive
|
(cond-> {:type :positive
|
||||||
:text (mute-duration-text (when (some? muted-till)
|
:id :mute-chat-toast
|
||||||
(str (format-mute-till muted-till))))}]}))
|
:text (mute-duration-text (when (some? muted-till)
|
||||||
|
(str (format-mute-till muted-till))))}
|
||||||
|
muted? (assoc :duration constants/mute-undo-time-limit-ms
|
||||||
|
:undo-duration (/ constants/mute-undo-time-limit-ms 1000)
|
||||||
|
:undo-on-press #(rf/dispatch [:chat.ui/undo-mute chat-id])))]}))
|
||||||
|
|
||||||
(rf/defn mute-chat
|
(rf/defn mute-chat
|
||||||
{:events [:chat.ui/mute]}
|
{:events [:chat.ui/mute]}
|
||||||
|
@ -349,6 +353,27 @@
|
||||||
:on-success #(rf/dispatch [:chat/mute-successfully chat-id % mute-type
|
:on-success #(rf/dispatch [:chat/mute-successfully chat-id % mute-type
|
||||||
muted? chat-type])}]}))
|
muted? chat-type])}]}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:chat.ui/undo-mute
|
||||||
|
(fn [_ [chat-id]]
|
||||||
|
{:fx [[:json-rpc/call
|
||||||
|
[{:method "wakuext_unmuteChat"
|
||||||
|
:params [chat-id]
|
||||||
|
:on-error #(rf/dispatch [:chat/mute-failed chat-id false %])
|
||||||
|
:on-success #(rf/dispatch [:chat/undo-mute-success chat-id])}]]]}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:chat/undo-mute-success
|
||||||
|
(fn [{:keys [db]} [chat-id]]
|
||||||
|
{:db (update-in db
|
||||||
|
[:chats chat-id]
|
||||||
|
(fn [chat]
|
||||||
|
(-> chat
|
||||||
|
(dissoc :muted-till)
|
||||||
|
(assoc :muted false))))
|
||||||
|
:fx [[:dispatch [:toasts/close :mute-chat-toast]]
|
||||||
|
[:dispatch [:chat/unmute-chat-community chat-id]]]}))
|
||||||
|
|
||||||
(rf/defn show-clear-history-confirmation
|
(rf/defn show-clear-history-confirmation
|
||||||
{:events [:chat.ui/show-clear-history-confirmation]}
|
{:events [:chat.ui/show-clear-history-confirmation]}
|
||||||
[_ chat-id]
|
[_ chat-id]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
(ns status-im.contexts.communities.actions.community-options.events
|
(ns status-im.contexts.communities.actions.community-options.events
|
||||||
(:require [status-im.common.muting.helpers :as muting.helpers]
|
(:require [status-im.common.muting.helpers :as muting.helpers]
|
||||||
|
[status-im.constants :as constants]
|
||||||
[taoensso.timbre :as log]
|
[taoensso.timbre :as log]
|
||||||
[utils.i18n :as i18n]
|
[utils.i18n :as i18n]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
@ -12,7 +13,8 @@
|
||||||
db
|
db
|
||||||
(keys (get-in db [:communities community-id :chats])))}))
|
(keys (get-in db [:communities community-id :chats])))}))
|
||||||
|
|
||||||
(rf/reg-event-fx :community/mute-community-failed
|
(rf/reg-event-fx
|
||||||
|
:community/mute-community-failed
|
||||||
(fn [{:keys [db]} [community-id muted? error]]
|
(fn [{:keys [db]} [community-id muted? error]]
|
||||||
(log/error "mute community failed" community-id error)
|
(log/error "mute community failed" community-id error)
|
||||||
{:db (assoc-in db [:communities community-id :muted] (not muted?))
|
{:db (assoc-in db [:communities community-id :muted] (not muted?))
|
||||||
|
@ -22,15 +24,42 @@
|
||||||
(fn [{:keys [db]} [community-id muted? muted-till]]
|
(fn [{:keys [db]} [community-id muted? muted-till]]
|
||||||
(let [time-string (fn [mute-title mute-duration]
|
(let [time-string (fn [mute-title mute-duration]
|
||||||
(i18n/label mute-title {:duration mute-duration}))]
|
(i18n/label mute-title {:duration mute-duration}))]
|
||||||
{:db (assoc-in db [:communities community-id :muted-till] muted-till)
|
{:db (assoc-in db [:communities community-id :muted-till] muted-till)
|
||||||
:dispatch-n [[:community/update-community-chats-mute-status community-id muted? muted-till]
|
:fx [[:dispatch [:community/update-community-chats-mute-status community-id muted? muted-till]]
|
||||||
[:toasts/upsert
|
[:dispatch
|
||||||
{:type :positive
|
[:toasts/upsert
|
||||||
:text (if muted?
|
(cond-> {:type :positive
|
||||||
(when (some? muted-till)
|
:id :mute-community-toast
|
||||||
(time-string :t/muted-until
|
:text (if muted?
|
||||||
(muting.helpers/format-mute-till muted-till)))
|
(when (some? muted-till)
|
||||||
(i18n/label :t/community-unmuted))}]]})))
|
(time-string :t/muted-until
|
||||||
|
(muting.helpers/format-mute-till muted-till)))
|
||||||
|
(i18n/label :t/community-unmuted))}
|
||||||
|
muted? (assoc :duration constants/mute-undo-time-limit-ms
|
||||||
|
:undo-duration (/ constants/mute-undo-time-limit-ms 1000)
|
||||||
|
:undo-on-press #(rf/dispatch [:community/undo-mute
|
||||||
|
community-id])))]]]})))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:community/undo-mute
|
||||||
|
(fn [_ [community-id]]
|
||||||
|
{:fx [[:json-rpc/call
|
||||||
|
[{:method "wakuext_unMuteCommunityChats"
|
||||||
|
:params [community-id]
|
||||||
|
:on-error #(rf/dispatch [:community/mute-community-failed community-id false %])
|
||||||
|
:on-success #(rf/dispatch [:community/undo-mute-success community-id])}]]]}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:community/undo-mute-success
|
||||||
|
(fn [{:keys [db]} [community-id]]
|
||||||
|
{:db (update-in db
|
||||||
|
[:communities community-id]
|
||||||
|
(fn [community-id]
|
||||||
|
(-> community-id
|
||||||
|
(dissoc :muted-till)
|
||||||
|
(assoc :muted false))))
|
||||||
|
:fx [[:dispatch [:toasts/close :mute-community-toast]]
|
||||||
|
[:dispatch [:community/update-community-chats-mute-status community-id false nil]]]}))
|
||||||
|
|
||||||
(rf/reg-event-fx :community/set-muted
|
(rf/reg-event-fx :community/set-muted
|
||||||
(fn [{:keys [db]} [community-id muted? muted-type]]
|
(fn [{:keys [db]} [community-id muted? muted-type]]
|
||||||
|
|
|
@ -56,6 +56,22 @@
|
||||||
(h/wait-for [:chat/mute-successfully])
|
(h/wait-for [:chat/mute-successfully])
|
||||||
(is (not @(rf/subscribe [:chats/muted chat-id])))))))
|
(is (not @(rf/subscribe [:chats/muted chat-id])))))))
|
||||||
|
|
||||||
|
(deftest undo-mute-chat-test
|
||||||
|
(h/test-async ::undo-mute-chat
|
||||||
|
(fn []
|
||||||
|
(promesa/do
|
||||||
|
(rf/dispatch-sync [:chat.ui/start-chat chat-id])
|
||||||
|
(h/wait-for [:chat/one-to-one-chat-created])
|
||||||
|
(rf/dispatch-sync [:chat/navigate-to-chat chat-id])
|
||||||
|
|
||||||
|
(rf/dispatch-sync [:chat.ui/mute chat-id true constants/mute-till-unmuted])
|
||||||
|
(h/wait-for [:chat/mute-successfully :toasts/upsert])
|
||||||
|
(is @(rf/subscribe [:chats/muted chat-id]))
|
||||||
|
|
||||||
|
(rf/dispatch-sync [:chat.ui/undo-mute chat-id])
|
||||||
|
(h/wait-for [:chat/undo-mute-success :toasts/close])
|
||||||
|
(is (not @(rf/subscribe [:chats/muted chat-id])))))))
|
||||||
|
|
||||||
(deftest add-contact-test
|
(deftest add-contact-test
|
||||||
(h/test-async ::add-contact
|
(h/test-async ::add-contact
|
||||||
(fn []
|
(fn []
|
||||||
|
|
|
@ -2336,19 +2336,19 @@
|
||||||
"oct": "Oct",
|
"oct": "Oct",
|
||||||
"nov": "Nov",
|
"nov": "Nov",
|
||||||
"dec": "Dec",
|
"dec": "Dec",
|
||||||
"channel-muted-for-15-minutes": "Channel muted for 15 minutes\n (until {{duration}}) ",
|
"channel-muted-for-15-minutes": "Channel muted for 15 minutes \n(until {{duration}})",
|
||||||
"channel-muted-for-1-hour": "Channel muted for 1 hour\n (until {{duration}}) ",
|
"channel-muted-for-1-hour": "Channel muted for 1 hour \n(until {{duration}})",
|
||||||
"channel-muted-for-8-hours": "Channel muted for 8 hours\n (until {{duration}}) ",
|
"channel-muted-for-8-hours": "Channel muted for 8 hours \n(until {{duration}})",
|
||||||
"channel-muted-for-1-week": "Channel muted for 1 week \n (until {{duration}}) ",
|
"channel-muted-for-1-week": "Channel muted for 1 week \n(until {{duration}})",
|
||||||
"channel-muted-till-unmuted": "Channel muted till unmuted\n (until {{duration}}) ",
|
"channel-muted-till-unmuted": "Channel muted till unmuted \n(until {{duration}})",
|
||||||
"chat-muted-for-15-minutes": "Chat muted for 15 minutes\n (until {{duration}}) ",
|
"chat-muted-for-15-minutes": "Chat muted for 15 minutes \n(until {{duration}})",
|
||||||
"chat-muted-for-1-hour": "Chat muted for 1 hour\n (until {{duration}}) ",
|
"chat-muted-for-1-hour": "Chat muted for 1 hour \n(until {{duration}})",
|
||||||
"chat-muted-for-8-hours": "Chat muted for 8 hours\n (until {{duration}}) ",
|
"chat-muted-for-8-hours": "Chat muted for 8 hours \n(until {{duration}})",
|
||||||
"chat-muted-for-1-week": "Chat muted for 1 week\n (until {{duration}}) ",
|
"chat-muted-for-1-week": "Chat muted for 1 week \n(until {{duration}})",
|
||||||
"chat-muted-till-unmuted": "Chat muted till unmuted\n (until {{duration}}) ",
|
"chat-muted-till-unmuted": "Chat muted till unmuted \n(until {{duration}})",
|
||||||
"until": "until",
|
"until": "until",
|
||||||
"chat-unmuted-successfully": "Chat unmuted successfully! ",
|
"chat-unmuted-successfully": "Chat unmuted successfully!",
|
||||||
"channel-unmuted-successfully": "Channel 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",
|
"community-unmuted": "Community unmuted",
|
||||||
"all-time": "All time",
|
"all-time": "All time",
|
||||||
|
|
Loading…
Reference in New Issue