< Summary

Class:WorldChatWindowController
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/WorldChatWindowController.cs
Covered lines:252
Uncovered lines:56
Coverable lines:308
Total lines:617
Line coverage:81.8% (252 of 308)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WorldChatWindowController(...)0%110100%
Initialize(...)0%990100%
Dispose()0%440100%
SetVisibility(...)0%11.0111095.24%
OpenChannelCreationWindow()0%6200%
SetVisiblePanelList(...)0%220100%
LeaveChannel(...)0%220100%
RequestJoinedChannels()0%3.013088.89%
WaitThenHideChannelsLoading()0%9.834028.57%
HandleChatInitialization()0%2.062075%
HandleFriendsControllerInitialization()0%330100%
OpenPrivateChat(...)0%220100%
OpenPublicChat(...)0%440100%
HandleViewCloseRequest()0%220100%
HandleFriendshipUpdated(...)0%220100%
HandleUserStatusChanged(...)0%220100%
HandleMessageAdded(...)0%5.735069.23%
HandleFriendsWithDirectMessagesAdded(...)0%6.755058.82%
CreatePrivateChatModel(...)0%110100%
ExtractRecipientId(...)0%220100%
OnUserProfileUpdate(...)0%220100%
SearchChats(...)0%440100%
ShowMorePrivateChats()0%4.254075%
UpdateMoreChannelsToLoadHint()0%330100%
RequestFriendsWithDirectMessages()0%220100%
HidePrivateChatsLoadingWhenTimeout()0%6.984042.86%
RequestFriendsWithDirectMessagesFromSearch(...)0%220100%
HandleChannelUpdated(...)0%3.113076.92%
ClearOfflineUnseenMessages(...)0%220100%
HandleChannelJoined(...)0%220100%
HandleJoinChannelError(...)0%20400%
HandleLeaveChannelError(...)0%2100%
HandleChannelLeft(...)0%440100%
HandleChannelOpenedFromLink(...)0%6200%
RequestUnreadMessages()0%110100%
RequestUnreadChannelsMessages()0%110100%
OpenChannelSearch()0%12300%
HideSearchLoadingWhenTimeout()0%9.834028.57%
OnAllowedToCreateChannelsChanged(...)0%2100%
SetAutomaticChannelsInfoUpdatingActive(...)0%2.52050%
ReloadChannelsInfoPeriodically()0%20400%
GetCurrentChannelsInfo()0%12300%
OpenWalletReadme()0%110100%
SignUp()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/WorldChatWindowController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL;
 3using DCL.Chat;
 4using DCL.Chat.Channels;
 5using DCL.Friends.WebApi;
 6using DCL.Interface;
 7using SocialFeaturesAnalytics;
 8using System;
 9using System.Collections.Generic;
 10using System.Linq;
 11using System.Threading;
 12using DCL.Browser;
 13using UnityEngine;
 14using Channel = DCL.Chat.Channels.Channel;
 15
 16public class WorldChatWindowController : IHUD
 17{
 18    private const int DMS_PAGE_SIZE = 30;
 19    private const int USER_DM_ENTRIES_TO_REQUEST_FOR_SEARCH = 20;
 20    private const int CHANNELS_PAGE_SIZE = 10;
 21    private const int MINUTES_FOR_AUTOMATIC_CHANNELS_INFO_RELOADING = 1;
 22
 23    private readonly IUserProfileBridge userProfileBridge;
 24    private readonly IFriendsController friendsController;
 25    private readonly IChatController chatController;
 26    private readonly DataStore dataStore;
 27    private readonly IMouseCatcher mouseCatcher;
 28    private readonly ISocialAnalytics socialAnalytics;
 29    private readonly IChannelsFeatureFlagService channelsFeatureFlagService;
 30    private readonly IBrowserBridge browserBridge;
 4931    private readonly Dictionary<string, PublicChatModel> publicChannels = new Dictionary<string, PublicChatModel>();
 4932    private readonly Dictionary<string, ChatMessage> lastPrivateMessages = new Dictionary<string, ChatMessage>();
 4933    private readonly HashSet<string> channelsClearedUnseenNotifications = new HashSet<string>();
 4034    private BaseVariable<HashSet<string>> visibleTaskbarPanels => dataStore.HUDs.visibleTaskbarPanels;
 35    private int hiddenDMs;
 4936    private string currentSearch = "";
 37    private DateTime channelsRequestTimestamp;
 38    private bool areDMsRequestedByFirstTime;
 39    private int lastSkipForDMs;
 4940    private CancellationTokenSource hideLoadingCancellationToken = new CancellationTokenSource();
 41    private IWorldChatWindowView view;
 42    private UserProfile ownUserProfile;
 43    private bool isRequestingDMs;
 44    private bool areJoinedChannelsRequestedByFirstTime;
 45    private bool areUnseenMessajesRequestedByFirstTime;
 4946    private CancellationTokenSource hideChannelsLoadingCancellationToken = new CancellationTokenSource();
 4947    private CancellationTokenSource hidePrivateChatsLoadingCancellationToken = new CancellationTokenSource();
 4948    private CancellationTokenSource reloadingChannelsInfoCancellationToken = new CancellationTokenSource();
 49
 050    public IWorldChatWindowView View => view;
 51
 52    public event Action OnCloseView;
 53    public event Action<string> OnOpenPrivateChat;
 54    public event Action<string> OnOpenPublicChat;
 55    public event Action<string> OnOpenChannel;
 56    public event Action OnOpen;
 57    public event Action OnOpenChannelSearch;
 58    public event Action OnOpenChannelCreation;
 59    public event Action<string> OnOpenChannelLeave;
 60
 4961    public WorldChatWindowController(
 62        IUserProfileBridge userProfileBridge,
 63        IFriendsController friendsController,
 64        IChatController chatController,
 65        DataStore dataStore,
 66        IMouseCatcher mouseCatcher,
 67        ISocialAnalytics socialAnalytics,
 68        IChannelsFeatureFlagService channelsFeatureFlagService,
 69        IBrowserBridge browserBridge)
 70    {
 4971        this.userProfileBridge = userProfileBridge;
 4972        this.friendsController = friendsController;
 4973        this.chatController = chatController;
 4974        this.dataStore = dataStore;
 4975        this.mouseCatcher = mouseCatcher;
 4976        this.socialAnalytics = socialAnalytics;
 4977        this.channelsFeatureFlagService = channelsFeatureFlagService;
 4978        this.browserBridge = browserBridge;
 4979    }
 80
 81    public void Initialize(IWorldChatWindowView view)
 82    {
 4983        this.view = view;
 4984        view.Initialize(chatController);
 85
 4986        if (mouseCatcher != null)
 4987            mouseCatcher.OnMouseLock += HandleViewCloseRequest;
 88
 4989        view.OnClose += HandleViewCloseRequest;
 4990        view.OnOpenPrivateChat += OpenPrivateChat;
 4991        view.OnOpenPublicChat += OpenPublicChat;
 4992        view.OnSearchChatRequested += SearchChats;
 4993        view.OnRequireMorePrivateChats += ShowMorePrivateChats;
 4994        view.OnSignUp += SignUp;
 4995        view.OnRequireWalletReadme += OpenWalletReadme;
 96
 4997        ownUserProfile = userProfileBridge.GetOwn();
 4998        if (ownUserProfile != null)
 4899            ownUserProfile.OnUpdate += OnUserProfileUpdate;
 100
 49101        var channel = chatController.GetAllocatedChannel(ChatUtils.NEARBY_CHANNEL_ID);
 49102        publicChannels[ChatUtils.NEARBY_CHANNEL_ID] = new PublicChatModel(ChatUtils.NEARBY_CHANNEL_ID, channel.Name,
 103            channel.Description,
 104            channel.Joined,
 105            channel.MemberCount,
 106            false);
 49107        view.SetPublicChat(publicChannels[ChatUtils.NEARBY_CHANNEL_ID]);
 108
 112109        foreach (var value in chatController.GetAllocatedEntries())
 7110            HandleMessageAdded(value);
 111
 49112        if (!friendsController.IsInitialized)
 7113            if (ownUserProfile?.hasConnectedWeb3 ?? false)
 5114                view.ShowPrivateChatsLoading();
 115
 49116        chatController.OnInitialized += HandleChatInitialization;
 49117        chatController.OnAddMessage += HandleMessageAdded;
 49118        friendsController.OnAddFriendsWithDirectMessages += HandleFriendsWithDirectMessagesAdded;
 49119        friendsController.OnUpdateUserStatus += HandleUserStatusChanged;
 49120        friendsController.OnUpdateFriendship += HandleFriendshipUpdated;
 49121        friendsController.OnInitialized += HandleFriendsControllerInitialization;
 122
 49123        if (channelsFeatureFlagService.IsChannelsFeatureEnabled())
 124        {
 46125            channelsFeatureFlagService.OnAllowedToCreateChannelsChanged += OnAllowedToCreateChannelsChanged;
 126
 46127            view.OnOpenChannelSearch += OpenChannelSearch;
 46128            view.OnLeaveChannel += LeaveChannel;
 46129            view.OnCreateChannel += OpenChannelCreationWindow;
 130
 46131            chatController.OnChannelUpdated += HandleChannelUpdated;
 46132            chatController.OnChannelJoined += HandleChannelJoined;
 46133            chatController.OnJoinChannelError += HandleJoinChannelError;
 46134            chatController.OnChannelLeaveError += HandleLeaveChannelError;
 46135            chatController.OnChannelLeft += HandleChannelLeft;
 46136            dataStore.channels.channelToBeOpenedFromLink.OnChange += HandleChannelOpenedFromLink;
 137
 46138            view.ShowChannelsLoading();
 46139            view.SetSearchAndCreateContainerActive(true);
 46140        }
 141        else
 142        {
 3143            view.HideChannelsLoading();
 3144            view.SetSearchAndCreateContainerActive(false);
 145        }
 3146    }
 147
 148    public void Dispose()
 149    {
 3150        view.OnClose -= HandleViewCloseRequest;
 3151        view.OnOpenPrivateChat -= OpenPrivateChat;
 3152        view.OnOpenPublicChat -= OpenPublicChat;
 3153        view.OnSearchChatRequested -= SearchChats;
 3154        view.OnRequireMorePrivateChats -= ShowMorePrivateChats;
 3155        view.OnOpenChannelSearch -= OpenChannelSearch;
 3156        view.OnCreateChannel -= OpenChannelCreationWindow;
 3157        view.OnSignUp -= SignUp;
 3158        view.OnRequireWalletReadme -= OpenWalletReadme;
 3159        view.Dispose();
 3160        chatController.OnInitialized -= HandleChatInitialization;
 3161        chatController.OnAddMessage -= HandleMessageAdded;
 3162        chatController.OnChannelUpdated -= HandleChannelUpdated;
 3163        chatController.OnChannelJoined -= HandleChannelJoined;
 3164        chatController.OnJoinChannelError -= HandleJoinChannelError;
 3165        chatController.OnChannelLeaveError += HandleLeaveChannelError;
 3166        chatController.OnChannelLeft -= HandleChannelLeft;
 3167        friendsController.OnAddFriendsWithDirectMessages -= HandleFriendsWithDirectMessagesAdded;
 3168        friendsController.OnUpdateUserStatus -= HandleUserStatusChanged;
 3169        friendsController.OnUpdateFriendship -= HandleFriendshipUpdated;
 3170        friendsController.OnInitialized -= HandleFriendsControllerInitialization;
 3171        dataStore.channels.channelToBeOpenedFromLink.OnChange -= HandleChannelOpenedFromLink;
 172
 3173        if (ownUserProfile != null)
 2174            ownUserProfile.OnUpdate -= OnUserProfileUpdate;
 175
 3176        hideChannelsLoadingCancellationToken?.Cancel();
 3177        hideChannelsLoadingCancellationToken?.Dispose();
 3178        reloadingChannelsInfoCancellationToken.Cancel();
 3179        reloadingChannelsInfoCancellationToken.Dispose();
 180
 3181        channelsFeatureFlagService.OnAllowedToCreateChannelsChanged -= OnAllowedToCreateChannelsChanged;
 3182    }
 183
 184    public void SetVisibility(bool visible)
 185    {
 20186        SetVisiblePanelList(visible);
 187
 20188        if (visible)
 189        {
 14190            view.Show();
 14191            OnOpen?.Invoke();
 192
 14193            if (friendsController.IsInitialized && !areDMsRequestedByFirstTime)
 194            {
 11195                RequestFriendsWithDirectMessages();
 11196                RequestUnreadMessages();
 197            }
 198
 14199            if (channelsFeatureFlagService.IsChannelsFeatureEnabled())
 200            {
 13201                if (!areJoinedChannelsRequestedByFirstTime)
 13202                    RequestJoinedChannels();
 203                else
 0204                    SetAutomaticChannelsInfoUpdatingActive(true);
 205
 13206                if (!areUnseenMessajesRequestedByFirstTime)
 13207                    RequestUnreadChannelsMessages();
 208            }
 209
 14210            if (ownUserProfile?.isGuest ?? false)
 1211                view.ShowConnectWallet();
 212            else
 13213                view.HideConnectWallet();
 13214        }
 215        else
 216        {
 6217            view.DisableSearchMode();
 6218            view.Hide();
 6219            SetAutomaticChannelsInfoUpdatingActive(false);
 220        }
 6221    }
 222
 223    private void OpenChannelCreationWindow()
 224    {
 0225        dataStore.channels.channelJoinedSource.Set(ChannelJoinedSource.ConversationList);
 0226        OnOpenChannelCreation?.Invoke();
 0227    }
 228
 229    private void SetVisiblePanelList(bool visible)
 230    {
 20231        HashSet<string> newSet = visibleTaskbarPanels.Get();
 20232        if (visible)
 14233            newSet.Add("WorldChatPanel");
 234        else
 6235            newSet.Remove("WorldChatPanel");
 236
 20237        visibleTaskbarPanels.Set(newSet, true);
 20238    }
 239
 240    private void LeaveChannel(string channelId)
 241    {
 1242        dataStore.channels.channelLeaveSource.Set(ChannelLeaveSource.ConversationList);
 1243        OnOpenChannelLeave?.Invoke(channelId);
 1244    }
 245
 246    private void RequestJoinedChannels()
 247    {
 14248        if ((DateTime.UtcNow - channelsRequestTimestamp).TotalSeconds < 3) return;
 249
 250        // skip=0: we do not support pagination for channels, it is supposed that a user can have a limited amount of jo
 14251        chatController.GetJoinedChannels(CHANNELS_PAGE_SIZE, 0);
 14252        channelsRequestTimestamp = DateTime.UtcNow;
 253
 14254        areJoinedChannelsRequestedByFirstTime = true;
 255
 14256        hideChannelsLoadingCancellationToken?.Cancel();
 14257        hideChannelsLoadingCancellationToken = new CancellationTokenSource();
 14258        WaitThenHideChannelsLoading(hideChannelsLoadingCancellationToken.Token).Forget();
 14259    }
 260
 261    private async UniTask WaitThenHideChannelsLoading(CancellationToken cancellationToken)
 262    {
 28263        await UniTask.Delay(3000, cancellationToken: cancellationToken);
 0264        if (cancellationToken.IsCancellationRequested) return;
 0265        view.HideChannelsLoading();
 0266    }
 267
 268    private void HandleChatInitialization()
 269    {
 1270        if (areJoinedChannelsRequestedByFirstTime) return;
 271        // we do request joined channels as soon as possible to be able to display messages correctly in the notificatio
 1272        RequestJoinedChannels();
 1273    }
 274
 275    private void HandleFriendsControllerInitialization()
 276    {
 3277        if (view.IsActive && !areDMsRequestedByFirstTime)
 278        {
 2279            RequestFriendsWithDirectMessages();
 2280            RequestUnreadMessages();
 2281        }
 282        else
 1283            view.HidePrivateChatsLoading();
 1284    }
 285
 286    private void OpenPrivateChat(string userId)
 287    {
 1288        OnOpenPrivateChat?.Invoke(userId);
 1289    }
 290
 291    private void OpenPublicChat(string channelId)
 292    {
 4293        if (channelId == ChatUtils.NEARBY_CHANNEL_ID)
 1294            OnOpenPublicChat?.Invoke(channelId);
 295        else
 3296            OnOpenChannel?.Invoke(channelId);
 1297    }
 298
 299    private void HandleViewCloseRequest()
 300    {
 1301        OnCloseView?.Invoke();
 1302        SetVisibility(false);
 1303    }
 304
 305    private void HandleFriendshipUpdated(string userId, FriendshipAction friendship)
 306    {
 6307        if (friendship != FriendshipAction.APPROVED)
 308        {
 309            // show only private chats from friends. Change it whenever the catalyst supports to send pms to any user
 6310            view.RemovePrivateChat(userId);
 311        }
 6312    }
 313
 314    private void HandleUserStatusChanged(string userId, UserStatus status)
 315    {
 4316        if (status.friendshipStatus != FriendshipStatus.FRIEND)
 317        {
 318            // show only private chats from friends. Change it whenever the catalyst supports to send pms to any user
 4319            view.RemovePrivateChat(userId);
 320        }
 4321    }
 322
 323    private void HandleMessageAdded(ChatMessage message)
 324    {
 11325        if (message.messageType != ChatMessage.Type.PRIVATE) return;
 326
 7327        var userId = ExtractRecipientId(message);
 328
 7329        if (lastPrivateMessages.ContainsKey(userId))
 330        {
 0331            if (message.timestamp > lastPrivateMessages[userId].timestamp)
 0332                lastPrivateMessages[userId] = message;
 0333        }
 334        else
 7335            lastPrivateMessages[userId] = message;
 336
 7337        var profile = userProfileBridge.Get(userId);
 7338        if (profile == null) return;
 339
 7340        view.SetPrivateChat(CreatePrivateChatModel(message, profile));
 7341    }
 342
 343    private void HandleFriendsWithDirectMessagesAdded(List<FriendWithDirectMessages> usersWithDM)
 344    {
 12345        for (var i = 0; i < usersWithDM.Count; i++)
 346        {
 3347            var profile = userProfileBridge.Get(usersWithDM[i].userId);
 3348            if (profile == null) continue;
 349
 0350            var lastMessage = new ChatMessage
 351            {
 352                messageType = ChatMessage.Type.PRIVATE,
 353                body = usersWithDM[i].lastMessageBody,
 354                timestamp = (ulong) usersWithDM[i].lastMessageTimestamp
 355            };
 356
 0357            if (lastPrivateMessages.ContainsKey(profile.userId))
 358            {
 0359                if (lastMessage.timestamp > lastPrivateMessages[profile.userId].timestamp)
 0360                    lastPrivateMessages[profile.userId] = lastMessage;
 0361            }
 362            else
 0363                lastPrivateMessages[profile.userId] = lastMessage;
 364
 0365            view.SetPrivateChat(CreatePrivateChatModel(lastMessage, profile));
 366        }
 367
 3368        UpdateMoreChannelsToLoadHint();
 3369        view.HidePrivateChatsLoading();
 3370        view.HideSearchLoading();
 371
 3372        isRequestingDMs = false;
 3373    }
 374
 375    private PrivateChatModel CreatePrivateChatModel(ChatMessage recentMessage, UserProfile profile)
 376    {
 7377        return new PrivateChatModel
 378        {
 379            user = profile,
 380            recentMessage = recentMessage,
 381            isBlocked = ownUserProfile.IsBlocked(profile.userId),
 382            isOnline = friendsController.GetUserStatus(profile.userId).presence == PresenceStatus.ONLINE
 383        };
 384    }
 385
 386    private string ExtractRecipientId(ChatMessage message)
 387    {
 7388        return message.sender != ownUserProfile.userId ? message.sender : message.recipient;
 389    }
 390
 391    private void OnUserProfileUpdate(UserProfile profile)
 392    {
 2393        view.RefreshBlockedDirectMessages(profile.blocked);
 394
 2395        if (profile.isGuest)
 1396            view.ShowConnectWallet();
 397        else
 1398            view.HideConnectWallet();
 1399    }
 400
 401    private void SearchChats(string search)
 402    {
 2403        currentSearch = search;
 404
 2405        if (string.IsNullOrEmpty(search))
 406        {
 1407            View.DisableSearchMode();
 1408            UpdateMoreChannelsToLoadHint();
 1409            return;
 410        }
 411
 1412        UpdateMoreChannelsToLoadHint();
 1413        View.EnableSearchMode();
 414
 1415        var matchedChannels = publicChannels.Values
 2416            .Where(model => model.name.ToLower().Contains(search.ToLower()));
 4417        foreach (var channelMatch in matchedChannels)
 1418            View.SetPublicChat(channelMatch);
 419
 1420        RequestFriendsWithDirectMessagesFromSearch(search, USER_DM_ENTRIES_TO_REQUEST_FOR_SEARCH);
 1421    }
 422
 423    private void ShowMorePrivateChats()
 424    {
 1425        if (isRequestingDMs ||
 426            hiddenDMs == 0 ||
 427            !string.IsNullOrEmpty(currentSearch))
 0428            return;
 429
 1430        RequestFriendsWithDirectMessages();
 1431    }
 432
 433    private void UpdateMoreChannelsToLoadHint()
 434    {
 5435        hiddenDMs = Mathf.Clamp(friendsController.TotalFriendsWithDirectMessagesCount - lastSkipForDMs,
 436            0,
 437            friendsController.TotalFriendsWithDirectMessagesCount);
 438
 5439        if (hiddenDMs <= 0 || !string.IsNullOrEmpty(currentSearch))
 3440            View.HideMoreChatsToLoadHint();
 441        else
 2442            View.ShowMoreChatsToLoadHint(hiddenDMs);
 2443    }
 444
 445    private void RequestFriendsWithDirectMessages()
 446    {
 14447        isRequestingDMs = true;
 448
 14449        if (!areDMsRequestedByFirstTime)
 450        {
 13451            view.ShowPrivateChatsLoading();
 13452            view.HideMoreChatsToLoadHint();
 453        }
 454
 14455        friendsController.GetFriendsWithDirectMessages(DMS_PAGE_SIZE, lastSkipForDMs);
 14456        lastSkipForDMs += DMS_PAGE_SIZE;
 14457        areDMsRequestedByFirstTime = true;
 458
 14459        hidePrivateChatsLoadingCancellationToken.Cancel();
 14460        hidePrivateChatsLoadingCancellationToken = new CancellationTokenSource();
 14461        HidePrivateChatsLoadingWhenTimeout(hidePrivateChatsLoadingCancellationToken.Token).Forget();
 14462    }
 463
 464    private async UniTaskVoid HidePrivateChatsLoadingWhenTimeout(CancellationToken cancellationToken)
 465    {
 29466        await UniTask.Delay(3000, cancellationToken: cancellationToken);
 0467        if (cancellationToken.IsCancellationRequested) return;
 0468        view.HidePrivateChatsLoading();
 0469    }
 470
 471    internal void RequestFriendsWithDirectMessagesFromSearch(string userNameOrId, int limit)
 472    {
 2473        view.ShowSearchLoading();
 2474        friendsController.GetFriendsWithDirectMessages(userNameOrId, limit);
 2475        hideLoadingCancellationToken?.Cancel();
 2476        hideLoadingCancellationToken = new CancellationTokenSource();
 2477        HideSearchLoadingWhenTimeout(hideLoadingCancellationToken.Token).Forget();
 2478    }
 479
 480    private void HandleChannelUpdated(Channel channel)
 481    {
 4482        if (!channel.Joined)
 483        {
 0484            view.RemovePublicChat(channel.ChannelId);
 0485            publicChannels.Remove(channel.ChannelId);
 0486            return;
 487        }
 488
 4489        var channelId = channel.ChannelId;
 4490        var model = new PublicChatModel(channelId, channel.Name, channel.Description, channel.Joined, channel.MemberCoun
 491
 4492        if (publicChannels.ContainsKey(channelId))
 1493            publicChannels[channelId].CopyFrom(model);
 494        else
 3495            publicChannels[channelId] = model;
 496
 4497        view.SetPublicChat(model);
 4498        view.HideChannelsLoading();
 499
 500        // we clear the unseen messages to avoid showing many of them while the user was offline
 501        // TODO: we should consider avoid clearing when the channel is private in the future
 4502        ClearOfflineUnseenMessages(channelId);
 4503    }
 504
 505    private void ClearOfflineUnseenMessages(string channelId)
 506    {
 5507        if (channelsClearedUnseenNotifications.Contains(channelId)) return;
 3508        chatController.MarkChannelMessagesAsSeen(channelId);
 3509        channelsClearedUnseenNotifications.Add(channelId);
 3510    }
 511
 512    private void HandleChannelJoined(Channel channel)
 513    {
 2514        if (channel.MemberCount <= 1)
 1515            socialAnalytics.SendEmptyChannelCreated(channel.Name, dataStore.channels.channelJoinedSource.Get());
 516        else
 1517            socialAnalytics.SendPopulatedChannelJoined(channel.Name, dataStore.channels.channelJoinedSource.Get());
 518
 2519        OpenPublicChat(channel.ChannelId);
 2520    }
 521
 522    private void HandleJoinChannelError(string channelId, ChannelErrorCode errorCode)
 523    {
 0524        if (dataStore.channels.isCreationModalVisible.Get()) return;
 525
 526        switch (errorCode)
 527        {
 528            case ChannelErrorCode.LimitExceeded:
 0529                dataStore.channels.currentChannelLimitReached.Set(channelId, true);
 0530                break;
 531            case ChannelErrorCode.Unknown:
 0532                dataStore.channels.joinChannelError.Set(channelId, true);
 533                break;
 534        }
 0535    }
 536
 537    private void HandleLeaveChannelError(string channelId, ChannelErrorCode errorCode) =>
 0538        dataStore.channels.leaveChannelError.Set(channelId, true);
 539
 540    private void HandleChannelLeft(string channelId)
 541    {
 1542        publicChannels.Remove(channelId);
 1543        view.RemovePublicChat(channelId);
 1544        var channel = chatController.GetAllocatedChannel(channelId);
 1545        socialAnalytics.SendLeaveChannel(channel?.Name ?? channelId, dataStore.channels.channelLeaveSource.Get());
 1546    }
 547
 548    private void HandleChannelOpenedFromLink(string channelId, string previousChannelId)
 549    {
 0550        if (string.IsNullOrEmpty(channelId))
 0551            return;
 552
 0553        OpenPublicChat(channelId);
 0554    }
 555
 13556    private void RequestUnreadMessages() => chatController.GetUnseenMessagesByUser();
 557
 558    private void RequestUnreadChannelsMessages()
 559    {
 13560        chatController.GetUnseenMessagesByChannel();
 13561        areUnseenMessajesRequestedByFirstTime = true;
 13562    }
 563
 564    private void OpenChannelSearch()
 565    {
 0566        if (!ownUserProfile.isGuest)
 0567            OnOpenChannelSearch?.Invoke();
 568        else
 0569            dataStore.HUDs.connectWalletModalVisible.Set(true);
 0570    }
 571
 572    private async UniTask HideSearchLoadingWhenTimeout(CancellationToken cancellationToken)
 573    {
 4574        await UniTask.Delay(3000, cancellationToken: cancellationToken);
 0575        if (cancellationToken.IsCancellationRequested) return;
 0576        view.HideSearchLoading();
 0577    }
 578
 0579    private void OnAllowedToCreateChannelsChanged(bool isAllowed) => view.SetCreateChannelButtonActive(isAllowed);
 580
 581    private void SetAutomaticChannelsInfoUpdatingActive(bool isActive)
 582    {
 6583        reloadingChannelsInfoCancellationToken.Cancel();
 584
 6585        if (isActive)
 586        {
 0587            GetCurrentChannelsInfo();
 0588            reloadingChannelsInfoCancellationToken = new CancellationTokenSource();
 0589            ReloadChannelsInfoPeriodically(reloadingChannelsInfoCancellationToken.Token).Forget();
 590        }
 6591    }
 592
 593    private async UniTask ReloadChannelsInfoPeriodically(CancellationToken cancellationToken)
 594    {
 0595        while (true)
 596        {
 0597            await UniTask.Delay(MINUTES_FOR_AUTOMATIC_CHANNELS_INFO_RELOADING * 60 * 1000, cancellationToken: cancellati
 598
 0599            if (cancellationToken.IsCancellationRequested)
 0600                return;
 601
 0602            GetCurrentChannelsInfo();
 603        }
 0604    }
 605
 606    private void GetCurrentChannelsInfo()
 607    {
 0608        chatController.GetChannelInfo(publicChannels
 0609                .Select(x => x.Key)
 0610                .Where(x => x != ChatUtils.NEARBY_CHANNEL_ID)
 611                .ToArray());
 0612    }
 613
 1614    private void OpenWalletReadme() => browserBridge.OpenUrl("https://docs.decentraland.org/player/blockchain-integratio
 615
 1616    private void SignUp() => userProfileBridge.SignUp();
 617}

Methods/Properties

WorldChatWindowController(IUserProfileBridge, IFriendsController, IChatController, DCL.DataStore, DCL.IMouseCatcher, SocialFeaturesAnalytics.ISocialAnalytics, DCL.Chat.IChannelsFeatureFlagService, DCL.Browser.IBrowserBridge)
visibleTaskbarPanels()
View()
Initialize(IWorldChatWindowView)
Dispose()
SetVisibility(System.Boolean)
OpenChannelCreationWindow()
SetVisiblePanelList(System.Boolean)
LeaveChannel(System.String)
RequestJoinedChannels()
WaitThenHideChannelsLoading()
HandleChatInitialization()
HandleFriendsControllerInitialization()
OpenPrivateChat(System.String)
OpenPublicChat(System.String)
HandleViewCloseRequest()
HandleFriendshipUpdated(System.String, FriendshipAction)
HandleUserStatusChanged(System.String, UserStatus)
HandleMessageAdded(DCL.Interface.ChatMessage)
HandleFriendsWithDirectMessagesAdded(System.Collections.Generic.List[FriendWithDirectMessages])
CreatePrivateChatModel(DCL.Interface.ChatMessage, UserProfile)
ExtractRecipientId(DCL.Interface.ChatMessage)
OnUserProfileUpdate(UserProfile)
SearchChats(System.String)
ShowMorePrivateChats()
UpdateMoreChannelsToLoadHint()
RequestFriendsWithDirectMessages()
HidePrivateChatsLoadingWhenTimeout()
RequestFriendsWithDirectMessagesFromSearch(System.String, System.Int32)
HandleChannelUpdated(DCL.Chat.Channels.Channel)
ClearOfflineUnseenMessages(System.String)
HandleChannelJoined(DCL.Chat.Channels.Channel)
HandleJoinChannelError(System.String, DCL.Chat.Channels.ChannelErrorCode)
HandleLeaveChannelError(System.String, DCL.Chat.Channels.ChannelErrorCode)
HandleChannelLeft(System.String)
HandleChannelOpenedFromLink(System.String, System.String)
RequestUnreadMessages()
RequestUnreadChannelsMessages()
OpenChannelSearch()
HideSearchLoadingWhenTimeout()
OnAllowedToCreateChannelsChanged(System.Boolean)
SetAutomaticChannelsInfoUpdatingActive(System.Boolean)
ReloadChannelsInfoPeriodically()
GetCurrentChannelsInfo()
OpenWalletReadme()
SignUp()