From 70ffd7ded8d18906a615a8815fad06c1181f0e13 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Tue, 15 Mar 2022 17:21:36 +0530 Subject: [PATCH] Fix muted room show unread indicator (#386) * Move getNotifType function Signed-off-by: Ajay Bura * Fix bug in getNotiType Signed-off-by: Ajay Bura * Add isMuted prop in room selector Signed-off-by: Ajay Bura * Fix muted room show unread indicator Signed-off-by: Ajay Bura * Fix muted room notification visible in space Signed-off-by: Ajay Bura * Fix space shows muted room notification on load Signed-off-by: Ajay Bura * Toggle room mute when changed from other client Signed-off-by: Ajay Bura --- .../room-notification/RoomNotification.jsx | 28 ++------ .../molecules/room-selector/RoomSelector.jsx | 18 +++-- .../molecules/room-selector/RoomSelector.scss | 4 ++ src/app/organisms/navigation/Directs.jsx | 2 + src/app/organisms/navigation/Home.jsx | 2 + .../organisms/navigation/RoomsCategory.jsx | 2 +- src/app/organisms/navigation/Selector.jsx | 7 +- src/client/state/Notifications.js | 72 +++++++++++++++++++ src/client/state/cons.js | 1 + 9 files changed, 106 insertions(+), 30 deletions(-) diff --git a/src/app/molecules/room-notification/RoomNotification.jsx b/src/app/molecules/room-notification/RoomNotification.jsx index 5d11863..26d123b 100644 --- a/src/app/molecules/room-notification/RoomNotification.jsx +++ b/src/app/molecules/room-notification/RoomNotification.jsx @@ -32,28 +32,9 @@ const items = [{ type: cons.notifs.MUTE, }]; -function getNotifType(roomId) { - const mx = initMatrix.matrixClient; - const pushRule = mx.getRoomPushRule('global', roomId); - - if (typeof pushRule === 'undefined') { - const overridePushRules = mx.getAccountData('m.push_rules')?.getContent()?.global?.override; - if (typeof overridePushRules === 'undefined') return 0; - - const isMuteOverride = overridePushRules.find((rule) => ( - rule.rule_id === roomId - && rule.actions[0] === 'dont_notify' - && rule.conditions[0].kind === 'event_match' - )); - - return isMuteOverride ? cons.notifs.MUTE : cons.notifs.DEFAULT; - } - if (pushRule.actions[0] === 'notify') return cons.notifs.ALL_MESSAGES; - return cons.notifs.MENTIONS_AND_KEYWORDS; -} - function setRoomNotifType(roomId, newType) { const mx = initMatrix.matrixClient; + const { notifications } = initMatrix; const roomPushRule = mx.getRoomPushRule('global', roomId); const promises = []; @@ -76,7 +57,7 @@ function setRoomNotifType(roomId, newType) { return promises; } - const oldState = getNotifType(roomId); + const oldState = notifications.getNotiType(roomId); if (oldState === cons.notifs.MUTE) { promises.push(mx.deletePushRule('global', 'override', roomId)); } @@ -115,8 +96,9 @@ function setRoomNotifType(roomId, newType) { } function useNotifications(roomId) { - const [activeType, setActiveType] = useState(getNotifType(roomId)); - useEffect(() => setActiveType(getNotifType(roomId)), [roomId]); + const { notifications } = initMatrix; + const [activeType, setActiveType] = useState(notifications.getNotiType(roomId)); + useEffect(() => setActiveType(notifications.getNotiType(roomId)), [roomId]); const setNotification = useCallback((item) => { if (item.type === activeType.type) return; diff --git a/src/app/molecules/room-selector/RoomSelector.jsx b/src/app/molecules/room-selector/RoomSelector.jsx index 8bd6c20..fa6daa9 100644 --- a/src/app/molecules/room-selector/RoomSelector.jsx +++ b/src/app/molecules/room-selector/RoomSelector.jsx @@ -11,13 +11,16 @@ import NotificationBadge from '../../atoms/badge/NotificationBadge'; import { blurOnBubbling } from '../../atoms/button/script'; function RoomSelectorWrapper({ - isSelected, isUnread, onClick, + isSelected, isMuted, isUnread, onClick, content, options, onContextMenu, }) { - let myClass = isUnread ? ' room-selector--unread' : ''; - myClass += isSelected ? ' room-selector--selected' : ''; + const classes = ['room-selector']; + if (isMuted) classes.push('room-selector--muted'); + if (isUnread) classes.push('room-selector--unread'); + if (isSelected) classes.push('room-selector--selected'); + return ( -
+