fix: disable attachments and voice messages and warn a user when starting a new convo

even if they haven't sent a message request yet
pull/3137/head
yougotwill 8 months ago
parent 4478ee160d
commit 6c291e38c4

@ -6,7 +6,10 @@ import {
declineConversationWithConfirm,
} from '../../interactions/conversationInteractions';
import { getConversationController } from '../../session/conversations';
import { hasSelectedConversationIncomingMessages } from '../../state/selectors/conversations';
import {
getSelectedHasMessages,
hasSelectedConversationIncomingMessages,
} from '../../state/selectors/conversations';
import { useSelectedConversationKey } from '../../state/selectors/selectedConversation';
import { SessionButton, SessionButtonColor } from '../basic/SessionButton';
import {
@ -78,9 +81,10 @@ 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);
const isOutgoingRequest = useIsOutgoingRequest(selectedConvoId, hasMessages);
if (!selectedConvoId || (!isIncomingRequest && !isOutgoingRequest)) {
return null;

@ -35,7 +35,8 @@ const TextInner = styled.div`
*/
export const ConversationOutgoingRequestExplanation = () => {
const selectedConversation = useSelectedConversationKey();
const isOutgoingMessageRequest = useIsOutgoingRequest(selectedConversation);
const hasMessages = useSelector(getSelectedHasMessages);
const isOutgoingMessageRequest = useIsOutgoingRequest(selectedConversation, hasMessages);
const hasIncomingMessages = useSelector(hasSelectedConversationIncomingMessages);
const showMsgRequestUI = selectedConversation && isOutgoingMessageRequest;

@ -1,8 +1,10 @@
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 {
@ -20,7 +22,8 @@ const StyledChatButtonContainer = styled.div<{ disabled?: boolean }>`
export const AddStagedAttachmentButton = (props: { onClick: () => void }) => {
const selectedConvoKey = useSelectedConversationKey();
const isOutgoingRequest = useIsOutgoingRequest(selectedConvoKey);
const hasMessages = useSelector(getSelectedHasMessages);
const isOutgoingRequest = useIsOutgoingRequest(selectedConvoKey, hasMessages);
return (
<StyledChatButtonContainer disabled={isOutgoingRequest}>

@ -1,5 +1,8 @@
import { useDispatch, useSelector } from 'react-redux';
import { isMessageSelectionMode } from '../../../state/selectors/conversations';
import {
getSelectedHasMessages,
isMessageSelectionMode,
} from '../../../state/selectors/conversations';
import { openRightPanel } from '../../../state/ducks/conversations';
@ -13,7 +16,8 @@ import { ConversationHeaderTitle } from './ConversationHeaderTitle';
export const ConversationHeaderWithDetails = () => {
const isSelectionMode = useSelector(isMessageSelectionMode);
const selectedConvoKey = useSelectedConversationKey();
const isOutgoingRequest = useIsOutgoingRequest(selectedConvoKey);
const hasMessages = useSelector(getSelectedHasMessages);
const isOutgoingRequest = useIsOutgoingRequest(selectedConvoKey, hasMessages);
const dispatch = useDispatch();

@ -18,6 +18,7 @@ import { MessageBody } from '../../conversation/message/message-content/MessageB
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();
@ -27,7 +28,8 @@ export const MessageItem = () => {
const hasUnread = useHasUnread(conversationId);
const isConvoTyping = useIsTyping(conversationId);
const isMessageRequest = useSelector(getIsMessageRequestOverlayShown);
const isOutgoingRequest = useIsOutgoingRequest(conversationId);
const hasMessages = useSelector(getSelectedHasMessages);
const isOutgoingRequest = useIsOutgoingRequest(conversationId, hasMessages);
const isSearchingMode = useSelector(isSearching);

@ -194,11 +194,12 @@ export function useIsIncomingRequest(convoId?: string) {
);
}
export function useIsOutgoingRequest(convoId?: string) {
export function useIsOutgoingRequest(convoId?: string, hasMessages?: boolean) {
const convoProps = useConversationPropsById(convoId);
if (!convoProps) {
return false;
}
return Boolean(
convoProps &&
hasValidOutgoingRequestValues({
@ -208,6 +209,7 @@ export function useIsOutgoingRequest(convoId?: string) {
isPrivate: convoProps.isPrivate || false,
isBlocked: convoProps.isBlocked || false,
activeAt: convoProps.activeAt || 0,
hasMessages,
})
);
}

@ -2588,6 +2588,7 @@ export function hasValidOutgoingRequestValues({
isBlocked,
isPrivate,
activeAt,
hasMessages,
}: {
isMe: boolean;
isApproved: boolean;
@ -2595,10 +2596,19 @@ export function hasValidOutgoingRequestValues({
isBlocked: boolean;
isPrivate: boolean;
activeAt: number;
hasMessages?: boolean;
}): boolean {
const isActive = activeAt && isFinite(activeAt) && activeAt > 0;
return Boolean(!isMe && isApproved && isPrivate && !isBlocked && !didApproveMe && isActive);
// Started a new message, but haven't sent a message yet
const emptyConvo =
!hasMessages && !isMe && !isApproved && isPrivate && !isBlocked && !didApproveMe && !!isActive;
// Started a new message, and sent a message
const sentOutgoingRequest =
!isMe && isApproved && isPrivate && !isBlocked && !didApproveMe && !!isActive;
return emptyConvo || sentOutgoingRequest;
}
/**

Loading…
Cancel
Save