< Summary

Class:WorldChatWindowController
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/WorldChatWindowController.cs
Covered lines:253
Uncovered lines:56
Coverable lines:309
Total lines:619
Line coverage:81.8% (253 of 309)
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        }
 146
 49147        view.SetChannelsPromoteLabelVisible(channelsFeatureFlagService.IsPromoteChannelsToastEnabled());
 49148    }
 149
 150    public void Dispose()
 151    {
 3152        view.OnClose -= HandleViewCloseRequest;
 3153        view.OnOpenPrivateChat -= OpenPrivateChat;
 3154        view.OnOpenPublicChat -= OpenPublicChat;
 3155        view.OnSearchChatRequested -= SearchChats;
 3156        view.OnRequireMorePrivateChats -= ShowMorePrivateChats;
 3157        view.OnOpenChannelSearch -= OpenChannelSearch;
 3158        view.OnCreateChannel -= OpenChannelCreationWindow;
 3159        view.OnSignUp -= SignUp;
 3160        view.OnRequireWalletReadme -= OpenWalletReadme;
 3161        view.Dispose();
 3162        chatController.OnInitialized -= HandleChatInitialization;
 3163        chatController.OnAddMessage -= HandleMessageAdded;
 3164        chatController.OnChannelUpdated -= HandleChannelUpdated;
 3165        chatController.OnChannelJoined -= HandleChannelJoined;
 3166        chatController.OnJoinChannelError -= HandleJoinChannelError;
 3167        chatController.OnChannelLeaveError += HandleLeaveChannelError;
 3168        chatController.OnChannelLeft -= HandleChannelLeft;
 3169        friendsController.OnAddFriendsWithDirectMessages -= HandleFriendsWithDirectMessagesAdded;
 3170        friendsController.OnUpdateUserStatus -= HandleUserStatusChanged;
 3171        friendsController.OnUpdateFriendship -= HandleFriendshipUpdated;
 3172        friendsController.OnInitialized -= HandleFriendsControllerInitialization;
 3173        dataStore.channels.channelToBeOpenedFromLink.OnChange -= HandleChannelOpenedFromLink;
 174
 3175        if (ownUserProfile != null)
 2176            ownUserProfile.OnUpdate -= OnUserProfileUpdate;
 177
 3178        hideChannelsLoadingCancellationToken?.Cancel();
 3179        hideChannelsLoadingCancellationToken?.Dispose();
 3180        reloadingChannelsInfoCancellationToken.Cancel();
 3181        reloadingChannelsInfoCancellationToken.Dispose();
 182
 3183        channelsFeatureFlagService.OnAllowedToCreateChannelsChanged -= OnAllowedToCreateChannelsChanged;
 3184    }
 185
 186    public void SetVisibility(bool visible)
 187    {
 20188        SetVisiblePanelList(visible);
 189
 20190        if (visible)
 191        {
 15192            view.Show();
 15193            OnOpen?.Invoke();
 194
 15195            if (friendsController.IsInitialized && !areDMsRequestedByFirstTime)
 196            {
 11197                RequestFriendsWithDirectMessages();
 11198                RequestUnreadMessages();
 199            }
 200
 15201            if (channelsFeatureFlagService.IsChannelsFeatureEnabled())
 202            {
 13203                if (!areJoinedChannelsRequestedByFirstTime)
 13204                    RequestJoinedChannels();
 205                else
 0206                    SetAutomaticChannelsInfoUpdatingActive(true);
 207
 13208                if (!areUnseenMessajesRequestedByFirstTime)
 13209                    RequestUnreadChannelsMessages();
 210            }
 211
 15212            if (ownUserProfile?.isGuest ?? false)
 1213                view.ShowConnectWallet();
 214            else
 14215                view.HideConnectWallet();
 14216        }
 217        else
 218        {
 5219            view.DisableSearchMode();
 5220            view.Hide();
 5221            SetAutomaticChannelsInfoUpdatingActive(false);
 222        }
 5223    }
 224
 225    private void OpenChannelCreationWindow()
 226    {
 0227        dataStore.channels.channelJoinedSource.Set(ChannelJoinedSource.ConversationList);
 0228        OnOpenChannelCreation?.Invoke();
 0229    }
 230
 231    private void SetVisiblePanelList(bool visible)
 232    {
 20233        HashSet<string> newSet = visibleTaskbarPanels.Get();
 20234        if (visible)
 15235            newSet.Add("WorldChatPanel");
 236        else
 5237            newSet.Remove("WorldChatPanel");
 238
 20239        visibleTaskbarPanels.Set(newSet, true);
 20240    }
 241
 242    private void LeaveChannel(string channelId)
 243    {
 1244        dataStore.channels.channelLeaveSource.Set(ChannelLeaveSource.ConversationList);
 1245        OnOpenChannelLeave?.Invoke(channelId);
 1246    }
 247
 248    private void RequestJoinedChannels()
 249    {
 14250        if ((DateTime.UtcNow - channelsRequestTimestamp).TotalSeconds < 3) return;
 251
 252        // skip=0: we do not support pagination for channels, it is supposed that a user can have a limited amount of jo
 14253        chatController.GetJoinedChannels(CHANNELS_PAGE_SIZE, 0);
 14254        channelsRequestTimestamp = DateTime.UtcNow;
 255
 14256        areJoinedChannelsRequestedByFirstTime = true;
 257
 14258        hideChannelsLoadingCancellationToken?.Cancel();
 14259        hideChannelsLoadingCancellationToken = new CancellationTokenSource();
 14260        WaitThenHideChannelsLoading(hideChannelsLoadingCancellationToken.Token).Forget();
 14261    }
 262
 263    private async UniTask WaitThenHideChannelsLoading(CancellationToken cancellationToken)
 264    {
 28265        await UniTask.Delay(3000, cancellationToken: cancellationToken);
 0266        if (cancellationToken.IsCancellationRequested) return;
 0267        view.HideChannelsLoading();
 0268    }
 269
 270    private void HandleChatInitialization()
 271    {
 1272        if (areJoinedChannelsRequestedByFirstTime) return;
 273        // we do request joined channels as soon as possible to be able to display messages correctly in the notificatio
 1274        RequestJoinedChannels();
 1275    }
 276
 277    private void HandleFriendsControllerInitialization()
 278    {
 3279        if (view.IsActive && !areDMsRequestedByFirstTime)
 280        {
 2281            RequestFriendsWithDirectMessages();
 2282            RequestUnreadMessages();
 2283        }
 284        else
 1285            view.HidePrivateChatsLoading();
 1286    }
 287
 288    private void OpenPrivateChat(string userId)
 289    {
 1290        OnOpenPrivateChat?.Invoke(userId);
 1291    }
 292
 293    private void OpenPublicChat(string channelId)
 294    {
 4295        if (channelId == ChatUtils.NEARBY_CHANNEL_ID)
 1296            OnOpenPublicChat?.Invoke(channelId);
 297        else
 3298            OnOpenChannel?.Invoke(channelId);
 1299    }
 300
 301    private void HandleViewCloseRequest()
 302    {
 1303        OnCloseView?.Invoke();
 1304        SetVisibility(false);
 1305    }
 306
 307    private void HandleFriendshipUpdated(string userId, FriendshipAction friendship)
 308    {
 6309        if (friendship != FriendshipAction.APPROVED)
 310        {
 311            // show only private chats from friends. Change it whenever the catalyst supports to send pms to any user
 6312            view.RemovePrivateChat(userId);
 313        }
 6314    }
 315
 316    private void HandleUserStatusChanged(string userId, UserStatus status)
 317    {
 4318        if (status.friendshipStatus != FriendshipStatus.FRIEND)
 319        {
 320            // show only private chats from friends. Change it whenever the catalyst supports to send pms to any user
 4321            view.RemovePrivateChat(userId);
 322        }
 4323    }
 324
 325    private void HandleMessageAdded(ChatMessage message)
 326    {
 11327        if (message.messageType != ChatMessage.Type.PRIVATE) return;
 328
 7329        var userId = ExtractRecipientId(message);
 330
 7331        if (lastPrivateMessages.ContainsKey(userId))
 332        {
 0333            if (message.timestamp > lastPrivateMessages[userId].timestamp)
 0334                lastPrivateMessages[userId] = message;
 0335        }
 336        else
 7337            lastPrivateMessages[userId] = message;
 338
 7339        var profile = userProfileBridge.Get(userId);
 7340        if (profile == null) return;
 341
 7342        view.SetPrivateChat(CreatePrivateChatModel(message, profile));
 7343    }
 344
 345    private void HandleFriendsWithDirectMessagesAdded(List<FriendWithDirectMessages> usersWithDM)
 346    {
 12347        for (var i = 0; i < usersWithDM.Count; i++)
 348        {
 3349            var profile = userProfileBridge.Get(usersWithDM[i].userId);
 3350            if (profile == null) continue;
 351
 0352            var lastMessage = new ChatMessage
 353            {
 354                messageType = ChatMessage.Type.PRIVATE,
 355                body = usersWithDM[i].lastMessageBody,
 356                timestamp = (ulong) usersWithDM[i].lastMessageTimestamp
 357            };
 358
 0359            if (lastPrivateMessages.ContainsKey(profile.userId))
 360            {
 0361                if (lastMessage.timestamp > lastPrivateMessages[profile.userId].timestamp)
 0362                    lastPrivateMessages[profile.userId] = lastMessage;
 0363            }
 364            else
 0365                lastPrivateMessages[profile.userId] = lastMessage;
 366
 0367            view.SetPrivateChat(CreatePrivateChatModel(lastMessage, profile));
 368        }
 369
 3370        UpdateMoreChannelsToLoadHint();
 3371        view.HidePrivateChatsLoading();
 3372        view.HideSearchLoading();
 373
 3374        isRequestingDMs = false;
 3375    }
 376
 377    private PrivateChatModel CreatePrivateChatModel(ChatMessage recentMessage, UserProfile profile)
 378    {
 7379        return new PrivateChatModel
 380        {
 381            user = profile,
 382            recentMessage = recentMessage,
 383            isBlocked = ownUserProfile.IsBlocked(profile.userId),
 384            isOnline = friendsController.GetUserStatus(profile.userId).presence == PresenceStatus.ONLINE
 385        };
 386    }
 387
 388    private string ExtractRecipientId(ChatMessage message)
 389    {
 7390        return message.sender != ownUserProfile.userId ? message.sender : message.recipient;
 391    }
 392
 393    private void OnUserProfileUpdate(UserProfile profile)
 394    {
 2395        view.RefreshBlockedDirectMessages(profile.blocked);
 396
 2397        if (profile.isGuest)
 1398            view.ShowConnectWallet();
 399        else
 1400            view.HideConnectWallet();
 1401    }
 402
 403    private void SearchChats(string search)
 404    {
 2405        currentSearch = search;
 406
 2407        if (string.IsNullOrEmpty(search))
 408        {
 1409            View.DisableSearchMode();
 1410            UpdateMoreChannelsToLoadHint();
 1411            return;
 412        }
 413
 1414        UpdateMoreChannelsToLoadHint();
 1415        View.EnableSearchMode();
 416
 1417        var matchedChannels = publicChannels.Values
 2418            .Where(model => model.name.ToLower().Contains(search.ToLower()));
 4419        foreach (var channelMatch in matchedChannels)
 1420            View.SetPublicChat(channelMatch);
 421
 1422        RequestFriendsWithDirectMessagesFromSearch(search, USER_DM_ENTRIES_TO_REQUEST_FOR_SEARCH);
 1423    }
 424
 425    private void ShowMorePrivateChats()
 426    {
 1427        if (isRequestingDMs ||
 428            hiddenDMs == 0 ||
 429            !string.IsNullOrEmpty(currentSearch))
 0430            return;
 431
 1432        RequestFriendsWithDirectMessages();
 1433    }
 434
 435    private void UpdateMoreChannelsToLoadHint()
 436    {
 5437        hiddenDMs = Mathf.Clamp(friendsController.TotalFriendsWithDirectMessagesCount - lastSkipForDMs,
 438            0,
 439            friendsController.TotalFriendsWithDirectMessagesCount);
 440
 5441        if (hiddenDMs <= 0 || !string.IsNullOrEmpty(currentSearch))
 3442            View.HideMoreChatsToLoadHint();
 443        else
 2444            View.ShowMoreChatsToLoadHint(hiddenDMs);
 2445    }
 446
 447    private void RequestFriendsWithDirectMessages()
 448    {
 14449        isRequestingDMs = true;
 450
 14451        if (!areDMsRequestedByFirstTime)
 452        {
 13453            view.ShowPrivateChatsLoading();
 13454            view.HideMoreChatsToLoadHint();
 455        }
 456
 14457        friendsController.GetFriendsWithDirectMessages(DMS_PAGE_SIZE, lastSkipForDMs);
 14458        lastSkipForDMs += DMS_PAGE_SIZE;
 14459        areDMsRequestedByFirstTime = true;
 460
 14461        hidePrivateChatsLoadingCancellationToken.Cancel();
 14462        hidePrivateChatsLoadingCancellationToken = new CancellationTokenSource();
 14463        HidePrivateChatsLoadingWhenTimeout(hidePrivateChatsLoadingCancellationToken.Token).Forget();
 14464    }
 465
 466    private async UniTaskVoid HidePrivateChatsLoadingWhenTimeout(CancellationToken cancellationToken)
 467    {
 29468        await UniTask.Delay(3000, cancellationToken: cancellationToken);
 0469        if (cancellationToken.IsCancellationRequested) return;
 0470        view.HidePrivateChatsLoading();
 0471    }
 472
 473    internal void RequestFriendsWithDirectMessagesFromSearch(string userNameOrId, int limit)
 474    {
 2475        view.ShowSearchLoading();
 2476        friendsController.GetFriendsWithDirectMessages(userNameOrId, limit);
 2477        hideLoadingCancellationToken?.Cancel();
 2478        hideLoadingCancellationToken = new CancellationTokenSource();
 2479        HideSearchLoadingWhenTimeout(hideLoadingCancellationToken.Token).Forget();
 2480    }
 481
 482    private void HandleChannelUpdated(Channel channel)
 483    {
 4484        if (!channel.Joined)
 485        {
 0486            view.RemovePublicChat(channel.ChannelId);
 0487            publicChannels.Remove(channel.ChannelId);
 0488            return;
 489        }
 490
 4491        var channelId = channel.ChannelId;
 4492        var model = new PublicChatModel(channelId, channel.Name, channel.Description, channel.Joined, channel.MemberCoun
 493
 4494        if (publicChannels.ContainsKey(channelId))
 1495            publicChannels[channelId].CopyFrom(model);
 496        else
 3497            publicChannels[channelId] = model;
 498
 4499        view.SetPublicChat(model);
 4500        view.HideChannelsLoading();
 501
 502        // we clear the unseen messages to avoid showing many of them while the user was offline
 503        // TODO: we should consider avoid clearing when the channel is private in the future
 4504        ClearOfflineUnseenMessages(channelId);
 4505    }
 506
 507    private void ClearOfflineUnseenMessages(string channelId)
 508    {
 5509        if (channelsClearedUnseenNotifications.Contains(channelId)) return;
 3510        chatController.MarkChannelMessagesAsSeen(channelId);
 3511        channelsClearedUnseenNotifications.Add(channelId);
 3512    }
 513
 514    private void HandleChannelJoined(Channel channel)
 515    {
 2516        if (channel.MemberCount <= 1)
 1517            socialAnalytics.SendEmptyChannelCreated(channel.Name, dataStore.channels.channelJoinedSource.Get());
 518        else
 1519            socialAnalytics.SendPopulatedChannelJoined(channel.Name, dataStore.channels.channelJoinedSource.Get());
 520
 2521        OpenPublicChat(channel.ChannelId);
 2522    }
 523
 524    private void HandleJoinChannelError(string channelId, ChannelErrorCode errorCode)
 525    {
 0526        if (dataStore.channels.isCreationModalVisible.Get()) return;
 527
 528        switch (errorCode)
 529        {
 530            case ChannelErrorCode.LimitExceeded:
 0531                dataStore.channels.currentChannelLimitReached.Set(channelId, true);
 0532                break;
 533            case ChannelErrorCode.Unknown:
 0534                dataStore.channels.joinChannelError.Set(channelId, true);
 535                break;
 536        }
 0537    }
 538
 539    private void HandleLeaveChannelError(string channelId, ChannelErrorCode errorCode) =>
 0540        dataStore.channels.leaveChannelError.Set(channelId, true);
 541
 542    private void HandleChannelLeft(string channelId)
 543    {
 1544        publicChannels.Remove(channelId);
 1545        view.RemovePublicChat(channelId);
 1546        var channel = chatController.GetAllocatedChannel(channelId);
 1547        socialAnalytics.SendLeaveChannel(channel?.Name ?? channelId, dataStore.channels.channelLeaveSource.Get());
 1548    }
 549
 550    private void HandleChannelOpenedFromLink(string channelId, string previousChannelId)
 551    {
 0552        if (string.IsNullOrEmpty(channelId))
 0553            return;
 554
 0555        OpenPublicChat(channelId);
 0556    }
 557
 13558    private void RequestUnreadMessages() => chatController.GetUnseenMessagesByUser();
 559
 560    private void RequestUnreadChannelsMessages()
 561    {
 13562        chatController.GetUnseenMessagesByChannel();
 13563        areUnseenMessajesRequestedByFirstTime = true;
 13564    }
 565
 566    private void OpenChannelSearch()
 567    {
 0568        if (!ownUserProfile.isGuest)
 0569            OnOpenChannelSearch?.Invoke();
 570        else
 0571            dataStore.HUDs.connectWalletModalVisible.Set(true);
 0572    }
 573
 574    private async UniTask HideSearchLoadingWhenTimeout(CancellationToken cancellationToken)
 575    {
 4576        await UniTask.Delay(3000, cancellationToken: cancellationToken);
 0577        if (cancellationToken.IsCancellationRequested) return;
 0578        view.HideSearchLoading();
 0579    }
 580
 0581    private void OnAllowedToCreateChannelsChanged(bool isAllowed) => view.SetCreateChannelButtonActive(isAllowed);
 582
 583    private void SetAutomaticChannelsInfoUpdatingActive(bool isActive)
 584    {
 5585        reloadingChannelsInfoCancellationToken.Cancel();
 586
 5587        if (isActive)
 588        {
 0589            GetCurrentChannelsInfo();
 0590            reloadingChannelsInfoCancellationToken = new CancellationTokenSource();
 0591            ReloadChannelsInfoPeriodically(reloadingChannelsInfoCancellationToken.Token).Forget();
 592        }
 5593    }
 594
 595    private async UniTask ReloadChannelsInfoPeriodically(CancellationToken cancellationToken)
 596    {
 0597        while (true)
 598        {
 0599            await UniTask.Delay(MINUTES_FOR_AUTOMATIC_CHANNELS_INFO_RELOADING * 60 * 1000, cancellationToken: cancellati
 600
 0601            if (cancellationToken.IsCancellationRequested)
 0602                return;
 603
 0604            GetCurrentChannelsInfo();
 605        }
 0606    }
 607
 608    private void GetCurrentChannelsInfo()
 609    {
 0610        chatController.GetChannelInfo(publicChannels
 0611                .Select(x => x.Key)
 0612                .Where(x => x != ChatUtils.NEARBY_CHANNEL_ID)
 613                .ToArray());
 0614    }
 615
 1616    private void OpenWalletReadme() => browserBridge.OpenUrl("https://docs.decentraland.org/player/blockchain-integratio
 617
 1618    private void SignUp() => userProfileBridge.SignUp();
 619}

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()