| | 1 | | using System; |
| | 2 | | using System.Linq; |
| | 3 | | using DCL; |
| | 4 | | using DCL.Chat; |
| | 5 | | using SocialFeaturesAnalytics; |
| | 6 | |
|
| | 7 | | public 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 | |
|
| 7 | 18 | | public JoinChannelComponentController( |
| | 19 | | IJoinChannelComponentView joinChannelView, |
| | 20 | | IChatController chatController, |
| | 21 | | DataStore dataStore, |
| | 22 | | ISocialAnalytics socialAnalytics, |
| | 23 | | StringVariable currentPlayerInfoCardId, |
| | 24 | | IChannelsFeatureFlagService channelsFeatureFlagService) |
| | 25 | | { |
| 7 | 26 | | this.joinChannelView = joinChannelView; |
| 7 | 27 | | this.chatController = chatController; |
| 7 | 28 | | this.dataStore = dataStore; |
| 7 | 29 | | channelsDataStore = dataStore.channels; |
| 7 | 30 | | this.socialAnalytics = socialAnalytics; |
| 7 | 31 | | this.currentPlayerInfoCardId = currentPlayerInfoCardId; |
| 7 | 32 | | this.channelsFeatureFlagService = channelsFeatureFlagService; |
| | 33 | |
|
| 7 | 34 | | channelsDataStore.currentJoinChannelModal.OnChange += OnChannelToJoinChanged; |
| 7 | 35 | | this.joinChannelView.OnCancelJoin += OnCancelJoin; |
| 7 | 36 | | this.joinChannelView.OnConfirmJoin += OnConfirmJoin; |
| 7 | 37 | | } |
| | 38 | |
|
| | 39 | | public void Dispose() |
| | 40 | | { |
| 7 | 41 | | channelsDataStore.currentJoinChannelModal.OnChange -= OnChannelToJoinChanged; |
| 7 | 42 | | joinChannelView.OnCancelJoin -= OnCancelJoin; |
| 7 | 43 | | joinChannelView.OnConfirmJoin -= OnConfirmJoin; |
| 7 | 44 | | } |
| | 45 | |
|
| | 46 | | private void OnChannelToJoinChanged(string currentChannelId, string previousChannelId) |
| | 47 | | { |
| 6 | 48 | | if (!channelsFeatureFlagService.IsChannelsFeatureEnabled()) |
| 0 | 49 | | return; |
| | 50 | |
|
| 6 | 51 | | if (string.IsNullOrEmpty(currentChannelId)) |
| 3 | 52 | | return; |
| | 53 | |
|
| 3 | 54 | | channelId = currentChannelId; |
| 3 | 55 | | joinChannelView.SetChannel(currentChannelId); |
| 3 | 56 | | joinChannelView.Show(); |
| 3 | 57 | | } |
| | 58 | |
|
| | 59 | | private void OnCancelJoin() |
| | 60 | | { |
| 2 | 61 | | if (channelsDataStore.channelJoinedSource.Get() == ChannelJoinedSource.Link) |
| 1 | 62 | | socialAnalytics.SendChannelLinkClicked(channelId, false, GetChannelLinkSource()); |
| | 63 | |
|
| 2 | 64 | | joinChannelView.Hide(); |
| 2 | 65 | | channelsDataStore.currentJoinChannelModal.Set(null); |
| 2 | 66 | | } |
| | 67 | |
|
| | 68 | | private void OnConfirmJoin(string channelName) |
| | 69 | | { |
| 2 | 70 | | channelName = channelName |
| | 71 | | .Replace("#", "") |
| | 72 | | .Replace("~", "") |
| | 73 | | .ToLower(); |
| | 74 | |
|
| 2 | 75 | | var alreadyJoinedChannel = chatController.GetAllocatedChannelByName(channelName); |
| | 76 | |
|
| 2 | 77 | | if (alreadyJoinedChannel == null || !alreadyJoinedChannel.Joined) |
| 2 | 78 | | chatController.JoinOrCreateChannel(channelName); |
| | 79 | | else |
| 0 | 80 | | dataStore.channels.channelToBeOpened.Set(alreadyJoinedChannel.ChannelId); |
| | 81 | |
|
| 2 | 82 | | if (channelsDataStore.channelJoinedSource.Get() == ChannelJoinedSource.Link) |
| 1 | 83 | | socialAnalytics.SendChannelLinkClicked(channelName, true, GetChannelLinkSource()); |
| | 84 | |
|
| 2 | 85 | | joinChannelView.Hide(); |
| 2 | 86 | | channelsDataStore.currentJoinChannelModal.Set(null); |
| 2 | 87 | | } |
| | 88 | |
|
| | 89 | | private ChannelLinkSource GetChannelLinkSource() |
| | 90 | | { |
| 2 | 91 | | if (dataStore.exploreV2.isOpen.Get() |
| | 92 | | && dataStore.exploreV2.placesAndEventsVisible.Get() |
| | 93 | | && dataStore.exploreV2.isSomeModalOpen.Get()) |
| | 94 | | { |
| 0 | 95 | | switch (dataStore.exploreV2.currentVisibleModal.Get()) |
| | 96 | | { |
| | 97 | | case ExploreV2CurrentModal.Events: |
| 0 | 98 | | return ChannelLinkSource.Event; |
| | 99 | | case ExploreV2CurrentModal.Places: |
| 0 | 100 | | return ChannelLinkSource.Place; |
| | 101 | | } |
| | 102 | | } |
| | 103 | |
|
| 2 | 104 | | if (!string.IsNullOrEmpty(currentPlayerInfoCardId.Get())) |
| 1 | 105 | | return ChannelLinkSource.Profile; |
| | 106 | |
|
| 1 | 107 | | var visibleTaskbarPanels = dataStore.HUDs.visibleTaskbarPanels.Get(); |
| | 108 | |
|
| 2 | 109 | | if (visibleTaskbarPanels.Any(panel => panel == "PrivateChatChannel" |
| | 110 | | || panel == "ChatChannel" |
| | 111 | | || panel == "PublicChatChannel")) |
| 1 | 112 | | return ChannelLinkSource.Chat; |
| | 113 | |
|
| 0 | 114 | | return ChannelLinkSource.Unknown; |
| | 115 | | } |
| | 116 | | } |