= props =>
{ friend.name }
{ !isExpanded && <>
- { friend.followingAllowed && }
- { friend.online && }
+ { friend.followingAllowed && }
+ { friend.online && }
setIsExpanded(true) } title={ LocalizeText('infostand.link.relationship') } />
> }
{ isExpanded && <>
diff --git a/src/views/friends/views/messenger/FriendsMessengerView.tsx b/src/views/friends/views/messenger/FriendsMessengerView.tsx
index 38a3c07b..b64ed9d2 100644
--- a/src/views/friends/views/messenger/FriendsMessengerView.tsx
+++ b/src/views/friends/views/messenger/FriendsMessengerView.tsx
@@ -1,9 +1,80 @@
-import { FC } from 'react';
-import { LocalizeText } from '../../../../api';
+import { ILinkEventTracker, NitroEvent } from '@nitrots/nitro-renderer';
+import { FC, useCallback, useEffect, useState } from 'react';
+import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker } from '../../../../api';
+import { FriendsEvent } from '../../../../events/friends/FriendsEvent';
+import { useUiEvent } from '../../../../hooks';
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../layout';
+import { MessengerChat } from '../../common/MessengerChat';
+import { useFriendsContext } from '../../context/FriendsContext';
+import { FriendsActions } from '../../reducers/FriendsReducer';
export const FriendsMessengerView: FC<{}> = props =>
{
+ const { friendsState = null, dispatchFriendsState = null } = useFriendsContext();
+ const { activeChats = [] } = friendsState;
+
+ const [ isVisible, setIsVisible ] = useState(false);
+ const [ activeChatIndex, setActiveChatIndex ] = useState(0);
+
+ const onNitroEvent = useCallback((event: NitroEvent) =>
+ {
+ switch(event.type)
+ {
+ case FriendsEvent.SHOW_FRIEND_MESSENGER:
+ setIsVisible(true);
+ return;
+ case FriendsEvent.TOGGLE_FRIEND_MESSENGER:
+ setIsVisible(value => !value);
+ return;
+ }
+ }, []);
+
+ useUiEvent(FriendsEvent.SHOW_FRIEND_MESSENGER, onNitroEvent);
+ useUiEvent(FriendsEvent.TOGGLE_FRIEND_MESSENGER, onNitroEvent);
+
+ const linkReceived = useCallback((url: string) =>
+ {
+ const parts = url.split('/');
+ console.log(parts);
+ if(parts.length < 3) return;
+
+ const friendId = parseInt(parts[2]);
+ console.log(friendId);
+ let existingChatIndex = activeChats.findIndex(c => c.friendId === friendId);
+
+ if(existingChatIndex === -1)
+ {
+ const clonedActiveChats = Array.from(activeChats);
+ clonedActiveChats.push(new MessengerChat(friendId, true));
+
+ dispatchFriendsState({
+ type: FriendsActions.SET_ACTIVE_CHATS,
+ payload: {
+ chats: clonedActiveChats
+ }
+ });
+
+ existingChatIndex = clonedActiveChats.length - 1;
+ }
+
+ setActiveChatIndex(existingChatIndex);
+ setIsVisible(true);
+ }, [ activeChats, dispatchFriendsState ]);
+
+ useEffect(() =>
+ {
+ const linkTracker: ILinkEventTracker = {
+ linkReceived,
+ eventUrlPrefix: 'friends/messenger/'
+ };
+
+ AddEventLinkTracker(linkTracker);
+
+ return () => RemoveLinkEventTracker(linkTracker);
+ }, [ linkReceived ]);
+
+ if(!isVisible) return null;
+
return (
{} } />