< Summary

Class:DCL.Social.Friends.SentFriendRequestHUDController
Assembly:FriendRequestHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendRequestHUD/SentFriendRequestHUDController.cs
Covered lines:0
Uncovered lines:66
Coverable lines:66
Total lines:143
Line coverage:0% (0 of 66)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:8
Method coverage:0% (0 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SentFriendRequestHUDController(...)0%2100%
Dispose()0%2100%
ShowOrHide(...)0%6200%
Show(...)0%12300%
Cancel()0%2100%
<Cancel()0%42600%
Hide()0%2100%
OpenProfile()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendRequestHUD/SentFriendRequestHUDController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Tasks;
 3using SocialFeaturesAnalytics;
 4using System;
 5using System.Threading;
 6using UnityEngine;
 7
 8namespace DCL.Social.Friends
 9{
 10    public class SentFriendRequestHUDController
 11    {
 12        private const string PROCESS_REQUEST_ERROR_MESSAGE = "There was an error while trying to process your request. P
 13        private const string OPEN_PASSPORT_SOURCE = "FriendRequest";
 14
 15        private readonly ISentFriendRequestHUDView view;
 16        private readonly DataStore dataStore;
 17        private readonly IUserProfileBridge userProfileBridge;
 18        private readonly IFriendsController friendsController;
 19        private readonly ISocialAnalytics socialAnalytics;
 20        private readonly BaseVariable<(string playerId, string source)> openPassportVariable;
 21
 022        private CancellationTokenSource friendRequestOperationsCancellationToken = new ();
 23        private string friendRequestId;
 24
 025        public SentFriendRequestHUDController(
 26            ISentFriendRequestHUDView view,
 27            DataStore dataStore,
 28            IUserProfileBridge userProfileBridge,
 29            IFriendsController friendsController,
 30            ISocialAnalytics socialAnalytics)
 31        {
 032            this.view = view;
 033            this.dataStore = dataStore;
 034            this.userProfileBridge = userProfileBridge;
 035            this.friendsController = friendsController;
 036            this.socialAnalytics = socialAnalytics;
 037            this.openPassportVariable = dataStore.HUDs.currentPlayerId;
 38
 039            dataStore.HUDs.openSentFriendRequestDetail.OnChange += ShowOrHide;
 040            view.OnCancel += Cancel;
 041            view.OnClose += Hide;
 042            view.OnOpenProfile += OpenProfile;
 043            view.Close();
 044        }
 45
 46        public void Dispose()
 47        {
 048            friendRequestOperationsCancellationToken.SafeCancelAndDispose();
 049            dataStore.HUDs.openSentFriendRequestDetail.OnChange -= ShowOrHide;
 050            view.OnCancel -= Cancel;
 051            view.OnClose -= Hide;
 052            view.OnOpenProfile += OpenProfile;
 053            view.Dispose();
 054        }
 55
 56        private void ShowOrHide(string current, string previous)
 57        {
 058            if (string.IsNullOrEmpty(current))
 059                Hide();
 60            else
 061                Show(current);
 062        }
 63
 64        private void Show(string friendRequestId)
 65        {
 066            this.friendRequestId = friendRequestId;
 067            bool wasFound = friendsController.TryGetAllocatedFriendRequest(friendRequestId, out FriendRequest friendRequ
 68
 069            if (!wasFound)
 70            {
 071                Debug.LogError($"Cannot display friend request {friendRequestId}, is not allocated");
 072                return;
 73            }
 74
 075            view.SetBodyMessage(friendRequest.MessageBody);
 076            view.SetTimestamp(friendRequest.Timestamp);
 77
 078            var recipientProfile = userProfileBridge.Get(friendRequest.To);
 79
 080            if (recipientProfile != null)
 81            {
 082                view.SetRecipientName(recipientProfile.userName);
 083                view.SetRecipientProfilePicture(recipientProfile.snapshotObserver);
 84            }
 85            else
 086                Debug.LogError($"Cannot display user profile {friendRequest.To}, is not allocated");
 87
 088            var ownProfile = userProfileBridge.GetOwn();
 089            view.SetSenderProfilePicture(ownProfile.snapshotObserver);
 90
 091            view.SetSortingOrder(dataStore.HUDs.currentPassportSortingOrder.Get() + 1);
 092            view.Show();
 093        }
 94
 95        private void Cancel()
 96        {
 097            friendRequestOperationsCancellationToken = friendRequestOperationsCancellationToken.SafeRestart();
 98
 99            async UniTask CancelAsync(CancellationToken cancellationToken = default)
 100            {
 0101                view.ShowPendingToCancel();
 102
 103                try
 104                {
 0105                    FriendRequest request = await friendsController.CancelRequestAsync(friendRequestId, cancellationToke
 106
 0107                    socialAnalytics.SendFriendRequestCancelled(request.From, request.To, "modal", request.FriendRequestI
 108
 0109                    view.Close();
 0110                }
 0111                catch (Exception e) when (e is not OperationCanceledException)
 112                {
 0113                    e.ReportFriendRequestErrorToAnalyticsByRequestId(friendRequestId, "modal", friendsController, social
 0114                    view.Show();
 0115                    dataStore.notifications.DefaultErrorNotification.Set(PROCESS_REQUEST_ERROR_MESSAGE, true);
 0116                    throw;
 117                }
 0118            }
 119
 0120            CancelAsync(friendRequestOperationsCancellationToken.Token).Forget();
 0121        }
 122
 123        private void Hide()
 124        {
 0125            dataStore.HUDs.openSentFriendRequestDetail.Set(null, false);
 0126            view.Close();
 0127        }
 128
 129        private void OpenProfile()
 130        {
 0131            bool wasFound = friendsController.TryGetAllocatedFriendRequest(friendRequestId, out FriendRequest friendRequ
 132
 0133            if (!wasFound)
 134            {
 0135                Debug.LogError($"Cannot open passport {friendRequestId}, is not allocated");
 0136                return;
 137            }
 138
 0139            openPassportVariable.Set((friendRequest.To, OPEN_PASSPORT_SOURCE));
 0140            view.SetSortingOrder(dataStore.HUDs.currentPassportSortingOrder.Get() - 1);
 0141        }
 142    }
 143}