2014-10-20 08:14:45 -04:00
|
|
|
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "FriendsAndChatPrivatePCH.h"
|
|
|
|
|
#include "FriendViewModel.h"
|
|
|
|
|
|
|
|
|
|
class FFriendViewModelImpl
|
|
|
|
|
: public FFriendViewModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
virtual void EnumerateActions(TArray<EFriendActionType::Type>& Actions)
|
|
|
|
|
{
|
2014-11-11 04:54:47 -05:00
|
|
|
if(FriendItem->IsGameRequest())
|
|
|
|
|
{
|
2014-11-11 20:34:01 -05:00
|
|
|
if (FriendItem->IsGameJoinable())
|
|
|
|
|
{
|
|
|
|
|
Actions.Add(EFriendActionType::JoinGame);
|
|
|
|
|
}
|
2014-11-11 04:54:47 -05:00
|
|
|
Actions.Add(EFriendActionType::RejectGame);
|
|
|
|
|
}
|
|
|
|
|
else if(FriendItem->IsPendingAccepted())
|
2014-10-20 08:14:45 -04:00
|
|
|
{
|
|
|
|
|
Actions.Add(EFriendActionType::Updating);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
switch (FriendItem->GetInviteStatus())
|
|
|
|
|
{
|
|
|
|
|
case EInviteStatus::Accepted :
|
|
|
|
|
{
|
2014-11-11 13:50:57 -05:00
|
|
|
if (FriendItem->IsGameJoinable())
|
2014-10-20 08:14:45 -04:00
|
|
|
{
|
|
|
|
|
Actions.Add(EFriendActionType::JoinGame);
|
|
|
|
|
}
|
2014-11-03 15:47:28 -05:00
|
|
|
|
2014-11-11 15:42:14 -05:00
|
|
|
if (FFriendsAndChatManager::Get()->IsInJoinableGameSession())
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
Actions.Add(EFriendActionType::InviteToGame);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-03 15:47:28 -05:00
|
|
|
// TODO. Move to user is online. Here for testing until Chat is ready
|
|
|
|
|
Actions.Add(EFriendActionType::Chat);
|
|
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
Actions.Add(EFriendActionType::RemoveFriend);
|
2014-10-20 08:14:45 -04:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EInviteStatus::PendingInbound :
|
|
|
|
|
{
|
|
|
|
|
Actions.Add(EFriendActionType::AcceptFriendRequest);
|
2014-11-03 15:47:28 -05:00
|
|
|
Actions.Add(EFriendActionType::RejectFriendRequest);
|
2014-10-20 08:14:45 -04:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EInviteStatus::PendingOutbound :
|
|
|
|
|
{
|
2014-11-06 15:17:11 -05:00
|
|
|
Actions.Add(EFriendActionType::CancelFriendRequest);
|
2014-10-20 08:14:45 -04:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Actions.Add(EFriendActionType::SendFriendRequest);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void PerformAction(const EFriendActionType::Type ActionType)
|
|
|
|
|
{
|
|
|
|
|
switch(ActionType)
|
|
|
|
|
{
|
2014-11-11 09:47:06 -05:00
|
|
|
case EFriendActionType::AcceptFriendRequest :
|
|
|
|
|
{
|
|
|
|
|
AcceptFriend();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-10-20 08:14:45 -04:00
|
|
|
case EFriendActionType::RemoveFriend :
|
|
|
|
|
case EFriendActionType::IgnoreFriendRequest :
|
|
|
|
|
case EFriendActionType::BlockFriend :
|
2014-11-03 15:47:28 -05:00
|
|
|
case EFriendActionType::RejectFriendRequest:
|
2014-11-06 15:17:11 -05:00
|
|
|
case EFriendActionType::CancelFriendRequest:
|
2014-10-20 08:14:45 -04:00
|
|
|
{
|
|
|
|
|
RemoveFriend();
|
2014-11-11 09:47:06 -05:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case EFriendActionType::SendFriendRequest :
|
|
|
|
|
{
|
|
|
|
|
SendFriendRequest();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case EFriendActionType::InviteToGame :
|
|
|
|
|
{
|
|
|
|
|
InviteToGame();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case EFriendActionType::JoinGame :
|
|
|
|
|
{
|
|
|
|
|
JoinGame();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case EFriendActionType::RejectGame:
|
|
|
|
|
{
|
|
|
|
|
RejectGame();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case EFriendActionType::Chat:
|
|
|
|
|
{
|
|
|
|
|
StartChat();
|
|
|
|
|
break;
|
2014-10-20 08:14:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~FFriendViewModelImpl()
|
|
|
|
|
{
|
|
|
|
|
Uninitialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual FText GetFriendName() const override
|
|
|
|
|
{
|
|
|
|
|
return FText::FromString(FriendItem->GetName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual FText GetFriendLocation() const override
|
|
|
|
|
{
|
|
|
|
|
return FriendItem.IsValid() ? FriendItem->GetFriendLocation() : FText::GetEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual bool IsOnline() const override
|
|
|
|
|
{
|
|
|
|
|
return FriendItem.IsValid() ? FriendItem->IsOnline() : false;
|
|
|
|
|
}
|
2014-11-06 15:17:11 -05:00
|
|
|
|
2014-11-11 09:46:40 -05:00
|
|
|
virtual FString GetClientId() const override
|
|
|
|
|
{
|
|
|
|
|
return FriendItem.IsValid() ? FriendItem->GetClientId() : FString();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-03 15:47:28 -05:00
|
|
|
private:
|
2014-10-20 08:14:45 -04:00
|
|
|
|
|
|
|
|
void RemoveFriend() const
|
|
|
|
|
{
|
|
|
|
|
FFriendsAndChatManager::Get()->DeleteFriend( FriendItem );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AcceptFriend() const
|
|
|
|
|
{
|
|
|
|
|
FFriendsAndChatManager::Get()->AcceptFriend( FriendItem );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SendFriendRequest() const
|
|
|
|
|
{
|
2014-11-11 04:54:47 -05:00
|
|
|
if (FriendItem.IsValid())
|
2014-10-20 08:14:45 -04:00
|
|
|
{
|
|
|
|
|
FFriendsAndChatManager::Get()->RequestFriend(FText::FromString(FriendItem->GetName()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InviteToGame()
|
|
|
|
|
{
|
2014-11-11 09:47:20 -05:00
|
|
|
if (FriendItem.IsValid() &&
|
|
|
|
|
FriendItem->GetOnlineFriend().IsValid())
|
2014-10-20 08:14:45 -04:00
|
|
|
{
|
2014-11-11 09:47:20 -05:00
|
|
|
FFriendsAndChatManager::Get()->SendGameInvite(FriendItem);
|
2014-10-20 08:14:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JoinGame()
|
|
|
|
|
{
|
2014-11-11 09:47:06 -05:00
|
|
|
if (FriendItem.IsValid() &&
|
|
|
|
|
FriendItem->GetOnlineFriend().IsValid() &&
|
|
|
|
|
FriendItem->IsGameRequest())
|
2014-10-20 08:14:45 -04:00
|
|
|
{
|
2014-11-11 09:47:06 -05:00
|
|
|
FFriendsAndChatManager::Get()->AcceptGameInvite(FriendItem);
|
2014-10-20 08:14:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 04:54:47 -05:00
|
|
|
void RejectGame()
|
|
|
|
|
{
|
2014-11-11 09:47:06 -05:00
|
|
|
if (FriendItem.IsValid() &&
|
|
|
|
|
FriendItem->GetOnlineFriend().IsValid() &&
|
|
|
|
|
FriendItem->IsGameRequest())
|
2014-11-11 04:54:47 -05:00
|
|
|
{
|
2014-11-11 09:47:06 -05:00
|
|
|
FFriendsAndChatManager::Get()->RejectGameInvite(FriendItem);
|
2014-11-11 04:54:47 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-03 15:47:28 -05:00
|
|
|
void StartChat()
|
|
|
|
|
{
|
|
|
|
|
if ( FriendItem.IsValid() && FriendItem->GetOnlineFriend().IsValid() )
|
|
|
|
|
{
|
|
|
|
|
FFriendsAndChatManager::Get()->GenerateChatWindow(FriendItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-20 08:14:45 -04:00
|
|
|
private:
|
|
|
|
|
void Initialize()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Uninitialize()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FFriendViewModelImpl(
|
2014-11-11 10:10:45 -05:00
|
|
|
const TSharedRef<IFriendItem>& FriendItem
|
2014-10-20 08:14:45 -04:00
|
|
|
)
|
|
|
|
|
: FriendItem(FriendItem)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2014-11-11 10:10:45 -05:00
|
|
|
TSharedPtr<IFriendItem> FriendItem;
|
2014-10-20 08:14:45 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
friend FFriendViewModelFactory;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TSharedRef< FFriendViewModel > FFriendViewModelFactory::Create(
|
2014-11-11 10:10:45 -05:00
|
|
|
const TSharedRef<IFriendItem>& FriendItem
|
2014-10-20 08:14:45 -04:00
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
TSharedRef< FFriendViewModelImpl > ViewModel(new FFriendViewModelImpl(FriendItem));
|
|
|
|
|
ViewModel->Initialize();
|
|
|
|
|
return ViewModel;
|
|
|
|
|
}
|