From 6be95b717769756579f6d1a1457f021aa3d4e2ae Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 7 Jul 2023 11:52:44 +0200 Subject: [PATCH] fix: notif settings in list item convoId from contextprovider --- ts/components/menu/Menu.tsx | 45 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/ts/components/menu/Menu.tsx b/ts/components/menu/Menu.tsx index d1010df93..695d0acf9 100644 --- a/ts/components/menu/Menu.tsx +++ b/ts/components/menu/Menu.tsx @@ -6,6 +6,7 @@ import { useAvatarPath, useConversationUsername, useHasNickname, + useIsActive, useIsBlinded, useIsBlocked, useIsIncomingRequest, @@ -15,6 +16,7 @@ import { useIsPrivate, useIsPrivateAndFriend, useIsPublic, + useNotificationSetting, useWeAreAdmin, } from '../../hooks/useParamSelector'; import { @@ -35,6 +37,10 @@ import { showUpdateGroupNameByConvoId, unblockConvoById, } from '../../interactions/conversationInteractions'; +import { + ConversationNotificationSetting, + ConversationNotificationSettingType, +} from '../../models/conversationAttributes'; import { getConversationController } from '../../session/conversations'; import { PubKey } from '../../session/types'; import { @@ -43,23 +49,10 @@ import { updateUserDetailsModal, } from '../../state/ducks/modalDialog'; import { getIsMessageSection } from '../../state/selectors/section'; -import { - useSelectedConversationKey, - useSelectedIsActive, - useSelectedIsBlocked, - useSelectedIsKickedFromGroup, - useSelectedIsLeft, - useSelectedIsPrivate, - useSelectedIsPrivateFriend, - useSelectedNotificationSetting, -} from '../../state/selectors/selectedConversation'; +import { useSelectedConversationKey } from '../../state/selectors/selectedConversation'; +import { LocalizerKeys } from '../../types/LocalizerKeys'; import { SessionButtonColor } from '../basic/SessionButton'; import { useConvoIdFromContext } from '../leftpane/conversation-list-item/ConvoIdContext'; -import { - ConversationNotificationSetting, - ConversationNotificationSettingType, -} from '../../models/conversationAttributes'; -import { LocalizerKeys } from '../../types/LocalizerKeys'; /** Menu items standardized */ @@ -556,18 +549,20 @@ export const DeclineAndBlockMsgRequestMenuItem = () => { }; export const NotificationForConvoMenuItem = (): JSX.Element | null => { - const selectedConvoId = useSelectedConversationKey(); + // Note: this item is used in the header and in the list item, so we need to grab the details + // from the convoId from the context itself, not the redux selected state + const convoId = useConvoIdFromContext(); - const currentNotificationSetting = useSelectedNotificationSetting(); - const isBlocked = useSelectedIsBlocked(); - const isActive = useSelectedIsActive(); - const isLeft = useSelectedIsLeft(); - const isKickedFromGroup = useSelectedIsKickedFromGroup(); - const isFriend = useSelectedIsPrivateFriend(); - const isPrivate = useSelectedIsPrivate(); + const currentNotificationSetting = useNotificationSetting(convoId); + const isBlocked = useIsBlocked(convoId); + const isActive = useIsActive(convoId); + const isLeft = useIsLeft(convoId); + const isKickedFromGroup = useIsKickedFromGroup(convoId); + const isFriend = useIsPrivateAndFriend(convoId); + const isPrivate = useIsPrivate(convoId); if ( - !selectedConvoId || + !convoId || isLeft || isKickedFromGroup || isBlocked || @@ -606,7 +601,7 @@ export const NotificationForConvoMenuItem = (): JSX.Element | null => { { - await setNotificationForConvoId(selectedConvoId, item.value); + await setNotificationForConvoId(convoId, item.value); }} disabled={disabled} >