< Summary

Class:UsersSearchFriendsHandler
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/UsersSearchPrompt/UsersSearchFriendsHandler.cs
Covered lines:23
Uncovered lines:16
Coverable lines:39
Total lines:93
Line coverage:58.9% (23 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;
 4using DCl.Social.Friends;
 5using DCL.Social.Friends;
 6
 7internal class UsersSearchFriendsHandler : IDisposable
 8{
 9    public event Action<string> OnFriendRemoved;
 3210    public bool isFriendlistDirty { private set; get; }
 11
 12    private readonly IFriendsController friendsController;
 13
 14    private bool waitingFriendsInitialize;
 15    private Promise<Dictionary<string, UserStatus>> friendListPromise;
 16
 1717    public UsersSearchFriendsHandler(IFriendsController friendsController)
 18    {
 1719        this.friendsController = friendsController;
 1720        isFriendlistDirty = true;
 1721        waitingFriendsInitialize = true;
 22
 1723        if (friendsController != null)
 24        {
 1725            friendsController.OnUpdateFriendship += OnUpdateFriendship;
 26        }
 1727    }
 28
 29    public Promise<Dictionary<string, UserStatus>> GetFriendList()
 30    {
 531        if (friendListPromise == null)
 32        {
 533            friendListPromise = new Promise<Dictionary<string, UserStatus>>();
 34        }
 35
 536        if (friendsController == null)
 37        {
 038            return friendListPromise;
 39        }
 40
 541        if (isFriendlistDirty && friendsController.IsInitialized)
 42        {
 543            isFriendlistDirty = false;
 544            waitingFriendsInitialize = false;
 545            friendListPromise.Resolve(friendsController.GetAllocatedFriends());
 46        }
 47
 548        if (waitingFriendsInitialize)
 49        {
 050            waitingFriendsInitialize = false;
 051            friendsController.OnInitialized += OnFriendsInitialized;
 52        }
 53
 554        return friendListPromise;
 55    }
 56
 57    public void Dispose()
 58    {
 1759        if (friendsController != null)
 60        {
 1761            friendsController.OnUpdateFriendship -= OnUpdateFriendship;
 1762            friendsController.OnInitialized -= OnFriendsInitialized;
 63        }
 64
 1765        friendListPromise?.Dispose();
 1766        friendListPromise = null;
 1767    }
 68
 69    private void OnFriendsInitialized()
 70    {
 071        friendsController.OnInitialized -= OnFriendsInitialized;
 072        isFriendlistDirty = false;
 073        friendListPromise?.Resolve(friendsController.GetAllocatedFriends());
 074    }
 75
 76    private void OnUpdateFriendship(string userId, FriendshipAction friendshipAction)
 77    {
 078        if (!friendsController.IsInitialized)
 079            return;
 80
 081        if (friendshipAction == FriendshipAction.APPROVED)
 82        {
 083            isFriendlistDirty = true;
 084            return;
 85        }
 86
 087        if (friendshipAction == FriendshipAction.DELETED)
 88        {
 089            isFriendlistDirty = true;
 090            OnFriendRemoved?.Invoke(userId);
 91        }
 092    }
 93}