2014-12-07 19:09:38 -05:00
|
|
|
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
#include "FriendsAndChatPrivatePCH.h"
|
2014-10-20 08:14:45 -04:00
|
|
|
#include "SFriendsContainer.h"
|
2014-11-06 15:17:11 -05:00
|
|
|
#include "SChatWindow.h"
|
2014-10-20 08:14:45 -04:00
|
|
|
#include "FriendsViewModel.h"
|
2014-11-19 05:28:05 -05:00
|
|
|
#include "FriendViewModel.h"
|
2014-11-28 04:31:48 -05:00
|
|
|
#include "FriendsStatusViewModel.h"
|
2014-11-03 15:47:28 -05:00
|
|
|
#include "ChatViewModel.h"
|
2014-11-06 15:17:11 -05:00
|
|
|
#include "SNotificationList.h"
|
2014-11-06 15:19:23 -05:00
|
|
|
#include "SWindowTitleBar.h"
|
2014-11-28 04:31:48 -05:00
|
|
|
#include "SFriendsStatus.h"
|
2014-11-11 04:54:47 -05:00
|
|
|
#include "FriendRecentPlayerItems.h"
|
2014-11-11 09:47:06 -05:00
|
|
|
#include "FriendGameInviteItem.h"
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
#define LOCTEXT_NAMESPACE "FriendsAndChatManager"
|
|
|
|
|
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
/* FFriendsAndChatManager structors
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
FFriendsAndChatManager::FFriendsAndChatManager( )
|
2014-11-11 13:50:57 -05:00
|
|
|
: OnlineSubMcp(nullptr)
|
|
|
|
|
, MessageManager(FFriendsMessageManagerFactory::Create())
|
2014-11-19 05:28:05 -05:00
|
|
|
, ManagerState ( EFriendsAndManagerState::OffLine )
|
2014-03-14 14:13:41 -04:00
|
|
|
, bIsInited( false )
|
2014-11-06 15:17:11 -05:00
|
|
|
, bRequiresListRefresh(false)
|
2014-11-11 04:54:47 -05:00
|
|
|
, bRequiresRecentPlayersRefresh(false)
|
2014-11-15 10:30:13 -05:00
|
|
|
, bCreateChatWindow(false)
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
}
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
FFriendsAndChatManager::~FFriendsAndChatManager( )
|
2014-09-21 20:35:48 -04:00
|
|
|
{ }
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
/* IFriendsAndChatManager interface
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
2014-11-03 15:47:28 -05:00
|
|
|
void FFriendsAndChatManager::Login()
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
// Clear existing data
|
|
|
|
|
Logout();
|
|
|
|
|
|
|
|
|
|
bIsInited = false;
|
|
|
|
|
|
|
|
|
|
OnlineSubMcp = static_cast< FOnlineSubsystemMcp* >( IOnlineSubsystem::Get( TEXT( "MCP" ) ) );
|
|
|
|
|
|
2014-09-21 20:35:48 -04:00
|
|
|
if (OnlineSubMcp != nullptr &&
|
2014-03-14 14:13:41 -04:00
|
|
|
OnlineSubMcp->GetMcpAccountMappingService().IsValid() &&
|
|
|
|
|
OnlineSubMcp->GetIdentityInterface().IsValid())
|
|
|
|
|
{
|
|
|
|
|
OnlineIdentity = OnlineSubMcp->GetIdentityInterface();
|
|
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
if(OnlineIdentity->GetUniquePlayerId(0).IsValid())
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-11-06 15:17:11 -05:00
|
|
|
IOnlineUserPtr UserInterface = OnlineSubMcp->GetUserInterface();
|
|
|
|
|
check(UserInterface.IsValid());
|
|
|
|
|
|
|
|
|
|
FriendsInterface = OnlineSubMcp->GetFriendsInterface();
|
|
|
|
|
check( FriendsInterface.IsValid() )
|
|
|
|
|
|
|
|
|
|
// Create delegates for list refreshes
|
2014-11-11 04:54:47 -05:00
|
|
|
OnQueryRecentPlayersCompleteDelegate = FOnQueryRecentPlayersCompleteDelegate::CreateRaw(this, &FFriendsAndChatManager::OnQueryRecentPlayersComplete);
|
2014-11-06 15:17:11 -05:00
|
|
|
OnFriendsListChangedDelegate = FOnFriendsChangeDelegate::CreateSP(this, &FFriendsAndChatManager::OnFriendsListChanged);
|
|
|
|
|
OnDeleteFriendCompleteDelegate = FOnDeleteFriendCompleteDelegate::CreateSP( this, &FFriendsAndChatManager::OnDeleteFriendComplete );
|
|
|
|
|
OnQueryUserIdMappingCompleteDelegate = FOnQueryUserIdMappingCompleteDelegate::CreateSP( this, &FFriendsAndChatManager::OnQueryUserIdMappingComplete );
|
|
|
|
|
OnQueryUserInfoCompleteDelegate = FOnQueryUserInfoCompleteDelegate::CreateSP( this, &FFriendsAndChatManager::OnQueryUserInfoComplete );
|
|
|
|
|
OnPresenceReceivedCompleteDelegate = FOnPresenceReceivedDelegate::CreateSP(this, &FFriendsAndChatManager::OnPresenceReceived);
|
|
|
|
|
OnPresenceUpdatedCompleteDelegate = IOnlinePresence::FOnPresenceTaskCompleteDelegate::CreateSP(this, &FFriendsAndChatManager::OnPresenceUpdated);
|
|
|
|
|
OnFriendInviteReceivedDelegate = FOnInviteReceivedDelegate::CreateSP(this, &FFriendsAndChatManager::OnFriendInviteReceived);
|
|
|
|
|
OnFriendRemovedDelegate = FOnFriendRemovedDelegate::CreateSP(this, &FFriendsAndChatManager::OnFriendRemoved);
|
|
|
|
|
OnFriendInviteRejected = FOnInviteRejectedDelegate::CreateSP(this, &FFriendsAndChatManager::OnInviteRejected);
|
|
|
|
|
OnFriendInviteAccepted = FOnInviteAcceptedDelegate::CreateSP(this, &FFriendsAndChatManager::OnInviteAccepted);
|
2014-11-11 09:47:06 -05:00
|
|
|
OnGameInviteReceivedDelegate = FOnSessionInviteReceivedDelegate::CreateSP(this, &FFriendsAndChatManager::OnGameInviteReceived);
|
2014-11-11 13:50:57 -05:00
|
|
|
OnDestroySessionCompleteDelegate = FOnDestroySessionCompleteDelegate::CreateSP(this, &FFriendsAndChatManager::OnGameDestroyed);
|
2014-11-06 15:17:11 -05:00
|
|
|
|
2014-11-11 04:54:47 -05:00
|
|
|
FriendsInterface->AddOnQueryRecentPlayersCompleteDelegate(OnQueryRecentPlayersCompleteDelegate);
|
2014-11-06 15:17:11 -05:00
|
|
|
FriendsInterface->AddOnFriendsChangeDelegate(0, OnFriendsListChangedDelegate);
|
|
|
|
|
FriendsInterface->AddOnInviteReceivedDelegate(OnFriendInviteReceivedDelegate);
|
|
|
|
|
FriendsInterface->AddOnFriendRemovedDelegate(OnFriendRemovedDelegate);
|
|
|
|
|
FriendsInterface->AddOnInviteRejectedDelegate(OnFriendInviteRejected);
|
|
|
|
|
FriendsInterface->AddOnInviteAcceptedDelegate(OnFriendInviteAccepted);
|
|
|
|
|
FriendsInterface->AddOnDeleteFriendCompleteDelegate( 0, OnDeleteFriendCompleteDelegate );
|
|
|
|
|
UserInterface->AddOnQueryUserInfoCompleteDelegate(0, OnQueryUserInfoCompleteDelegate);
|
|
|
|
|
OnlineSubMcp->GetPresenceInterface()->AddOnPresenceReceivedDelegate(OnPresenceReceivedCompleteDelegate);
|
2014-11-11 09:47:06 -05:00
|
|
|
OnlineSubMcp->GetSessionInterface()->AddOnSessionInviteReceivedDelegate(OnGameInviteReceivedDelegate);
|
2014-11-11 13:50:57 -05:00
|
|
|
OnlineSubMcp->GetSessionInterface()->AddOnDestroySessionCompleteDelegate(OnDestroySessionCompleteDelegate);
|
2014-11-11 15:42:14 -05:00
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
FOnlinePersonaMcpPtr OnlinePersonaMcp = OnlineSubMcp->GetMcpPersonaService();
|
|
|
|
|
OnlinePersonaMcp->AddOnQueryUserIdMappingCompleteDelegate(OnQueryUserIdMappingCompleteDelegate);
|
|
|
|
|
|
|
|
|
|
ManagerState = EFriendsAndManagerState::Idle;
|
|
|
|
|
|
|
|
|
|
FriendsList.Empty();
|
|
|
|
|
PendingFriendsList.Empty();
|
|
|
|
|
|
|
|
|
|
if ( UpdateFriendsTickerDelegate.IsBound() == false )
|
|
|
|
|
{
|
|
|
|
|
UpdateFriendsTickerDelegate = FTickerDelegate::CreateSP( this, &FFriendsAndChatManager::Tick );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FTicker::GetCoreTicker().AddTicker( UpdateFriendsTickerDelegate );
|
|
|
|
|
|
|
|
|
|
SetState(EFriendsAndManagerState::RequestFriendsListRefresh);
|
2014-11-11 04:54:47 -05:00
|
|
|
RequestRecentPlayersListRefresh();
|
2014-11-06 15:17:11 -05:00
|
|
|
|
|
|
|
|
MessageManager->LogIn();
|
2014-11-08 11:02:45 -05:00
|
|
|
for (auto RoomName : ChatRoomstoJoin)
|
|
|
|
|
{
|
|
|
|
|
MessageManager->JoinPublicRoom(RoomName);
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
2014-11-06 15:17:11 -05:00
|
|
|
else
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-11-06 15:17:11 -05:00
|
|
|
SetState(EFriendsAndManagerState::OffLine);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::Logout()
|
|
|
|
|
{
|
2014-11-11 13:50:57 -05:00
|
|
|
if (OnlineSubMcp != nullptr)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-11-11 13:50:57 -05:00
|
|
|
if (OnlineSubMcp->GetFriendsInterface().IsValid())
|
|
|
|
|
{
|
|
|
|
|
OnlineSubMcp->GetFriendsInterface()->ClearOnQueryRecentPlayersCompleteDelegate(OnQueryRecentPlayersCompleteDelegate);
|
|
|
|
|
OnlineSubMcp->GetFriendsInterface()->ClearOnFriendsChangeDelegate(0, OnFriendsListChangedDelegate);
|
|
|
|
|
OnlineSubMcp->GetFriendsInterface()->ClearOnInviteReceivedDelegate(OnFriendInviteReceivedDelegate);
|
|
|
|
|
OnlineSubMcp->GetFriendsInterface()->ClearOnFriendRemovedDelegate(OnFriendRemovedDelegate);
|
|
|
|
|
OnlineSubMcp->GetFriendsInterface()->ClearOnInviteRejectedDelegate(OnFriendInviteRejected);
|
|
|
|
|
OnlineSubMcp->GetFriendsInterface()->ClearOnInviteAcceptedDelegate(OnFriendInviteAccepted);
|
|
|
|
|
OnlineSubMcp->GetFriendsInterface()->ClearOnDeleteFriendCompleteDelegate(0, OnDeleteFriendCompleteDelegate);
|
|
|
|
|
}
|
|
|
|
|
if (OnlineSubMcp->GetPresenceInterface().IsValid())
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-11-03 15:47:28 -05:00
|
|
|
OnlineSubMcp->GetPresenceInterface()->ClearOnPresenceReceivedDelegate(OnPresenceReceivedCompleteDelegate);
|
2014-11-11 13:50:57 -05:00
|
|
|
}
|
|
|
|
|
if (OnlineSubMcp->GetSessionInterface().IsValid())
|
|
|
|
|
{
|
2014-11-11 09:47:06 -05:00
|
|
|
OnlineSubMcp->GetSessionInterface()->ClearOnSessionInviteReceivedDelegate(OnGameInviteReceivedDelegate);
|
2014-11-11 13:50:57 -05:00
|
|
|
OnlineSubMcp->GetSessionInterface()->ClearOnDestroySessionCompleteDelegate(OnDestroySessionCompleteDelegate);
|
|
|
|
|
}
|
|
|
|
|
if (OnlineSubMcp->GetUserInterface().IsValid())
|
|
|
|
|
{
|
|
|
|
|
OnlineSubMcp->GetUserInterface()->ClearOnQueryUserInfoCompleteDelegate(0, OnQueryUserInfoCompleteDelegate);
|
|
|
|
|
}
|
|
|
|
|
if (OnlineSubMcp->GetMcpPersonaService().IsValid())
|
|
|
|
|
{
|
|
|
|
|
OnlineSubMcp->GetMcpPersonaService()->ClearOnQueryUserIdMappingCompleteDelegate(OnQueryUserIdMappingCompleteDelegate);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FriendsList.Empty();
|
|
|
|
|
PendingFriendsList.Empty();
|
|
|
|
|
FriendByNameRequests.Empty();
|
|
|
|
|
FilteredFriendsList.Empty();
|
|
|
|
|
PendingOutgoingDeleteFriendRequests.Empty();
|
|
|
|
|
PendingOutgoingAcceptFriendRequests.Empty();
|
|
|
|
|
PendingIncomingInvitesList.Empty();
|
2014-11-11 09:47:06 -05:00
|
|
|
PendingGameInvitesList.Empty();
|
2014-03-14 14:13:41 -04:00
|
|
|
NotifiedRequest.Empty();
|
|
|
|
|
|
|
|
|
|
if ( FriendWindow.IsValid() )
|
|
|
|
|
{
|
|
|
|
|
FriendWindow->RequestDestroyWindow();
|
2014-09-21 20:35:48 -04:00
|
|
|
FriendWindow = nullptr;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( ChatWindow.IsValid() )
|
|
|
|
|
{
|
2014-11-19 05:28:05 -05:00
|
|
|
Analytics.FlushChatStats();
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
ChatWindow->RequestDestroyWindow();
|
2014-09-21 20:35:48 -04:00
|
|
|
ChatWindow = nullptr;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
MessageManager->LogOut();
|
|
|
|
|
|
2014-09-21 20:35:48 -04:00
|
|
|
OnlineSubMcp = nullptr;
|
2014-03-14 14:13:41 -04:00
|
|
|
if ( UpdateFriendsTickerDelegate.IsBound() )
|
|
|
|
|
{
|
|
|
|
|
FTicker::GetCoreTicker().RemoveTicker( UpdateFriendsTickerDelegate );
|
|
|
|
|
}
|
2014-11-19 05:28:05 -05:00
|
|
|
|
|
|
|
|
SetState(EFriendsAndManagerState::OffLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FFriendsAndChatManager::IsLoggedIn()
|
|
|
|
|
{
|
|
|
|
|
return ManagerState != EFriendsAndManagerState::OffLine;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-27 06:36:11 -05:00
|
|
|
void FFriendsAndChatManager::SetApplicationViewModel(TSharedPtr<IFriendsApplicationViewModel> InApplicationViewModel)
|
|
|
|
|
{
|
|
|
|
|
ApplicationViewModel = InApplicationViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-18 17:39:35 -05:00
|
|
|
void FFriendsAndChatManager::SetUserSettings(const FFriendsAndChatSettings& UserSettings)
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
this->UserSettings = UserSettings;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-18 17:39:35 -05:00
|
|
|
void FFriendsAndChatManager::SetAnalyticsProvider(const TSharedPtr<IAnalyticsProvider>& AnalyticsProvider)
|
|
|
|
|
{
|
|
|
|
|
Analytics.SetProvider(AnalyticsProvider);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::InsertNetworkChatMessage(const FString& InMessage)
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
2014-11-11 04:54:47 -05:00
|
|
|
MessageManager->InsertNetworkMessage(InMessage);
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
|
2014-11-08 11:02:45 -05:00
|
|
|
void FFriendsAndChatManager::JoinPublicChatRoom(const FString& RoomName)
|
|
|
|
|
{
|
|
|
|
|
if (!RoomName.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
ChatRoomstoJoin.AddUnique(RoomName);
|
|
|
|
|
if (MessageManager.IsValid())
|
|
|
|
|
{
|
|
|
|
|
MessageManager->JoinPublicRoom(RoomName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
// UI Creation
|
|
|
|
|
|
2014-12-10 13:14:16 -05:00
|
|
|
void FFriendsAndChatManager::CreateFriendsListWindow(const FFriendsAndChatStyle* InStyle)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-12-10 13:14:16 -05:00
|
|
|
const FVector2D DEFAULT_WINDOW_SIZE = FVector2D(400, 458);
|
2014-11-15 10:30:13 -05:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
Style = *InStyle;
|
2014-12-02 09:42:28 -05:00
|
|
|
FFriendsAndChatModuleStyle::Initialize(Style);
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-11-19 05:28:05 -05:00
|
|
|
if (!FriendWindow.IsValid())
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
FriendWindow = SNew( SWindow )
|
2014-11-19 05:28:05 -05:00
|
|
|
.Title(LOCTEXT("FFriendsAndChatManager_FriendsTitle", "Friends List"))
|
2014-12-10 13:14:16 -05:00
|
|
|
.Style(&Style.WindowStyle)
|
2014-11-19 05:28:05 -05:00
|
|
|
.ClientSize(DEFAULT_WINDOW_SIZE)
|
|
|
|
|
.ScreenPosition(FVector2D(100, 100))
|
2014-03-14 14:13:41 -04:00
|
|
|
.AutoCenter( EAutoCenter::None )
|
2014-12-17 12:42:40 -05:00
|
|
|
.SizingRule(ESizingRule::UserSized)
|
|
|
|
|
.SupportsMaximize(true)
|
2014-11-15 10:30:13 -05:00
|
|
|
.SupportsMinimize(true)
|
2014-11-19 05:28:05 -05:00
|
|
|
.bDragAnywhere(true)
|
|
|
|
|
.CreateTitleBar(false);
|
2014-10-20 08:14:45 -04:00
|
|
|
|
2014-11-11 06:34:45 -05:00
|
|
|
FriendWindow->SetOnWindowClosed(FOnWindowClosed::CreateRaw(this, &FFriendsAndChatManager::HandleFriendsWindowClosed));
|
|
|
|
|
|
2014-10-20 08:15:49 -04:00
|
|
|
BuildFriendsUI();
|
2014-11-15 10:30:13 -05:00
|
|
|
FriendWindow = FSlateApplication::Get().AddWindow(FriendWindow.ToSharedRef());
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
2014-12-03 14:35:35 -05:00
|
|
|
else if(FriendWindow->IsWindowMinimized())
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
FriendWindow->Restore();
|
2014-10-20 08:15:49 -04:00
|
|
|
BuildFriendsUI();
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
2014-11-03 15:47:28 -05:00
|
|
|
|
2014-12-03 14:35:35 -05:00
|
|
|
FriendWindow->BringToFront(true);
|
|
|
|
|
|
2014-11-03 15:47:28 -05:00
|
|
|
// Clear notifications
|
|
|
|
|
OnFriendsNotification().Broadcast(false);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 06:34:45 -05:00
|
|
|
void FFriendsAndChatManager::HandleFriendsWindowClosed(const TSharedRef<SWindow>& InWindow)
|
|
|
|
|
{
|
|
|
|
|
FriendWindow.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
void FFriendsAndChatManager::BuildFriendsUI()
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-11-06 15:17:11 -05:00
|
|
|
check(FriendWindow.IsValid());
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-11-06 15:19:23 -05:00
|
|
|
TSharedPtr<SWindowTitleBar> TitleBar;
|
2014-11-06 15:17:11 -05:00
|
|
|
FriendWindow->SetContent(
|
2014-11-06 15:19:23 -05:00
|
|
|
SNew(SBorder)
|
|
|
|
|
.BorderImage( &Style.Background )
|
|
|
|
|
.VAlign( VAlign_Fill )
|
|
|
|
|
.HAlign( HAlign_Fill )
|
|
|
|
|
.Padding(0)
|
2014-11-06 15:17:11 -05:00
|
|
|
[
|
2014-11-06 15:19:23 -05:00
|
|
|
SNew(SOverlay)
|
|
|
|
|
+SOverlay::Slot()
|
|
|
|
|
[
|
|
|
|
|
SNew(SVerticalBox)
|
|
|
|
|
+ SVerticalBox::Slot()
|
|
|
|
|
.AutoHeight()
|
|
|
|
|
[
|
|
|
|
|
SAssignNew(TitleBar, SWindowTitleBar, FriendWindow.ToSharedRef(), nullptr, HAlign_Center)
|
2014-12-10 13:14:16 -05:00
|
|
|
.Style(&Style.WindowStyle)
|
2014-11-06 15:19:23 -05:00
|
|
|
.ShowAppIcon(false)
|
|
|
|
|
.Title(FText::GetEmpty())
|
|
|
|
|
]
|
|
|
|
|
+ SVerticalBox::Slot()
|
|
|
|
|
[
|
|
|
|
|
SNew(SFriendsContainer, FFriendsViewModelFactory::Create(SharedThis(this)))
|
|
|
|
|
.FriendStyle( &Style )
|
2014-11-20 15:04:53 -05:00
|
|
|
.Method(EPopupMethod::CreateNewWindow)
|
2014-11-06 15:19:23 -05:00
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
+SOverlay::Slot()
|
|
|
|
|
.HAlign(HAlign_Fill)
|
|
|
|
|
.VAlign(VAlign_Bottom)
|
|
|
|
|
[
|
|
|
|
|
SAssignNew(FriendsNotificationBox, SNotificationList)
|
|
|
|
|
]
|
2014-11-06 15:17:11 -05:00
|
|
|
]
|
2014-11-06 15:19:23 -05:00
|
|
|
);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
TSharedPtr< SWidget > FFriendsAndChatManager::GenerateFriendsListWidget( const FFriendsAndChatStyle* InStyle )
|
|
|
|
|
{
|
|
|
|
|
if ( !FriendListWidget.IsValid() )
|
|
|
|
|
{
|
|
|
|
|
Style = *InStyle;
|
2014-12-02 09:42:28 -05:00
|
|
|
FFriendsAndChatModuleStyle::Initialize(Style);
|
2014-11-06 15:17:11 -05:00
|
|
|
SAssignNew(FriendListWidget, SOverlay)
|
|
|
|
|
+SOverlay::Slot()
|
|
|
|
|
[
|
|
|
|
|
SNew(SFriendsContainer, FFriendsViewModelFactory::Create(SharedThis(this)))
|
|
|
|
|
.FriendStyle( &Style )
|
2014-11-20 15:04:53 -05:00
|
|
|
.Method(EPopupMethod::UseCurrentWindow)
|
2014-11-06 15:17:11 -05:00
|
|
|
]
|
|
|
|
|
+SOverlay::Slot()
|
|
|
|
|
.HAlign(HAlign_Fill)
|
|
|
|
|
.VAlign(VAlign_Bottom)
|
|
|
|
|
[
|
|
|
|
|
SAssignNew(FriendsNotificationBox, SNotificationList)
|
|
|
|
|
];
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-03 15:47:28 -05:00
|
|
|
// Clear notifications
|
|
|
|
|
OnFriendsNotification().Broadcast(false);
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
return FriendListWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-11-26 04:56:03 -05:00
|
|
|
TSharedPtr< SWidget > FFriendsAndChatManager::GenerateChatWidget(const FFriendsAndChatStyle* InStyle, TSharedRef<IChatViewModel> ViewModel)
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
2014-11-26 04:56:03 -05:00
|
|
|
// todo - NDavies = find a better way to do this
|
|
|
|
|
TSharedRef<FChatViewModel> ChatViewModel = StaticCastSharedRef<FChatViewModel>(ViewModel);
|
2014-12-03 10:16:36 -05:00
|
|
|
ChatViewModel->SetInGameUI(true);
|
|
|
|
|
ChatViewModel->SetCaptureFocus(true);
|
2014-11-06 15:17:11 -05:00
|
|
|
|
2014-11-26 04:56:03 -05:00
|
|
|
TSharedPtr<SChatWindow> ChatWidget;
|
2014-11-19 05:28:05 -05:00
|
|
|
Style = *InStyle;
|
2014-11-26 04:56:03 -05:00
|
|
|
SAssignNew(ChatWidget, SChatWindow, ChatViewModel)
|
|
|
|
|
.FriendStyle(&Style)
|
2014-12-08 13:30:39 -05:00
|
|
|
.Method(EPopupMethod::UseCurrentWindow);
|
2014-11-06 15:17:11 -05:00
|
|
|
return ChatWidget;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-13 16:15:33 -05:00
|
|
|
TSharedPtr<IChatViewModel> FFriendsAndChatManager::GetChatViewModel()
|
|
|
|
|
{
|
2014-11-26 04:56:03 -05:00
|
|
|
return FChatViewModelFactory::Create(MessageManager.ToSharedRef());
|
2014-11-13 16:15:33 -05:00
|
|
|
}
|
2014-11-06 15:17:11 -05:00
|
|
|
|
2014-12-17 12:42:40 -05:00
|
|
|
void FFriendsAndChatManager::CreateChatWindow(const struct FFriendsAndChatStyle* InStyle)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-12-03 14:35:35 -05:00
|
|
|
const FVector2D DEFAULT_WINDOW_SIZE = FVector2D(420, 500);
|
2014-11-06 15:17:11 -05:00
|
|
|
check(MessageManager.IsValid());
|
2014-11-15 10:30:13 -05:00
|
|
|
bCreateChatWindow = true;
|
2014-11-06 15:17:11 -05:00
|
|
|
|
2014-11-19 05:28:05 -05:00
|
|
|
if (!ChatWindow.IsValid())
|
|
|
|
|
{
|
2014-12-10 13:14:16 -05:00
|
|
|
Style = *InStyle;
|
|
|
|
|
FFriendsAndChatModuleStyle::Initialize(Style);
|
|
|
|
|
|
2014-11-19 05:28:05 -05:00
|
|
|
ChatWindow = SNew( SWindow )
|
|
|
|
|
.Title( LOCTEXT( "FriendsAndChatManager_ChatTitle", "Chat Window") )
|
2014-12-10 13:14:16 -05:00
|
|
|
.Style(&Style.WindowStyle)
|
2014-11-19 05:28:05 -05:00
|
|
|
.ClientSize( DEFAULT_WINDOW_SIZE )
|
|
|
|
|
.ScreenPosition( FVector2D( 200, 100 ) )
|
|
|
|
|
.AutoCenter( EAutoCenter::None )
|
2014-12-17 12:42:40 -05:00
|
|
|
.SupportsMaximize( true )
|
2014-11-19 05:28:05 -05:00
|
|
|
.SupportsMinimize( true )
|
|
|
|
|
.CreateTitleBar( false )
|
2014-12-17 12:42:40 -05:00
|
|
|
.SizingRule(ESizingRule::UserSized);
|
2014-11-12 06:43:48 -05:00
|
|
|
|
2014-11-19 05:28:05 -05:00
|
|
|
ChatWindow->SetOnWindowClosed(FOnWindowClosed::CreateRaw(this, &FFriendsAndChatManager::HandleChatWindowClosed));
|
2014-11-12 06:43:48 -05:00
|
|
|
|
2014-11-19 05:28:05 -05:00
|
|
|
SetChatWindowContents();
|
2014-12-17 12:42:40 -05:00
|
|
|
ChatWindow = FSlateApplication::Get().AddWindow(ChatWindow.ToSharedRef());
|
2014-11-15 10:30:13 -05:00
|
|
|
}
|
2014-11-19 05:28:05 -05:00
|
|
|
else if(ChatWindow->IsWindowMinimized())
|
|
|
|
|
{
|
|
|
|
|
ChatWindow->Restore();
|
|
|
|
|
SetChatWindowContents();
|
|
|
|
|
}
|
2014-12-03 14:35:35 -05:00
|
|
|
ChatWindow->BringToFront(true);
|
2014-12-17 12:42:40 -05:00
|
|
|
OnChatFriendSelected().Broadcast(nullptr);
|
2014-11-19 05:28:05 -05:00
|
|
|
}
|
2014-11-15 10:30:13 -05:00
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::SetChatFriend( TSharedPtr< IFriendItem > FriendItem )
|
|
|
|
|
{
|
2014-12-17 12:42:40 -05:00
|
|
|
if(bCreateChatWindow)
|
2014-11-15 10:30:13 -05:00
|
|
|
{
|
2014-12-17 12:42:40 -05:00
|
|
|
CreateChatWindow(&Style);
|
2014-11-15 10:30:13 -05:00
|
|
|
}
|
2014-12-17 12:42:40 -05:00
|
|
|
OnChatFriendSelected().Broadcast(FriendItem);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 06:34:45 -05:00
|
|
|
void FFriendsAndChatManager::HandleChatWindowClosed(const TSharedRef<SWindow>& InWindow)
|
|
|
|
|
{
|
|
|
|
|
ChatWindow.Reset();
|
2014-11-19 05:28:05 -05:00
|
|
|
|
|
|
|
|
Analytics.FlushChatStats();
|
2014-11-11 06:34:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::SetChatWindowContents()
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<SWindowTitleBar> TitleBar;
|
2014-11-26 04:56:03 -05:00
|
|
|
TSharedPtr<FChatViewModel> ChatViewModel = FChatViewModelFactory::Create(MessageManager.ToSharedRef());
|
|
|
|
|
ChatViewModel->SetInGameUI(false);
|
|
|
|
|
ChatViewModel->SetCaptureFocus(false);
|
2014-11-11 06:34:45 -05:00
|
|
|
|
2014-11-28 04:31:48 -05:00
|
|
|
TSharedRef< FFriendsStatusViewModel > StatusViewModel = FFriendsStatusViewModelFactory::Create(SharedThis(this));
|
|
|
|
|
|
2014-11-11 06:34:45 -05:00
|
|
|
ChatWindow->SetContent(
|
|
|
|
|
SNew( SBorder )
|
|
|
|
|
.VAlign( VAlign_Fill )
|
|
|
|
|
.HAlign( HAlign_Fill )
|
|
|
|
|
.BorderImage( &Style.Background )
|
|
|
|
|
[
|
|
|
|
|
SNew(SVerticalBox)
|
|
|
|
|
+ SVerticalBox::Slot()
|
|
|
|
|
.AutoHeight()
|
|
|
|
|
[
|
|
|
|
|
SAssignNew(TitleBar, SWindowTitleBar, ChatWindow.ToSharedRef(), nullptr, HAlign_Center)
|
2014-12-10 13:14:16 -05:00
|
|
|
.Style(&Style.WindowStyle)
|
2014-11-11 06:34:45 -05:00
|
|
|
.ShowAppIcon(false)
|
|
|
|
|
.Title(FText::GetEmpty())
|
|
|
|
|
]
|
|
|
|
|
+ SVerticalBox::Slot()
|
2014-11-28 04:31:48 -05:00
|
|
|
.AutoHeight()
|
2014-11-28 12:16:38 -05:00
|
|
|
.Padding(20.0f, 0.0f)
|
2014-11-28 04:31:48 -05:00
|
|
|
.VAlign(VAlign_Top)
|
|
|
|
|
[
|
|
|
|
|
SNew(SFriendsStatus, StatusViewModel)
|
|
|
|
|
.FriendStyle(&Style)
|
|
|
|
|
.Method(EPopupMethod::UseCurrentWindow)
|
|
|
|
|
]
|
|
|
|
|
+ SVerticalBox::Slot()
|
2014-11-11 06:34:45 -05:00
|
|
|
[
|
|
|
|
|
SNew(SChatWindow, ChatViewModel.ToSharedRef())
|
|
|
|
|
.FriendStyle( &Style )
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
}
|
2014-11-06 15:17:11 -05:00
|
|
|
// Actions
|
|
|
|
|
|
2014-11-13 22:10:45 -05:00
|
|
|
void FFriendsAndChatManager::SetUserIsOnline(EOnlinePresenceState::Type OnlineState)
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
if ( OnlineSubMcp != nullptr )
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FUniqueNetId> UserId = OnlineIdentity->GetUniquePlayerId(0);
|
2014-11-14 19:13:40 -05:00
|
|
|
if (UserId.IsValid())
|
2014-11-13 22:10:45 -05:00
|
|
|
{
|
2014-11-14 19:13:40 -05:00
|
|
|
TSharedPtr<FOnlineUserPresence> CurrentPresence;
|
|
|
|
|
OnlineSubMcp->GetPresenceInterface()->GetCachedPresence(*UserId, CurrentPresence);
|
2014-11-19 05:28:05 -05:00
|
|
|
FOnlineUserPresenceStatus NewStatus;
|
2014-11-14 19:13:40 -05:00
|
|
|
if (CurrentPresence.IsValid())
|
|
|
|
|
{
|
|
|
|
|
NewStatus = CurrentPresence->Status;
|
|
|
|
|
}
|
|
|
|
|
NewStatus.State = OnlineState;
|
|
|
|
|
OnlineSubMcp->GetPresenceInterface()->SetPresence(*UserId, NewStatus, OnPresenceUpdatedCompleteDelegate);
|
2014-11-19 05:28:05 -05:00
|
|
|
}
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
}
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
void FFriendsAndChatManager::AcceptFriend( TSharedPtr< IFriendItem > FriendItem )
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-11-19 05:28:05 -05:00
|
|
|
PendingOutgoingAcceptFriendRequests.Add(FUniqueNetIdString(FriendItem->GetOnlineUser()->GetUserId()->ToString()));
|
2014-03-14 14:13:41 -04:00
|
|
|
FriendItem->SetPendingAccept();
|
|
|
|
|
RefreshList();
|
2014-11-03 15:47:28 -05:00
|
|
|
OnFriendsNotification().Broadcast(false);
|
2014-11-18 17:39:35 -05:00
|
|
|
|
|
|
|
|
Analytics.RecordFriendAction(*FriendItem, TEXT("Social.FriendAction.Accept"));
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
void FFriendsAndChatManager::RejectFriend( TSharedPtr< IFriendItem > FriendItem )
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
NotifiedRequest.Remove( FriendItem->GetOnlineUser()->GetUserId() );
|
2014-10-20 08:14:45 -04:00
|
|
|
PendingOutgoingDeleteFriendRequests.Add(FUniqueNetIdString(FriendItem->GetOnlineUser()->GetUserId().Get().ToString()));
|
2014-03-14 14:13:41 -04:00
|
|
|
FriendsList.Remove( FriendItem );
|
|
|
|
|
RefreshList();
|
2014-11-03 15:47:28 -05:00
|
|
|
OnFriendsNotification().Broadcast(false);
|
2014-11-18 17:39:35 -05:00
|
|
|
|
|
|
|
|
Analytics.RecordFriendAction(*FriendItem, TEXT("Social.FriendAction.Reject"));
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
void FFriendsAndChatManager::DeleteFriend( TSharedPtr< IFriendItem > FriendItem )
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
TSharedRef<FUniqueNetId> UserID = FriendItem->GetOnlineFriend()->GetUserId();
|
|
|
|
|
NotifiedRequest.Remove( UserID );
|
|
|
|
|
PendingOutgoingDeleteFriendRequests.Add(FUniqueNetIdString(UserID.Get().ToString()));
|
|
|
|
|
FriendsList.Remove( FriendItem );
|
|
|
|
|
FriendItem->SetPendingDelete();
|
|
|
|
|
RefreshList();
|
|
|
|
|
// Clear notifications
|
|
|
|
|
OnFriendsNotification().Broadcast(false);
|
2014-11-18 17:39:35 -05:00
|
|
|
|
|
|
|
|
Analytics.RecordFriendAction(*FriendItem, TEXT("Social.FriendAction.Delete"));
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::RequestFriend( const FText& FriendName )
|
|
|
|
|
{
|
|
|
|
|
if ( !FriendName.IsEmpty() )
|
|
|
|
|
{
|
2014-11-19 05:28:05 -05:00
|
|
|
FriendByNameRequests.AddUnique(*FriendName.ToString());
|
|
|
|
|
}
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Process action responses
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
FReply FFriendsAndChatManager::HandleMessageAccepted( TSharedPtr< FFriendsAndChatMessage > ChatMessage, EFriendsResponseType::Type ResponseType )
|
|
|
|
|
{
|
|
|
|
|
switch ( ResponseType )
|
|
|
|
|
{
|
|
|
|
|
case EFriendsResponseType::Response_Accept:
|
|
|
|
|
{
|
2014-10-20 08:14:45 -04:00
|
|
|
PendingOutgoingAcceptFriendRequests.Add(FUniqueNetIdString(ChatMessage->GetUniqueID()->ToString()));
|
2014-11-11 10:10:45 -05:00
|
|
|
TSharedPtr< IFriendItem > User = FindUser(ChatMessage->GetUniqueID().Get());
|
2014-03-14 14:13:41 -04:00
|
|
|
if ( User.IsValid() )
|
|
|
|
|
{
|
2014-12-08 04:45:45 -05:00
|
|
|
AcceptFriend(User);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EFriendsResponseType::Response_Reject:
|
|
|
|
|
{
|
|
|
|
|
NotifiedRequest.Remove( ChatMessage->GetUniqueID() );
|
2014-11-11 10:10:45 -05:00
|
|
|
TSharedPtr< IFriendItem > User = FindUser( ChatMessage->GetUniqueID().Get());
|
2014-03-14 14:13:41 -04:00
|
|
|
if ( User.IsValid() )
|
|
|
|
|
{
|
2014-12-08 04:45:45 -05:00
|
|
|
RejectFriend(User);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NotificationMessages.Remove( ChatMessage );
|
|
|
|
|
|
|
|
|
|
return FReply::Handled();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
// Getters
|
|
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
int32 FFriendsAndChatManager::GetFilteredFriendsList( TArray< TSharedPtr< IFriendItem > >& OutFriendsList )
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
OutFriendsList = FilteredFriendsList;
|
|
|
|
|
return OutFriendsList.Num();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
TArray< TSharedPtr< IFriendItem > >& FFriendsAndChatManager::GetrecentPlayerList()
|
2014-11-11 04:54:47 -05:00
|
|
|
{
|
|
|
|
|
return RecentPlayersList;
|
|
|
|
|
}
|
2014-11-06 15:17:11 -05:00
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
int32 FFriendsAndChatManager::GetFilteredOutgoingFriendsList( TArray< TSharedPtr< IFriendItem > >& OutFriendsList )
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
OutFriendsList = FilteredOutgoingList;
|
|
|
|
|
return OutFriendsList.Num();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
int32 FFriendsAndChatManager::GetFilteredGameInviteList(TArray< TSharedPtr< IFriendItem > >& OutFriendsList)
|
2014-11-11 09:47:06 -05:00
|
|
|
{
|
|
|
|
|
for (auto It = PendingGameInvitesList.CreateConstIterator(); It; ++It)
|
|
|
|
|
{
|
|
|
|
|
OutFriendsList.Add(It.Value());
|
|
|
|
|
}
|
|
|
|
|
return OutFriendsList.Num();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-15 19:00:16 -05:00
|
|
|
FString FFriendsAndChatManager::GetGameSessionId() const
|
|
|
|
|
{
|
|
|
|
|
FString Result;
|
|
|
|
|
if (OnlineSubMcp != nullptr &&
|
|
|
|
|
OnlineIdentity.IsValid() &&
|
|
|
|
|
OnlineSubMcp->GetSessionInterface().IsValid())
|
|
|
|
|
{
|
|
|
|
|
const FNamedOnlineSession* GameSession = OnlineSubMcp->GetSessionInterface()->GetNamedSession(GameSessionName);
|
|
|
|
|
if (GameSession != nullptr)
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FOnlineSessionInfo> UserSessionInfo = GameSession->SessionInfo;
|
|
|
|
|
if (UserSessionInfo.IsValid())
|
|
|
|
|
{
|
|
|
|
|
Result = UserSessionInfo->GetSessionId().ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 15:42:14 -05:00
|
|
|
bool FFriendsAndChatManager::IsInGameSession() const
|
2014-11-11 13:50:57 -05:00
|
|
|
{
|
|
|
|
|
if (OnlineSubMcp != nullptr &&
|
|
|
|
|
OnlineIdentity.IsValid() &&
|
|
|
|
|
OnlineSubMcp->GetSessionInterface().IsValid() &&
|
|
|
|
|
OnlineSubMcp->GetSessionInterface()->GetNamedSession(GameSessionName) != nullptr)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 15:42:14 -05:00
|
|
|
bool FFriendsAndChatManager::IsInJoinableGameSession() const
|
|
|
|
|
{
|
2014-11-28 03:31:38 -05:00
|
|
|
bool bIsGameJoinable = false;
|
|
|
|
|
|
|
|
|
|
if (OnlineSubMcp != nullptr &&
|
|
|
|
|
OnlineSubMcp->GetIdentityInterface().IsValid() &&
|
|
|
|
|
OnlineSubMcp->GetPresenceInterface().IsValid())
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FUniqueNetId> CurrentUserId = OnlineSubMcp->GetIdentityInterface()->GetUniquePlayerId(0);
|
|
|
|
|
TSharedPtr<FOnlineUserPresence> Presence;
|
|
|
|
|
OnlineSubMcp->GetPresenceInterface()->GetCachedPresence(*CurrentUserId, Presence);
|
|
|
|
|
if (Presence.IsValid())
|
|
|
|
|
{
|
|
|
|
|
bIsGameJoinable = Presence->bIsJoinable;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 15:42:14 -05:00
|
|
|
return bIsGameJoinable && IsInGameSession();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-28 03:31:38 -05:00
|
|
|
bool FFriendsAndChatManager::JoinGameAllowed()
|
|
|
|
|
{
|
|
|
|
|
if (AllowFriendsJoinGame().IsBound())
|
|
|
|
|
{
|
|
|
|
|
return AllowFriendsJoinGame().Execute();
|
|
|
|
|
}
|
2014-11-28 04:21:38 -05:00
|
|
|
else if (ApplicationViewModel.IsValid())
|
|
|
|
|
{
|
|
|
|
|
return ApplicationViewModel->IsAppJoinable();
|
|
|
|
|
}
|
2014-11-28 03:31:38 -05:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-06 08:42:04 -05:00
|
|
|
const bool FFriendsAndChatManager::IsInLauncher() const
|
|
|
|
|
{
|
|
|
|
|
// ToDo NDavies - Find a better way to identify if we are in game
|
|
|
|
|
return !AllowFriendsJoinGameDelegate.IsBound();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-14 19:13:52 -05:00
|
|
|
EOnlinePresenceState::Type FFriendsAndChatManager::GetUserIsOnline()
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
if (OnlineSubMcp != nullptr)
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FOnlineUserPresence> Presence;
|
|
|
|
|
TSharedPtr<FUniqueNetId> UserId = OnlineIdentity->GetUniquePlayerId(0);
|
|
|
|
|
if(UserId.IsValid())
|
|
|
|
|
{
|
2014-11-14 19:13:40 -05:00
|
|
|
OnlineSubMcp->GetPresenceInterface()->GetCachedPresence(*UserId, Presence);
|
2014-11-06 15:17:11 -05:00
|
|
|
if(Presence.IsValid())
|
|
|
|
|
{
|
2014-11-14 19:13:52 -05:00
|
|
|
return Presence->Status.State;
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-11-14 19:13:52 -05:00
|
|
|
return EOnlinePresenceState::Offline;
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// List processing
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::RequestListRefresh()
|
|
|
|
|
{
|
|
|
|
|
bRequiresListRefresh = true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 04:54:47 -05:00
|
|
|
void FFriendsAndChatManager::RequestRecentPlayersListRefresh()
|
|
|
|
|
{
|
|
|
|
|
bRequiresRecentPlayersRefresh = true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
bool FFriendsAndChatManager::Tick( float Delta )
|
|
|
|
|
{
|
|
|
|
|
if ( ManagerState == EFriendsAndManagerState::Idle )
|
|
|
|
|
{
|
|
|
|
|
if ( FriendByNameRequests.Num() > 0 )
|
|
|
|
|
{
|
|
|
|
|
SetState(EFriendsAndManagerState::RequestingFriendName );
|
|
|
|
|
}
|
|
|
|
|
else if ( PendingOutgoingDeleteFriendRequests.Num() > 0 )
|
|
|
|
|
{
|
|
|
|
|
SetState( EFriendsAndManagerState::DeletingFriends );
|
|
|
|
|
}
|
|
|
|
|
else if ( PendingOutgoingAcceptFriendRequests.Num() > 0 )
|
|
|
|
|
{
|
|
|
|
|
SetState( EFriendsAndManagerState::AcceptingFriendRequest );
|
|
|
|
|
}
|
|
|
|
|
else if ( PendingIncomingInvitesList.Num() > 0 )
|
|
|
|
|
{
|
|
|
|
|
SendFriendInviteNotification();
|
|
|
|
|
}
|
|
|
|
|
else if (bRequiresListRefresh)
|
|
|
|
|
{
|
|
|
|
|
bRequiresListRefresh = false;
|
|
|
|
|
SetState( EFriendsAndManagerState::RequestFriendsListRefresh );
|
|
|
|
|
}
|
2014-11-11 04:54:47 -05:00
|
|
|
else if (bRequiresRecentPlayersRefresh)
|
|
|
|
|
{
|
|
|
|
|
bRequiresRecentPlayersRefresh = false;
|
|
|
|
|
SetState( EFriendsAndManagerState::RequestRecentPlayersListRefresh );
|
|
|
|
|
}
|
2014-11-28 03:31:38 -05:00
|
|
|
else if (ReceivedGameInvites.Num() > 0)
|
|
|
|
|
{
|
|
|
|
|
SetState(EFriendsAndManagerState::RequestGameInviteRefresh);
|
|
|
|
|
}
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
2014-12-15 15:29:48 -05:00
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::SetState( EFriendsAndManagerState::Type NewState )
|
|
|
|
|
{
|
|
|
|
|
ManagerState = NewState;
|
|
|
|
|
|
|
|
|
|
switch ( NewState )
|
|
|
|
|
{
|
|
|
|
|
case EFriendsAndManagerState::Idle:
|
|
|
|
|
{
|
|
|
|
|
// Do nothing in this state
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EFriendsAndManagerState::RequestFriendsListRefresh:
|
|
|
|
|
{
|
2014-12-02 13:48:04 -05:00
|
|
|
FOnReadFriendsListComplete Delegate = FOnReadFriendsListComplete::CreateSP(this, &FFriendsAndChatManager::OnReadFriendsListComplete);
|
|
|
|
|
if (FriendsInterface->ReadFriendsList(0, EFriendsLists::ToString(EFriendsLists::Default), Delegate))
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
SetState(EFriendsAndManagerState::RequestingFriendsList);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SetState(EFriendsAndManagerState::Idle);
|
|
|
|
|
RequestListRefresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-11-11 04:54:47 -05:00
|
|
|
case EFriendsAndManagerState::RequestRecentPlayersListRefresh:
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FUniqueNetId> UserId = OnlineIdentity->GetUniquePlayerId(0);
|
2014-11-14 19:13:40 -05:00
|
|
|
if (UserId.IsValid() &&
|
|
|
|
|
FriendsInterface->QueryRecentPlayers(*UserId))
|
2014-11-11 04:54:47 -05:00
|
|
|
{
|
|
|
|
|
SetState(EFriendsAndManagerState::RequestingRecentPlayersIDs);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SetState(EFriendsAndManagerState::Idle);
|
|
|
|
|
RequestRecentPlayersListRefresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-11-06 15:17:11 -05:00
|
|
|
case EFriendsAndManagerState::RequestingFriendsList:
|
2014-11-11 04:54:47 -05:00
|
|
|
case EFriendsAndManagerState::RequestingRecentPlayersIDs:
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
// Do Nothing
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EFriendsAndManagerState::ProcessFriendsList:
|
|
|
|
|
{
|
|
|
|
|
if ( ProcessFriendsList() )
|
|
|
|
|
{
|
|
|
|
|
RefreshList();
|
|
|
|
|
}
|
|
|
|
|
SetState( EFriendsAndManagerState::Idle );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EFriendsAndManagerState::RequestingFriendName:
|
|
|
|
|
{
|
|
|
|
|
SendFriendRequests();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EFriendsAndManagerState::DeletingFriends:
|
|
|
|
|
{
|
|
|
|
|
FriendsInterface->DeleteFriend( 0, PendingOutgoingDeleteFriendRequests[0], EFriendsLists::ToString( EFriendsLists::Default ) );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case EFriendsAndManagerState::AcceptingFriendRequest:
|
|
|
|
|
{
|
2014-12-05 11:23:15 -05:00
|
|
|
FOnAcceptInviteComplete Delegate = FOnAcceptInviteComplete::CreateSP(this, &FFriendsAndChatManager::OnAcceptInviteComplete);
|
|
|
|
|
FriendsInterface->AcceptInvite( 0, PendingOutgoingAcceptFriendRequests[0], EFriendsLists::ToString( EFriendsLists::Default ), Delegate );
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
break;
|
2014-11-28 03:31:38 -05:00
|
|
|
case EFriendsAndManagerState::RequestGameInviteRefresh:
|
|
|
|
|
{
|
|
|
|
|
// process invites and remove entries that are completed
|
|
|
|
|
ProcessReceivedGameInvites();
|
|
|
|
|
if (!RequestGameInviteUserInfo())
|
|
|
|
|
{
|
|
|
|
|
SetState(EFriendsAndManagerState::Idle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2014-11-06 15:17:11 -05:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::OnReadFriendsListComplete( int32 LocalPlayer, bool bWasSuccessful, const FString& ListName, const FString& ErrorStr )
|
|
|
|
|
{
|
|
|
|
|
PreProcessList(ListName);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 04:54:47 -05:00
|
|
|
void FFriendsAndChatManager::OnQueryRecentPlayersComplete(const FUniqueNetId& UserId, bool bWasSuccessful, const FString& ErrorStr)
|
|
|
|
|
{
|
|
|
|
|
bool bFoundAllIds = true;
|
|
|
|
|
|
|
|
|
|
if (bWasSuccessful)
|
|
|
|
|
{
|
|
|
|
|
RecentPlayersList.Empty();
|
|
|
|
|
TArray< TSharedRef<FOnlineRecentPlayer> > Players;
|
|
|
|
|
if (FriendsInterface->GetRecentPlayers(UserId, Players))
|
|
|
|
|
{
|
|
|
|
|
for (const auto& RecentPlayer : Players)
|
|
|
|
|
{
|
|
|
|
|
if(RecentPlayer->GetDisplayName().IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
QueryUserIds.Add(RecentPlayer->GetUserId());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RecentPlayersList.Add(MakeShareable(new FFriendRecentPlayerItem(RecentPlayer)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(QueryUserIds.Num())
|
|
|
|
|
{
|
|
|
|
|
check(OnlineSubMcp != nullptr && OnlineSubMcp->GetMcpPersonaService().IsValid());
|
|
|
|
|
IOnlineUserPtr UserInterface = OnlineSubMcp->GetUserInterface();
|
|
|
|
|
UserInterface->QueryUserInfo(0, QueryUserIds);
|
|
|
|
|
bFoundAllIds = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OnFriendsListUpdated().Broadcast();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(bFoundAllIds)
|
|
|
|
|
{
|
|
|
|
|
SetState(EFriendsAndManagerState::Idle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
void FFriendsAndChatManager::PreProcessList(const FString& ListName)
|
|
|
|
|
{
|
|
|
|
|
TArray< TSharedRef<FOnlineFriend> > Friends;
|
|
|
|
|
bool bReadyToChangeState = true;
|
|
|
|
|
|
|
|
|
|
if ( FriendsInterface->GetFriendsList(0, ListName, Friends) )
|
|
|
|
|
{
|
|
|
|
|
if (Friends.Num() > 0)
|
|
|
|
|
{
|
|
|
|
|
for ( const auto& Friend : Friends)
|
|
|
|
|
{
|
2014-11-11 10:10:45 -05:00
|
|
|
TSharedPtr< IFriendItem > ExistingFriend = FindUser(Friend->GetUserId().Get());
|
2014-11-06 15:17:11 -05:00
|
|
|
if ( ExistingFriend.IsValid() )
|
|
|
|
|
{
|
2014-11-20 00:00:24 -05:00
|
|
|
if (Friend->GetInviteStatus() != ExistingFriend->GetOnlineFriend()->GetInviteStatus() || (ExistingFriend->IsPendingAccepted() && Friend->GetInviteStatus() == EInviteStatus::Accepted))
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
ExistingFriend->SetOnlineFriend(Friend);
|
|
|
|
|
}
|
|
|
|
|
PendingFriendsList.Add(ExistingFriend);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QueryUserIds.Add(Friend->GetUserId());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check(OnlineSubMcp != nullptr && OnlineSubMcp->GetMcpPersonaService().IsValid());
|
|
|
|
|
IOnlineUserPtr UserInterface = OnlineSubMcp->GetUserInterface();
|
|
|
|
|
|
|
|
|
|
if ( QueryUserIds.Num() > 0 )
|
|
|
|
|
{
|
|
|
|
|
UserInterface->QueryUserInfo(0, QueryUserIds);
|
|
|
|
|
// OnQueryUserInfoComplete will handle state change
|
|
|
|
|
bReadyToChangeState = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogOnline, Warning, TEXT("Failed to obtain Friends List %s"), *ListName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (bReadyToChangeState)
|
|
|
|
|
{
|
|
|
|
|
SetState(EFriendsAndManagerState::ProcessFriendsList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::OnQueryUserInfoComplete( int32 LocalPlayer, bool bWasSuccessful, const TArray< TSharedRef<class FUniqueNetId> >& UserIds, const FString& ErrorStr )
|
|
|
|
|
{
|
|
|
|
|
if( ManagerState == EFriendsAndManagerState::RequestingFriendsList)
|
|
|
|
|
{
|
|
|
|
|
check(OnlineSubMcp != nullptr && OnlineSubMcp->GetMcpPersonaService().IsValid());
|
|
|
|
|
IOnlineUserPtr UserInterface = OnlineSubMcp->GetUserInterface();
|
|
|
|
|
|
|
|
|
|
for ( int32 UserIdx=0; UserIdx < UserIds.Num(); UserIdx++ )
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FOnlineFriend> OnlineFriend = FriendsInterface->GetFriend( 0, *UserIds[UserIdx], EFriendsLists::ToString( EFriendsLists::Default ) );
|
|
|
|
|
TSharedPtr<FOnlineUser> OnlineUser = OnlineSubMcp->GetUserInterface()->GetUserInfo( LocalPlayer, *UserIds[UserIdx] );
|
|
|
|
|
if (OnlineFriend.IsValid() && OnlineUser.IsValid())
|
|
|
|
|
{
|
2014-11-18 13:35:01 -05:00
|
|
|
TSharedPtr<IFriendItem> Existing;
|
|
|
|
|
for (auto FriendEntry : PendingFriendsList)
|
|
|
|
|
{
|
|
|
|
|
if (*FriendEntry->GetUniqueID() == *UserIds[UserIdx])
|
|
|
|
|
{
|
|
|
|
|
Existing = FriendEntry;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (Existing.IsValid())
|
|
|
|
|
{
|
|
|
|
|
Existing->SetOnlineUser(OnlineUser);
|
|
|
|
|
Existing->SetOnlineFriend(OnlineFriend);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr< FFriendItem > FriendItem = MakeShareable(new FFriendItem(OnlineFriend, OnlineUser, EFriendsDisplayLists::DefaultDisplay));
|
|
|
|
|
PendingFriendsList.Add(FriendItem);
|
|
|
|
|
}
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UE_LOG(LogOnline, Log, TEXT("PlayerId=%s not found"), *UserIds[UserIdx]->ToDebugString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QueryUserIds.Empty();
|
|
|
|
|
|
|
|
|
|
SetState( EFriendsAndManagerState::ProcessFriendsList );
|
|
|
|
|
}
|
2014-11-11 04:54:47 -05:00
|
|
|
else if(ManagerState == EFriendsAndManagerState::RequestingRecentPlayersIDs)
|
|
|
|
|
{
|
|
|
|
|
RecentPlayersList.Empty();
|
2014-11-14 19:13:40 -05:00
|
|
|
TSharedPtr<FUniqueNetId> UserId = OnlineIdentity->GetUniquePlayerId(0);
|
|
|
|
|
if (UserId.IsValid())
|
2014-11-11 04:54:47 -05:00
|
|
|
{
|
2014-11-19 05:28:05 -05:00
|
|
|
TArray< TSharedRef<FOnlineRecentPlayer> > Players;
|
2014-11-14 19:13:40 -05:00
|
|
|
if (FriendsInterface->GetRecentPlayers(*UserId, Players))
|
2014-11-11 04:54:47 -05:00
|
|
|
{
|
2014-11-19 05:28:05 -05:00
|
|
|
for (const auto& RecentPlayer : Players)
|
|
|
|
|
{
|
|
|
|
|
TSharedRef<FFriendRecentPlayerItem> RecentPlayerItem = MakeShareable(new FFriendRecentPlayerItem(RecentPlayer));
|
|
|
|
|
TSharedPtr<FOnlineUser> OnlineUser = OnlineSubMcp->GetUserInterface()->GetUserInfo(LocalPlayer, *RecentPlayer->GetUserId());
|
|
|
|
|
RecentPlayerItem->SetOnlineUser(OnlineUser);
|
|
|
|
|
RecentPlayersList.Add(RecentPlayerItem);
|
|
|
|
|
}
|
2014-11-11 04:54:47 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
OnFriendsListUpdated().Broadcast();
|
|
|
|
|
SetState(EFriendsAndManagerState::Idle);
|
|
|
|
|
}
|
2014-11-28 03:31:38 -05:00
|
|
|
else if (ManagerState == EFriendsAndManagerState::RequestGameInviteRefresh)
|
|
|
|
|
{
|
|
|
|
|
ProcessReceivedGameInvites();
|
|
|
|
|
ReceivedGameInvites.Empty();
|
|
|
|
|
SetState(EFriendsAndManagerState::Idle);
|
|
|
|
|
}
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FFriendsAndChatManager::ProcessFriendsList()
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-10-20 08:14:45 -04:00
|
|
|
/** Functor for comparing friends list */
|
|
|
|
|
struct FCompareGroupByName
|
|
|
|
|
{
|
2014-11-11 10:10:45 -05:00
|
|
|
FORCEINLINE bool operator()( const TSharedPtr< IFriendItem > A, const TSharedPtr< IFriendItem > B ) const
|
2014-10-20 08:14:45 -04:00
|
|
|
{
|
|
|
|
|
check( A.IsValid() );
|
|
|
|
|
check ( B.IsValid() );
|
|
|
|
|
return ( A->GetName() > B->GetName() );
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
bool bChanged = false;
|
|
|
|
|
// Early check if list has changed
|
|
|
|
|
if ( PendingFriendsList.Num() != FriendsList.Num() )
|
|
|
|
|
{
|
|
|
|
|
bChanged = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Need to check each item
|
|
|
|
|
FriendsList.Sort( FCompareGroupByName() );
|
|
|
|
|
PendingFriendsList.Sort( FCompareGroupByName() );
|
|
|
|
|
for ( int32 Index = 0; Index < FriendsList.Num(); Index++ )
|
|
|
|
|
{
|
2014-11-11 04:54:47 -05:00
|
|
|
if (PendingFriendsList[Index]->IsUpdated() || FriendsList[Index]->GetUniqueID() != PendingFriendsList[Index]->GetUniqueID())
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
bChanged = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( bChanged )
|
|
|
|
|
{
|
|
|
|
|
PendingIncomingInvitesList.Empty();
|
|
|
|
|
|
|
|
|
|
for ( int32 Index = 0; Index < PendingFriendsList.Num(); Index++ )
|
|
|
|
|
{
|
|
|
|
|
PendingFriendsList[Index]->ClearUpdated();
|
|
|
|
|
EInviteStatus::Type FriendStatus = PendingFriendsList[ Index ].Get()->GetOnlineFriend()->GetInviteStatus();
|
|
|
|
|
if ( FriendStatus == EInviteStatus::PendingInbound )
|
|
|
|
|
{
|
|
|
|
|
if ( NotifiedRequest.Contains( PendingFriendsList[ Index ].Get()->GetUniqueID() ) == false )
|
|
|
|
|
{
|
|
|
|
|
PendingIncomingInvitesList.Add( PendingFriendsList[ Index ] );
|
|
|
|
|
NotifiedRequest.Add( PendingFriendsList[ Index ]->GetUniqueID() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
FriendByNameInvites.Empty();
|
|
|
|
|
FriendsList = PendingFriendsList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PendingFriendsList.Empty();
|
|
|
|
|
|
|
|
|
|
return bChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::RefreshList()
|
|
|
|
|
{
|
|
|
|
|
FilteredFriendsList.Empty();
|
|
|
|
|
|
2014-10-20 08:14:45 -04:00
|
|
|
for( const auto& Friend : FriendsList)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-10-20 08:14:45 -04:00
|
|
|
if( !Friend->IsPendingDelete())
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
|
|
|
|
FilteredFriendsList.Add( Friend );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 09:47:06 -05:00
|
|
|
OnFriendsListUpdated().Broadcast();
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::SendFriendRequests()
|
|
|
|
|
{
|
|
|
|
|
// Invite Friends
|
2014-11-03 15:47:28 -05:00
|
|
|
FOnlinePersonaMcpPtr OnlinePersonaMcp = OnlineSubMcp->GetMcpPersonaService();
|
2014-03-14 14:13:41 -04:00
|
|
|
TSharedPtr<FUniqueNetId> UserId = OnlineIdentity->GetUniquePlayerId(0);
|
2014-11-14 19:13:40 -05:00
|
|
|
if (UserId.IsValid())
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-11-19 05:28:05 -05:00
|
|
|
for (int32 Index = 0; Index < FriendByNameRequests.Num(); Index++)
|
|
|
|
|
{
|
|
|
|
|
OnlinePersonaMcp->QueryUserIdMapping(*UserId, FriendByNameRequests[Index]);
|
|
|
|
|
}
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TSharedPtr< FUniqueNetId > FFriendsAndChatManager::FindUserID( const FString& InUsername )
|
|
|
|
|
{
|
|
|
|
|
for ( int32 Index = 0; Index < FriendsList.Num(); Index++ )
|
|
|
|
|
{
|
|
|
|
|
if ( FriendsList[ Index ]->GetOnlineUser()->GetDisplayName() == InUsername )
|
|
|
|
|
{
|
|
|
|
|
return FriendsList[ Index ]->GetUniqueID();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-21 20:35:48 -04:00
|
|
|
return nullptr;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
TSharedPtr< IFriendItem > FFriendsAndChatManager::FindUser(const FUniqueNetId& InUserID)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-10-20 08:14:45 -04:00
|
|
|
for ( const auto& Friend : FriendsList)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-11-06 15:17:11 -05:00
|
|
|
if (Friend->GetUniqueID().Get() == InUserID)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-10-20 08:14:45 -04:00
|
|
|
return Friend;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 20:35:48 -04:00
|
|
|
return nullptr;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-18 17:39:35 -05:00
|
|
|
TSharedPtr< IFriendItem > FFriendsAndChatManager::FindRecentPlayer(const FUniqueNetId& InUserID)
|
|
|
|
|
{
|
|
|
|
|
for (const auto& Friend : RecentPlayersList)
|
|
|
|
|
{
|
|
|
|
|
if (Friend->GetUniqueID().Get() == InUserID)
|
|
|
|
|
{
|
|
|
|
|
return Friend;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-19 05:28:05 -05:00
|
|
|
TSharedPtr<FFriendViewModel> FFriendsAndChatManager::GetFriendViewModel(const FUniqueNetId& InUserID)
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<IFriendItem> FoundFriend = FindUser(InUserID);
|
|
|
|
|
if(FoundFriend.IsValid())
|
|
|
|
|
{
|
|
|
|
|
return FFriendViewModelFactory::Create(FoundFriend.ToSharedRef());
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
void FFriendsAndChatManager::SendFriendInviteNotification()
|
|
|
|
|
{
|
2014-11-06 15:17:11 -05:00
|
|
|
for( const auto& FriendRequest : PendingIncomingInvitesList)
|
|
|
|
|
{
|
2014-12-08 04:45:45 -05:00
|
|
|
if(OnFriendsActionNotification().IsBound())
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
FFormatNamedArguments Args;
|
|
|
|
|
Args.Add(TEXT("Username"), FText::FromString(FriendRequest->GetName()));
|
|
|
|
|
const FText FriendRequestMessage = FText::Format(LOCTEXT("FFriendsAndChatManager_AddedYou", "Friend request from {Username}"), Args);
|
|
|
|
|
|
|
|
|
|
TSharedPtr< FFriendsAndChatMessage > NotificationMessage = MakeShareable(new FFriendsAndChatMessage(FriendRequestMessage.ToString(), FriendRequest->GetUniqueID()));
|
|
|
|
|
NotificationMessage->SetButtonCallback( FOnClicked::CreateSP(this, &FFriendsAndChatManager::HandleMessageAccepted, NotificationMessage, EFriendsResponseType::Response_Accept));
|
2014-12-08 04:45:45 -05:00
|
|
|
NotificationMessage->SetButtonCallback( FOnClicked::CreateSP(this, &FFriendsAndChatManager::HandleMessageAccepted, NotificationMessage, EFriendsResponseType::Response_Reject));
|
|
|
|
|
NotificationMessage->SetButtonDescription(LOCTEXT("FFriendsAndChatManager_Accept", "Accept"));
|
|
|
|
|
NotificationMessage->SetButtonDescription(LOCTEXT("FFriendsAndChatManager_Reject", "Reject"));
|
2014-11-06 15:17:11 -05:00
|
|
|
NotificationMessage->SetMessageType(EFriendsRequestType::FriendInvite);
|
2014-12-08 04:45:45 -05:00
|
|
|
OnFriendsActionNotification().Broadcast(NotificationMessage.ToSharedRef());
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-03 15:47:28 -05:00
|
|
|
PendingIncomingInvitesList.Empty();
|
|
|
|
|
FriendsListNotificationDelegate.Broadcast(true);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
void FFriendsAndChatManager::SendInviteAcceptedNotification(const TSharedPtr< IFriendItem > Friend)
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
2014-12-08 04:45:45 -05:00
|
|
|
if(OnFriendsActionNotification().IsBound())
|
2014-11-06 15:17:11 -05:00
|
|
|
{
|
|
|
|
|
FFormatNamedArguments Args;
|
|
|
|
|
Args.Add(TEXT("Username"), FText::FromString(Friend->GetName()));
|
|
|
|
|
const FText FriendRequestMessage = FText::Format(LOCTEXT("FFriendsAndChatManager_Accepted", "{Username} accepted your request"), Args);
|
|
|
|
|
|
|
|
|
|
TSharedPtr< FFriendsAndChatMessage > NotificationMessage = MakeShareable(new FFriendsAndChatMessage(FriendRequestMessage.ToString()));
|
|
|
|
|
NotificationMessage->SetMessageType(EFriendsRequestType::FriendAccepted);
|
|
|
|
|
OnFriendsActionNotification().Broadcast(NotificationMessage.ToSharedRef());
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-11-03 15:47:28 -05:00
|
|
|
void FFriendsAndChatManager::OnQueryUserIdMappingComplete(bool bWasSuccessful, const FUniqueNetId& RequestingUserId, const FString& DisplayName, const FUniqueNetId& IdentifiedUserId, const FString& Error)
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-11-03 15:47:28 -05:00
|
|
|
check( OnlineSubMcp != nullptr && OnlineSubMcp->GetMcpPersonaService().IsValid() );
|
2014-03-14 14:13:41 -04:00
|
|
|
|
2014-11-18 17:39:35 -05:00
|
|
|
EFindFriendResult::Type FindFriendResult = EFindFriendResult::NotFound;
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
if ( bWasSuccessful && IdentifiedUserId.IsValid() )
|
|
|
|
|
{
|
2014-11-14 14:43:39 -05:00
|
|
|
TSharedPtr<IFriendItem> ExistingFriend = FindUser(IdentifiedUserId);
|
|
|
|
|
if (ExistingFriend.IsValid())
|
2014-03-14 14:13:41 -04:00
|
|
|
{
|
2014-11-14 14:43:39 -05:00
|
|
|
if (ExistingFriend->GetInviteStatus() == EInviteStatus::Accepted)
|
|
|
|
|
{
|
|
|
|
|
AddFriendsToast(FText::FromString("Already friends"));
|
2014-11-18 17:39:35 -05:00
|
|
|
|
|
|
|
|
FindFriendResult = EFindFriendResult::AlreadyFriends;
|
2014-11-14 14:43:39 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AddFriendsToast(FText::FromString("Friend already requested"));
|
2014-11-18 17:39:35 -05:00
|
|
|
|
|
|
|
|
FindFriendResult = EFindFriendResult::FriendsPending;
|
2014-11-14 14:43:39 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (IdentifiedUserId == RequestingUserId)
|
|
|
|
|
{
|
|
|
|
|
AddFriendsToast(FText::FromString("Can't friend yourself"));
|
2014-11-18 17:39:35 -05:00
|
|
|
|
|
|
|
|
FindFriendResult = EFindFriendResult::AddingSelfFail;
|
2014-11-14 14:43:39 -05:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-11-19 05:28:05 -05:00
|
|
|
TSharedPtr<FUniqueNetId> FriendId = OnlineIdentity->CreateUniquePlayerId(IdentifiedUserId.ToString());
|
|
|
|
|
PendingOutgoingFriendRequests.Add(FriendId.ToSharedRef());
|
2014-11-14 14:43:39 -05:00
|
|
|
FriendByNameInvites.AddUnique(DisplayName);
|
2014-11-18 17:39:35 -05:00
|
|
|
|
|
|
|
|
FindFriendResult = EFindFriendResult::Success;
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
2014-11-06 15:17:11 -05:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const FString DiplayMessage = DisplayName + TEXT(" not found");
|
|
|
|
|
AddFriendsToast(FText::FromString(DiplayMessage));
|
|
|
|
|
}
|
2014-10-20 08:14:45 -04:00
|
|
|
|
2014-11-18 17:39:35 -05:00
|
|
|
bool bRecentPlayer = false;
|
|
|
|
|
if (FindFriendResult == EFindFriendResult::Success)
|
|
|
|
|
{
|
|
|
|
|
bRecentPlayer = FindRecentPlayer(IdentifiedUserId).IsValid();
|
|
|
|
|
}
|
|
|
|
|
Analytics.RecordAddFriend(DisplayName, IdentifiedUserId, FindFriendResult, bRecentPlayer, TEXT("Social.AddFriend"));
|
|
|
|
|
|
2014-08-06 16:12:41 -04:00
|
|
|
FriendByNameRequests.Remove( DisplayName );
|
2014-03-14 14:13:41 -04:00
|
|
|
if ( FriendByNameRequests.Num() == 0 )
|
|
|
|
|
{
|
|
|
|
|
if ( PendingOutgoingFriendRequests.Num() > 0 )
|
|
|
|
|
{
|
|
|
|
|
for ( int32 Index = 0; Index < PendingOutgoingFriendRequests.Num(); Index++ )
|
|
|
|
|
{
|
2014-12-05 11:23:15 -05:00
|
|
|
FOnSendInviteComplete Delegate = FOnSendInviteComplete::CreateSP(this, &FFriendsAndChatManager::OnSendInviteComplete);
|
|
|
|
|
FriendsInterface->SendInvite(0, PendingOutgoingFriendRequests[Index].Get(), EFriendsLists::ToString( EFriendsLists::Default ), Delegate);
|
2015-01-06 07:19:34 -05:00
|
|
|
AddFriendsToast(LOCTEXT("FFriendsAndChatManager_FriendRequestSent", "Request Sent"));
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RefreshList();
|
2014-10-20 08:14:45 -04:00
|
|
|
SetState(EFriendsAndManagerState::Idle);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
void FFriendsAndChatManager::OnSendInviteComplete( int32 LocalPlayer, bool bWasSuccessful, const FUniqueNetId& FriendId, const FString& ListName, const FString& ErrorStr )
|
|
|
|
|
{
|
|
|
|
|
PendingOutgoingFriendRequests.RemoveAt( 0 );
|
|
|
|
|
|
|
|
|
|
if ( PendingOutgoingFriendRequests.Num() == 0 )
|
|
|
|
|
{
|
2014-10-20 08:14:45 -04:00
|
|
|
RefreshList();
|
2014-11-06 15:17:11 -05:00
|
|
|
RequestListRefresh();
|
2014-10-20 08:14:45 -04:00
|
|
|
SetState(EFriendsAndManagerState::Idle);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-03 15:47:28 -05:00
|
|
|
void FFriendsAndChatManager::OnPresenceReceived( const FUniqueNetId& UserId, const TSharedRef<FOnlineUserPresence>& Presence)
|
|
|
|
|
{
|
2014-11-28 03:31:38 -05:00
|
|
|
RefreshList();
|
2014-11-03 15:47:28 -05:00
|
|
|
}
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
void FFriendsAndChatManager::OnPresenceUpdated(const FUniqueNetId& UserId, const bool bWasSuccessful)
|
|
|
|
|
{
|
2014-11-28 03:31:38 -05:00
|
|
|
RefreshList();
|
2014-11-06 15:17:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::OnFriendsListChanged()
|
|
|
|
|
{
|
|
|
|
|
// TODO: May need to do something here
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::OnFriendInviteReceived(const FUniqueNetId& UserId, const FUniqueNetId& FriendId)
|
|
|
|
|
{
|
|
|
|
|
RequestListRefresh();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 09:47:06 -05:00
|
|
|
void FFriendsAndChatManager::OnGameInviteReceived(const FUniqueNetId& UserId, const FUniqueNetId& FromId, const FOnlineSessionSearchResult& InviteResult)
|
|
|
|
|
{
|
2014-11-28 03:31:38 -05:00
|
|
|
if (OnlineSubMcp != NULL &&
|
|
|
|
|
OnlineSubMcp->GetIdentityInterface().IsValid())
|
2014-11-11 09:47:06 -05:00
|
|
|
{
|
2014-11-28 03:31:38 -05:00
|
|
|
TSharedPtr<FUniqueNetId> FromIdPtr = OnlineSubMcp->GetIdentityInterface()->CreateUniquePlayerId(FromId.ToString());
|
|
|
|
|
if (FromIdPtr.IsValid())
|
|
|
|
|
{
|
|
|
|
|
ReceivedGameInvites.AddUnique(FReceivedGameInvite(FromIdPtr.ToSharedRef(), InviteResult));
|
|
|
|
|
}
|
2014-11-12 14:12:02 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-28 03:31:38 -05:00
|
|
|
void FFriendsAndChatManager::ProcessReceivedGameInvites()
|
|
|
|
|
{
|
|
|
|
|
if (OnlineSubMcp != NULL &&
|
|
|
|
|
OnlineSubMcp->GetUserInterface().IsValid())
|
|
|
|
|
{
|
|
|
|
|
for (int32 Idx = 0; Idx < ReceivedGameInvites.Num(); Idx++)
|
|
|
|
|
{
|
|
|
|
|
const FReceivedGameInvite& Invite = ReceivedGameInvites[Idx];
|
|
|
|
|
|
|
|
|
|
TSharedPtr<FOnlineUser> UserInfo;
|
|
|
|
|
TSharedPtr<IFriendItem> Friend = FindUser(*Invite.FromId);
|
|
|
|
|
if (Friend.IsValid())
|
|
|
|
|
{
|
|
|
|
|
UserInfo = Friend->GetOnlineUser();
|
|
|
|
|
}
|
|
|
|
|
if (!UserInfo.IsValid())
|
|
|
|
|
{
|
|
|
|
|
UserInfo = OnlineSubMcp->GetUserInterface()->GetUserInfo(0, *Invite.FromId);
|
|
|
|
|
}
|
|
|
|
|
if (UserInfo.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FFriendGameInviteItem> GameInvite = MakeShareable(
|
|
|
|
|
new FFriendGameInviteItem(UserInfo.ToSharedRef(), Invite.InviteResult)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
PendingGameInvitesList.Add(Invite.FromId->ToString(), GameInvite);
|
|
|
|
|
|
|
|
|
|
OnGameInvitesUpdated().Broadcast();
|
|
|
|
|
SendGameInviteNotification(GameInvite);
|
|
|
|
|
|
|
|
|
|
ReceivedGameInvites.RemoveAt(Idx--);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FFriendsAndChatManager::RequestGameInviteUserInfo()
|
|
|
|
|
{
|
|
|
|
|
bool bPending = false;
|
|
|
|
|
|
|
|
|
|
// query for user ids that are not already cached from game invites
|
|
|
|
|
IOnlineUserPtr UserInterface = OnlineSubMcp->GetUserInterface();
|
|
|
|
|
IOnlineIdentityPtr IdentityInterface = OnlineSubMcp->GetIdentityInterface();
|
|
|
|
|
if (UserInterface.IsValid() &&
|
|
|
|
|
IdentityInterface.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TArray<TSharedRef<FUniqueNetId>> GameInviteUserIds;
|
|
|
|
|
for (auto GameInvite : ReceivedGameInvites)
|
|
|
|
|
{
|
|
|
|
|
GameInviteUserIds.Add(GameInvite.FromId);
|
|
|
|
|
}
|
|
|
|
|
if (GameInviteUserIds.Num() > 0)
|
|
|
|
|
{
|
|
|
|
|
UserInterface->QueryUserInfo(0, GameInviteUserIds);
|
|
|
|
|
bPending = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bPending;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-12 14:12:02 -05:00
|
|
|
void FFriendsAndChatManager::SendGameInviteNotification(const TSharedPtr<IFriendItem>& FriendItem)
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
FFormatNamedArguments Args;
|
|
|
|
|
Args.Add(TEXT("Username"), FText::FromString(FriendItem->GetName()));
|
|
|
|
|
const FText FriendRequestMessage = FText::Format(LOCTEXT("FFriendsAndChatManager_GameInvite", "Game invite from {Username}"), Args);
|
|
|
|
|
|
|
|
|
|
TSharedPtr< FFriendsAndChatMessage > NotificationMessage = MakeShareable(new FFriendsAndChatMessage(FriendRequestMessage.ToString()));
|
|
|
|
|
NotificationMessage->SetMessageType(EFriendsRequestType::GameInvite);
|
|
|
|
|
OnFriendsActionNotification().Broadcast(NotificationMessage.ToSharedRef());
|
2014-11-11 09:47:06 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-17 12:42:40 -05:00
|
|
|
void FFriendsAndChatManager::SendChatMessageReceivedEvent()
|
|
|
|
|
{
|
|
|
|
|
OnChatMessageRecieved().Broadcast();;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 13:50:57 -05:00
|
|
|
void FFriendsAndChatManager::OnGameDestroyed(const FName SessionName, bool bWasSuccessful)
|
|
|
|
|
{
|
|
|
|
|
if (SessionName == GameSessionName)
|
|
|
|
|
{
|
|
|
|
|
RequestRecentPlayersListRefresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
void FFriendsAndChatManager::RejectGameInvite(const TSharedPtr<IFriendItem>& FriendItem)
|
2014-11-11 09:47:06 -05:00
|
|
|
{
|
2014-11-11 10:10:45 -05:00
|
|
|
TSharedPtr<IFriendItem>* Existing = PendingGameInvitesList.Find(FriendItem->GetUniqueID()->ToString());
|
2014-11-11 09:47:20 -05:00
|
|
|
if (Existing != nullptr)
|
2014-11-11 09:47:06 -05:00
|
|
|
{
|
|
|
|
|
(*Existing)->SetPendingDelete();
|
|
|
|
|
PendingGameInvitesList.Remove(FriendItem->GetUniqueID()->ToString());
|
|
|
|
|
}
|
2014-11-11 20:34:01 -05:00
|
|
|
// update game invite UI
|
2014-11-11 09:47:06 -05:00
|
|
|
OnGameInvitesUpdated().Broadcast();
|
2014-11-18 17:39:35 -05:00
|
|
|
|
2014-11-20 04:05:40 -05:00
|
|
|
Analytics.RecordGameInvite(*FriendItem->GetUniqueID(), TEXT("Social.GameInvite.Reject"));
|
2014-11-11 09:47:06 -05:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
void FFriendsAndChatManager::AcceptGameInvite(const TSharedPtr<IFriendItem>& FriendItem)
|
2014-11-11 09:47:06 -05:00
|
|
|
{
|
2014-11-11 20:34:01 -05:00
|
|
|
TSharedPtr<IFriendItem>* Existing = PendingGameInvitesList.Find(FriendItem->GetUniqueID()->ToString());
|
|
|
|
|
if (Existing != nullptr)
|
|
|
|
|
{
|
|
|
|
|
(*Existing)->SetPendingDelete();
|
|
|
|
|
PendingGameInvitesList.Remove(FriendItem->GetUniqueID()->ToString());
|
|
|
|
|
}
|
|
|
|
|
// update game invite UI
|
2014-11-11 09:47:06 -05:00
|
|
|
OnGameInvitesUpdated().Broadcast();
|
2014-11-11 20:34:01 -05:00
|
|
|
// notify for further processing of join game request
|
|
|
|
|
OnFriendsJoinGame().Broadcast(*FriendItem->GetUniqueID(), FriendItem->GetGameSessionId());
|
2014-11-18 17:39:35 -05:00
|
|
|
|
2014-11-27 06:36:11 -05:00
|
|
|
if(ApplicationViewModel.IsValid())
|
|
|
|
|
{
|
2014-12-02 10:17:27 -05:00
|
|
|
const FString AdditionalCommandline = TEXT("-invitesession=") + FriendItem->GetGameSessionId() + TEXT(" -invitefrom=") + FriendItem->GetUniqueID()->ToString();
|
2014-11-27 06:36:11 -05:00
|
|
|
ApplicationViewModel->LaunchFriendApp(AdditionalCommandline);
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 04:05:40 -05:00
|
|
|
Analytics.RecordGameInvite(*FriendItem->GetUniqueID(), TEXT("Social.GameInvite.Accept"));
|
2014-11-11 09:47:06 -05:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 10:10:45 -05:00
|
|
|
void FFriendsAndChatManager::SendGameInvite(const TSharedPtr<IFriendItem>& FriendItem)
|
2014-11-20 04:05:40 -05:00
|
|
|
{
|
|
|
|
|
SendGameInvite(*FriendItem->GetUniqueID());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::SendGameInvite(const FUniqueNetId& ToUser)
|
2014-11-11 09:47:20 -05:00
|
|
|
{
|
|
|
|
|
if (OnlineSubMcp != nullptr &&
|
|
|
|
|
OnlineIdentity.IsValid() &&
|
|
|
|
|
OnlineSubMcp->GetSessionInterface().IsValid() &&
|
|
|
|
|
OnlineSubMcp->GetSessionInterface()->GetNamedSession(GameSessionName) != nullptr)
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FUniqueNetId> UserId = OnlineIdentity->GetUniquePlayerId(0);
|
|
|
|
|
if (UserId.IsValid())
|
|
|
|
|
{
|
2014-11-20 04:05:40 -05:00
|
|
|
OnlineSubMcp->GetSessionInterface()->SendSessionInviteToFriend(*UserId, GameSessionName, ToUser);
|
2015-01-06 07:19:34 -05:00
|
|
|
AddFriendsToast(LOCTEXT("FFriendsAndChatManager_InviteToGameSent", "Invite Sent"));
|
2014-11-20 04:05:40 -05:00
|
|
|
Analytics.RecordGameInvite(ToUser, TEXT("Social.GameInvite.Send"));
|
2014-11-11 09:47:20 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
void FFriendsAndChatManager::OnFriendRemoved(const FUniqueNetId& UserId, const FUniqueNetId& FriendId)
|
|
|
|
|
{
|
|
|
|
|
RequestListRefresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::OnInviteRejected(const FUniqueNetId& UserId, const FUniqueNetId& FriendId)
|
|
|
|
|
{
|
|
|
|
|
RequestListRefresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::OnInviteAccepted(const FUniqueNetId& UserId, const FUniqueNetId& FriendId)
|
|
|
|
|
{
|
2014-11-11 10:10:45 -05:00
|
|
|
TSharedPtr< IFriendItem > Friend = FindUser(FriendId);
|
2014-11-06 15:17:11 -05:00
|
|
|
if(Friend.IsValid())
|
|
|
|
|
{
|
|
|
|
|
Friend->SetPendingAccept();
|
|
|
|
|
SendInviteAcceptedNotification(Friend);
|
|
|
|
|
}
|
|
|
|
|
RefreshList();
|
|
|
|
|
RequestListRefresh();
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
void FFriendsAndChatManager::OnAcceptInviteComplete( int32 LocalPlayer, bool bWasSuccessful, const FUniqueNetId& FriendId, const FString& ListName, const FString& ErrorStr )
|
|
|
|
|
{
|
2014-10-20 08:14:45 -04:00
|
|
|
PendingOutgoingAcceptFriendRequests.Remove(FUniqueNetIdString(FriendId.ToString()));
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
// Do something with an accepted invite
|
|
|
|
|
if ( PendingOutgoingAcceptFriendRequests.Num() > 0 )
|
|
|
|
|
{
|
|
|
|
|
SetState( EFriendsAndManagerState::AcceptingFriendRequest );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RefreshList();
|
2014-11-06 15:17:11 -05:00
|
|
|
RequestListRefresh();
|
2014-03-14 14:13:41 -04:00
|
|
|
SetState( EFriendsAndManagerState::Idle );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatManager::OnDeleteFriendComplete( int32 LocalPlayer, bool bWasSuccessful, const FUniqueNetId& DeletedFriendID, const FString& ListName, const FString& ErrorStr )
|
|
|
|
|
{
|
2014-10-20 08:14:45 -04:00
|
|
|
PendingOutgoingDeleteFriendRequests.Remove(FUniqueNetIdString(DeletedFriendID.ToString()));
|
|
|
|
|
|
|
|
|
|
RefreshList();
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
if ( PendingOutgoingDeleteFriendRequests.Num() > 0 )
|
|
|
|
|
{
|
|
|
|
|
SetState( EFriendsAndManagerState::DeletingFriends );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-10-20 08:14:45 -04:00
|
|
|
SetState(EFriendsAndManagerState::Idle);
|
2014-03-14 14:13:41 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-06 15:17:11 -05:00
|
|
|
void FFriendsAndChatManager::AddFriendsToast(const FText Message)
|
|
|
|
|
{
|
|
|
|
|
if( FriendsNotificationBox.IsValid())
|
|
|
|
|
{
|
|
|
|
|
FNotificationInfo Info(Message);
|
|
|
|
|
Info.ExpireDuration = 2.0f;
|
|
|
|
|
Info.bUseLargeFont = false;
|
|
|
|
|
FriendsNotificationBox->AddNotification(Info);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-11-18 17:39:35 -05:00
|
|
|
// Analytics
|
|
|
|
|
|
2014-11-20 04:05:40 -05:00
|
|
|
void FFriendsAndChatAnalytics::RecordGameInvite(const FUniqueNetId& ToUser, const FString& EventStr) const
|
2014-11-18 17:39:35 -05:00
|
|
|
{
|
|
|
|
|
if (Provider.IsValid())
|
|
|
|
|
{
|
|
|
|
|
IOnlineIdentityPtr OnlineIdentity = Online::GetIdentityInterface(MCP_SUBSYSTEM);
|
|
|
|
|
if (OnlineIdentity.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FUniqueNetId> UserId = OnlineIdentity->GetUniquePlayerId(0);
|
|
|
|
|
if (UserId.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TArray<FAnalyticsEventAttribute> Attributes;
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("User"), UserId->ToString()));
|
2014-11-20 04:05:40 -05:00
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("Friend"), ToUser.ToString()));
|
2014-11-18 17:39:35 -05:00
|
|
|
AddPresenceAttributes(*UserId, Attributes);
|
|
|
|
|
Provider->RecordEvent(EventStr, Attributes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatAnalytics::RecordFriendAction(const IFriendItem& Friend, const FString& EventStr) const
|
|
|
|
|
{
|
|
|
|
|
if (Provider.IsValid())
|
|
|
|
|
{
|
|
|
|
|
IOnlineIdentityPtr OnlineIdentity = Online::GetIdentityInterface(MCP_SUBSYSTEM);
|
|
|
|
|
if (OnlineIdentity.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FUniqueNetId> UserId = OnlineIdentity->GetUniquePlayerId(0);
|
|
|
|
|
if (UserId.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TArray<FAnalyticsEventAttribute> Attributes;
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("User"), UserId->ToString()));
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("Friend"), Friend.GetUniqueID()->ToString()));
|
|
|
|
|
AddPresenceAttributes(*UserId, Attributes);
|
|
|
|
|
Provider->RecordEvent(EventStr, Attributes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatAnalytics::RecordAddFriend(const FString& FriendName, const FUniqueNetId& FriendId, EFindFriendResult::Type Result, bool bRecentPlayer, const FString& EventStr) const
|
|
|
|
|
{
|
|
|
|
|
if (Provider.IsValid())
|
|
|
|
|
{
|
|
|
|
|
IOnlineIdentityPtr OnlineIdentity = Online::GetIdentityInterface(MCP_SUBSYSTEM);
|
|
|
|
|
if (OnlineIdentity.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FUniqueNetId> UserId = OnlineIdentity->GetUniquePlayerId(0);
|
|
|
|
|
if (UserId.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TArray<FAnalyticsEventAttribute> Attributes;
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("User"), UserId->ToString()));
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("Friend"), FriendId.ToString()));
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("FriendName"), FriendName));
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("Result"), EFindFriendResult::ToString(Result)));
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("bRecentPlayer"), bRecentPlayer));
|
|
|
|
|
AddPresenceAttributes(*UserId, Attributes);
|
|
|
|
|
Provider->RecordEvent(EventStr, Attributes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatAnalytics::RecordToggleChat(const FString& Channel, bool bEnabled, const FString& EventStr) const
|
|
|
|
|
{
|
|
|
|
|
if (Provider.IsValid())
|
|
|
|
|
{
|
|
|
|
|
IOnlineIdentityPtr OnlineIdentity = Online::GetIdentityInterface(MCP_SUBSYSTEM);
|
|
|
|
|
if (OnlineIdentity.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FUniqueNetId> UserId = OnlineIdentity->GetUniquePlayerId(0);
|
|
|
|
|
if (UserId.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TArray<FAnalyticsEventAttribute> Attributes;
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("User"), UserId->ToString()));
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("Channel"), Channel));
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("bEnabled"), bEnabled));
|
|
|
|
|
AddPresenceAttributes(*UserId, Attributes);
|
|
|
|
|
Provider->RecordEvent(EventStr, Attributes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-19 05:28:05 -05:00
|
|
|
void FFriendsAndChatAnalytics::RecordPrivateChat(const FString& ToUser)
|
|
|
|
|
{
|
|
|
|
|
int32& Count = ChatCounts.FindOrAdd(ToUser);
|
|
|
|
|
Count += 1;
|
|
|
|
|
int32& TotalCount = ChatCounts.FindOrAdd(TEXT("TotalPrivate"));
|
|
|
|
|
TotalCount += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatAnalytics::RecordChannelChat(const FString& ToChannel)
|
|
|
|
|
{
|
|
|
|
|
int32& Count = ChatCounts.FindOrAdd(ToChannel);
|
|
|
|
|
Count += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FFriendsAndChatAnalytics::FlushChatStats()
|
|
|
|
|
{
|
|
|
|
|
if (Provider.IsValid())
|
|
|
|
|
{
|
|
|
|
|
IOnlineIdentityPtr OnlineIdentity = Online::GetIdentityInterface(MCP_SUBSYSTEM);
|
|
|
|
|
if (OnlineIdentity.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FUniqueNetId> UserId = OnlineIdentity->GetUniquePlayerId(0);
|
|
|
|
|
if (UserId.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TArray<FAnalyticsEventAttribute> Attributes;
|
|
|
|
|
for (auto It = ChatCounts.CreateConstIterator(); It; ++It)
|
|
|
|
|
{
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(It.Key(), It.Value()));
|
|
|
|
|
}
|
|
|
|
|
Provider->RecordEvent(TEXT("Social.Chat.Counts"), Attributes);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ChatCounts.Empty();
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-18 17:39:35 -05:00
|
|
|
void FFriendsAndChatAnalytics::AddPresenceAttributes(const FUniqueNetId& UserId, TArray<FAnalyticsEventAttribute>& Attributes) const
|
|
|
|
|
{
|
|
|
|
|
IOnlinePresencePtr OnlinePresence = Online::GetPresenceInterface(MCP_SUBSYSTEM);
|
|
|
|
|
if (OnlinePresence.IsValid())
|
|
|
|
|
{
|
|
|
|
|
TSharedPtr<FOnlineUserPresence> Presence;
|
|
|
|
|
OnlinePresence->GetCachedPresence(UserId, Presence);
|
|
|
|
|
if (Presence.IsValid())
|
|
|
|
|
{
|
|
|
|
|
FVariantData* ClientIdData = Presence->Status.Properties.Find(DefaultClientIdKey);
|
|
|
|
|
if (ClientIdData != nullptr)
|
|
|
|
|
{
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("ClientId"), ClientIdData->ToString()));
|
|
|
|
|
}
|
|
|
|
|
Attributes.Add(FAnalyticsEventAttribute(TEXT("Status"), Presence->Status.StatusStr));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
/* FFriendsAndChatManager system singletons
|
|
|
|
|
*****************************************************************************/
|
2014-09-21 20:35:48 -04:00
|
|
|
|
|
|
|
|
TSharedPtr< FFriendsAndChatManager > FFriendsAndChatManager::SingletonInstance = nullptr;
|
2014-03-14 14:13:41 -04:00
|
|
|
|
|
|
|
|
TSharedRef< FFriendsAndChatManager > FFriendsAndChatManager::Get()
|
|
|
|
|
{
|
|
|
|
|
if ( !SingletonInstance.IsValid() )
|
|
|
|
|
{
|
|
|
|
|
SingletonInstance = MakeShareable( new FFriendsAndChatManager() );
|
|
|
|
|
}
|
|
|
|
|
return SingletonInstance.ToSharedRef();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
void FFriendsAndChatManager::Shutdown()
|
|
|
|
|
{
|
|
|
|
|
SingletonInstance.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-21 20:35:48 -04:00
|
|
|
|
2014-03-14 14:13:41 -04:00
|
|
|
#undef LOCTEXT_NAMESPACE
|