fix: show msg request description using libsession state and not msgs

pull/3137/head
Audric Ackermann 8 months ago
parent 29d4f8497c
commit 0437390922

@ -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;

@ -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 (
<Container data-testid={'empty-conversation-control-message'} style={{ padding: 0 }}>
<TextInner>{window.i18n('messageRequestPendingDescription')}</TextInner>
</Container>
);
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 (
<Container data-testid={'empty-conversation-control-message'} style={{ padding: 0 }}>
<TextInner>{window.i18n('messageRequestPendingDescription')}</TextInner>
</Container>
);
}
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';

@ -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 (
<StyledChatButtonContainer disabled={isOutgoingRequest}>

@ -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();

@ -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);

@ -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,
})
);
}

@ -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 =

Loading…
Cancel
Save