From f055b78d970a59ebae06d9e97faa6f55325b9fd0 Mon Sep 17 00:00:00 2001 From: DomW Date: Sun, 2 Mar 2025 11:48:19 +0000 Subject: [PATCH] =?UTF-8?q?Revert=20"feat:=20rebuild=20muting/unmuting=20r?= =?UTF-8?q?oom=20functionality=20using=20matrix=20push=20ru=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 264992b49f52ba68f3add4cee86eefdf3d2f017e. --- src/apps/feed/components/sidekick/index.tsx | 18 +--- .../feed/components/sidekick/lib/selectors.ts | 12 --- .../components/sidekick/lib/useSidekick.ts | 5 +- .../components/sidekick/styles.module.scss | 8 -- src/components/app-bar/container.tsx | 8 +- .../conversation-actions/container.tsx | 16 ++-- .../list/conversation-item/index.test.tsx | 5 +- .../list/conversation-item/index.tsx | 6 +- .../notifications-feed/index.test.tsx | 10 +- src/components/notifications-feed/index.tsx | 8 +- src/lib/chat/index.ts | 9 -- src/lib/chat/matrix-client.ts | 95 +------------------ src/store/channels/index.ts | 9 +- src/store/channels/saga.test.ts | 62 +----------- src/store/channels/saga.ts | 33 ------- src/store/chat/bus.ts | 4 - src/store/messages/saga.test.ts | 2 +- src/store/messages/saga.ts | 7 +- 18 files changed, 40 insertions(+), 277 deletions(-) diff --git a/src/apps/feed/components/sidekick/index.tsx b/src/apps/feed/components/sidekick/index.tsx index ad94246e3..533a6ccc2 100644 --- a/src/apps/feed/components/sidekick/index.tsx +++ b/src/apps/feed/components/sidekick/index.tsx @@ -9,23 +9,14 @@ import { CurrentUserDetails } from '../../../../components/sidekick/components/c import { ScrollbarContainer } from '../../../../components/scrollbar-container'; import { Input } from '@zero-tech/zui/components/Input/Input'; import { LoadingIndicator } from '@zero-tech/zui/components/LoadingIndicator'; -import { IconBellOff1, IconSearchMd } from '@zero-tech/zui/icons'; +import { IconSearchMd } from '@zero-tech/zui/icons'; import { Panel, PanelBody } from '../../../../components/layout/panel'; import styles from './styles.module.scss'; export const Sidekick = () => { - const { - isErrorZids, - isLoadingZids, - isProfileOpen, - selectedZId, - zids, - search, - setSearch, - unreadCounts, - isMutedChannels, - } = useSidekick(); + const { isErrorZids, isLoadingZids, isProfileOpen, selectedZId, zids, search, setSearch, unreadCounts } = + useSidekick(); return ( @@ -55,7 +46,6 @@ export const Sidekick = () => { {zids?.map((zid) => { const hasUnreadHighlights = unreadCounts[zid]?.highlight > 0; const hasUnreadTotal = unreadCounts[zid]?.total > 0; - const isMuted = isMutedChannels[zid]; return ( @@ -63,8 +53,6 @@ export const Sidekick = () => { 0://
{zid}
- - {isMuted && } {!hasUnreadHighlights && hasUnreadTotal && (
{unreadCounts[zid]?.total}
)} diff --git a/src/apps/feed/components/sidekick/lib/selectors.ts b/src/apps/feed/components/sidekick/lib/selectors.ts index c0cd51803..16226c3cc 100644 --- a/src/apps/feed/components/sidekick/lib/selectors.ts +++ b/src/apps/feed/components/sidekick/lib/selectors.ts @@ -14,15 +14,3 @@ export const selectSocialChannelsUnreadCounts = createSelector( }, {} as { [zid: string]: UnreadCount }); } ); - -export const selectIsMutedChannels = createSelector( - [(state: RootState) => denormalizeConversations(state)], - (conversations) => { - return conversations - .filter((c) => c.isSocialChannel && c.zid) - .reduce((acc, channel) => { - acc[channel.zid!] = channel.isMuted; - return acc; - }, {} as { [zid: string]: boolean }); - } -); diff --git a/src/apps/feed/components/sidekick/lib/useSidekick.ts b/src/apps/feed/components/sidekick/lib/useSidekick.ts index c379c3c8e..0d418b22f 100644 --- a/src/apps/feed/components/sidekick/lib/useSidekick.ts +++ b/src/apps/feed/components/sidekick/lib/useSidekick.ts @@ -5,7 +5,7 @@ import { useSelector } from 'react-redux'; import { RootState } from '../../../../../store/reducer'; import { Stage as ProfileStage } from '../../../../../store/user-profile'; import { useState } from 'react'; -import { selectIsMutedChannels, selectSocialChannelsUnreadCounts } from './selectors'; +import { selectSocialChannelsUnreadCounts } from './selectors'; export interface UnreadCount { total: number; @@ -20,7 +20,6 @@ interface UseSidekickReturn { zids?: string[]; search: string; unreadCounts: { [zid: string]: UnreadCount }; - isMutedChannels: { [zid: string]: boolean }; setSearch: (search: string) => void; } @@ -40,7 +39,6 @@ export const useSidekick = (): UseSidekickReturn => { const filteredZids = uniqueWorldZids?.filter((zid) => zid.toLowerCase().includes(search.toLowerCase())); const unreadCounts = useSelector(selectSocialChannelsUnreadCounts); - const isMutedChannels = useSelector(selectIsMutedChannels); return { isErrorZids: isError, @@ -51,6 +49,5 @@ export const useSidekick = (): UseSidekickReturn => { search, setSearch, unreadCounts, - isMutedChannels, }; }; diff --git a/src/apps/feed/components/sidekick/styles.module.scss b/src/apps/feed/components/sidekick/styles.module.scss index 635852761..73b82bdd5 100644 --- a/src/apps/feed/components/sidekick/styles.module.scss +++ b/src/apps/feed/components/sidekick/styles.module.scss @@ -1,5 +1,3 @@ -@import '../../../../glass'; - .Container { width: 100%; max-width: 288px; @@ -144,9 +142,3 @@ line-height: 11px; letter-spacing: 0.32px; } - -.MutedIcon { - @include glass-text-tertiary-color; - - align-self: center; -} diff --git a/src/components/app-bar/container.tsx b/src/components/app-bar/container.tsx index 2197c7574..4955fc614 100644 --- a/src/components/app-bar/container.tsx +++ b/src/components/app-bar/container.tsx @@ -24,7 +24,9 @@ const useAppBar = () => { const conversations = denormalizeConversations(state); return conversations.some( (channel) => - channel.unreadCount?.total > 0 && !channel.labels?.includes(DefaultRoomLabels.ARCHIVED) && !channel.isMuted + channel.unreadCount?.total > 0 && + !channel.labels?.includes(DefaultRoomLabels.ARCHIVED) && + !channel.labels?.includes(DefaultRoomLabels.MUTE) ); }); @@ -32,7 +34,9 @@ const useAppBar = () => { const conversations = denormalizeConversations(state); return conversations.some( (channel) => - channel.unreadCount?.highlight > 0 && !channel.labels?.includes(DefaultRoomLabels.ARCHIVED) && !channel.isMuted + channel.unreadCount?.highlight > 0 && + !channel.labels?.includes(DefaultRoomLabels.ARCHIVED) && + !channel.labels?.includes(DefaultRoomLabels.MUTE) ); }); diff --git a/src/components/messenger/conversation-actions/container.tsx b/src/components/messenger/conversation-actions/container.tsx index d6a2691f0..37f8b7066 100644 --- a/src/components/messenger/conversation-actions/container.tsx +++ b/src/components/messenger/conversation-actions/container.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { RootState } from '../../../store/reducer'; import { connectContainer } from '../../../store/redux-container'; -import { Channel, denormalize, onMuteRoom, onUnmuteRoom } from '../../../store/channels'; +import { Channel, DefaultRoomLabels, denormalize, onAddLabel, onRemoveLabel } from '../../../store/channels'; import { currentUserSelector } from '../../../store/authentication/selectors'; import { startAddGroupMember, @@ -36,8 +36,8 @@ export interface Properties extends PublicProperties { setLeaveGroupStatus: (status: LeaveGroupDialogStatus) => void; viewGroupInformation: () => void; toggleSecondarySidekick: () => void; - onMuteRoom: (payload: { roomId: string }) => void; - onUnmuteRoom: (payload: { roomId: string }) => void; + onAddLabel: (payload: { roomId: string; label: string }) => void; + onRemoveLabel: (payload: { roomId: string; label: string }) => void; openReportUserModal: (payload: { reportedUserId: string }) => void; } @@ -83,8 +83,8 @@ export class Container extends React.Component { setLeaveGroupStatus, viewGroupInformation, toggleSecondarySidekick, - onMuteRoom, - onUnmuteRoom, + onAddLabel, + onRemoveLabel, openReportUserModal, }; } @@ -98,15 +98,15 @@ export class Container extends React.Component { }; muteRoom = () => { - this.props.onMuteRoom({ roomId: this.props.activeConversationId }); + this.props.onAddLabel({ roomId: this.props.activeConversationId, label: DefaultRoomLabels.MUTE }); }; unmuteRoom = () => { - this.props.onUnmuteRoom({ roomId: this.props.activeConversationId }); + this.props.onRemoveLabel({ roomId: this.props.activeConversationId, label: DefaultRoomLabels.MUTE }); }; get isMuted() { - return this.props.directMessage.isMuted; + return this.props.directMessage.labels?.includes(DefaultRoomLabels.MUTE); } render() { diff --git a/src/components/messenger/list/conversation-item/index.test.tsx b/src/components/messenger/list/conversation-item/index.test.tsx index 140c889b3..31aee989e 100644 --- a/src/components/messenger/list/conversation-item/index.test.tsx +++ b/src/components/messenger/list/conversation-item/index.test.tsx @@ -6,6 +6,7 @@ import { ContentHighlighter } from '../../../content-highlighter'; import { Avatar } from '@zero-tech/zui/components'; import { bem } from '../../../../lib/bem'; import { IconBellOff1 } from '@zero-tech/zui/icons'; +import { DefaultRoomLabels } from '../../../../store/channels'; const c = bem('.conversation-item'); @@ -66,7 +67,7 @@ describe(ConversationItem, () => { it('renders muted icon if conversation is muted', function () { const wrapper = subject({ - conversation: { ...convoWith(), id: 'test-conversation-id', isMuted: true }, + conversation: { ...convoWith(), id: 'test-conversation-id', labels: [DefaultRoomLabels.MUTE] }, }); expect(wrapper).toHaveElement(IconBellOff1); @@ -74,7 +75,7 @@ describe(ConversationItem, () => { it('does not render muted icon if conversation is not muted', function () { const wrapper = subject({ - conversation: { ...convoWith(), id: 'test-conversation-id', isMuted: false }, + conversation: { ...convoWith(), id: 'test-conversation-id', labels: [] }, }); expect(wrapper).not.toHaveElement(IconBellOff1); diff --git a/src/components/messenger/list/conversation-item/index.tsx b/src/components/messenger/list/conversation-item/index.tsx index 1aed2a84f..73e15f09c 100644 --- a/src/components/messenger/list/conversation-item/index.tsx +++ b/src/components/messenger/list/conversation-item/index.tsx @@ -2,7 +2,7 @@ import * as React from 'react'; import { otherMembersToString } from '../../../../platform-apps/channels/util'; import { getOtherMembersTypingDisplayText, highlightFilter } from '../../lib/utils'; -import { Channel } from '../../../../store/channels'; +import { Channel, DefaultRoomLabels } from '../../../../store/channels'; import { MoreMenu } from './more-menu'; import { Avatar } from '@zero-tech/zui/components'; @@ -152,7 +152,9 @@ export class ConversationItem extends React.Component {
{this.highlightedName()}
- {conversation.isMuted && } + {conversation.labels?.includes(DefaultRoomLabels.MUTE) && ( + + )}
{previewDisplayDate}
diff --git a/src/components/notifications-feed/index.test.tsx b/src/components/notifications-feed/index.test.tsx index 3b73a6bdb..c614eb7c4 100644 --- a/src/components/notifications-feed/index.test.tsx +++ b/src/components/notifications-feed/index.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { Container } from './index'; import { NotificationItem } from './notification-item'; -import { Channel } from '../../store/channels'; +import { Channel, DefaultRoomLabels } from '../../store/channels'; describe('NotificationsFeed', () => { const mockConversations: Channel[] = [ @@ -49,13 +49,13 @@ describe('NotificationsFeed', () => { id: 'channel-1', unreadCount: { total: 3, highlight: 0 }, name: 'Regular Chat', - isMuted: false, + labels: [], }, { id: 'channel-2', unreadCount: { total: 1, highlight: 1 }, name: 'Muted Chat', - isMuted: true, + labels: [DefaultRoomLabels.MUTE], }, ] as Channel[]; @@ -95,13 +95,13 @@ describe('NotificationsFeed', () => { id: 'channel-1', unreadCount: { total: 3, highlight: 0 }, name: 'Regular Chat', - isMuted: false, + labels: [], }, { id: 'channel-2', unreadCount: { total: 1, highlight: 1 }, name: 'Muted Chat', - isMuted: true, + labels: [DefaultRoomLabels.MUTE], }, ] as Channel[]; diff --git a/src/components/notifications-feed/index.tsx b/src/components/notifications-feed/index.tsx index 4727eb734..0c5838def 100644 --- a/src/components/notifications-feed/index.tsx +++ b/src/components/notifications-feed/index.tsx @@ -80,19 +80,21 @@ export class Container extends React.Component { (conversation) => conversation.unreadCount?.highlight > 0 && !conversation.labels?.includes(DefaultRoomLabels.ARCHIVED) && - !conversation.isMuted + !conversation.labels?.includes(DefaultRoomLabels.MUTE) ); case Tab.Muted: return conversations.filter( (conversation) => - conversation.isMuted && + conversation.labels?.includes(DefaultRoomLabels.MUTE) && !conversation.labels?.includes(DefaultRoomLabels.ARCHIVED) && (conversation.unreadCount?.total > 0 || conversation.unreadCount?.highlight > 0) ); case Tab.All: default: return conversations.filter( - (conversation) => !conversation.labels?.includes(DefaultRoomLabels.ARCHIVED) && !conversation.isMuted + (conversation) => + !conversation.labels?.includes(DefaultRoomLabels.ARCHIVED) && + !conversation.labels?.includes(DefaultRoomLabels.MUTE) ); } } diff --git a/src/lib/chat/index.ts b/src/lib/chat/index.ts index 371c13dcd..d619cdfc4 100644 --- a/src/lib/chat/index.ts +++ b/src/lib/chat/index.ts @@ -24,7 +24,6 @@ export interface RealtimeChatEvents { roomLabelChange: (roomId: string, labels: string[]) => void; postMessageReactionChange: (roomId: string, reaction: any) => void; messageEmojiReactionChange: (roomId: string, reaction: any) => void; - roomMuteStatusChanged: (roomId: string, isMuted: boolean) => void; } export interface MatrixKeyBackupInfo { @@ -439,11 +438,3 @@ export function getProfileInfo(userId: string): Promise<{ export async function getAliasForRoomId(roomId: string) { return chat.get().matrix.getAliasForRoomId(roomId); } - -export async function muteRoom(roomId: string) { - return await chat.get().matrix.muteRoom(roomId); -} - -export async function unmuteRoom(roomId: string) { - return await chat.get().matrix.unmuteRoom(roomId); -} diff --git a/src/lib/chat/matrix-client.ts b/src/lib/chat/matrix-client.ts index 751ba2289..c16fa3062 100644 --- a/src/lib/chat/matrix-client.ts +++ b/src/lib/chat/matrix-client.ts @@ -19,7 +19,6 @@ import { IRoomTimelineData, RoomMember, ReceiptType, - PushRuleKind, } from 'matrix-js-sdk'; import { RealtimeChatEvents, IChatClient } from './'; import { @@ -1249,52 +1248,6 @@ export class MatrixClient implements IChatClient { await this.matrix.deleteRoomTag(roomId, label); } - async muteRoom(roomId: string): Promise { - await this.waitForConnection(); - - const rule = { - actions: ['dont_notify'], - conditions: [ - { - kind: 'event_match' as any, - key: 'room_id', - pattern: roomId, - }, - ], - } as any; - - try { - // Try to add a new push rule - await this.matrix.addPushRule('global', PushRuleKind.Override, roomId, rule); - } catch (error: any) { - // If the rule already exists, update it - if (error.errcode === 'M_UNKNOWN') { - await this.matrix.setPushRuleEnabled('global', PushRuleKind.Override, roomId, true); - await this.matrix.setPushRuleActions('global', PushRuleKind.Override, roomId, ['dont_notify'] as any); - } else { - throw error; - } - } - this.events.roomMuteStatusChanged(roomId, true); - } - - async unmuteRoom(roomId: string): Promise { - await this.waitForConnection(); - - try { - // Try to delete the push rule - await this.matrix.deletePushRule('global', PushRuleKind.Override, roomId); - } catch (error: any) { - // If the rule doesn't exist, that's fine - if (error.errcode !== 'M_NOT_FOUND') { - // Try disabling the rule instead - await this.matrix.setPushRuleEnabled('global', PushRuleKind.Override, roomId, false); - } - // If M_NOT_FOUND, we don't need to do anything as the room is already unmuted - } - this.events.roomMuteStatusChanged(roomId, false); - } - async sendTypingEvent(roomId: string, isTyping: boolean): Promise { await this.waitForConnection(); @@ -1417,12 +1370,6 @@ export class MatrixClient implements IChatClient { } }); - this.matrix.on(ClientEvent.AccountData, (event) => { - if (event.getType() === EventType.PushRules) { - this.publishRoomMuteStatusChanged(event); - } - }); - this.matrix.on(RoomEvent.Name, this.publishRoomNameChange); this.matrix.on(RoomMemberEvent.Typing, this.publishRoomMemberTyping); this.matrix.on(RoomMemberEvent.PowerLevel, this.publishRoomMemberPowerLevelsChanged); @@ -1627,26 +1574,6 @@ export class MatrixClient implements IChatClient { this.events.roomLabelChange(roomId, tagKeys); } - private publishRoomMuteStatusChanged = (event) => { - const pushRules = event.getContent(); - - if (pushRules?.global?.override) { - pushRules.global.override.forEach((rule) => { - const roomCondition = rule.conditions?.find( - (condition) => condition.kind === 'event_match' && condition.key === 'room_id' - ); - - if (roomCondition) { - const roomId = roomCondition.pattern; - // A room is muted if the rule is enabled and has "dont_notify" action - const isMuted = rule.enabled && rule.actions.some((action) => action === 'dont_notify'); - - this.events.roomMuteStatusChanged(roomId, isMuted); - } - }); - } - }; - private publishReceiptEvent(event: MatrixEvent, room: Room) { const content = event.getContent(); for (const eventId in content) { @@ -1666,8 +1593,6 @@ export class MatrixClient implements IChatClient { const avatarUrl = this.getRoomAvatar(room); const createdAt = this.getRoomCreatedAt(room); const groupType = this.getRoomGroupType(room); - const isSocialChannel = groupType === 'social'; - const isMuted = this.getRoomMuteStatus(room); featureFlags.enableTimerLogs && console.time(`xxxgetUpToLatestUserMessageFromRoom${room.roomId}`); const messages = await this.getUpToLatestUserMessageFromRoom(room); @@ -1677,6 +1602,7 @@ export class MatrixClient implements IChatClient { const highlightCount = room.getUnreadNotificationCount(NotificationCountType.Highlight); const [admins, mods] = this.getRoomAdminsAndMods(room); + const isSocialChannel = groupType === 'social'; const result = { id: room.roomId, @@ -1696,7 +1622,6 @@ export class MatrixClient implements IChatClient { moderatorIds: mods, labels: [], isSocialChannel, - isMuted, // this isn't the best way to get the zid as it relies on the name format, but it's a quick fix zid: isSocialChannel ? name?.split('://')[1] : null, }; @@ -1739,24 +1664,6 @@ export class MatrixClient implements IChatClient { return roomAvatarEvent?.getContent()?.url; } - private getRoomMuteStatus(room: Room): boolean { - if (!room.client?.pushRules?.global?.override) { - return false; - } - - const muteRule = room.client.pushRules.global.override.find((rule) => { - const roomCondition = rule.conditions?.find( - (condition) => - condition.kind === 'event_match' && condition.key === 'room_id' && condition.pattern === room.roomId - ); - - // A room is muted if there's a matching condition, the rule is enabled, and has "dont_notify" action - return roomCondition && rule.enabled && rule.actions.some((action) => action === 'dont_notify'); - }); - - return !!muteRule; - } - private getRoomCreatedAt(room: Room): number { return this.getLatestEvent(room, EventType.RoomCreate)?.getTs() || 0; } diff --git a/src/store/channels/index.ts b/src/store/channels/index.ts index 2e74dbd71..a3cd7e2c6 100644 --- a/src/store/channels/index.ts +++ b/src/store/channels/index.ts @@ -41,6 +41,7 @@ export enum DefaultRoomLabels { SOCIAL = 'm.social', ARCHIVED = 'm.archived', FAVORITE = 'm.favorite', + MUTE = 'm.mute', } export interface Channel { @@ -67,7 +68,6 @@ export interface Channel { labels?: string[]; isSocialChannel?: boolean; zid?: string; - isMuted?: boolean; } export const CHANNEL_DEFAULTS = { @@ -92,7 +92,6 @@ export const CHANNEL_DEFAULTS = { labels: [], isSocialChannel: false, zid: null, - isMuted: false, }; export enum SagaActionTypes { @@ -103,8 +102,6 @@ export enum SagaActionTypes { UserTypingInRoom = 'channels/saga/userTypingInRoom', OnAddLabel = 'channels/saga/onAddLabel', OnRemoveLabel = 'channels/saga/onRemoveLabel', - OnMuteRoom = 'channels/saga/onMuteRoom', - OnUnmuteRoom = 'channels/saga/onUnmuteRoom', } const openConversation = createAction<{ conversationId: string }>(SagaActionTypes.OpenConversation); @@ -114,8 +111,6 @@ const onRemoveReply = createAction(SagaActionTypes.OnRemoveReply); const userTypingInRoom = createAction<{ roomId: string }>(SagaActionTypes.UserTypingInRoom); const onAddLabel = createAction<{ roomId: string; label: string }>(SagaActionTypes.OnAddLabel); const onRemoveLabel = createAction<{ roomId: string; label: string }>(SagaActionTypes.OnRemoveLabel); -const onMuteRoom = createAction<{ roomId: string }>(SagaActionTypes.OnMuteRoom); -const onUnmuteRoom = createAction<{ roomId: string }>(SagaActionTypes.OnUnmuteRoom); const slice = createNormalizedSlice({ name: 'channels', @@ -137,6 +132,4 @@ export { userTypingInRoom, onAddLabel, onRemoveLabel, - onMuteRoom, - onUnmuteRoom, }; diff --git a/src/store/channels/saga.test.ts b/src/store/channels/saga.test.ts index e6b7aaf8e..17bc13014 100644 --- a/src/store/channels/saga.test.ts +++ b/src/store/channels/saga.test.ts @@ -12,15 +12,12 @@ import { onAddLabel, onRemoveLabel, roomLabelChange, - onMuteRoom, - onUnmuteRoom, - receivedRoomMuteStatusChanged, } from './saga'; import { rootReducer } from '../reducer'; import { ConversationStatus, DefaultRoomLabels, denormalize as denormalizeChannel } from '../channels'; import { StoreBuilder } from '../test/store'; -import { addRoomToLabel, chat, muteRoom, removeRoomFromLabel, sendTypingEvent, unmuteRoom } from '../../lib/chat'; +import { addRoomToLabel, chat, removeRoomFromLabel, sendTypingEvent } from '../../lib/chat'; import { getHistory } from '../../lib/browser'; const userId = 'user-id'; @@ -192,62 +189,6 @@ describe(roomLabelChange, () => { }); }); -describe(onMuteRoom, () => { - it('calls muteRoom with the roomId', async () => { - const initialState = new StoreBuilder().withConversationList({ id: 'room-id', isMuted: false }).build(); - - await expectSaga(onMuteRoom, { payload: { roomId: 'room-id' } }) - .withReducer(rootReducer, initialState) - .provide([ - [matchers.call.fn(muteRoom), undefined], - ]) - .call(muteRoom, 'room-id') - .run(); - }); -}); - -describe(onUnmuteRoom, () => { - it('calls unmuteRoom with the roomId', async () => { - const initialState = new StoreBuilder().withConversationList({ id: 'room-id', isMuted: true }).build(); - - await expectSaga(onUnmuteRoom, { payload: { roomId: 'room-id' } }) - .withReducer(rootReducer, initialState) - .provide([ - [matchers.call.fn(unmuteRoom), undefined], - ]) - .call(unmuteRoom, 'room-id') - .run(); - }); -}); - -describe(receivedRoomMuteStatusChanged, () => { - it('updates room mute status to true', async () => { - const initialState = new StoreBuilder().withConversationList({ id: 'room-id', isMuted: false }).build(); - - const { storeState } = await expectSaga(receivedRoomMuteStatusChanged, { - payload: { roomId: 'room-id', isMuted: true }, - }) - .withReducer(rootReducer, initialState) - .run(); - - const channel = denormalizeChannel('room-id', storeState); - expect(channel.isMuted).toEqual(true); - }); - - it('updates room mute status to false', async () => { - const initialState = new StoreBuilder().withConversationList({ id: 'room-id', isMuted: true }).build(); - - const { storeState } = await expectSaga(receivedRoomMuteStatusChanged, { - payload: { roomId: 'room-id', isMuted: false }, - }) - .withReducer(rootReducer, initialState) - .run(); - - const channel = denormalizeChannel('room-id', storeState); - expect(channel.isMuted).toEqual(false); - }); -}); - describe(publishUserTypingEvent, () => { it('sends typing event', async () => { const initialState = new StoreBuilder().withConversationList({ id: 'room-id' }).build(); @@ -387,6 +328,5 @@ const CHANNEL_DEFAULTS = { otherMembersTyping: [], labels: [], isSocialChannel: false, - isMuted: false, zid: null, }; diff --git a/src/store/channels/saga.ts b/src/store/channels/saga.ts index 0ffa21aa7..e8e5cdd0b 100644 --- a/src/store/channels/saga.ts +++ b/src/store/channels/saga.ts @@ -9,8 +9,6 @@ import { sendTypingEvent as matrixSendUserTypingEvent, addRoomToLabel, removeRoomFromLabel, - muteRoom, - unmuteRoom, } from '../../lib/chat'; import { mostRecentConversation } from '../channels-list/selectors'; import { setActiveConversation } from '../chat/saga'; @@ -175,34 +173,6 @@ export function* roomLabelChange(action) { } } -export function* onMuteRoom(action) { - const { roomId } = action.payload; - try { - yield call(muteRoom, roomId); - } catch (error) { - console.error(`Failed to mute room ${roomId}:`, error); - } -} - -export function* onUnmuteRoom(action) { - const { roomId } = action.payload; - try { - yield call(unmuteRoom, roomId); - } catch (error) { - console.error(`Failed to unmute room ${roomId}:`, error); - } -} - -export function* receivedRoomMuteStatusChanged(action) { - const { roomId, isMuted } = action.payload; - - try { - yield call(receiveChannel, { id: roomId, isMuted }); - } catch (error) { - console.error(`Failed to update mute status for room ${roomId}:`, error); - } -} - export function* receivedRoomMembersTyping(action) { const { roomId, userIds: matrixIds } = action.payload; @@ -285,13 +255,10 @@ export function* saga() { yield takeLatest(SagaActionTypes.OnRemoveReply, onRemoveReply); yield takeLatest(SagaActionTypes.OnAddLabel, onAddLabel); yield takeLatest(SagaActionTypes.OnRemoveLabel, onRemoveLabel); - yield takeLatest(SagaActionTypes.OnMuteRoom, onMuteRoom); - yield takeLatest(SagaActionTypes.OnUnmuteRoom, onUnmuteRoom); yield takeEveryFromBus(yield call(getChatBus), ChatEvents.UnreadCountChanged, unreadCountUpdated); yield takeEveryFromBus(yield call(getChatBus), ChatEvents.RoomMemberTyping, receivedRoomMembersTyping); yield takeEveryFromBus(yield call(getChatBus), ChatEvents.RoomLabelChange, roomLabelChange); - yield takeEveryFromBus(yield call(getChatBus), ChatEvents.RoomMuteStatusChanged, receivedRoomMuteStatusChanged); yield takeEveryFromBus( yield call(getChatBus), ChatEvents.RoomMemberPowerLevelChanged, diff --git a/src/store/chat/bus.ts b/src/store/chat/bus.ts index 05699083c..a9e394aff 100644 --- a/src/store/chat/bus.ts +++ b/src/store/chat/bus.ts @@ -24,7 +24,6 @@ export enum Events { RoomLabelChange = 'chat/channel/roomLabelChange', PostMessageReactionChange = 'chat/message/postMessageReactionChange', MessageEmojiReactionChange = 'chat/message/messageEmojiReactionChange', - RoomMuteStatusChanged = 'chat/channel/roomMuteStatusChanged', } let theBus; @@ -103,8 +102,6 @@ export function createChatConnection(userId, chatAccessToken, chatClient: Chat) emit({ type: Events.PostMessageReactionChange, payload: { roomId, reaction } }); const messageEmojiReactionChange = (roomId, reaction) => emit({ type: Events.MessageEmojiReactionChange, payload: { roomId, reaction } }); - const roomMuteStatusChanged = (roomId, isMuted) => - emit({ type: Events.RoomMuteStatusChanged, payload: { roomId, isMuted } }); chatClient.initChat({ receiveNewMessage, @@ -125,7 +122,6 @@ export function createChatConnection(userId, chatAccessToken, chatClient: Chat) roomLabelChange, postMessageReactionChange, messageEmojiReactionChange, - roomMuteStatusChanged, }); connectionPromise = chatClient.connect(userId, chatAccessToken); diff --git a/src/store/messages/saga.test.ts b/src/store/messages/saga.test.ts index eaa44e6dc..b3ba13f8c 100644 --- a/src/store/messages/saga.test.ts +++ b/src/store/messages/saga.test.ts @@ -135,7 +135,7 @@ describe('messages saga', () => { const initialState = { normalized: { channels: { - 'room-id-1': { isMuted: true }, + 'room-id-1': { labels: [DefaultRoomLabels.MUTE] }, }, }, }; diff --git a/src/store/messages/saga.ts b/src/store/messages/saga.ts index f7c006ed3..737d55ec4 100644 --- a/src/store/messages/saga.ts +++ b/src/store/messages/saga.ts @@ -97,10 +97,6 @@ export const roomLabelSelector = (channelId) => (state) => { return getDeepProperty(state, `normalized.channels['${channelId}'].labels`, []); }; -export const isMutedSelector = (roomId) => (state) => { - return getDeepProperty(state, `normalized.channels['${roomId}'].isMuted`, false); -}; - export function* getLocalZeroUsersMap() { const users = yield select((state) => state.normalized.users || {}); const zeroUsersMap: { [matrixId: string]: User } = {}; @@ -578,8 +574,7 @@ export function* sendBrowserNotification(eventData) { if (isOwner(yield select(currentUserSelector()), eventData.sender?.userId)) return; const roomLabels = yield select(roomLabelSelector(eventData?.roomId)); - const isMuted = yield select(isMutedSelector(eventData?.roomId)); - if (isMuted || roomLabels?.includes(DefaultRoomLabels.ARCHIVED)) return; + if (roomLabels?.includes(DefaultRoomLabels.MUTE) || roomLabels?.includes(DefaultRoomLabels.ARCHIVED)) return; if (eventData.type === NotifiableEventType.RoomMessage) { yield call(sendBrowserMessage, mapMessage(eventData));