Changeset View
Changeset View
Standalone View
Standalone View
native/chat/text-message.react.js
Show All 16 Lines | |||||
import { InnerTextMessage } from './inner-text-message.react.js'; | import { InnerTextMessage } from './inner-text-message.react.js'; | ||||
import { | import { | ||||
MessagePressResponderContext, | MessagePressResponderContext, | ||||
type MessagePressResponderContextType, | type MessagePressResponderContextType, | ||||
} from './message-press-responder-context.js'; | } from './message-press-responder-context.js'; | ||||
import textMessageSendFailed from './text-message-send-failed.js'; | import textMessageSendFailed from './text-message-send-failed.js'; | ||||
import { getMessageTooltipKey } from './utils.js'; | import { getMessageTooltipKey } from './utils.js'; | ||||
import { ChatContext, type ChatContextType } from '../chat/chat-context.js'; | import { ChatContext, type ChatContextType } from '../chat/chat-context.js'; | ||||
import { InputStateContext } from '../input/input-state.js'; | |||||
import { MarkdownContext } from '../markdown/markdown-context.js'; | import { MarkdownContext } from '../markdown/markdown-context.js'; | ||||
import type { AppNavigationProp } from '../navigation/app-navigator.react'; | import type { AppNavigationProp } from '../navigation/app-navigator.react'; | ||||
import { | import { | ||||
OverlayContext, | OverlayContext, | ||||
type OverlayContextType, | type OverlayContextType, | ||||
} from '../navigation/overlay-context.js'; | } from '../navigation/overlay-context.js'; | ||||
import type { NavigationRoute } from '../navigation/route-names.js'; | import type { NavigationRoute } from '../navigation/route-names.js'; | ||||
import { TextMessageTooltipModalRouteName } from '../navigation/route-names.js'; | import { TextMessageTooltipModalRouteName } from '../navigation/route-names.js'; | ||||
▲ Show 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | class TextMessage extends React.PureComponent<Props> { | ||||
}; | }; | ||||
} | } | ||||
const ConnectedTextMessage: React.ComponentType<BaseProps> = | const ConnectedTextMessage: React.ComponentType<BaseProps> = | ||||
React.memo<BaseProps>(function ConnectedTextMessage(props: BaseProps) { | React.memo<BaseProps>(function ConnectedTextMessage(props: BaseProps) { | ||||
const overlayContext = React.useContext(OverlayContext); | const overlayContext = React.useContext(OverlayContext); | ||||
const chatContext = React.useContext(ChatContext); | const chatContext = React.useContext(ChatContext); | ||||
const markdownContext = React.useContext(MarkdownContext); | const markdownContext = React.useContext(MarkdownContext); | ||||
const inputContext = React.useContext(InputStateContext); | |||||
invariant(markdownContext, 'markdownContext should be set'); | invariant(markdownContext, 'markdownContext should be set'); | ||||
const { linkModalActive, clearMarkdownContextData } = markdownContext; | const { linkModalActive, clearMarkdownContextData } = markdownContext; | ||||
const key = messageKey(props.item.messageInfo); | const key = messageKey(props.item.messageInfo); | ||||
// We check if there is an key in the object - if not, we | // We check if there is an key in the object - if not, we | ||||
// default to false. The likely situation where the former statement | // default to false. The likely situation where the former statement | ||||
// evaluates to null is when the thread is opened for the first time. | // evaluates to null is when the thread is opened for the first time. | ||||
const isLinkModalActive = linkModalActive[key] ?? false; | const isLinkModalActive = linkModalActive[key] ?? false; | ||||
const canCreateSidebarFromMessage = useCanCreateSidebarFromMessage( | const canCreateSidebarFromMessage = useCanCreateSidebarFromMessage( | ||||
props.item.threadInfo, | props.item.threadInfo, | ||||
props.item.messageInfo, | props.item.messageInfo, | ||||
); | ); | ||||
const canEditMessage = useCanEditMessage( | const isThisMessageEdited = | ||||
props.item.threadInfo, | inputContext?.editState.editedMessage?.id === props.item.messageInfo.id; | ||||
props.item.messageInfo, | |||||
); | const canEditMessage = | ||||
useCanEditMessage(props.item.threadInfo, props.item.messageInfo) && | |||||
!isThisMessageEdited; | |||||
const canTogglePins = threadHasPermission( | const canTogglePins = threadHasPermission( | ||||
props.item.threadInfo, | props.item.threadInfo, | ||||
threadPermissions.MANAGE_PINS, | threadPermissions.MANAGE_PINS, | ||||
); | ); | ||||
React.useEffect(() => clearMarkdownContextData, [clearMarkdownContextData]); | React.useEffect(() => clearMarkdownContextData, [clearMarkdownContextData]); | ||||
Show All 14 Lines |