Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor into proper function components, otherwise we would not be allowed to use hooks in those functions if they just return JSX without being a component. #4000

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- "Realtime Webxdc Channels" toggle not reflecting actual setting value #3992
- even faster load of contact lists in "New Chat" and "New Group" #3927
- really hide 3dot menu when it is hidden #3998
- fix react crash when downloading a video message on demand #4000

<a id="1_46_1"></a>

Expand Down
82 changes: 47 additions & 35 deletions src/renderer/components/message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ import styles from './styles.module.scss'
import type { OpenDialog } from '../../contexts/DialogContext'
import type { PrivateReply } from '../../hooks/chat/usePrivateReply'

const Avatar = (
contact: T.Contact,
const Avatar = ({
contact,
onContactClick,
}: {
contact: T.Contact
onContactClick: (contact: T.Contact) => void
) => {
}) => {
const { profileImage, color, displayName } = contact

const onClick = () => onContactClick(contact)
Expand Down Expand Up @@ -83,11 +86,15 @@ const Avatar = (
}
}

const AuthorName = (
contact: T.Contact,
onContactClick: (contact: T.Contact) => void,
overrideSenderName?: string
) => {
const AuthorName = ({
contact,
onContactClick,
overrideSenderName,
}: {
contact: T.Contact
onContactClick: (contact: T.Contact) => void
overrideSenderName: string | null
}) => {
const accountId = selectedAccountId()
const { color, id } = contact
const [displayName, setDisplayName] = useState<string>(contact.displayName)
Expand Down Expand Up @@ -118,13 +125,19 @@ const AuthorName = (
)
}

const ForwardedTitle = (
contact: T.Contact,
onContactClick: (contact: T.Contact) => void,
direction: 'incoming' | 'outgoing',
conversationType: ConversationType,
overrideSenderName?: string
) => {
const ForwardedTitle = ({
contact,
onContactClick,
direction,
conversationType,
overrideSenderName,
}: {
contact: T.Contact
onContactClick: (contact: T.Contact) => void
direction: 'incoming' | 'outgoing'
conversationType: ConversationType
overrideSenderName: string | null
}) => {
const tx = useTranslationFunction()

const { displayName, color } = contact
Expand Down Expand Up @@ -555,9 +568,7 @@ export default function Message(props: {
)
}

// we need this typeconversion, if we don't have it esbuild tries bundling deltachat-node again,
// which fails because it imports stuff only available in nodejs
const downloadState = message.downloadState
farooqkz marked this conversation as resolved.
Show resolved Hide resolved
const { downloadState } = message

if (downloadState !== 'Done') {
content = (
Expand Down Expand Up @@ -605,22 +616,23 @@ export default function Message(props: {
})}
id={message.id.toString()}
>
{showAuthor &&
direction === 'incoming' &&
Avatar(message.sender, onContactClick)}
{showAuthor && direction === 'incoming' && (
<Avatar contact={message.sender} onContactClick={onContactClick} />
)}
<div
onContextMenu={showContextMenu}
className='msg-container'
style={{ borderColor: message.sender.color }}
>
{message.isForwarded &&
ForwardedTitle(
message.sender,
onContactClick,
direction,
conversationType,
message.overrideSenderName || undefined
)}
{message.isForwarded && (
<ForwardedTitle
contact={message.sender}
onContactClick={onContactClick}
direction={direction}
conversationType={conversationType}
overrideSenderName={message.overrideSenderName}
/>
)}
{!message.isForwarded && (
<div
className={classNames('author-wrapper', {
Expand All @@ -629,11 +641,11 @@ export default function Message(props: {
!showAuthor,
})}
>
{AuthorName(
message.sender,
onContactClick,
message.overrideSenderName || undefined
)}
<AuthorName
contact={message.sender}
onContactClick={onContactClick}
overrideSenderName={message.overrideSenderName}
/>
</div>
)}
<div
Expand Down Expand Up @@ -785,7 +797,7 @@ export const Quote = ({

export function getAuthorName(
displayName: string,
overrideSenderName?: string
overrideSenderName?: string | null
) {
return overrideSenderName ? `~${overrideSenderName}` : displayName
}
Expand Down
Loading