diff --git a/ts/components/UserDetailsDialog.tsx b/ts/components/UserDetailsDialog.tsx index f2896f334..749fdc357 100644 --- a/ts/components/UserDetailsDialog.tsx +++ b/ts/components/UserDetailsDialog.tsx @@ -14,7 +14,7 @@ import useKey from 'react-use/lib/useKey'; import { getFirstUnreadMessageIdInConversation } from '../data/data'; type Props = { conversationId: string; - authorAvatarPath?: string; + authorAvatarPath: string | null; userName: string; }; diff --git a/ts/components/conversation/AttachmentList.tsx b/ts/components/conversation/AttachmentList.tsx index 409831397..e7ce3eca2 100644 --- a/ts/components/conversation/AttachmentList.tsx +++ b/ts/components/conversation/AttachmentList.tsx @@ -23,7 +23,7 @@ type Props = { const IMAGE_WIDTH = 120; const IMAGE_HEIGHT = 120; -export const AttachmentList = (props: Props) => { +export const StagedAttachmentList = (props: Props) => { const { attachments, onAddAttachment, onClickAttachment, onCloseAttachment, onClose } = props; if (!attachments.length) { diff --git a/ts/components/conversation/Image.tsx b/ts/components/conversation/Image.tsx index 9ce7142f6..1e0a5b087 100644 --- a/ts/components/conversation/Image.tsx +++ b/ts/components/conversation/Image.tsx @@ -2,12 +2,12 @@ import React from 'react'; import classNames from 'classnames'; import { Spinner } from '../basic/Spinner'; -import { AttachmentTypeWithPath } from '../../types/Attachment'; +import { AttachmentType, AttachmentTypeWithPath } from '../../types/Attachment'; import { useEncryptedFileFetch } from '../../hooks/useEncryptedFileFetch'; type Props = { alt: string; - attachment: AttachmentTypeWithPath; + attachment: AttachmentTypeWithPath | AttachmentType; url: string; height?: number; @@ -28,8 +28,8 @@ type Props = { playIconOverlay?: boolean; softCorners?: boolean; - onClick?: (attachment: AttachmentTypeWithPath) => void; - onClickClose?: (attachment: AttachmentTypeWithPath) => void; + onClick?: (attachment: AttachmentTypeWithPath | AttachmentType) => void; + onClickClose?: (attachment: AttachmentTypeWithPath | AttachmentType) => void; onError?: () => void; }; diff --git a/ts/components/conversation/ImageGrid.tsx b/ts/components/conversation/ImageGrid.tsx index a12a8b3d4..3731506ee 100644 --- a/ts/components/conversation/ImageGrid.tsx +++ b/ts/components/conversation/ImageGrid.tsx @@ -3,6 +3,7 @@ import classNames from 'classnames'; import { areAllAttachmentsVisual, + AttachmentType, AttachmentTypeWithPath, getAlt, getImageDimensions, @@ -20,7 +21,7 @@ type Props = { bottomOverlay?: boolean; onError: () => void; - onClickAttachment?: (attachment: AttachmentTypeWithPath) => void; + onClickAttachment?: (attachment: AttachmentTypeWithPath | AttachmentType) => void; }; export const ImageGrid = (props: Props) => { diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index ecade58fb..3dc0c81fc 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -10,6 +10,7 @@ import { ContactName } from './ContactName'; import { Quote } from './Quote'; import { + AttachmentType, AttachmentTypeWithPath, canDisplayImage, getExtensionForDisplay, @@ -26,12 +27,10 @@ import { import { getIncrement } from '../../util/timer'; import { isFileDangerous } from '../../util/isFileDangerous'; import _ from 'lodash'; -import { contextMenu, Menu } from 'react-contexify'; +import { contextMenu } from 'react-contexify'; import uuid from 'uuid'; -import { InView } from 'react-intersection-observer'; -import { MessageMetadata } from './message/MessageMetadata'; import { PubKey } from '../../session/types'; -import { MessageRegularProps } from '../../models/messageType'; +import { MessageRenderingProps } from '../../models/messageType'; import { updateUserDetailsModal } from '../../state/ducks/modalDialog'; import autoBind from 'auto-bind'; import { AudioPlayerWithEncryptedFile } from './H5AudioPlayer'; @@ -52,9 +51,9 @@ import { saveAttachmentToDisk } from '../../util/attachmentsUtil'; import { LightBoxOptions } from '../session/conversation/SessionConversation'; import { MessageContextMenu } from './MessageContextMenu'; import { ReadableMessage } from './ReadableMessage'; -import { remote } from 'electron'; import { isElectronWindowFocused } from '../../session/utils/WindowUtils'; import { getConversationController } from '../../session/conversations'; +import { MessageMetadata } from './message/MessageMetadata'; // Same as MIN_WIDTH in ImageGrid.tsx const MINIMUM_LINK_PREVIEW_IMAGE_WIDTH = 200; @@ -68,13 +67,17 @@ interface State { const EXPIRATION_CHECK_MINIMUM = 2000; const EXPIRED_DELAY = 600; -type Props = MessageRegularProps & { +type Props = MessageRenderingProps & { selectedMessages: Array; quotedMessageToAnimate: string | undefined; }; +function attachmentIsAttachmentTypeWithPath(attac: any): attac is AttachmentTypeWithPath { + return attac.path !== undefined; +} + const onClickAttachment = async (onClickProps: { - attachment: AttachmentTypeWithPath; + attachment: AttachmentTypeWithPath | AttachmentType; messageId: string; }) => { let index = -1; @@ -101,11 +104,16 @@ const onClickAttachment = async (onClickProps: { messageId: onClickProps.messageId, }; }); - const lightBoxOptions: LightBoxOptions = { - media: media as any, - attachment: onClickProps.attachment, - }; - window.inboxStore?.dispatch(showLightBox(lightBoxOptions)); + + if (attachmentIsAttachmentTypeWithPath(onClickProps.attachment)) { + const lightBoxOptions: LightBoxOptions = { + media: media as any, + attachment: onClickProps.attachment, + }; + window.inboxStore?.dispatch(showLightBox(lightBoxOptions)); + } else { + window.log.warn('Attachment is not of the right type'); + } }; class MessageInner extends React.PureComponent { @@ -438,7 +446,7 @@ class MessageInner extends React.PureComponent { authorPhoneNumber, authorProfileName, collapseMetadata, - isAdmin, + isSenderAdmin, conversationType, direction, isPublic, @@ -463,7 +471,7 @@ class MessageInner extends React.PureComponent { onAvatarClick={this.onMessageAvatarClick} pubkey={authorPhoneNumber} /> - {isPublic && isAdmin && ( + {isPublic && isSenderAdmin && (
@@ -665,7 +673,7 @@ class MessageInner extends React.PureComponent { timestamp={this.props.timestamp} collapseMetadata={this.props.collapseMetadata} expirationLength={this.props.expirationLength} - isAdmin={this.props.isAdmin} + isAdmin={this.props.isSenderAdmin} serverTimestamp={this.props.serverTimestamp} isPublic={this.props.isPublic} status={this.props.status} @@ -688,7 +696,7 @@ class MessageInner extends React.PureComponent { timestamp={this.props.timestamp} serverTimestamp={this.props.serverTimestamp} attachments={this.props.attachments} - isAdmin={this.props.isAdmin} + isAdmin={this.props.isSenderAdmin} isOpenGroupV2={this.props.isOpenGroupV2} isPublic={this.props.isPublic} status={this.props.status} @@ -784,7 +792,7 @@ class MessageInner extends React.PureComponent { ); } - private onClickOnImageGrid(attachment: AttachmentTypeWithPath) { + private onClickOnImageGrid(attachment: AttachmentTypeWithPath | AttachmentType) { const { multiSelectMode, id } = this.props; if (multiSelectMode) { diff --git a/ts/components/conversation/MessageDetail.tsx b/ts/components/conversation/MessageDetail.tsx index d8bebfa56..a42304ac3 100644 --- a/ts/components/conversation/MessageDetail.tsx +++ b/ts/components/conversation/MessageDetail.tsx @@ -5,7 +5,7 @@ import moment from 'moment'; import { Avatar, AvatarSize } from '../Avatar'; import { ContactName } from './ContactName'; import { Message } from './Message'; -import { MessageRegularProps } from '../../models/messageType'; +import { MessageRenderingProps } from '../../models/messageType'; import { deleteMessagesById } from '../../interactions/conversationInteractions'; import { useSelector } from 'react-redux'; import { ContactPropsMessageDetail } from '../../state/ducks/conversations'; @@ -20,16 +20,14 @@ const AvatarItem = (props: { contact: ContactPropsMessageDetail }) => { ); }; -const DeleteButtonItem = (props: { message: MessageRegularProps }) => { +const DeleteButtonItem = (props: { id: string; convoId: string; isDeletable: boolean }) => { const { i18n } = window; - const { message } = props; - - return message.isDeletable ? ( + return props.isDeletable ? (