diff --git a/ts/components/conversation/MessageRequestButtons.tsx b/ts/components/conversation/MessageRequestButtons.tsx index ffdc58b7c..13872f90d 100644 --- a/ts/components/conversation/MessageRequestButtons.tsx +++ b/ts/components/conversation/MessageRequestButtons.tsx @@ -6,10 +6,7 @@ import { declineConversationWithConfirm, } from '../../interactions/conversationInteractions'; import { getConversationController } from '../../session/conversations'; -import { - getSelectedHasMessages, - hasSelectedConversationIncomingMessages, -} from '../../state/selectors/conversations'; +import { hasSelectedConversationIncomingMessages } from '../../state/selectors/conversations'; import { useSelectedConversationKey } from '../../state/selectors/selectedConversation'; import { SessionButton, SessionButtonColor } from '../basic/SessionButton'; import { @@ -81,10 +78,9 @@ const handleAcceptConversationRequest = async (convoId: string) => { export const ConversationMessageRequestButtons = () => { const selectedConvoId = useSelectedConversationKey(); - const hasMessages = useSelector(getSelectedHasMessages); const hasIncomingMessages = useSelector(hasSelectedConversationIncomingMessages); const isIncomingRequest = useIsIncomingRequest(selectedConvoId); - const isOutgoingRequest = useIsOutgoingRequest(selectedConvoId, hasMessages); + const isOutgoingRequest = useIsOutgoingRequest(selectedConvoId); if (!selectedConvoId || (!isIncomingRequest && !isOutgoingRequest)) { return null; diff --git a/ts/components/conversation/SubtleNotification.tsx b/ts/components/conversation/SubtleNotification.tsx index 6ec6080b7..86bbc8422 100644 --- a/ts/components/conversation/SubtleNotification.tsx +++ b/ts/components/conversation/SubtleNotification.tsx @@ -10,10 +10,12 @@ import { useSelectedConversationKey, useSelectedHasDisabledBlindedMsgRequests, useSelectedIsNoteToSelf, + useSelectedIsPrivate, useSelectedNicknameOrProfileNameOrShortenedPubkey, } from '../../state/selectors/selectedConversation'; import { LocalizerKeys } from '../../types/LocalizerKeys'; import { SessionHtmlRenderer } from '../basic/SessionHTMLRenderer'; +import { SessionUtilContact } from '../../session/utils/libsession/libsession_utils_contacts'; const Container = styled.div` display: flex; @@ -35,21 +37,29 @@ const TextInner = styled.div` */ export const ConversationOutgoingRequestExplanation = () => { const selectedConversation = useSelectedConversationKey(); - const hasMessages = useSelector(getSelectedHasMessages); - const isOutgoingMessageRequest = useIsOutgoingRequest(selectedConversation, hasMessages); + const isOutgoingMessageRequest = useIsOutgoingRequest(selectedConversation); const hasIncomingMessages = useSelector(hasSelectedConversationIncomingMessages); const showMsgRequestUI = selectedConversation && isOutgoingMessageRequest; - if (!showMsgRequestUI || hasIncomingMessages) { + const selectedIsPrivate = useSelectedIsPrivate(); + + if (!showMsgRequestUI || hasIncomingMessages || !selectedIsPrivate) { return null; } - - return ( - - {window.i18n('messageRequestPendingDescription')} - - ); + const contactFromLibsession = SessionUtilContact.getContactCached(selectedConversation); + // Note: we want to display this description when the conversation is private (or blinded) AND + // - the conversation is brand new (and not saved yet in libsession: transient conversation), + // - the conversation exists in libsession but we are not approved yet. + // This works because a blinded conversation is not saved in libsession currently, and will only be once approved_me is true + if (!contactFromLibsession || !contactFromLibsession.approvedMe) { + return ( + + {window.i18n('messageRequestPendingDescription')} + + ); + } + return null; }; /** @@ -80,7 +90,7 @@ export const ConversationIncomingRequestExplanation = () => { export const NoMessageInConversation = () => { const selectedConversation = useSelectedConversationKey(); - const hasMessage = useSelector(getSelectedHasMessages); + const hasMessages = useSelector(getSelectedHasMessages); const isMe = useSelectedIsNoteToSelf(); const canWrite = useSelector(getSelectedCanWrite); @@ -88,7 +98,7 @@ export const NoMessageInConversation = () => { // TODOLATER use this selector across the whole application (left pane excluded) const nameToRender = useSelectedNicknameOrProfileNameOrShortenedPubkey(); - if (!selectedConversation || hasMessage) { + if (!selectedConversation || hasMessages) { return null; } let localizedKey: LocalizerKeys = 'noMessagesInEverythingElse'; diff --git a/ts/components/conversation/composition/CompositionButtons.tsx b/ts/components/conversation/composition/CompositionButtons.tsx index 47d8d0051..00af99e9d 100644 --- a/ts/components/conversation/composition/CompositionButtons.tsx +++ b/ts/components/conversation/composition/CompositionButtons.tsx @@ -1,10 +1,8 @@ import { forwardRef } from 'react'; import styled from 'styled-components'; -import { useSelector } from 'react-redux'; import { useIsOutgoingRequest } from '../../../hooks/useParamSelector'; import { useSelectedConversationKey } from '../../../state/selectors/selectedConversation'; import { SessionIconButton } from '../../icon'; -import { getSelectedHasMessages } from '../../../state/selectors/conversations'; const StyledChatButtonContainer = styled.div<{ disabled?: boolean }>` .session-icon-button { @@ -22,8 +20,7 @@ const StyledChatButtonContainer = styled.div<{ disabled?: boolean }>` export const AddStagedAttachmentButton = (props: { onClick: () => void }) => { const selectedConvoKey = useSelectedConversationKey(); - const hasMessages = useSelector(getSelectedHasMessages); - const isOutgoingRequest = useIsOutgoingRequest(selectedConvoKey, hasMessages); + const isOutgoingRequest = useIsOutgoingRequest(selectedConvoKey); return ( diff --git a/ts/components/conversation/header/ConversationHeader.tsx b/ts/components/conversation/header/ConversationHeader.tsx index 0097b6e90..238c7aba6 100644 --- a/ts/components/conversation/header/ConversationHeader.tsx +++ b/ts/components/conversation/header/ConversationHeader.tsx @@ -1,8 +1,5 @@ import { useDispatch, useSelector } from 'react-redux'; -import { - getSelectedHasMessages, - isMessageSelectionMode, -} from '../../../state/selectors/conversations'; +import { isMessageSelectionMode } from '../../../state/selectors/conversations'; import { openRightPanel } from '../../../state/ducks/conversations'; @@ -16,8 +13,7 @@ import { ConversationHeaderTitle } from './ConversationHeaderTitle'; export const ConversationHeaderWithDetails = () => { const isSelectionMode = useSelector(isMessageSelectionMode); const selectedConvoKey = useSelectedConversationKey(); - const hasMessages = useSelector(getSelectedHasMessages); - const isOutgoingRequest = useIsOutgoingRequest(selectedConvoKey, hasMessages); + const isOutgoingRequest = useIsOutgoingRequest(selectedConvoKey); const dispatch = useDispatch(); diff --git a/ts/components/leftpane/conversation-list-item/MessageItem.tsx b/ts/components/leftpane/conversation-list-item/MessageItem.tsx index 1cf873f5e..644138225 100644 --- a/ts/components/leftpane/conversation-list-item/MessageItem.tsx +++ b/ts/components/leftpane/conversation-list-item/MessageItem.tsx @@ -10,6 +10,7 @@ import { useIsTyping, useLastMessage, } from '../../../hooks/useParamSelector'; +import { LastMessageStatusType } from '../../../state/ducks/types'; import { isSearching } from '../../../state/selectors/search'; import { getIsMessageRequestOverlayShown } from '../../../state/selectors/section'; import { assertUnreachable } from '../../../types/sqlSharedTypes'; @@ -17,8 +18,6 @@ import { TypingAnimation } from '../../conversation/TypingAnimation'; import { MessageBody } from '../../conversation/message/message-content/MessageBody'; import { SessionIcon } from '../../icon'; import { InteractionItem } from './InteractionItem'; -import { LastMessageStatusType } from '../../../state/ducks/types'; -import { getSelectedHasMessages } from '../../../state/selectors/conversations'; export const MessageItem = () => { const conversationId = useConvoIdFromContext(); @@ -28,8 +27,7 @@ export const MessageItem = () => { const hasUnread = useHasUnread(conversationId); const isConvoTyping = useIsTyping(conversationId); const isMessageRequest = useSelector(getIsMessageRequestOverlayShown); - const hasMessages = useSelector(getSelectedHasMessages); - const isOutgoingRequest = useIsOutgoingRequest(conversationId, hasMessages); + const isOutgoingRequest = useIsOutgoingRequest(conversationId); const isSearchingMode = useSelector(isSearching); diff --git a/ts/hooks/useParamSelector.ts b/ts/hooks/useParamSelector.ts index cd212c4d1..142a65471 100644 --- a/ts/hooks/useParamSelector.ts +++ b/ts/hooks/useParamSelector.ts @@ -194,7 +194,7 @@ export function useIsIncomingRequest(convoId?: string) { ); } -export function useIsOutgoingRequest(convoId?: string, hasMessages?: boolean) { +export function useIsOutgoingRequest(convoId?: string) { const convoProps = useConversationPropsById(convoId); if (!convoProps) { return false; @@ -209,7 +209,6 @@ export function useIsOutgoingRequest(convoId?: string, hasMessages?: boolean) { isPrivate: convoProps.isPrivate || false, isBlocked: convoProps.isBlocked || false, activeAt: convoProps.activeAt || 0, - hasMessages, }) ); } diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 381b794b0..03e2fcd68 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -2588,7 +2588,6 @@ export function hasValidOutgoingRequestValues({ isBlocked, isPrivate, activeAt, - hasMessages, }: { isMe: boolean; isApproved: boolean; @@ -2596,13 +2595,11 @@ export function hasValidOutgoingRequestValues({ isBlocked: boolean; isPrivate: boolean; activeAt: number; - hasMessages?: boolean; }): boolean { const isActive = activeAt && isFinite(activeAt) && activeAt > 0; // Started a new message, but haven't sent a message yet - const emptyConvo = - !hasMessages && !isMe && !isApproved && isPrivate && !isBlocked && !didApproveMe && !!isActive; + const emptyConvo = !isMe && !isApproved && isPrivate && !isBlocked && !didApproveMe && !!isActive; // Started a new message, and sent a message const sentOutgoingRequest =