/* * Copyright (C) 2026 Fluxer Contributors * * This file is part of Fluxer. * * Fluxer is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Fluxer is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Fluxer. If not, see . */ import {Trans, useLingui} from '@lingui/react/macro'; import {observer} from 'mobx-react-lite'; import React from 'react'; import * as RelationshipActionCreators from '~/actions/RelationshipActionCreators'; import * as UserProfileActionCreators from '~/actions/UserProfileActionCreators'; import {RelationshipTypes} from '~/Constants'; import {GuildIcon} from '~/components/popouts/GuildIcon'; import {UserProfileBadges} from '~/components/popouts/UserProfileBadges'; import {AvatarStack} from '~/components/uikit/avatars/AvatarStack'; import {Button} from '~/components/uikit/Button/Button'; import FocusRing from '~/components/uikit/FocusRing/FocusRing'; import {StatusAwareAvatar} from '~/components/uikit/StatusAwareAvatar'; import {Tooltip} from '~/components/uikit/Tooltip/Tooltip'; import type {GuildRecord} from '~/records/GuildRecord'; import type {ProfileRecord} from '~/records/ProfileRecord'; import GuildStore from '~/stores/GuildStore'; import MobileLayoutStore from '~/stores/MobileLayoutStore'; import RelationshipStore from '~/stores/RelationshipStore'; import UserStore from '~/stores/UserStore'; import styles from './DMWelcomeSection.module.css'; interface DMWelcomeSectionProps { userId: string; } export const DMWelcomeSection: React.FC = observer(function DMWelcomeSection({userId}) { const {t} = useLingui(); const user = UserStore.getUser(userId); const relationship = RelationshipStore.getRelationship(user?.id ?? ''); const relationshipType = relationship?.type; const [profile, setProfile] = React.useState(null); const mobileLayout = MobileLayoutStore; const profileMutualGuilds = React.useMemo(() => profile?.mutualGuilds ?? [], [profile?.mutualGuilds]); const mutualGuildRecords = React.useMemo(() => { return profileMutualGuilds .map((mutualGuild) => GuildStore.getGuild(mutualGuild.id)) .filter((guild): guild is GuildRecord => guild !== undefined); }, [profileMutualGuilds]); React.useEffect(() => { if (!user) return; UserProfileActionCreators.fetch(user.id) .then((fetchedProfile) => { setProfile(fetchedProfile); }) .catch((error) => { console.error('Failed to fetch user profile:', error); }); }, [user]); const openFullProfile = React.useCallback(() => { if (!user) return; UserProfileActionCreators.openUserProfile(user.id); }, [user]); if (!user) { return null; } const handleSendFriendRequest = () => { RelationshipActionCreators.sendFriendRequest(user.id); }; const handleAcceptFriendRequest = () => { RelationshipActionCreators.acceptFriendRequest(user.id); }; const handleRemoveFriend = () => { RelationshipActionCreators.removeRelationship(user.id); }; const handleCancelFriendRequest = () => { RelationshipActionCreators.removeRelationship(user.id); }; const handleIgnoreFriendRequest = () => { RelationshipActionCreators.removeRelationship(user.id); }; const hasMutualGuilds = profileMutualGuilds.length > 0; const currentUserUnclaimed = !(UserStore.currentUser?.isClaimed() ?? true); const shouldShowActionButton = !user.bot && (relationshipType === undefined || relationshipType === RelationshipTypes.INCOMING_REQUEST || relationshipType === RelationshipTypes.OUTGOING_REQUEST || relationshipType === RelationshipTypes.FRIEND); const mutualGuildCount = profileMutualGuilds.length; const renderActionButton = () => { if (user.bot) return null; switch (relationshipType) { case undefined: { const tooltipText = t`Claim your account to send friend requests.`; const button = ( ); if (currentUserUnclaimed) { return (
{button}
); } return button; } case RelationshipTypes.INCOMING_REQUEST: return (
); case RelationshipTypes.OUTGOING_REQUEST: return ( ); case RelationshipTypes.FRIEND: return ( ); default: return null; } }; const renderMutualGuilds = () => { if (!hasMutualGuilds) return null; return (
{mutualGuildRecords.length > 0 && ( {mutualGuildRecords.map((guild) => (
))}
)} {mutualGuildCount === 1 ? t`${mutualGuildCount} mutual commmunity` : t`${mutualGuildCount} mutual communities`}
); }; return (

This is the beginning of your direct message history with {user.username}.

{(hasMutualGuilds || shouldShowActionButton) && (
{renderMutualGuilds()} {shouldShowActionButton && renderActionButton()}
)}
); });