< Summary

Class:DCL.Chat.ChatController
Assembly:ChatController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ChatController/ChatController.cs
/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ChatController/ChatControllerContextMenuUtility.cs
Covered lines:22
Uncovered lines:189
Coverable lines:211
Total lines:623
Line coverage:10.4% (22 of 211)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ChatController()0%110100%
Awake()0%110100%
InitializeChat(...)0%20400%
AddMessageToChatWindow(...)0%2100%
AddChatMessages(...)0%12300%
UpdateTotalUnseenMessages(...)0%6200%
UpdateUserUnseenMessages(...)0%6200%
UpdateTotalUnseenMessagesByUser(...)0%12300%
UpdateTotalUnseenMessagesByChannel(...)0%6200%
UpdateChannelMembers(...)0%6200%
JoinChannelConfirmation(...)0%42600%
JoinChannelError(...)0%6200%
LeaveChannelError(...)0%6200%
UpdateChannelInfo(...)0%72800%
MuteChannelError(...)0%6200%
LeaveChannel(...)0%2100%
UpdateChannelSearchResults(...)0%20400%
JoinOrCreateChannel(...)0%2100%
GetChannelMessages(...)0%2100%
GetJoinedChannels(...)0%2100%
GetChannelsByName(...)0%2100%
GetChannels(...)0%110100%
MuteChannel(...)0%6200%
UnmuteChannel(...)0%6200%
GetAllocatedChannel(...)0%220100%
GetAllocatedChannelByName(...)0%2100%
GetPrivateMessages(...)0%2100%
MarkChannelMessagesAsSeen(...)0%330100%
GetAllocatedEntries()0%2100%
GetUnseenMessagesByUser()0%2100%
GetUnseenMessagesByChannel()0%2100%
GetAllocatedUnseenMessages(...)0%220100%
GetAllocatedUnseenChannelMessages(...)0%330100%
CreateChannel(...)0%2100%
GetPrivateAllocatedEntriesByUser(...)0%2100%
GetChannelInfo(...)0%2100%
GetChannelMembers(...)0%2100%
GetChannelMembers(...)0%2100%
Send(...)0%2100%
MarkMessagesAsSeen(...)0%110100%
SendChannelWelcomeMessage(...)0%2100%
AddMessage(...)0%56700%
UpdateTotalUnseenMessagesByChannel(...)0%3.073080%
FakePublicMessage()0%6200%
FakePrivateMessage()0%2100%
AddManyFakeMessagesToNearby()0%30500%
AddManyFakeMessagesToUnityChannel()0%30500%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ChatController/ChatController.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL.Chat.Channels;
 5using DCL.Chat.WebApi;
 6using DCL.Interface;
 7using JetBrains.Annotations;
 8using UnityEngine;
 9
 10namespace DCL.Chat
 11{
 12
 13    public partial class ChatController : MonoBehaviour, IChatController
 14    {
 15        private const string NEARBY_CHANNEL_DESCRIPTION =
 16            "Talk to the people around you. If you move far away from someone you will lose contact. All whispers will b
 17
 18        private const string NEARBY_CHANNEL_ID = "nearby";
 19
 020        public static ChatController i { get; private set; }
 21
 222        private readonly Dictionary<string, int> unseenMessagesByUser = new Dictionary<string, int>();
 223        private readonly Dictionary<string, int> unseenMessagesByChannel = new Dictionary<string, int>();
 224        private readonly Dictionary<string, Channel> channels = new Dictionary<string, Channel>();
 225        private readonly List<ChatMessage> messages = new List<ChatMessage>();
 026        private BaseVariable<HashSet<string>> autoJoinChannelList => DataStore.i.HUDs.autoJoinChannelList;
 27        private bool chatAlreadyInitialized;
 28        private int totalUnseenMessages;
 29
 30        public event Action<Channel> OnChannelUpdated;
 31        public event Action<Channel> OnChannelJoined;
 32        public event Action<string, ChannelErrorCode> OnJoinChannelError;
 33        public event Action<string> OnChannelLeft;
 34        public event Action<string, ChannelErrorCode> OnChannelLeaveError;
 35        public event Action<string, ChannelErrorCode> OnMuteChannelError;
 36        public event Action OnInitialized;
 37        public event Action<ChatMessage> OnAddMessage;
 38        public event Action<int> OnTotalUnseenMessagesUpdated;
 39        public event Action<string, int> OnUserUnseenMessagesUpdated;
 40        public event Action<string, ChannelMember[]> OnUpdateChannelMembers;
 41        public event Action<string, Channel[]> OnChannelSearchResult;
 42        public event Action<string, int> OnChannelUnseenMessagesUpdated;
 43
 44        // since kernel does not calculate the #nearby channel unseen messages, it is handled on renderer side
 245        public int TotalUnseenMessages => totalUnseenMessages
 46                                          + (unseenMessagesByChannel.ContainsKey(NEARBY_CHANNEL_ID)
 47                                              ? unseenMessagesByChannel[NEARBY_CHANNEL_ID]
 48                                              : 0);
 49
 50        public void Awake()
 51        {
 252            i = this;
 53
 254            channels[NEARBY_CHANNEL_ID] = new Channel(NEARBY_CHANNEL_ID, NEARBY_CHANNEL_ID, 0, 0, true, false,
 55                NEARBY_CHANNEL_DESCRIPTION);
 256        }
 57
 58        // called by kernel
 59        [PublicAPI]
 60        public void InitializeChat(string json)
 61        {
 062            if (chatAlreadyInitialized)
 063                return;
 64
 065            var msg = JsonUtility.FromJson<InitializeChatPayload>(json);
 66
 067            totalUnseenMessages = msg.totalUnseenMessages;
 068            OnInitialized?.Invoke();
 069            OnTotalUnseenMessagesUpdated?.Invoke(TotalUnseenMessages);
 070            chatAlreadyInitialized = true;
 071        }
 72
 73        // called by kernel
 74        [PublicAPI]
 75        public void AddMessageToChatWindow(string jsonMessage) =>
 076            AddMessage(JsonUtility.FromJson<ChatMessage>(jsonMessage));
 77
 78        // called by kernel
 79        [PublicAPI]
 80        public void AddChatMessages(string jsonMessage)
 81        {
 082            var messages = JsonUtility.FromJson<ChatMessageListPayload>(jsonMessage);
 83
 084            if (messages == null) return;
 85
 086            foreach (var message in messages.messages)
 087                AddMessage(message);
 088        }
 89
 90        // called by kernel
 91        [PublicAPI]
 92        public void UpdateTotalUnseenMessages(string json)
 93        {
 094            var msg = JsonUtility.FromJson<UpdateTotalUnseenMessagesPayload>(json);
 095            totalUnseenMessages = msg.total;
 096            OnTotalUnseenMessagesUpdated?.Invoke(TotalUnseenMessages);
 097        }
 98
 99        // called by kernel
 100        [PublicAPI]
 101        public void UpdateUserUnseenMessages(string json)
 102        {
 0103            var msg = JsonUtility.FromJson<UpdateUserUnseenMessagesPayload>(json);
 0104            unseenMessagesByUser[msg.userId] = msg.total;
 0105            OnUserUnseenMessagesUpdated?.Invoke(msg.userId, msg.total);
 0106        }
 107
 108        // called by kernel
 109        [PublicAPI]
 110        public void UpdateTotalUnseenMessagesByUser(string json)
 111        {
 0112            var msg = JsonUtility.FromJson<UpdateTotalUnseenMessagesByUserPayload>(json);
 113
 0114            foreach (var unseenMessages in msg.unseenPrivateMessages)
 115            {
 0116                var userId = unseenMessages.userId;
 0117                var count = unseenMessages.count;
 0118                unseenMessagesByUser[userId] = count;
 0119                OnUserUnseenMessagesUpdated?.Invoke(userId, count);
 120            }
 0121        }
 122
 123        // called by kernel
 124        [PublicAPI]
 125        public void UpdateTotalUnseenMessagesByChannel(string json)
 126        {
 0127            var msg = JsonUtility.FromJson<UpdateTotalUnseenMessagesByChannelPayload>(json);
 0128            foreach (var unseenMessages in msg.unseenChannelMessages)
 0129                UpdateTotalUnseenMessagesByChannel(unseenMessages.channelId, unseenMessages.count);
 0130        }
 131
 132        // called by kernel
 133        [PublicAPI]
 134        public void UpdateChannelMembers(string payload)
 135        {
 0136            var msg = JsonUtility.FromJson<UpdateChannelMembersPayload>(payload);
 0137            OnUpdateChannelMembers?.Invoke(msg.channelId, msg.members);
 0138        }
 139
 140        // called by kernel
 141        [PublicAPI]
 142        public void JoinChannelConfirmation(string payload)
 143        {
 0144            var msg = JsonUtility.FromJson<ChannelInfoPayloads>(payload);
 145
 0146            if (msg.channelInfoPayload.Length == 0)
 0147                return;
 148
 0149            var channelInfo = msg.channelInfoPayload[0];
 0150            var channel = new Channel(channelInfo.channelId, channelInfo.name, channelInfo.unseenMessages, channelInfo.m
 0151            var channelId = channel.ChannelId;
 152
 0153            if (channels.ContainsKey(channelId))
 0154                channels[channelId].CopyFrom(channel);
 155            else
 0156                channels[channelId] = channel;
 157
 158            //TODO: rework as explained in PR #3351
 0159            if(!autoJoinChannelList.Get().Contains(channelId))
 160            {
 0161                OnChannelJoined?.Invoke(channel);
 162            }
 163
 0164            OnChannelUpdated?.Invoke(channel);
 0165            autoJoinChannelList.Get().Remove(channelId);
 166
 167            // TODO (responsibility issues): extract to another class
 0168            AudioScriptableObjects.joinChannel.Play(true);
 169
 0170            SendChannelWelcomeMessage(channel);
 0171        }
 172
 173        // called by kernel
 174        [PublicAPI]
 175        public void JoinChannelError(string payload)
 176        {
 0177            var msg = JsonUtility.FromJson<JoinChannelErrorPayload>(payload);
 0178            OnJoinChannelError?.Invoke(msg.channelId, (ChannelErrorCode) msg.errorCode);
 179
 0180            autoJoinChannelList.Get().Remove(msg.channelId);
 0181        }
 182
 183        // called by kernel
 184        [PublicAPI]
 185        public void LeaveChannelError(string payload)
 186        {
 0187            var msg = JsonUtility.FromJson<JoinChannelErrorPayload>(payload);
 0188            OnChannelLeaveError?.Invoke(msg.channelId, (ChannelErrorCode) msg.errorCode);
 189
 0190            autoJoinChannelList.Get().Remove(msg.channelId);
 0191        }
 192
 193        [PublicAPI]
 194        public void UpdateChannelInfo(string payload)
 195        {
 0196            var msg = JsonUtility.FromJson<ChannelInfoPayloads>(payload);
 0197            var anyChannelLeft = false;
 198
 0199            foreach (var channelInfo in msg.channelInfoPayload)
 200            {
 0201                var channelId = channelInfo.channelId;
 0202                var channel = new Channel(channelId, channelInfo.name, channelInfo.unseenMessages, channelInfo.memberCou
 203                    channelInfo.joined, channelInfo.muted, channelInfo.description);
 0204                var justLeft = !channel.Joined;
 205
 0206                if (channels.ContainsKey(channelId))
 207                {
 0208                    justLeft = channels[channelId].Joined && !channel.Joined;
 0209                    channels[channelId].CopyFrom(channel);
 0210                }
 211                else
 0212                    channels[channelId] = channel;
 213
 0214                if (justLeft)
 215                {
 0216                    OnChannelLeft?.Invoke(channelId);
 0217                    anyChannelLeft = true;
 218                }
 219
 0220                if (anyChannelLeft)
 221                {
 222                    // TODO (responsibility issues): extract to another class
 0223                    AudioScriptableObjects.leaveChannel.Play(true);
 224                }
 225
 0226                OnChannelUpdated?.Invoke(channel);
 227            }
 0228        }
 229
 230        // called by kernel
 231        [PublicAPI]
 232        public void MuteChannelError(string payload)
 233        {
 0234            var msg = JsonUtility.FromJson<MuteChannelErrorPayload>(payload);
 0235            OnMuteChannelError?.Invoke(msg.channelId, (ChannelErrorCode) msg.errorCode);
 0236        }
 237
 238        public void LeaveChannel(string channelId)
 239        {
 0240            WebInterface.LeaveChannel(channelId);
 241
 0242            autoJoinChannelList.Get().Remove(channelId);
 0243        }
 244
 245        // called by kernel
 246        [PublicAPI]
 247        public void UpdateChannelSearchResults(string payload)
 248        {
 0249            var msg = JsonUtility.FromJson<ChannelSearchResultsPayload>(payload);
 0250            var channelsResult = new Channel[msg.channels.Length];
 251
 0252            for (var i = 0; i < msg.channels.Length; i++)
 253            {
 0254                var channelPayload = msg.channels[i];
 0255                var channelId = channelPayload.channelId;
 0256                var channel = new Channel(channelId, channelPayload.name, channelPayload.unseenMessages,
 257                    channelPayload.memberCount,
 258                    channelPayload.joined, channelPayload.muted, channelPayload.description);
 259
 0260                if (channels.ContainsKey(channelId))
 0261                    channels[channelId].CopyFrom(channel);
 262                else
 0263                    channels[channelId] = channel;
 264
 0265                channelsResult[i] = channel;
 266            }
 267
 0268            OnChannelSearchResult?.Invoke(msg.since, channelsResult);
 0269        }
 270
 0271        public void JoinOrCreateChannel(string channelId) => WebInterface.JoinOrCreateChannel(channelId);
 272
 273
 274        public void GetChannelMessages(string channelId, int limit, string fromMessageId) =>
 0275            WebInterface.GetChannelMessages(channelId, limit, fromMessageId);
 276
 0277        public void GetJoinedChannels(int limit, int skip) => WebInterface.GetJoinedChannels(limit, skip);
 278
 279        public void GetChannelsByName(int limit, string name, string paginationToken = null) =>
 0280            WebInterface.GetChannels(limit, paginationToken, name);
 281
 282        public void GetChannels(int limit, string paginationToken) =>
 1283            WebInterface.GetChannels(limit, paginationToken, string.Empty);
 284
 285        public void MuteChannel(string channelId)
 286        {
 0287            if (channelId == NEARBY_CHANNEL_ID)
 288            {
 0289                var channel = GetAllocatedChannel(NEARBY_CHANNEL_ID);
 0290                var payload = new ChannelInfoPayloads
 291                {
 292                    channelInfoPayload = new[]
 293                    {
 294                        new ChannelInfoPayload
 295                        {
 296                            description = channel.Description,
 297                            joined = channel.Joined,
 298                            channelId = channel.ChannelId,
 299                            muted = true,
 300                            name = channel.Name,
 301                            memberCount = channel.MemberCount,
 302                            unseenMessages = channel.UnseenMessages
 303                        }
 304                    }
 305                };
 306
 0307                UpdateChannelInfo(JsonUtility.ToJson(payload));
 0308            }
 309            else
 0310                WebInterface.MuteChannel(channelId, true);
 0311        }
 312
 313        public void UnmuteChannel(string channelId)
 314        {
 0315            if (channelId == NEARBY_CHANNEL_ID)
 316            {
 0317                var channel = GetAllocatedChannel(NEARBY_CHANNEL_ID);
 0318                var payload = new ChannelInfoPayloads
 319                {
 320                    channelInfoPayload = new[]
 321                    {
 322                        new ChannelInfoPayload
 323                        {
 324                            description = channel.Description,
 325                            joined = channel.Joined,
 326                            channelId = channel.ChannelId,
 327                            muted = false,
 328                            name = channel.Name,
 329                            memberCount = channel.MemberCount,
 330                            unseenMessages = channel.UnseenMessages
 331                        }
 332                    }
 333                };
 334
 0335                UpdateChannelInfo(JsonUtility.ToJson(payload));
 0336            }
 337            else
 0338                WebInterface.MuteChannel(channelId, false);
 0339        }
 340
 341        public Channel GetAllocatedChannel(string channelId) =>
 2342            channels.ContainsKey(channelId) ? channels[channelId] : null;
 343
 344        public Channel GetAllocatedChannelByName(string channelName) =>
 0345            channels.Values.FirstOrDefault(x => x.Name == channelName);
 346
 347        public void GetPrivateMessages(string userId, int limit, string fromMessageId) =>
 0348            WebInterface.GetPrivateMessages(userId, limit, fromMessageId);
 349
 350        public void MarkChannelMessagesAsSeen(string channelId)
 351        {
 2352            if (channelId == NEARBY_CHANNEL_ID)
 353            {
 1354                UpdateTotalUnseenMessagesByChannel(NEARBY_CHANNEL_ID, 0);
 1355                OnTotalUnseenMessagesUpdated?.Invoke(TotalUnseenMessages);
 356            }
 357
 2358            WebInterface.MarkChannelMessagesAsSeen(channelId);
 2359        }
 360
 0361        public List<ChatMessage> GetAllocatedEntries() => new List<ChatMessage>(messages);
 362
 0363        public void GetUnseenMessagesByUser() => WebInterface.GetUnseenMessagesByUser();
 364
 0365        public void GetUnseenMessagesByChannel() => WebInterface.GetUnseenMessagesByChannel();
 366
 367        public int GetAllocatedUnseenMessages(string userId) =>
 1368            unseenMessagesByUser.ContainsKey(userId) ? unseenMessagesByUser[userId] : 0;
 369
 370        public int GetAllocatedUnseenChannelMessages(string channelId) =>
 1371            !string.IsNullOrEmpty(channelId)
 372                ? unseenMessagesByChannel.ContainsKey(channelId) ? unseenMessagesByChannel[channelId] : 0
 373                : 0;
 374
 0375        public void CreateChannel(string channelId) => WebInterface.CreateChannel(channelId);
 376
 377        public List<ChatMessage> GetPrivateAllocatedEntriesByUser(string userId)
 378        {
 0379            return messages
 0380                .Where(x => (x.sender == userId || x.recipient == userId) && x.messageType == ChatMessage.Type.PRIVATE)
 381                .ToList();
 382        }
 383
 0384        public void GetChannelInfo(string[] channelIds) => WebInterface.GetChannelInfo(channelIds);
 385
 386        public void GetChannelMembers(string channelId, int limit, int skip, string name) =>
 0387            WebInterface.GetChannelMembers(channelId, limit, skip, name);
 388
 389        public void GetChannelMembers(string channelId, int limit, int skip) =>
 0390            WebInterface.GetChannelMembers(channelId, limit, skip, string.Empty);
 391
 0392        public void Send(ChatMessage message) => WebInterface.SendChatMessage(message);
 393
 1394        public void MarkMessagesAsSeen(string userId) => WebInterface.MarkMessagesAsSeen(userId);
 395
 396        private void SendChannelWelcomeMessage(Channel channel)
 397        {
 0398            var message =
 399                new ChatMessage(ChatMessage.Type.SYSTEM, "", @$"This is the start of the channel #{channel.Name}.\n
 400Invite others to join by quoting the channel name in other chats or include it as a part of your bio.")
 401                {
 402                    recipient = channel.ChannelId,
 403                    timestamp = 0,
 404                    isChannelMessage = true,
 405                    messageId = Guid.NewGuid().ToString()
 406                };
 407
 0408            AddMessage(message);
 0409        }
 410
 411        private void AddMessage(ChatMessage message)
 412        {
 0413            if (message == null) return;
 414
 0415            messages.Add(message);
 416
 0417            if (message.messageType == ChatMessage.Type.PUBLIC && string.IsNullOrEmpty(message.recipient))
 418            {
 0419                if (!unseenMessagesByChannel.ContainsKey(NEARBY_CHANNEL_ID))
 0420                    unseenMessagesByChannel[NEARBY_CHANNEL_ID] = 0;
 421
 0422                UpdateTotalUnseenMessagesByChannel(NEARBY_CHANNEL_ID, unseenMessagesByChannel[NEARBY_CHANNEL_ID] + 1);
 0423                OnTotalUnseenMessagesUpdated?.Invoke(TotalUnseenMessages);
 424            }
 425
 0426            OnAddMessage?.Invoke(message);
 0427        }
 428
 429        private void UpdateTotalUnseenMessagesByChannel(string channelId, int count)
 430        {
 1431            unseenMessagesByChannel[channelId] = count;
 432
 1433            if (channels.ContainsKey(channelId))
 1434                channels[channelId].UnseenMessages = count;
 435
 1436            OnChannelUnseenMessagesUpdated?.Invoke(channelId, count);
 0437        }
 438    }
 439}

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ChatController/ChatControllerContextMenuUtility.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using Cysharp.Threading.Tasks;
 5using DCL.Interface;
 6using UnityEngine;
 7using Random = UnityEngine.Random;
 8
 9namespace DCL.Chat
 10{
 11    public partial class ChatController
 12    {
 13        [ContextMenu("Fake Public Message")]
 14        public void FakePublicMessage()
 15        {
 016            UserProfile ownProfile = UserProfile.GetOwnUserProfile();
 17            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
 018            var bodyLength = Random.Range(5, 30);
 019            var bodyText = "";
 020            for (var i = 0; i < bodyLength; i++)
 021                bodyText += chars[Random.Range(0, chars.Length)];
 22
 023            var model = new UserProfileModel
 24            {
 25                userId = "test user 1",
 26                name = "test user 1",
 27            };
 28
 029            UserProfileController.i.AddUserProfileToCatalog(model);
 30
 031            var model2 = new UserProfileModel()
 32            {
 33                userId = "test user 2",
 34                name = "test user 2",
 35            };
 36
 037            UserProfileController.i.AddUserProfileToCatalog(model2);
 38
 039            var msg = new ChatMessage()
 40            {
 41                body = bodyText,
 42                sender = model.userId,
 43                messageType = ChatMessage.Type.PUBLIC,
 44                timestamp = (ulong) DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
 45            };
 46
 047            var msg2 = new ChatMessage()
 48            {
 49                body = bodyText,
 50                sender = ownProfile.userId,
 51                messageType = ChatMessage.Type.PUBLIC,
 52                timestamp = (ulong) DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
 53            };
 54
 055            AddMessageToChatWindow(JsonUtility.ToJson(msg));
 056            AddMessageToChatWindow(JsonUtility.ToJson(msg2));
 057        }
 58
 59        [ContextMenu("Fake Private Message")]
 60        public void FakePrivateMessage()
 61        {
 062            UserProfile ownProfile = UserProfile.GetOwnUserProfile();
 63
 064            var model = new UserProfileModel()
 65            {
 66                userId = "test user 1",
 67                name = "test user 1",
 68            };
 69
 070            UserProfileController.i.AddUserProfileToCatalog(model);
 71
 072            var model2 = new UserProfileModel()
 73            {
 74                userId = "test user 2",
 75                name = "test user 2",
 76            };
 77
 078            UserProfileController.i.AddUserProfileToCatalog(model2);
 79
 080            var msg = new ChatMessage()
 81            {
 82                body = "test message",
 83                sender = model.userId,
 84                recipient = ownProfile.userId,
 85                messageType = ChatMessage.Type.PRIVATE,
 86                timestamp = (ulong) DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
 87            };
 88
 089            var msg2 = new ChatMessage()
 90            {
 91                body = "test message 2",
 92                recipient = model2.userId,
 93                sender = ownProfile.userId,
 94                messageType = ChatMessage.Type.PRIVATE,
 95                timestamp = (ulong) DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
 96            };
 97
 098            AddMessageToChatWindow(JsonUtility.ToJson(msg));
 099            AddMessageToChatWindow(JsonUtility.ToJson(msg2));
 0100        }
 101
 102        [ContextMenu("Add fake messages to nearby")]
 103        public async UniTask AddManyFakeMessagesToNearby()
 104        {
 0105            var users = new List<UserProfileModel>();
 106
 0107            for (var i = 0; i < 10; i++)
 108            {
 0109                var userId = Guid.NewGuid().ToString();
 0110                var userProfile = new UserProfileModel
 111                {
 112                    userId = userId,
 113                    name = $"TestUser{i}"
 114                };
 115
 0116                UserProfileController.i.AddUserProfileToCatalog(userProfile);
 0117                users.Add(userProfile);
 118            }
 119
 0120            for (var i = 0; i < 100; i++)
 121            {
 0122                var user = users[Random.Range(0, users.Count)];
 123
 0124                var msg = new ChatMessage
 125                {
 126                    body = "test message",
 127                    sender = user.userId,
 128                    recipient = null,
 129                    messageType = ChatMessage.Type.PUBLIC,
 130                    timestamp = (ulong) DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
 131                    isChannelMessage = true,
 132                    messageId = Guid.NewGuid().ToString(),
 133                    senderName = user.name
 134                };
 135
 0136                AddMessageToChatWindow(JsonUtility.ToJson(msg));
 137
 138                // for a real scenario, only one message is added by frame
 0139                await UniTask.NextFrame();
 140            }
 0141        }
 142
 143        [ContextMenu("Add fake messages to global")]
 144        public async UniTask AddManyFakeMessagesToUnityChannel()
 145        {
 0146            var users = new List<UserProfileModel>();
 147
 0148            for (var i = 0; i < 10; i++)
 149            {
 0150                var userId = Guid.NewGuid().ToString();
 0151                var userProfile = new UserProfileModel
 152                {
 153                    userId = userId,
 154                    name = $"TestUser{i}"
 155                };
 156
 0157                UserProfileController.i.AddUserProfileToCatalog(userProfile);
 0158                users.Add(userProfile);
 159            }
 160
 0161            for (var i = 0; i < 100; i++)
 162            {
 0163                var user = users[Random.Range(0, users.Count)];
 164
 0165                var msg = new ChatMessage
 166                {
 167                    body = "test message",
 168                    sender = user.userId,
 169                    recipient = GetAllocatedChannelByName("global").ChannelId,
 170                    messageType = ChatMessage.Type.PUBLIC,
 171                    timestamp = (ulong) DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
 172                    isChannelMessage = true,
 173                    messageId = Guid.NewGuid().ToString(),
 174                    senderName = user.name
 175                };
 176
 0177                AddMessageToChatWindow(JsonUtility.ToJson(msg));
 178
 179                // for a real scenario, only one message is added by frame
 0180                await UniTask.NextFrame();
 181            }
 0182        }
 183    }
 184}

Methods/Properties

i()
i(DCL.Chat.ChatController)
ChatController()
autoJoinChannelList()
TotalUnseenMessages()
Awake()
InitializeChat(System.String)
AddMessageToChatWindow(System.String)
AddChatMessages(System.String)
UpdateTotalUnseenMessages(System.String)
UpdateUserUnseenMessages(System.String)
UpdateTotalUnseenMessagesByUser(System.String)
UpdateTotalUnseenMessagesByChannel(System.String)
UpdateChannelMembers(System.String)
JoinChannelConfirmation(System.String)
JoinChannelError(System.String)
LeaveChannelError(System.String)
UpdateChannelInfo(System.String)
MuteChannelError(System.String)
LeaveChannel(System.String)
UpdateChannelSearchResults(System.String)
JoinOrCreateChannel(System.String)
GetChannelMessages(System.String, System.Int32, System.String)
GetJoinedChannels(System.Int32, System.Int32)
GetChannelsByName(System.Int32, System.String, System.String)
GetChannels(System.Int32, System.String)
MuteChannel(System.String)
UnmuteChannel(System.String)
GetAllocatedChannel(System.String)
GetAllocatedChannelByName(System.String)
GetPrivateMessages(System.String, System.Int32, System.String)
MarkChannelMessagesAsSeen(System.String)
GetAllocatedEntries()
GetUnseenMessagesByUser()
GetUnseenMessagesByChannel()
GetAllocatedUnseenMessages(System.String)
GetAllocatedUnseenChannelMessages(System.String)
CreateChannel(System.String)
GetPrivateAllocatedEntriesByUser(System.String)
GetChannelInfo(System.String[])
GetChannelMembers(System.String, System.Int32, System.Int32, System.String)
GetChannelMembers(System.String, System.Int32, System.Int32)
Send(DCL.Interface.ChatMessage)
MarkMessagesAsSeen(System.String)
SendChannelWelcomeMessage(DCL.Chat.Channels.Channel)
AddMessage(DCL.Interface.ChatMessage)
UpdateTotalUnseenMessagesByChannel(System.String, System.Int32)
FakePublicMessage()
FakePrivateMessage()
AddManyFakeMessagesToNearby()
AddManyFakeMessagesToUnityChannel()