diff --git a/packages/messenger-widget/src/components/Message/Message.tsx b/packages/messenger-widget/src/components/Message/Message.tsx index bc7d98d63..3a8e92e3d 100644 --- a/packages/messenger-widget/src/components/Message/Message.tsx +++ b/packages/messenger-widget/src/components/Message/Message.tsx @@ -17,6 +17,8 @@ import { ProfilePreview } from './ProfilePreview'; import { AuthContext } from '../../context/AuthContext'; import { ConversationContext } from '../../context/ConversationContext'; import { DM3UserProfileContext } from '../../context/DM3UserProfileContext'; +import { SettingsContext } from '../../context/SettingsContext'; +import { MsgViewType } from '../../hooks/settings/useSettings'; export function Message(props: MessageProps) { const { messageView } = useContext(UiViewContext); @@ -27,6 +29,8 @@ export function Message(props: MessageProps) { const { accountProfilePicture } = useContext(DM3UserProfileContext); + const { msgViewSelected } = useContext(SettingsContext); + return ( {/* Profile preview before every message content to show the actual sender of it */} - {props.showProfile && ( - - )} + {msgViewSelected.viewType === MsgViewType.NEW && + props.showProfile && ( + + )}
diff --git a/packages/messenger-widget/src/components/Message/ProfilePreview.tsx b/packages/messenger-widget/src/components/Message/ProfilePreview.tsx index fd87b0082..ca4f4582c 100644 --- a/packages/messenger-widget/src/components/Message/ProfilePreview.tsx +++ b/packages/messenger-widget/src/components/Message/ProfilePreview.tsx @@ -1,18 +1,49 @@ +import { useContext } from 'react'; import './Message.css'; +import { UiViewContext } from '../../context/UiViewContext'; +import { RightViewSelected } from '../../utils/enum-type-utils'; +import { closeContactMenu } from '../../utils/common-utils'; +import { ConversationContext } from '../../context/ConversationContext'; export interface ProfilePreviewProps { picture: string; name: string; + ownMessage: boolean; } export function ProfilePreview(props: ProfilePreviewProps) { + const { setSelectedRightView } = useContext(UiViewContext); + const { setSelectedContactName } = useContext(ConversationContext); + + // method to open the profile of selected account + const openProfile = () => { + // if our own profile icon is clicked + if (props.ownMessage) { + // select and open profile component + setSelectedRightView(RightViewSelected.Profile); + // unselect the contact + setSelectedContactName(undefined); + return; + } + // open contact info of the selected contact + setSelectedRightView(RightViewSelected.ContactInfo); + // close the contact menu + closeContactMenu(); + }; + return (
+ {/* profile picture of the account or contact selected */} openProfile()} /> -
+ {/* Name of the account or contact selected */} +
openProfile()} + > {props.name.length > 16 ? props.name.slice(0, 16) : props.name}
diff --git a/packages/messenger-widget/src/hooks/settings/useSettings.tsx b/packages/messenger-widget/src/hooks/settings/useSettings.tsx index ba4584f04..2027776ce 100644 --- a/packages/messenger-widget/src/hooks/settings/useSettings.tsx +++ b/packages/messenger-widget/src/hooks/settings/useSettings.tsx @@ -12,16 +12,21 @@ export type SettingsDataType = { messageView: string; }; +export enum MsgViewType { + OLD = 'OLD', + NEW = 'NEW', +} + // available message view options export const MSG_VIEW_OPTIONS = [ { name: 'Old message view', - viewType: 'OLD', + viewType: MsgViewType.OLD, isEnabled: true, }, { name: 'New message view', - viewType: 'NEW', + viewType: MsgViewType.NEW, isEnabled: true, }, ];