mattermost-mobile-upstream/app/components/post_list/post/header/header.tsx
Elias Nahum b6fc85385e
Migrate from RNN to Expo router (#9402)
* Expo-Router partial migration

* Full migration to ExpoRouter

* i18n

* add tests

* Merge branch 'main' into expo-router

* align package-lock.json

* i18n

* feedback review

* feedback review

* android 16kb patch

* Refactored emoji picker keyboard using a state machine

* set android launch_screen in drawables instead of layout

* no conditional hooks

* remove duplicate call in test

* address feedback

* fix tests and address more feedback

* small corrections

* small corrections

* small corrections

* fix draft test

* fix draft test 2

* remove navigateToScreen in draff test

* fix nit in draft test

* remove doc file

* Feedback review

* fix snapshots

* improve test coverage

* fix i18n

* Upgrade t o RN 0.83, other dependencies and new architecture (#9737)

* library hardware-keyboard android new arch support fix

* library rnshare android new arch support fix

* library rnutils android new arch support fix

* library secure-pdf-viewer add new arch support

* Enable new arch on iOS and Android

* update emm and network client with new-arch

* update intune to use new-arch

* performance improvements

* fix tests

* fixes post input on new-arch

* fix android emoji picker

* remove doc

* run tests in parallel

* upgrade to React Native 0.83.9, Expo 55, React 19, and New Architecture

Bumps core dependencies to their latest versions:
- React Native 0.77.3 → 0.83.9 (New Architecture enabled)
- React 18.3.1 → 19.2.5
- Expo SDK 52 → 55
- TypeScript 5.8.3 → 6.0.3
- Node.js 22.16.0 → 24.15.0
- react-native-reanimated 3.17.3 → 4.3.0
- Various other dependency upgrades

Migrates iOS AppDelegate from Objective-C to Swift, updates Android
build tooling and Gradle wrapper, refreshes all patches and font
assets, and adapts app code, tests, and CI workflows throughout for
API changes introduced by these upgrades.

* remove unecessary dismissKeyboard in notifications

* feedback review

* update intune to use new-arch

* update @mattermost deps

* missing i18n string

* additional fixes

* update fastlane
2026-05-13 17:44:55 +08:00

207 lines
8.2 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {useCallback, useMemo} from 'react';
import {useIntl} from 'react-intl';
import {View} from 'react-native';
import {removePost} from '@actions/local/post';
import CompassIcon from '@components/compass_icon';
import FormattedText from '@components/formatted_text';
import FormattedTime from '@components/formatted_time';
import ExpiryTimer from '@components/post_list/post/header/expiry_timer';
import PostPriorityLabel from '@components/post_priority/post_priority_label';
import {Screens} from '@constants';
import {usePostConfig} from '@context/post_config';
import {useServerUrl} from '@context/server';
import {useTheme} from '@context/theme';
import {DEFAULT_LOCALE} from '@i18n';
import {isUnrevealedBoRPost} from '@utils/bor';
import {getPostTranslation, postUserDisplayName} from '@utils/post';
import {makeStyleSheetFromTheme} from '@utils/theme';
import {ensureString} from '@utils/types';
import {typography} from '@utils/typography';
import {
displayUsername,
getUserCustomStatus,
getUserTimezone,
isCustomStatusExpired,
} from '@utils/user';
import HeaderCommentedOn from './commented_on';
import HeaderDisplayName from './display_name';
import HeaderReply from './reply';
import HeaderTag from './tag';
import TranslateIcon from './translate_icon';
import type PostModel from '@typings/database/models/servers/post';
import type UserModel from '@typings/database/models/servers/user';
import type {AvailableScreens} from '@typings/screens/navigation';
type HeaderProps = {
author?: UserModel;
commentCount: number;
currentUser?: UserModel;
isAutoResponse: boolean;
isChannelAutotranslated: boolean;
isCRTEnabled?: boolean;
isEphemeral: boolean;
isPendingOrFailed: boolean;
isSystemPost: boolean;
isWebHook: boolean;
location: AvailableScreens;
post: PostModel;
rootPostAuthor?: UserModel | null;
showPostPriority: boolean;
shouldRenderReplyButton?: boolean;
}
const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {
return {
container: {
flex: 1,
marginTop: 10,
},
pendingPost: {
opacity: 0.5,
},
wrapper: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
gap: 5,
},
time: {
color: theme.centerChannelColor,
opacity: 0.5,
...typography('Body', 75, 'Regular'),
},
visibleToYou: {
color: theme.centerChannelColor,
opacity: 0.5,
...typography('Body', 75, 'Regular'),
},
};
});
const Header = (props: HeaderProps) => {
const {
author, commentCount = 0, currentUser, isAutoResponse, isChannelAutotranslated, isCRTEnabled,
isEphemeral, isPendingOrFailed, isSystemPost, isWebHook,
location, post, rootPostAuthor, showPostPriority, shouldRenderReplyButton,
} = props;
const postConfig = usePostConfig();
const theme = useTheme();
const style = getStyleSheet(theme);
const pendingPostStyle = isPendingOrFailed ? style.pendingPost : undefined;
const isReplyPost = Boolean(post.rootId && !isEphemeral);
const showReply = !isReplyPost && (location !== Screens.THREAD) && (shouldRenderReplyButton && (!rootPostAuthor && commentCount > 0));
const displayName = postUserDisplayName(post, author, postConfig.teammateNameDisplay, postConfig.enablePostUsernameOverride);
const rootAuthorDisplayName = rootPostAuthor ? displayUsername(rootPostAuthor, currentUser?.locale, postConfig.teammateNameDisplay, true) : undefined;
const customStatus = getUserCustomStatus(author);
const showCustomStatusEmoji = Boolean(
postConfig.isCustomStatusEnabled && displayName && customStatus &&
!(isSystemPost || author?.isBot || isAutoResponse || isWebHook),
) &&
!isCustomStatusExpired(author) &&
Boolean(customStatus?.emoji);
const userIconOverride = ensureString(post.props?.override_icon_url);
const usernameOverride = ensureString(post.props?.override_username);
const intl = useIntl();
// We need to depend on the expire_at directly,
// since changes in it may not be reflected in the post object
// (it is still the same object reference).
// eslint-disable-next-line react-hooks/exhaustive-deps
const showBoRIcon = useMemo(() => isUnrevealedBoRPost(post), [post, post.metadata?.expire_at]);
const borExpireAt = post.metadata?.expire_at;
const serverUrl = useServerUrl();
const onBoRPostExpiry = useCallback(async () => {
await removePost(serverUrl, post);
}, [post, serverUrl]);
const translation = getPostTranslation(post, intl.locale);
return (
<>
<View style={[style.container, pendingPostStyle]}>
<View style={style.wrapper}>
<HeaderDisplayName
channelId={post.channelId}
commentCount={commentCount}
displayName={displayName}
location={location}
rootPostAuthor={rootAuthorDisplayName}
shouldRenderReplyButton={shouldRenderReplyButton}
theme={theme}
userIconOverride={userIconOverride}
userId={post.userId}
usernameOverride={usernameOverride}
showCustomStatusEmoji={showCustomStatusEmoji}
customStatus={customStatus!}
/>
{(!isSystemPost || isAutoResponse) &&
<HeaderTag
isAutoResponder={isAutoResponse}
isAutomation={isWebHook || author?.isBot}
showGuestTag={author?.isGuest && !postConfig.hideGuestTags}
/>
}
<FormattedTime
timezone={getUserTimezone(currentUser)}
isMilitaryTime={postConfig.isMilitaryTime}
value={post.createAt}
style={style.time}
testID='post_header.date_time'
/>
{isChannelAutotranslated && post.type === '' && (
<TranslateIcon translationState={translation?.state}/>
)}
{isEphemeral && (
<FormattedText
id='post_header.visible_message'
defaultMessage='(Only visible to you)'
style={style.visibleToYou}
testID='post_header.visible_message'
/>
)}
{showPostPriority && post.metadata?.priority?.priority && (
<PostPriorityLabel label={post.metadata.priority.priority}/>
)}
{showBoRIcon && (
<CompassIcon
name='fire'
size={16}
color={theme.dndIndicator}
/>
)}
{Boolean(borExpireAt) && (
<ExpiryTimer
expiryTime={borExpireAt as number}
onExpiry={onBoRPostExpiry}
/>
)}
{!isCRTEnabled && showReply && commentCount > 0 && (
<HeaderReply
commentCount={commentCount}
location={location}
post={post}
theme={theme}
/>
)}
</View>
</View>
{Boolean(rootAuthorDisplayName) && location === Screens.CHANNEL && (
<HeaderCommentedOn
locale={currentUser?.locale || DEFAULT_LOCALE}
name={rootAuthorDisplayName!}
theme={theme}
/>
)}
</>
);
};
export default Header;