From 856bbb598cc9d158f62d97afb4a183e0a45fd216 Mon Sep 17 00:00:00 2001 From: RigidStudios <34319439+RigidStudios@users.noreply.github.com> Date: Mon, 1 Nov 2021 01:10:42 +0400 Subject: [PATCH] fix: muted channels no longer have new messages badge (#297) --- .../navigation/items/ButtonItem.tsx | 24 ++++++++++++++----- .../navigation/items/Item.module.scss | 4 ++++ .../navigation/left/ServerSidebar.tsx | 18 ++++++++++---- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/components/navigation/items/ButtonItem.tsx b/src/components/navigation/items/ButtonItem.tsx index 1f7d274c..58fe2745 100644 --- a/src/components/navigation/items/ButtonItem.tsx +++ b/src/components/navigation/items/ButtonItem.tsx @@ -31,6 +31,7 @@ type CommonProps = Omit< alert?: "unread" | "mention"; alertCount?: number; margin?: boolean; + muted?: boolean; }; type UserProps = CommonProps & { @@ -39,6 +40,7 @@ type UserProps = CommonProps & { channel?: Channel; }; +// TODO: Gray out blocked names. export const UserButton = observer((props: UserProps) => { const { active, @@ -132,8 +134,16 @@ type ChannelProps = CommonProps & { }; export const ChannelButton = observer((props: ChannelProps) => { - const { active, alert, alertCount, channel, user, compact, ...divProps } = - props; + const { + active, + alert, + alertCount, + channel, + user, + compact, + muted, + ...divProps + } = props; if (channel.channel_type === "SavedMessages") throw "Invalid channel type."; if (channel.channel_type === "DirectMessage") { @@ -147,12 +157,13 @@ export const ChannelButton = observer((props: ChannelProps) => {
{ {channel.channel_type === "Group" && (
{typeof channel.last_message?.content === "string" && - alert ? ( + alert && + !muted ? ( channel.last_message.content.slice(0, 32) ) : ( { )}
- {alert && ( + {alert && !muted && (
{alertCount}
diff --git a/src/components/navigation/items/Item.module.scss b/src/components/navigation/items/Item.module.scss index cd832493..a0148f7c 100644 --- a/src/components/navigation/items/Item.module.scss +++ b/src/components/navigation/items/Item.module.scss @@ -116,6 +116,10 @@ } } + &[data-muted="true"] { + color: var(--tertiary-foreground); + } + &[data-alert="true"], &[data-active="true"], &:hover { diff --git a/src/components/navigation/left/ServerSidebar.tsx b/src/components/navigation/left/ServerSidebar.tsx index c07601df..a28c54f4 100644 --- a/src/components/navigation/left/ServerSidebar.tsx +++ b/src/components/navigation/left/ServerSidebar.tsx @@ -7,10 +7,12 @@ import { useEffect } from "preact/hooks"; import ConditionalLink from "../../../lib/ConditionalLink"; import PaintCounter from "../../../lib/PaintCounter"; +import { internalEmit } from "../../../lib/eventEmitter"; import { isTouchscreenDevice } from "../../../lib/isTouchscreenDevice"; import { dispatch } from "../../../redux"; import { connectState } from "../../../redux/connector"; +import { Notifications } from "../../../redux/reducers/notifications"; import { Unreads } from "../../../redux/reducers/unreads"; import { useClient } from "../../../context/revoltjs/RevoltClient"; @@ -22,10 +24,10 @@ import { mapChannelWithUnread, useUnreads } from "./common"; import { ChannelButton } from "../items/ButtonItem"; import ConnectionStatus from "../items/ConnectionStatus"; -import { internalEmit } from "../../../lib/eventEmitter"; interface Props { unreads: Unreads; + notifications: Notifications; } const ServerBase = styled.div` @@ -65,7 +67,12 @@ const ServerSidebar = observer((props: Props) => { const channel = channel_id ? client.channels.get(channel_id) : undefined; // The user selected no channel, let's see if there's a channel available - if (!channel && server.channel_ids.length > 0) return ; + if (!channel && server.channel_ids.length > 0) + return ( + + ); if (channel_id && !channel) return ; if (channel) useUnreads({ ...props, channel }); @@ -88,10 +95,11 @@ const ServerSidebar = observer((props: Props) => { if (!entry) return; const active = channel?._id === entry._id; + const muted = props.notifications[id] === "muted"; return ( { + onClick={(e) => { if (e.shiftKey) { internalEmit( "MessageBox", @@ -99,7 +107,7 @@ const ServerSidebar = observer((props: Props) => { `<#${entry._id}>`, "channel_mention", ); - e.preventDefault() + e.preventDefault(); } }} key={entry._id} @@ -111,6 +119,7 @@ const ServerSidebar = observer((props: Props) => { // ! FIXME: pull it out directly alert={mapChannelWithUnread(entry, props.unreads).unread} compact + muted={muted} /> ); @@ -157,5 +166,6 @@ const ServerSidebar = observer((props: Props) => { export default connectState(ServerSidebar, (state) => { return { unreads: state.unreads, + notifications: state.notifications, }; });