open new user profile in all places

This commit is contained in:
Ajay Bura 2025-08-09 16:33:09 +05:30
parent a44cefedcf
commit 1c56d626b1
3 changed files with 53 additions and 24 deletions

View file

@ -19,9 +19,10 @@ import { getMemberDisplayName } from '../../utils/room';
import { getMxIdLocalPart } from '../../utils/matrix'; import { getMxIdLocalPart } from '../../utils/matrix';
import * as css from './EventReaders.css'; import * as css from './EventReaders.css';
import { useMatrixClient } from '../../hooks/useMatrixClient'; import { useMatrixClient } from '../../hooks/useMatrixClient';
import { openProfileViewer } from '../../../client/action/navigation';
import { UserAvatar } from '../user-avatar'; import { UserAvatar } from '../user-avatar';
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication'; import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
import { useOpenUserRoomProfile } from '../../state/hooks/userRoomProfile';
import { useSpaceOptionally } from '../../hooks/useSpace';
export type EventReadersProps = { export type EventReadersProps = {
room: Room; room: Room;
@ -33,6 +34,8 @@ export const EventReaders = as<'div', EventReadersProps>(
const mx = useMatrixClient(); const mx = useMatrixClient();
const useAuthentication = useMediaAuthentication(); const useAuthentication = useMediaAuthentication();
const latestEventReaders = useRoomEventReaders(room, eventId); const latestEventReaders = useRoomEventReaders(room, eventId);
const openProfile = useOpenUserRoomProfile();
const space = useSpaceOptionally();
const getName = (userId: string) => const getName = (userId: string) =>
getMemberDisplayName(room, userId) ?? getMxIdLocalPart(userId) ?? userId; getMemberDisplayName(room, userId) ?? getMxIdLocalPart(userId) ?? userId;
@ -57,19 +60,32 @@ export const EventReaders = as<'div', EventReadersProps>(
<Box className={css.Content} direction="Column"> <Box className={css.Content} direction="Column">
{latestEventReaders.map((readerId) => { {latestEventReaders.map((readerId) => {
const name = getName(readerId); const name = getName(readerId);
const avatarMxcUrl = room const avatarMxcUrl = room.getMember(readerId)?.getMxcAvatarUrl();
.getMember(readerId) const avatarUrl = avatarMxcUrl
?.getMxcAvatarUrl(); ? mx.mxcUrlToHttp(
const avatarUrl = avatarMxcUrl ? mx.mxcUrlToHttp(avatarMxcUrl, 100, 100, 'crop', undefined, false, useAuthentication) : undefined; avatarMxcUrl,
100,
100,
'crop',
undefined,
false,
useAuthentication
)
: undefined;
return ( return (
<MenuItem <MenuItem
key={readerId} key={readerId}
style={{ padding: `0 ${config.space.S200}` }} style={{ padding: `0 ${config.space.S200}` }}
radii="400" radii="400"
onClick={() => { onClick={(event) => {
requestClose(); openProfile(
openProfileViewer(readerId, room.roomId); room.roomId,
space?.roomId,
readerId,
event.currentTarget.getBoundingClientRect(),
'Bottom'
);
}} }}
before={ before={
<Avatar size="200"> <Avatar size="200">

View file

@ -20,12 +20,13 @@ import { getMemberDisplayName } from '../../../utils/room';
import { eventWithShortcode, getMxIdLocalPart } from '../../../utils/matrix'; import { eventWithShortcode, getMxIdLocalPart } from '../../../utils/matrix';
import * as css from './ReactionViewer.css'; import * as css from './ReactionViewer.css';
import { useMatrixClient } from '../../../hooks/useMatrixClient'; import { useMatrixClient } from '../../../hooks/useMatrixClient';
import { openProfileViewer } from '../../../../client/action/navigation';
import { useRelations } from '../../../hooks/useRelations'; import { useRelations } from '../../../hooks/useRelations';
import { Reaction } from '../../../components/message'; import { Reaction } from '../../../components/message';
import { getHexcodeForEmoji, getShortcodeFor } from '../../../plugins/emoji'; import { getHexcodeForEmoji, getShortcodeFor } from '../../../plugins/emoji';
import { UserAvatar } from '../../../components/user-avatar'; import { UserAvatar } from '../../../components/user-avatar';
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication'; import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
import { useOpenUserRoomProfile } from '../../../state/hooks/userRoomProfile';
import { useSpaceOptionally } from '../../../hooks/useSpace';
export type ReactionViewerProps = { export type ReactionViewerProps = {
room: Room; room: Room;
@ -41,6 +42,8 @@ export const ReactionViewer = as<'div', ReactionViewerProps>(
relations, relations,
useCallback((rel) => [...(rel.getSortedAnnotationsByKey() ?? [])], []) useCallback((rel) => [...(rel.getSortedAnnotationsByKey() ?? [])], [])
); );
const space = useSpaceOptionally();
const openProfile = useOpenUserRoomProfile();
const [selectedKey, setSelectedKey] = useState<string>(() => { const [selectedKey, setSelectedKey] = useState<string>(() => {
if (initialKey) return initialKey; if (initialKey) return initialKey;
@ -111,24 +114,31 @@ export const ReactionViewer = as<'div', ReactionViewerProps>(
const name = (member ? getName(member) : getMxIdLocalPart(senderId)) ?? senderId; const name = (member ? getName(member) : getMxIdLocalPart(senderId)) ?? senderId;
const avatarMxcUrl = member?.getMxcAvatarUrl(); const avatarMxcUrl = member?.getMxcAvatarUrl();
const avatarUrl = avatarMxcUrl ? mx.mxcUrlToHttp( const avatarUrl = avatarMxcUrl
avatarMxcUrl, ? mx.mxcUrlToHttp(
100, avatarMxcUrl,
100, 100,
'crop', 100,
undefined, 'crop',
false, undefined,
useAuthentication false,
) : undefined; useAuthentication
)
: undefined;
return ( return (
<MenuItem <MenuItem
key={senderId} key={senderId}
style={{ padding: `0 ${config.space.S200}` }} style={{ padding: `0 ${config.space.S200}` }}
radii="400" radii="400"
onClick={() => { onClick={(event) => {
requestClose(); openProfile(
openProfileViewer(senderId, room.roomId); room.roomId,
space?.roomId,
senderId,
event.currentTarget.getBoundingClientRect(),
'Bottom'
);
}} }}
before={ before={
<Avatar size="200"> <Avatar size="200">

View file

@ -3,14 +3,17 @@ import { useNavigate } from 'react-router-dom';
import { useRoomNavigate } from './useRoomNavigate'; import { useRoomNavigate } from './useRoomNavigate';
import { useMatrixClient } from './useMatrixClient'; import { useMatrixClient } from './useMatrixClient';
import { isRoomId, isUserId } from '../utils/matrix'; import { isRoomId, isUserId } from '../utils/matrix';
import { openProfileViewer } from '../../client/action/navigation';
import { getHomeRoomPath, withSearchParam } from '../pages/pathUtils'; import { getHomeRoomPath, withSearchParam } from '../pages/pathUtils';
import { _RoomSearchParams } from '../pages/paths'; import { _RoomSearchParams } from '../pages/paths';
import { useOpenUserRoomProfile } from '../state/hooks/userRoomProfile';
import { useSpaceOptionally } from './useSpace';
export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLElement> => { export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLElement> => {
const mx = useMatrixClient(); const mx = useMatrixClient();
const { navigateRoom, navigateSpace } = useRoomNavigate(); const { navigateRoom, navigateSpace } = useRoomNavigate();
const navigate = useNavigate(); const navigate = useNavigate();
const openProfile = useOpenUserRoomProfile();
const space = useSpaceOptionally();
const handleClick: ReactEventHandler<HTMLElement> = useCallback( const handleClick: ReactEventHandler<HTMLElement> = useCallback(
(evt) => { (evt) => {
@ -21,7 +24,7 @@ export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLEl
if (typeof mentionId !== 'string') return; if (typeof mentionId !== 'string') return;
if (isUserId(mentionId)) { if (isUserId(mentionId)) {
openProfileViewer(mentionId, roomId); openProfile(roomId, space?.roomId, mentionId, target.getBoundingClientRect());
return; return;
} }
@ -37,7 +40,7 @@ export const useMentionClickHandler = (roomId: string): ReactEventHandler<HTMLEl
navigate(viaServers ? withSearchParam<_RoomSearchParams>(path, { viaServers }) : path); navigate(viaServers ? withSearchParam<_RoomSearchParams>(path, { viaServers }) : path);
}, },
[mx, navigate, navigateRoom, navigateSpace, roomId] [mx, navigate, navigateRoom, navigateSpace, roomId, space, openProfile]
); );
return handleClick; return handleClick;