< Summary

Class:JoinChannelComponentController
Assembly:JoinChannelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/JoinChannelHUD/JoinChannelComponentController.cs
Covered lines:43
Uncovered lines:6
Coverable lines:49
Total lines:116
Line coverage:87.7% (43 of 49)
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%4.024090%
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    {
 648        if (!channelsFeatureFlagService.IsChannelsFeatureEnabled())
 049            return;
 50
 651        if (string.IsNullOrEmpty(currentChannelId))
 352            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        channelsDataStore.currentJoinChannelModal.Set(null);
 266    }
 67
 68    private void OnConfirmJoin(string channelName)
 69    {
 270        channelName = channelName
 71            .Replace("#", "")
 72            .Replace("~", "")
 73            .ToLower();
 74
 275        var alreadyJoinedChannel = chatController.GetAllocatedChannelByName(channelName);
 76
 277        if (alreadyJoinedChannel == null || !alreadyJoinedChannel.Joined)
 278            chatController.JoinOrCreateChannel(channelName);
 79        else
 080            dataStore.channels.channelToBeOpened.Set(alreadyJoinedChannel.ChannelId);
 81
 282        if (channelsDataStore.channelJoinedSource.Get() == ChannelJoinedSource.Link)
 183            socialAnalytics.SendChannelLinkClicked(channelName, true, GetChannelLinkSource());
 84
 285        joinChannelView.Hide();
 286        channelsDataStore.currentJoinChannelModal.Set(null);
 287    }
 88
 89    private ChannelLinkSource GetChannelLinkSource()
 90    {
 291        if (dataStore.exploreV2.isOpen.Get()
 92            && dataStore.exploreV2.placesAndEventsVisible.Get()
 93            && dataStore.exploreV2.isSomeModalOpen.Get())
 94        {
 095            switch (dataStore.exploreV2.currentVisibleModal.Get())
 96            {
 97                case ExploreV2CurrentModal.Events:
 098                    return ChannelLinkSource.Event;
 99                case ExploreV2CurrentModal.Places:
 0100                    return ChannelLinkSource.Place;
 101            }
 102        }
 103
 2104        if (!string.IsNullOrEmpty(currentPlayerInfoCardId.Get()))
 1105            return ChannelLinkSource.Profile;
 106
 1107        var visibleTaskbarPanels = dataStore.HUDs.visibleTaskbarPanels.Get();
 108
 2109        if (visibleTaskbarPanels.Any(panel => panel == "PrivateChatChannel"
 110                                              || panel == "ChatChannel"
 111                                              || panel == "PublicChatChannel"))
 1112            return ChannelLinkSource.Chat;
 113
 0114        return ChannelLinkSource.Unknown;
 115    }
 116}