< Summary

Class:UsersSearchFriendsHandler
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/UsersSearchPrompt/UsersSearchFriendsHandler.cs
Covered lines:22
Uncovered lines:17
Coverable lines:39
Total lines:91
Line coverage:56.4% (22 of 39)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UsersSearchFriendsHandler(...)0%220100%
GetFriendList()0%6.566075%
Dispose()0%330100%
OnFriendsInitialized()0%6200%
OnUpdateFriendship(...)0%30500%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/UsersSearchPrompt/UsersSearchFriendsHandler.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Helpers;
 4
 5internal class UsersSearchFriendsHandler : IDisposable
 6{
 7    public event Action<string> OnFriendRemoved;
 08    public bool isFriendlistDirty { private set; get; }
 9
 10    private readonly IFriendsController friendsController;
 11
 12    private bool waitingFriendsInitialize;
 13    private Promise<Dictionary<string, FriendsController.UserStatus>> friendListPromise;
 14
 1715    public UsersSearchFriendsHandler(IFriendsController friendsController)
 16    {
 1717        this.friendsController = friendsController;
 1718        isFriendlistDirty = true;
 1719        waitingFriendsInitialize = true;
 20
 1721        if (friendsController != null)
 22        {
 1723            friendsController.OnUpdateFriendship += OnUpdateFriendship;
 24        }
 1725    }
 26
 27    public Promise<Dictionary<string, FriendsController.UserStatus>> GetFriendList()
 28    {
 529        if (friendListPromise == null)
 30        {
 531            friendListPromise = new Promise<Dictionary<string, FriendsController.UserStatus>>();
 32        }
 33
 534        if (friendsController == null)
 35        {
 036            return friendListPromise;
 37        }
 38
 539        if (isFriendlistDirty && friendsController.isInitialized)
 40        {
 541            isFriendlistDirty = false;
 542            waitingFriendsInitialize = false;
 543            friendListPromise.Resolve(friendsController.GetFriends());
 44        }
 45
 546        if (waitingFriendsInitialize)
 47        {
 048            waitingFriendsInitialize = false;
 049            friendsController.OnInitialized += OnFriendsInitialized;
 50        }
 51
 552        return friendListPromise;
 53    }
 54
 55    public void Dispose()
 56    {
 1757        if (friendsController != null)
 58        {
 1759            friendsController.OnUpdateFriendship -= OnUpdateFriendship;
 1760            friendsController.OnInitialized -= OnFriendsInitialized;
 61        }
 62
 1763        friendListPromise?.Dispose();
 1764        friendListPromise = null;
 1765    }
 66
 67    private void OnFriendsInitialized()
 68    {
 069        friendsController.OnInitialized -= OnFriendsInitialized;
 070        isFriendlistDirty = false;
 071        friendListPromise?.Resolve(friendsController.GetFriends());
 072    }
 73
 74    private void OnUpdateFriendship(string userId, FriendshipAction friendshipAction)
 75    {
 076        if (!friendsController.isInitialized)
 077            return;
 78
 079        if (friendshipAction == FriendshipAction.APPROVED)
 80        {
 081            isFriendlistDirty = true;
 082            return;
 83        }
 84
 085        if (friendshipAction == FriendshipAction.DELETED)
 86        {
 087            isFriendlistDirty = true;
 088            OnFriendRemoved?.Invoke(userId);
 89        }
 090    }
 91}