< Summary

Class:JoinChannelComponentController
Assembly:JoinChannelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/JoinChannelHUD/JoinChannelComponentController.cs
Covered lines:42
Uncovered lines:6
Coverable lines:48
Total lines:115
Line coverage:87.5% (42 of 48)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
JoinChannelComponentController(...)0%110100%
Dispose()0%110100%
OnChannelToJoinChanged(...)0%3.023087.5%
OnCancelJoin()0%220100%
OnConfirmJoin(...)0%3.013090%
GetChannelLinkSource()0%14.189060%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/JoinChannelHUD/JoinChannelComponentController.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using DCL;
 4using DCL.Chat;
 5using SocialFeaturesAnalytics;
 6
 7public class JoinChannelComponentController : IDisposable
 8{
 9    internal readonly IJoinChannelComponentView joinChannelView;
 10    internal readonly IChatController chatController;
 11    private readonly DataStore dataStore;
 12    internal readonly DataStore_Channels channelsDataStore;
 13    private readonly ISocialAnalytics socialAnalytics;
 14    private readonly StringVariable currentPlayerInfoCardId;
 15    private readonly IChannelsFeatureFlagService channelsFeatureFlagService;
 16    private string channelId;
 17
 718    public JoinChannelComponentController(
 19        IJoinChannelComponentView joinChannelView,
 20        IChatController chatController,
 21        DataStore dataStore,
 22        ISocialAnalytics socialAnalytics,
 23        StringVariable currentPlayerInfoCardId,
 24        IChannelsFeatureFlagService channelsFeatureFlagService)
 25    {
 726        this.joinChannelView = joinChannelView;
 727        this.chatController = chatController;
 728        this.dataStore = dataStore;
 729        channelsDataStore = dataStore.channels;
 730        this.socialAnalytics = socialAnalytics;
 731        this.currentPlayerInfoCardId = currentPlayerInfoCardId;
 732        this.channelsFeatureFlagService = channelsFeatureFlagService;
 33
 734        channelsDataStore.currentJoinChannelModal.OnChange += OnChannelToJoinChanged;
 735        this.joinChannelView.OnCancelJoin += OnCancelJoin;
 736        this.joinChannelView.OnConfirmJoin += OnConfirmJoin;
 737    }
 38
 39    public void Dispose()
 40    {
 741        channelsDataStore.currentJoinChannelModal.OnChange -= OnChannelToJoinChanged;
 742        joinChannelView.OnCancelJoin -= OnCancelJoin;
 743        joinChannelView.OnConfirmJoin -= OnConfirmJoin;
 744    }
 45
 46    private void OnChannelToJoinChanged(string currentChannelId, string previousChannelId)
 47    {
 548        if (!channelsFeatureFlagService.IsChannelsFeatureEnabled())
 049            return;
 50
 551        if (string.IsNullOrEmpty(currentChannelId))
 252            return;
 53
 354        channelId = currentChannelId;
 355        joinChannelView.SetChannel(currentChannelId);
 356        joinChannelView.Show();
 357    }
 58
 59    private void OnCancelJoin()
 60    {
 261        if (channelsDataStore.channelJoinedSource.Get() == ChannelJoinedSource.Link)
 162            socialAnalytics.SendChannelLinkClicked(channelId, false, GetChannelLinkSource());
 63
 264        joinChannelView.Hide();
 265    }
 66
 67    private void OnConfirmJoin(string channelName)
 68    {
 269        channelName = channelName
 70            .Replace("#", "")
 71            .Replace("~", "")
 72            .ToLower();
 73
 274        var alreadyJoinedChannel = chatController.GetAllocatedChannelByName(channelName);
 75
 276        if (alreadyJoinedChannel == null)
 277            chatController.JoinOrCreateChannel(channelName);
 78        else
 079            dataStore.channels.channelToBeOpenedFromLink.Set(alreadyJoinedChannel.ChannelId);
 80
 281        if (channelsDataStore.channelJoinedSource.Get() == ChannelJoinedSource.Link)
 182            socialAnalytics.SendChannelLinkClicked(channelName, true, GetChannelLinkSource());
 83
 284        joinChannelView.Hide();
 285        channelsDataStore.currentJoinChannelModal.Set(null);
 286    }
 87
 88    private ChannelLinkSource GetChannelLinkSource()
 89    {
 290        if (dataStore.exploreV2.isOpen.Get()
 91            && dataStore.exploreV2.placesAndEventsVisible.Get()
 92            && dataStore.exploreV2.isSomeModalOpen.Get())
 93        {
 094            switch (dataStore.exploreV2.currentVisibleModal.Get())
 95            {
 96                case ExploreV2CurrentModal.Events:
 097                    return ChannelLinkSource.Event;
 98                case ExploreV2CurrentModal.Places:
 099                    return ChannelLinkSource.Place;
 100            }
 101        }
 102
 2103        if (!string.IsNullOrEmpty(currentPlayerInfoCardId.Get()))
 1104            return ChannelLinkSource.Profile;
 105
 1106        var visibleTaskbarPanels = dataStore.HUDs.visibleTaskbarPanels.Get();
 107
 2108        if (visibleTaskbarPanels.Any(panel => panel == "PrivateChatChannel"
 109                                              || panel == "ChatChannel"
 110                                              || panel == "PublicChatChannel"))
 1111            return ChannelLinkSource.Chat;
 112
 0113        return ChannelLinkSource.Unknown;
 114    }
 115}