< Summary

Class:FriendsHUDController
Assembly:FriendsHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/FriendsHUDController.cs
Covered lines:242
Uncovered lines:73
Coverable lines:315
Total lines:612
Line coverage:76.8% (242 of 315)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FriendsHUDController(...)0%110100%
Initialize(...)0%550100%
SetVisiblePanelList(...)0%220100%
Dispose()0%770100%
SetVisibility(...)0%7.147085.71%
HandleViewClosed()0%6200%
HandleFriendsInitialized()0%9.166055.56%
HandleProfileUpdated(...)0%110100%
UpdateBlockStatus()0%13.2111073.68%
HandleRequestSent(...)0%4.024088.89%
AreAlreadyFriends(...)0%330100%
HandleUserStatusUpdated(...)0%110100%
UpdateUserStatus(...)0%37.1411040%
HandleFriendshipUpdated(...)0%27.3811048.65%
HandleFriendProfileUpdated(...)0%3.13077.78%
IsUserBlocked(...)0%3.333066.67%
OnFriendNotFound(...)0%110100%
UpdateNotificationsCounter()0%220100%
HandleOpenWhisperChat(...)0%220100%
HandleUnfriend(...)0%2100%
HandleRequestRejected(...)0%6200%
HandleRequestCancelled(...)0%12300%
HandleRequestAccepted(...)0%6200%
DisplayFriendsIfAnyIsLoaded()0%3.333066.67%
DisplayMoreFriends()0%220100%
DisplayMoreFriendRequests()0%110100%
DisplayMoreFriendRequestsAsync()0%8.056061.54%
AddFriendRequests(...)0%330100%
AddFriendRequest(...)0%6.096086.67%
DisplayFriendRequestsIfAnyIsLoaded()0%3.333066.67%
ShowOrHideMoreFriendRequestsToLoadHint()0%220100%
ShowOrHideMoreFriendsToLoadHint()0%330100%
SearchFriends(...)0%220100%
OpenFriendRequestDetails(...)0%4.594066.67%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/FriendsHUDController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL;
 3using DCL.Social.Friends;
 4using SocialFeaturesAnalytics;
 5using System;
 6using System.Collections.Generic;
 7using UnityEngine;
 8
 9public class FriendsHUDController : IHUD
 10{
 11    private const int LOAD_FRIENDS_ON_DEMAND_COUNT = 30;
 12    private const int MAX_SEARCHED_FRIENDS = 100;
 13    private const string NEW_FRIEND_REQUESTS_FLAG = "new_friend_requests";
 14    private const string ENABLE_QUICK_ACTIONS_FOR_FRIEND_REQUESTS_FLAG = "enable_quick_actions_on_friend_requests";
 15
 4216    private readonly Dictionary<string, FriendEntryModel> friends = new Dictionary<string, FriendEntryModel>();
 4217    private readonly Dictionary<string, FriendEntryModel> onlineFriends = new Dictionary<string, FriendEntryModel>();
 18    private readonly DataStore dataStore;
 19    private readonly IFriendsController friendsController;
 20    private readonly IUserProfileBridge userProfileBridge;
 21    private readonly ISocialAnalytics socialAnalytics;
 22    private readonly IChatController chatController;
 23    private readonly IMouseCatcher mouseCatcher;
 3824    private BaseVariable<HashSet<string>> visibleTaskbarPanels => dataStore.HUDs.visibleTaskbarPanels;
 1825    private bool isNewFriendRequestsEnabled => dataStore.featureFlags.flags.Get().IsFeatureEnabled(NEW_FRIEND_REQUESTS_F
 526    private bool isQuickActionsForFriendRequestsEnabled => !isNewFriendRequestsEnabled || dataStore.featureFlags.flags.G
 27
 28    private UserProfile ownUserProfile;
 29    private bool searchingFriends;
 30    private int lastSkipForFriends;
 31    private int lastSkipForFriendRequests;
 32
 96133    public IFriendsHUDComponentView View { get; private set; }
 34
 35    public event Action<string> OnPressWhisper;
 36    public event Action OnOpened;
 37    public event Action OnClosed;
 38    public event Action OnViewClosed;
 39
 4240    public FriendsHUDController(DataStore dataStore,
 41        IFriendsController friendsController,
 42        IUserProfileBridge userProfileBridge,
 43        ISocialAnalytics socialAnalytics,
 44        IChatController chatController,
 45        IMouseCatcher mouseCatcher)
 46    {
 4247        this.dataStore = dataStore;
 4248        this.friendsController = friendsController;
 4249        this.userProfileBridge = userProfileBridge;
 4250        this.socialAnalytics = socialAnalytics;
 4251        this.chatController = chatController;
 4252        this.mouseCatcher = mouseCatcher;
 4253    }
 54
 55    public void Initialize(IFriendsHUDComponentView view = null)
 56    {
 4257        view ??= FriendsHUDComponentView.Create();
 4258        View = view;
 59
 4260        view.Initialize(chatController, friendsController, socialAnalytics);
 4261        view.RefreshFriendsTab();
 4262        view.OnFriendRequestApproved += HandleRequestAccepted;
 4263        view.OnCancelConfirmation += HandleRequestCancelled;
 4264        view.OnRejectConfirmation += HandleRequestRejected;
 4265        view.OnFriendRequestSent += HandleRequestSent;
 4266        view.OnFriendRequestOpened += OpenFriendRequestDetails;
 4267        view.OnWhisper += HandleOpenWhisperChat;
 4268        view.OnClose += HandleViewClosed;
 4269        view.OnRequireMoreFriends += DisplayMoreFriends;
 4270        view.OnRequireMoreFriendRequests += DisplayMoreFriendRequests;
 4271        view.OnSearchFriendsRequested += SearchFriends;
 4272        view.OnFriendListDisplayed += DisplayFriendsIfAnyIsLoaded;
 4273        view.OnRequestListDisplayed += DisplayFriendRequestsIfAnyIsLoaded;
 74
 4275        if(mouseCatcher != null)
 4176            mouseCatcher.OnMouseLock += HandleViewClosed;
 77
 4278        ownUserProfile = userProfileBridge.GetOwn();
 4279        ownUserProfile.OnUpdate -= HandleProfileUpdated;
 4280        ownUserProfile.OnUpdate += HandleProfileUpdated;
 81
 4282        if (friendsController != null)
 83        {
 4284            friendsController.OnUpdateFriendship += HandleFriendshipUpdated;
 4285            friendsController.OnUpdateUserStatus += HandleUserStatusUpdated;
 4286            friendsController.OnFriendNotFound += OnFriendNotFound;
 4287            friendsController.OnAddFriendRequest += AddFriendRequest;
 88
 4289            if (friendsController.IsInitialized)
 90            {
 291                view.HideLoadingSpinner();
 92            }
 93            else
 94            {
 4095                view.ShowLoadingSpinner();
 4096                friendsController.OnInitialized -= HandleFriendsInitialized;
 4097                friendsController.OnInitialized += HandleFriendsInitialized;
 98            }
 99        }
 100
 42101        ShowOrHideMoreFriendsToLoadHint();
 42102        ShowOrHideMoreFriendRequestsToLoadHint();
 42103    }
 104
 105    private void SetVisiblePanelList(bool visible)
 106    {
 19107        HashSet<string> newSet = visibleTaskbarPanels.Get();
 19108        if (visible)
 15109            newSet.Add("FriendsPanel");
 110        else
 4111            newSet.Remove("FriendsPanel");
 112
 19113        visibleTaskbarPanels.Set(newSet, true);
 19114    }
 115
 116    public void Dispose()
 117    {
 43118        if (friendsController != null)
 119        {
 43120            friendsController.OnInitialized -= HandleFriendsInitialized;
 43121            friendsController.OnUpdateFriendship -= HandleFriendshipUpdated;
 43122            friendsController.OnUpdateUserStatus -= HandleUserStatusUpdated;
 123        }
 124
 43125        if (View != null)
 126        {
 43127            View.OnFriendRequestApproved -= HandleRequestAccepted;
 43128            View.OnCancelConfirmation -= HandleRequestCancelled;
 43129            View.OnRejectConfirmation -= HandleRequestRejected;
 43130            View.OnFriendRequestSent -= HandleRequestSent;
 43131            View.OnFriendRequestOpened -= OpenFriendRequestDetails;
 43132            View.OnWhisper -= HandleOpenWhisperChat;
 43133            View.OnDeleteConfirmation -= HandleUnfriend;
 43134            View.OnClose -= HandleViewClosed;
 43135            View.OnRequireMoreFriends -= DisplayMoreFriends;
 43136            View.OnRequireMoreFriendRequests -= DisplayMoreFriendRequests;
 43137            View.OnSearchFriendsRequested -= SearchFriends;
 43138            View.OnFriendListDisplayed -= DisplayFriendsIfAnyIsLoaded;
 43139            View.OnRequestListDisplayed -= DisplayFriendRequestsIfAnyIsLoaded;
 43140            View.Dispose();
 141        }
 142
 43143        if (ownUserProfile != null)
 43144            ownUserProfile.OnUpdate -= HandleProfileUpdated;
 145
 43146        if (userProfileBridge != null)
 147        {
 114148            foreach (var friendId in friends.Keys)
 149            {
 14150                var profile = userProfileBridge.Get(friendId);
 14151                if (profile == null) continue;
 14152                profile.OnUpdate -= HandleFriendProfileUpdated;
 153            }
 154        }
 43155    }
 156
 157    public void SetVisibility(bool visible)
 158    {
 19159        SetVisiblePanelList(visible);
 19160        if (visible)
 161        {
 15162            lastSkipForFriends = 0;
 15163            lastSkipForFriendRequests = 0;
 15164            View.ClearAll();
 15165            View.Show();
 15166            UpdateNotificationsCounter();
 167
 30168            foreach (var friend in onlineFriends)
 0169                View.Set(friend.Key, friend.Value);
 170
 15171            if (View.IsFriendListActive)
 7172                DisplayMoreFriends();
 8173            else if (View.IsRequestListActive)
 5174                DisplayMoreFriendRequestsAsync().Forget();
 175
 15176            OnOpened?.Invoke();
 177        }
 178        else
 179        {
 4180            View.Hide();
 4181            View.DisableSearchMode();
 4182            searchingFriends = false;
 4183            OnClosed?.Invoke();
 184        }
 0185    }
 186
 187    private void HandleViewClosed()
 188    {
 0189        OnViewClosed?.Invoke();
 0190        SetVisibility(false);
 0191    }
 192
 193    private void HandleFriendsInitialized()
 194    {
 1195        friendsController.OnInitialized -= HandleFriendsInitialized;
 1196        View.HideLoadingSpinner();
 197
 1198        if (View.IsActive())
 199        {
 0200            if (View.IsFriendListActive && lastSkipForFriends <= 0)
 0201                DisplayMoreFriends();
 0202            else if (View.IsRequestListActive && lastSkipForFriendRequests <= 0)
 0203                DisplayMoreFriendRequestsAsync().Forget();
 204        }
 205
 1206        UpdateNotificationsCounter();
 1207    }
 208
 2209    private void HandleProfileUpdated(UserProfile profile) => UpdateBlockStatus(profile).Forget();
 210
 211    private async UniTask UpdateBlockStatus(UserProfile profile)
 212    {
 213        const int iterationsPerFrame = 10;
 214
 215        //NOTE(Brian): HashSet to check Contains quicker.
 2216        var allBlockedUsers = profile.blocked != null
 217            ? new HashSet<string>(profile.blocked)
 218            : new HashSet<string>();
 219
 2220        var iterations = 0;
 221
 8222        foreach (var friendPair in friends)
 223        {
 2224            var friendId = friendPair.Key;
 2225            var model = friendPair.Value;
 226
 2227            model.blocked = allBlockedUsers.Contains(friendId);
 2228            await UniTask.SwitchToMainThread();
 2229            View.UpdateBlockStatus(friendId, model.blocked);
 230
 2231            iterations++;
 2232            if (iterations > 0 && iterations % iterationsPerFrame == 0)
 0233                await UniTask.NextFrame();
 2234        }
 2235    }
 236
 237    private void HandleRequestSent(string userNameOrId)
 238    {
 3239        if (AreAlreadyFriends(userNameOrId))
 240        {
 1241            View.ShowRequestSendError(FriendRequestError.AlreadyFriends);
 242        }
 243        else
 244        {
 2245            if (isNewFriendRequestsEnabled)
 2246                friendsController.RequestFriendshipAsync(userNameOrId, "").Forget();
 247            else
 0248                friendsController.RequestFriendship(userNameOrId);
 249
 2250            if (ownUserProfile != null)
 2251                socialAnalytics.SendFriendRequestSent(ownUserProfile.userId, userNameOrId, 0,
 252                    PlayerActionSource.FriendsHUD);
 253
 2254            View.ShowRequestSendSuccess();
 255        }
 2256    }
 257
 258    private bool AreAlreadyFriends(string userNameOrId)
 259    {
 3260        var userId = userNameOrId;
 3261        var profile = userProfileBridge.GetByName(userNameOrId);
 262
 3263        if (profile != default)
 1264            userId = profile.userId;
 265
 3266        return friendsController != null
 267               && friendsController.ContainsStatus(userId, FriendshipStatus.FRIEND);
 268    }
 269
 270    private void HandleUserStatusUpdated(string userId, UserStatus status) =>
 2271        UpdateUserStatus(userId, status);
 272
 273    private void UpdateUserStatus(string userId, UserStatus status)
 274    {
 3275        switch (status.friendshipStatus)
 276        {
 277            case FriendshipStatus.FRIEND:
 3278                var friend = friends.ContainsKey(userId)
 279                    ? new FriendEntryModel(friends[userId])
 280                    : new FriendEntryModel();
 3281                friend.CopyFrom(status);
 3282                friend.blocked = IsUserBlocked(userId);
 3283                friends[userId] = friend;
 3284                View.Set(userId, friend);
 285
 3286                if (status.presence == PresenceStatus.ONLINE)
 2287                    onlineFriends[userId] = friend;
 288                else
 1289                    onlineFriends.Remove(userId);
 290
 1291                break;
 292            case FriendshipStatus.NOT_FRIEND:
 0293                View.Remove(userId);
 0294                friends.Remove(userId);
 0295                onlineFriends.Remove(userId);
 0296                break;
 297            case FriendshipStatus.REQUESTED_TO: // TODO (NEW FRIEND REQUESTS): remove when we don't need to keep the ret
 0298                if (isNewFriendRequestsEnabled)
 0299                    return;
 0300                var sentRequest = friends.ContainsKey(userId)
 301                    ? new FriendRequestEntryModel(friends[userId], string.Empty, false, 0, isQuickActionsForFriendReques
 302                    : new FriendRequestEntryModel { bodyMessage = string.Empty, isReceived = false, timestamp = 0, isSho
 0303                sentRequest.CopyFrom(status);
 0304                sentRequest.blocked = IsUserBlocked(userId);
 0305                friends[userId] = sentRequest;
 0306                onlineFriends.Remove(userId);
 0307                View.Set(userId, sentRequest);
 0308                break;
 309            case FriendshipStatus.REQUESTED_FROM: // TODO (NEW FRIEND REQUESTS): remove when we don't need to keep the r
 0310                if (isNewFriendRequestsEnabled)
 0311                    return;
 0312                var receivedRequest = friends.ContainsKey(userId)
 313                    ? new FriendRequestEntryModel(friends[userId], string.Empty, true, 0, isQuickActionsForFriendRequest
 314                    : new FriendRequestEntryModel { bodyMessage = string.Empty, isReceived = true, timestamp = 0, isShor
 0315                receivedRequest.CopyFrom(status);
 0316                receivedRequest.blocked = IsUserBlocked(userId);
 0317                friends[userId] = receivedRequest;
 0318                onlineFriends.Remove(userId);
 0319                View.Set(userId, receivedRequest);
 320                break;
 321        }
 322
 3323        UpdateNotificationsCounter();
 3324        ShowOrHideMoreFriendsToLoadHint();
 3325        ShowOrHideMoreFriendRequestsToLoadHint();
 3326    }
 327
 328    private void HandleFriendshipUpdated(string userId, FriendshipAction friendshipAction)
 329    {
 10330        var userProfile = userProfileBridge.Get(userId);
 331
 10332        if (userProfile == null)
 333        {
 0334            Debug.LogError($"UserProfile is null for {userId}! ... friendshipAction {friendshipAction}");
 0335            return;
 336        }
 337
 10338        userProfile.OnUpdate -= HandleFriendProfileUpdated;
 339
 340        switch (friendshipAction)
 341        {
 342            case FriendshipAction.NONE:
 343            case FriendshipAction.REJECTED:
 344            case FriendshipAction.CANCELLED:
 345            case FriendshipAction.DELETED:
 3346                friends.Remove(userId);
 3347                View.Remove(userId);
 3348                onlineFriends.Remove(userId);
 3349                break;
 350            case FriendshipAction.APPROVED:
 7351                var approved = friends.ContainsKey(userId)
 352                    ? new FriendEntryModel(friends[userId])
 353                    : new FriendEntryModel();
 7354                approved.CopyFrom(userProfile);
 7355                approved.blocked = IsUserBlocked(userId);
 7356                friends[userId] = approved;
 7357                View.Set(userId, approved);
 7358                userProfile.OnUpdate += HandleFriendProfileUpdated;
 7359                break;
 360            case FriendshipAction.REQUESTED_FROM: // TODO (NEW FRIEND REQUESTS): remove when we don't need to keep the r
 0361                if (isNewFriendRequestsEnabled)
 0362                    return;
 0363                var requestReceived = friends.ContainsKey(userId)
 364                    ? new FriendRequestEntryModel(friends[userId], string.Empty, true, 0, isQuickActionsForFriendRequest
 365                    : new FriendRequestEntryModel { bodyMessage = string.Empty, isReceived = true, timestamp = 0, isShor
 0366                requestReceived.CopyFrom(userProfile);
 0367                requestReceived.blocked = IsUserBlocked(userId);
 0368                friends[userId] = requestReceived;
 0369                View.Set(userId, requestReceived);
 0370                userProfile.OnUpdate += HandleFriendProfileUpdated;
 0371                break;
 372            case FriendshipAction.REQUESTED_TO: // TODO (NEW FRIEND REQUESTS): remove when we don't need to keep the ret
 0373                if (isNewFriendRequestsEnabled)
 0374                    return;
 0375                var requestSent = friends.ContainsKey(userId)
 376                    ? new FriendRequestEntryModel(friends[userId], string.Empty, false, 0, isQuickActionsForFriendReques
 377                    : new FriendRequestEntryModel { bodyMessage = string.Empty, isReceived = false, timestamp = 0, isSho
 0378                requestSent.CopyFrom(userProfile);
 0379                requestSent.blocked = IsUserBlocked(userId);
 0380                friends[userId] = requestSent;
 0381                View.Set(userId, requestSent);
 0382                userProfile.OnUpdate += HandleFriendProfileUpdated;
 383                break;
 384        }
 385
 10386        UpdateNotificationsCounter();
 10387        ShowOrHideMoreFriendsToLoadHint();
 10388        ShowOrHideMoreFriendRequestsToLoadHint();
 10389    }
 390
 391    private void HandleFriendProfileUpdated(UserProfile profile)
 392    {
 1393        var userId = profile.userId;
 1394        if (!friends.ContainsKey(userId)) return;
 1395        friends[userId].CopyFrom(profile);
 396
 1397        var status = friendsController.GetUserStatus(profile.userId);
 1398        if (status == null) return;
 399
 1400        UpdateUserStatus(userId, status);
 1401    }
 402
 403    private bool IsUserBlocked(string userId)
 404    {
 15405        if (ownUserProfile != null && ownUserProfile.blocked != null)
 15406            return ownUserProfile.blocked.Contains(userId);
 0407        return false;
 408    }
 409
 410    private void OnFriendNotFound(string name)
 411    {
 1412        View.DisplayFriendUserNotFound();
 1413    }
 414
 415    private void UpdateNotificationsCounter()
 416    {
 29417        if (View.IsActive())
 9418            dataStore.friendNotifications.seenFriends.Set(View.FriendCount);
 419
 29420        dataStore.friendNotifications.pendingFriendRequestCount.Set(friendsController.ReceivedRequestCount);
 29421    }
 422
 1423    private void HandleOpenWhisperChat(FriendEntryModel entry) => OnPressWhisper?.Invoke(entry.userId);
 424
 0425    private void HandleUnfriend(string userId) => friendsController.RemoveFriend(userId);
 426
 427    private void HandleRequestRejected(FriendRequestEntryModel entry)
 428    {
 0429        friendsController.RejectFriendship(entry.userId);
 430
 0431        UpdateNotificationsCounter();
 432
 0433        if (ownUserProfile != null)
 0434            socialAnalytics.SendFriendRequestRejected(ownUserProfile.userId, entry.userId,
 435                PlayerActionSource.FriendsHUD);
 0436    }
 437
 438    private void HandleRequestCancelled(FriendRequestEntryModel entry)
 439    {
 0440        if (isNewFriendRequestsEnabled)
 0441            friendsController.CancelRequestByUserIdAsync(entry.userId).Forget();
 442        else
 0443            friendsController.CancelRequestByUserId(entry.userId);
 444
 0445        if (ownUserProfile != null)
 0446            socialAnalytics.SendFriendRequestCancelled(ownUserProfile.userId, entry.userId,
 447                PlayerActionSource.FriendsHUD);
 0448    }
 449
 450    private void HandleRequestAccepted(FriendRequestEntryModel entry)
 451    {
 0452        friendsController.AcceptFriendship(entry.userId);
 453
 0454        if (ownUserProfile != null)
 0455            socialAnalytics.SendFriendRequestApproved(ownUserProfile.userId, entry.userId,
 456                PlayerActionSource.FriendsHUD);
 0457    }
 458
 459    private void DisplayFriendsIfAnyIsLoaded()
 460    {
 1461        if (View.FriendCount > 0) return;
 1462        if (lastSkipForFriends > 0) return;
 1463        DisplayMoreFriends();
 1464    }
 465
 466    private void DisplayMoreFriends()
 467    {
 11468        if (!friendsController.IsInitialized) return;
 469
 9470        friendsController.GetFriends(LOAD_FRIENDS_ON_DEMAND_COUNT, lastSkipForFriends);
 471
 472        // We are not handling properly the case when the friends are not fetched correctly from server.
 473        // 'lastSkipForFriends' will have an invalid value.
 9474        lastSkipForFriends += LOAD_FRIENDS_ON_DEMAND_COUNT;
 475
 9476        ShowOrHideMoreFriendsToLoadHint();
 9477    }
 478
 4479    public void DisplayMoreFriendRequests() => DisplayMoreFriendRequestsAsync().Forget();
 480
 481    private async UniTaskVoid DisplayMoreFriendRequestsAsync()
 482    {
 10483        if (!friendsController.IsInitialized) return;
 10484        if (searchingFriends) return;
 485
 10486        if (isNewFriendRequestsEnabled)
 487        {
 10488            var allfriendRequests = await friendsController.GetFriendRequestsAsync(
 489                LOAD_FRIENDS_ON_DEMAND_COUNT, lastSkipForFriendRequests,
 490                LOAD_FRIENDS_ON_DEMAND_COUNT, lastSkipForFriendRequests);
 491
 10492            AddFriendRequests(allfriendRequests);
 493        }
 494        else
 495        {
 496            // TODO (NEW FRIEND REQUESTS): remove when we don't need to keep the retro-compatibility with the old versio
 0497            friendsController.GetFriendRequests(
 498                LOAD_FRIENDS_ON_DEMAND_COUNT, lastSkipForFriendRequests,
 499                LOAD_FRIENDS_ON_DEMAND_COUNT, lastSkipForFriendRequests);
 500        }
 501
 502        // We are not handling properly the case when the friend requests are not fetched correctly from server.
 503        // 'lastSkipForFriendRequests' will have an invalid value.
 10504        lastSkipForFriendRequests += LOAD_FRIENDS_ON_DEMAND_COUNT;
 505
 10506        ShowOrHideMoreFriendRequestsToLoadHint();
 10507    }
 508
 509    private void AddFriendRequests(List<FriendRequest> friendRequests)
 510    {
 10511        if (friendRequests == null)
 7512            return;
 513
 12514        foreach (var friendRequest in friendRequests)
 3515            AddFriendRequest(friendRequest);
 3516    }
 517
 518    private void AddFriendRequest(FriendRequest friendRequest)
 519    {
 5520        bool isReceivedRequest = friendRequest.To == ownUserProfile.userId;
 5521        string userId = isReceivedRequest ? friendRequest.From : friendRequest.To;
 5522        var userProfile = userProfileBridge.Get(userId);
 523
 5524        if (userProfile == null)
 525        {
 0526            Debug.LogError($"UserProfile is null for {userId}! ... friendshipAction {(isReceivedRequest ? FriendshipActi
 0527            return;
 528        }
 529
 5530        userProfile.OnUpdate -= HandleFriendProfileUpdated;
 531
 5532        var request = friends.ContainsKey(userId)
 533            ? new FriendRequestEntryModel(friends[userId], friendRequest.MessageBody, isReceivedRequest, friendRequest.T
 534            : new FriendRequestEntryModel
 535            {
 536                bodyMessage = friendRequest.MessageBody,
 537                isReceived = isReceivedRequest,
 538                timestamp = friendRequest.Timestamp,
 539                isShortcutButtonsActive = isQuickActionsForFriendRequestsEnabled
 540            };
 5541        request.CopyFrom(userProfile);
 5542        request.blocked = IsUserBlocked(userId);
 5543        friends[userId] = request;
 5544        onlineFriends.Remove(userId);
 5545        View.Set(userId, request);
 5546        userProfile.OnUpdate += HandleFriendProfileUpdated;
 5547    }
 548
 549    private void DisplayFriendRequestsIfAnyIsLoaded()
 550    {
 1551        if (View.FriendRequestCount > 0) return;
 1552        if (lastSkipForFriendRequests > 0) return;
 1553        DisplayMoreFriendRequestsAsync().Forget();
 1554    }
 555
 556    private void ShowOrHideMoreFriendRequestsToLoadHint()
 557    {
 65558        if (lastSkipForFriendRequests >= friendsController.TotalFriendRequestCount)
 64559            View.HideMoreRequestsToLoadHint();
 560        else
 1561            View.ShowMoreRequestsToLoadHint(Mathf.Clamp(friendsController.TotalFriendRequestCount - lastSkipForFriendReq
 562                0,
 563                friendsController.TotalFriendRequestCount));
 1564    }
 565
 566    private void ShowOrHideMoreFriendsToLoadHint()
 567    {
 65568        if (lastSkipForFriends >= friendsController.TotalFriendCount || searchingFriends)
 64569            View.HideMoreFriendsToLoadHint();
 570        else
 1571            View.ShowMoreFriendsToLoadHint(Mathf.Clamp(friendsController.TotalFriendCount - lastSkipForFriends,
 572                0,
 573                friendsController.TotalFriendCount));
 1574    }
 575
 576    private void SearchFriends(string search)
 577    {
 3578        if (string.IsNullOrEmpty(search))
 579        {
 1580            View.DisableSearchMode();
 1581            searchingFriends = false;
 1582            ShowOrHideMoreFriendsToLoadHint();
 1583            return;
 584        }
 585
 2586        friendsController.GetFriends(search, MAX_SEARCHED_FRIENDS);
 587
 2588        View.EnableSearchMode();
 2589        View.HideMoreFriendsToLoadHint();
 2590        searchingFriends = true;
 2591    }
 592
 593    private void OpenFriendRequestDetails(string userId)
 594    {
 1595        if (!isNewFriendRequestsEnabled) return;
 596
 1597        FriendRequest friendRequest = friendsController.GetAllocatedFriendRequestByUser(userId);
 598
 1599        if (friendRequest == null)
 600        {
 0601            Debug.LogError($"Could not find an allocated friend request for user: {userId}");
 0602            return;
 603        }
 604
 1605        if (friendRequest.IsSentTo(userId))
 1606            dataStore.HUDs.openSentFriendRequestDetail.Set(friendRequest.FriendRequestId, true);
 607        else
 608        {
 609            // TODO: open details for received friend requests
 610        }
 1611    }
 612}

Methods/Properties

FriendsHUDController(DCL.DataStore, DCL.Social.Friends.IFriendsController, IUserProfileBridge, SocialFeaturesAnalytics.ISocialAnalytics, IChatController, DCL.IMouseCatcher)
visibleTaskbarPanels()
isNewFriendRequestsEnabled()
isQuickActionsForFriendRequestsEnabled()
View()
View(IFriendsHUDComponentView)
Initialize(IFriendsHUDComponentView)
SetVisiblePanelList(System.Boolean)
Dispose()
SetVisibility(System.Boolean)
HandleViewClosed()
HandleFriendsInitialized()
HandleProfileUpdated(UserProfile)
UpdateBlockStatus()
HandleRequestSent(System.String)
AreAlreadyFriends(System.String)
HandleUserStatusUpdated(System.String, UserStatus)
UpdateUserStatus(System.String, UserStatus)
HandleFriendshipUpdated(System.String, DCL.Social.Friends.FriendshipAction)
HandleFriendProfileUpdated(UserProfile)
IsUserBlocked(System.String)
OnFriendNotFound(System.String)
UpdateNotificationsCounter()
HandleOpenWhisperChat(FriendEntryModel)
HandleUnfriend(System.String)
HandleRequestRejected(FriendRequestEntryModel)
HandleRequestCancelled(FriendRequestEntryModel)
HandleRequestAccepted(FriendRequestEntryModel)
DisplayFriendsIfAnyIsLoaded()
DisplayMoreFriends()
DisplayMoreFriendRequests()
DisplayMoreFriendRequestsAsync()
AddFriendRequests(System.Collections.Generic.List[FriendRequest])
AddFriendRequest(DCL.Social.Friends.FriendRequest)
DisplayFriendRequestsIfAnyIsLoaded()
ShowOrHideMoreFriendRequestsToLoadHint()
ShowOrHideMoreFriendsToLoadHint()
SearchFriends(System.String)
OpenFriendRequestDetails(System.String)