< 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:23
Uncovered lines:181
Coverable lines:204
Total lines:606
Line coverage:11.2% (23 of 204)
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%
UpdateChannelInfo(...)0%72800%
JoinChannelConfirmation(...)0%30500%
JoinChannelError(...)0%6200%
LeaveChannelError(...)0%6200%
MuteChannelError(...)0%6200%
UpdateChannelSearchResults(...)0%20400%
JoinOrCreateChannel(...)0%2100%
LeaveChannel(...)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%110100%
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    public partial class ChatController : MonoBehaviour, IChatController
 13    {
 14        private const string NEARBY_CHANNEL_DESCRIPTION =
 15            "Talk to the people around you. If you move far away from someone you will lose contact. All whispers will b
 16
 17        private const string NEARBY_CHANNEL_ID = "nearby";
 18
 019        public static ChatController i { get; private set; }
 20
 221        private readonly Dictionary<string, int> unseenMessagesByUser = new Dictionary<string, int>();
 222        private readonly Dictionary<string, int> unseenMessagesByChannel = new Dictionary<string, int>();
 223        private readonly Dictionary<string, Channel> channels = new Dictionary<string, Channel>();
 224        private readonly List<ChatMessage> messages = new List<ChatMessage>();
 25        private bool chatAlreadyInitialized;
 26        private int totalUnseenMessages;
 27
 28        public event Action<Channel> OnChannelUpdated;
 29        public event Action<Channel> OnChannelJoined;
 30        public event Action<string, ChannelErrorCode> OnJoinChannelError;
 31        public event Action<string> OnChannelLeft;
 32        public event Action<string, ChannelErrorCode> OnChannelLeaveError;
 33        public event Action<string, ChannelErrorCode> OnMuteChannelError;
 34        public event Action OnInitialized;
 35        public event Action<ChatMessage> OnAddMessage;
 36        public event Action<int> OnTotalUnseenMessagesUpdated;
 37        public event Action<string, int> OnUserUnseenMessagesUpdated;
 38        public event Action<string, ChannelMember[]> OnUpdateChannelMembers;
 39        public event Action<string, Channel[]> OnChannelSearchResult;
 40        public event Action<string, int> OnChannelUnseenMessagesUpdated;
 41
 42        // since kernel does not calculate the #nearby channel unseen messages, it is handled on renderer side
 243        public int TotalUnseenMessages => totalUnseenMessages
 44                                          + (unseenMessagesByChannel.ContainsKey(NEARBY_CHANNEL_ID)
 45                                              ? unseenMessagesByChannel[NEARBY_CHANNEL_ID]
 46                                              : 0);
 47
 48        public void Awake()
 49        {
 250            i = this;
 51
 252            channels[NEARBY_CHANNEL_ID] = new Channel(NEARBY_CHANNEL_ID, NEARBY_CHANNEL_ID, 0, 0, true, false,
 53                NEARBY_CHANNEL_DESCRIPTION);
 254        }
 55
 56        // called by kernel
 57        [PublicAPI]
 58        public void InitializeChat(string json)
 59        {
 060            if (chatAlreadyInitialized)
 061                return;
 62
 063            var msg = JsonUtility.FromJson<InitializeChatPayload>(json);
 64
 065            totalUnseenMessages = msg.totalUnseenMessages;
 066            OnInitialized?.Invoke();
 067            OnTotalUnseenMessagesUpdated?.Invoke(TotalUnseenMessages);
 068            chatAlreadyInitialized = true;
 069        }
 70
 71        // called by kernel
 72        [PublicAPI]
 73        public void AddMessageToChatWindow(string jsonMessage) =>
 074            AddMessage(JsonUtility.FromJson<ChatMessage>(jsonMessage));
 75
 76        // called by kernel
 77        [PublicAPI]
 78        public void AddChatMessages(string jsonMessage)
 79        {
 080            var messages = JsonUtility.FromJson<ChatMessageListPayload>(jsonMessage);
 81
 082            if (messages == null) return;
 83
 084            foreach (var message in messages.messages)
 085                AddMessage(message);
 086        }
 87
 88        // called by kernel
 89        [PublicAPI]
 90        public void UpdateTotalUnseenMessages(string json)
 91        {
 092            var msg = JsonUtility.FromJson<UpdateTotalUnseenMessagesPayload>(json);
 093            totalUnseenMessages = msg.total;
 094            OnTotalUnseenMessagesUpdated?.Invoke(TotalUnseenMessages);
 095        }
 96
 97        // called by kernel
 98        [PublicAPI]
 99        public void UpdateUserUnseenMessages(string json)
 100        {
 0101            var msg = JsonUtility.FromJson<UpdateUserUnseenMessagesPayload>(json);
 0102            unseenMessagesByUser[msg.userId] = msg.total;
 0103            OnUserUnseenMessagesUpdated?.Invoke(msg.userId, msg.total);
 0104        }
 105
 106        // called by kernel
 107        [PublicAPI]
 108        public void UpdateTotalUnseenMessagesByUser(string json)
 109        {
 0110            var msg = JsonUtility.FromJson<UpdateTotalUnseenMessagesByUserPayload>(json);
 111
 0112            foreach (var unseenMessages in msg.unseenPrivateMessages)
 113            {
 0114                var userId = unseenMessages.userId;
 0115                var count = unseenMessages.count;
 0116                unseenMessagesByUser[userId] = count;
 0117                OnUserUnseenMessagesUpdated?.Invoke(userId, count);
 118            }
 0119        }
 120
 121        // called by kernel
 122        [PublicAPI]
 123        public void UpdateTotalUnseenMessagesByChannel(string json)
 124        {
 0125            var msg = JsonUtility.FromJson<UpdateTotalUnseenMessagesByChannelPayload>(json);
 0126            foreach (var unseenMessages in msg.unseenChannelMessages)
 0127                UpdateTotalUnseenMessagesByChannel(unseenMessages.channelId, unseenMessages.count);
 0128        }
 129
 130        // called by kernel
 131        [PublicAPI]
 132        public void UpdateChannelMembers(string payload)
 133        {
 0134            var msg = JsonUtility.FromJson<UpdateChannelMembersPayload>(payload);
 0135            OnUpdateChannelMembers?.Invoke(msg.channelId, msg.members);
 0136        }
 137
 138        [PublicAPI]
 139        public void UpdateChannelInfo(string payload)
 140        {
 0141            var msg = JsonUtility.FromJson<ChannelInfoPayloads>(payload);
 0142            var anyChannelLeft = false;
 143
 0144            foreach (var channelInfo in msg.channelInfoPayload)
 145            {
 0146                var channelId = channelInfo.channelId;
 0147                var channel = new Channel(channelId, channelInfo.name, channelInfo.unseenMessages, channelInfo.memberCou
 148                    channelInfo.joined, channelInfo.muted, channelInfo.description);
 0149                var justLeft = !channel.Joined;
 150
 0151                if (channels.ContainsKey(channelId))
 152                {
 0153                    justLeft = channels[channelId].Joined && !channel.Joined;
 0154                    channels[channelId].CopyFrom(channel);
 0155                }
 156                else
 0157                    channels[channelId] = channel;
 158
 0159                if (justLeft)
 160                {
 0161                    OnChannelLeft?.Invoke(channelId);
 0162                    anyChannelLeft = true;
 163                }
 164
 0165                if (anyChannelLeft)
 166                {
 167                    // TODO (responsibility issues): extract to another class
 0168                    AudioScriptableObjects.leaveChannel.Play(true);
 169                }
 170
 0171                OnChannelUpdated?.Invoke(channel);
 172            }
 0173        }
 174
 175        // called by kernel
 176        [PublicAPI]
 177        public void JoinChannelConfirmation(string payload)
 178        {
 0179            var msg = JsonUtility.FromJson<ChannelInfoPayloads>(payload);
 180
 0181            if (msg.channelInfoPayload.Length == 0)
 0182                return;
 183
 0184            var channelInfo = msg.channelInfoPayload[0];
 0185            var channel = new Channel(channelInfo.channelId, channelInfo.name, channelInfo.unseenMessages,
 186                channelInfo.memberCount, channelInfo.joined, channelInfo.muted, channelInfo.description);
 0187            var channelId = channel.ChannelId;
 188
 0189            if (channels.ContainsKey(channelId))
 0190                channels[channelId].CopyFrom(channel);
 191            else
 0192                channels[channelId] = channel;
 193
 0194            OnChannelJoined?.Invoke(channel);
 0195            OnChannelUpdated?.Invoke(channel);
 196
 197            // TODO (responsibility issues): extract to another class
 0198            AudioScriptableObjects.joinChannel.Play(true);
 199
 0200            SendChannelWelcomeMessage(channel);
 0201        }
 202
 203        // called by kernel
 204        [PublicAPI]
 205        public void JoinChannelError(string payload)
 206        {
 0207            var msg = JsonUtility.FromJson<JoinChannelErrorPayload>(payload);
 0208            OnJoinChannelError?.Invoke(msg.channelId, (ChannelErrorCode) msg.errorCode);
 0209        }
 210
 211        // called by kernel
 212        [PublicAPI]
 213        public void LeaveChannelError(string payload)
 214        {
 0215            var msg = JsonUtility.FromJson<JoinChannelErrorPayload>(payload);
 0216            OnChannelLeaveError?.Invoke(msg.channelId, (ChannelErrorCode) msg.errorCode);
 0217        }
 218
 219        // called by kernel
 220        [PublicAPI]
 221        public void MuteChannelError(string payload)
 222        {
 0223            var msg = JsonUtility.FromJson<MuteChannelErrorPayload>(payload);
 0224            OnMuteChannelError?.Invoke(msg.channelId, (ChannelErrorCode) msg.errorCode);
 0225        }
 226
 227        // called by kernel
 228        [PublicAPI]
 229        public void UpdateChannelSearchResults(string payload)
 230        {
 0231            var msg = JsonUtility.FromJson<ChannelSearchResultsPayload>(payload);
 0232            var channelsResult = new Channel[msg.channels.Length];
 233
 0234            for (var i = 0; i < msg.channels.Length; i++)
 235            {
 0236                var channelPayload = msg.channels[i];
 0237                var channelId = channelPayload.channelId;
 0238                var channel = new Channel(channelId, channelPayload.name, channelPayload.unseenMessages,
 239                    channelPayload.memberCount,
 240                    channelPayload.joined, channelPayload.muted, channelPayload.description);
 241
 0242                if (channels.ContainsKey(channelId))
 0243                    channels[channelId].CopyFrom(channel);
 244                else
 0245                    channels[channelId] = channel;
 246
 0247                channelsResult[i] = channel;
 248            }
 249
 0250            OnChannelSearchResult?.Invoke(msg.since, channelsResult);
 0251        }
 252
 0253        public void JoinOrCreateChannel(string channelId) => WebInterface.JoinOrCreateChannel(channelId);
 254
 0255        public void LeaveChannel(string channelId) => WebInterface.LeaveChannel(channelId);
 256
 257        public void GetChannelMessages(string channelId, int limit, string fromMessageId) =>
 0258            WebInterface.GetChannelMessages(channelId, limit, fromMessageId);
 259
 0260        public void GetJoinedChannels(int limit, int skip) => WebInterface.GetJoinedChannels(limit, skip);
 261
 262        public void GetChannelsByName(int limit, string name, string paginationToken = null) =>
 0263            WebInterface.GetChannels(limit, paginationToken, name);
 264
 265        public void GetChannels(int limit, string paginationToken) =>
 1266            WebInterface.GetChannels(limit, paginationToken, string.Empty);
 267
 268        public void MuteChannel(string channelId)
 269        {
 0270            if (channelId == NEARBY_CHANNEL_ID)
 271            {
 0272                var channel = GetAllocatedChannel(NEARBY_CHANNEL_ID);
 0273                var payload = new ChannelInfoPayloads
 274                {
 275                    channelInfoPayload = new[]
 276                    {
 277                        new ChannelInfoPayload
 278                        {
 279                            description = channel.Description,
 280                            joined = channel.Joined,
 281                            channelId = channel.ChannelId,
 282                            muted = true,
 283                            name = channel.Name,
 284                            memberCount = channel.MemberCount,
 285                            unseenMessages = channel.UnseenMessages
 286                        }
 287                    }
 288                };
 289
 0290                UpdateChannelInfo(JsonUtility.ToJson(payload));
 0291            }
 292            else
 0293                WebInterface.MuteChannel(channelId, true);
 0294        }
 295
 296        public void UnmuteChannel(string channelId)
 297        {
 0298            if (channelId == NEARBY_CHANNEL_ID)
 299            {
 0300                var channel = GetAllocatedChannel(NEARBY_CHANNEL_ID);
 0301                var payload = new ChannelInfoPayloads
 302                {
 303                    channelInfoPayload = new[]
 304                    {
 305                        new ChannelInfoPayload
 306                        {
 307                            description = channel.Description,
 308                            joined = channel.Joined,
 309                            channelId = channel.ChannelId,
 310                            muted = false,
 311                            name = channel.Name,
 312                            memberCount = channel.MemberCount,
 313                            unseenMessages = channel.UnseenMessages
 314                        }
 315                    }
 316                };
 317
 0318                UpdateChannelInfo(JsonUtility.ToJson(payload));
 0319            }
 320            else
 0321                WebInterface.MuteChannel(channelId, false);
 0322        }
 323
 324        public Channel GetAllocatedChannel(string channelId) =>
 2325            channels.ContainsKey(channelId) ? channels[channelId] : null;
 326
 327        public Channel GetAllocatedChannelByName(string channelName) =>
 0328            channels.Values.FirstOrDefault(x => x.Name == channelName);
 329
 330        public void GetPrivateMessages(string userId, int limit, string fromMessageId) =>
 0331            WebInterface.GetPrivateMessages(userId, limit, fromMessageId);
 332
 333        public void MarkChannelMessagesAsSeen(string channelId)
 334        {
 2335            if (channelId == NEARBY_CHANNEL_ID)
 336            {
 1337                UpdateTotalUnseenMessagesByChannel(NEARBY_CHANNEL_ID, 0);
 1338                OnTotalUnseenMessagesUpdated?.Invoke(TotalUnseenMessages);
 339            }
 340
 2341            WebInterface.MarkChannelMessagesAsSeen(channelId);
 2342        }
 343
 2344        public List<ChatMessage> GetAllocatedEntries() => new List<ChatMessage>(messages);
 345
 0346        public void GetUnseenMessagesByUser() => WebInterface.GetUnseenMessagesByUser();
 347
 0348        public void GetUnseenMessagesByChannel() => WebInterface.GetUnseenMessagesByChannel();
 349
 350        public int GetAllocatedUnseenMessages(string userId) =>
 1351            unseenMessagesByUser.ContainsKey(userId) ? unseenMessagesByUser[userId] : 0;
 352
 353        public int GetAllocatedUnseenChannelMessages(string channelId) =>
 1354            !string.IsNullOrEmpty(channelId)
 355                ? unseenMessagesByChannel.ContainsKey(channelId) ? unseenMessagesByChannel[channelId] : 0
 356                : 0;
 357
 0358        public void CreateChannel(string channelId) => WebInterface.CreateChannel(channelId);
 359
 360        public List<ChatMessage> GetPrivateAllocatedEntriesByUser(string userId)
 361        {
 0362            return messages
 0363                .Where(x => (x.sender == userId || x.recipient == userId) && x.messageType == ChatMessage.Type.PRIVATE)
 364                .ToList();
 365        }
 366
 0367        public void GetChannelInfo(string[] channelIds) => WebInterface.GetChannelInfo(channelIds);
 368
 369        public void GetChannelMembers(string channelId, int limit, int skip, string name) =>
 0370            WebInterface.GetChannelMembers(channelId, limit, skip, name);
 371
 372        public void GetChannelMembers(string channelId, int limit, int skip) =>
 0373            WebInterface.GetChannelMembers(channelId, limit, skip, string.Empty);
 374
 0375        public void Send(ChatMessage message) => WebInterface.SendChatMessage(message);
 376
 1377        public void MarkMessagesAsSeen(string userId) => WebInterface.MarkMessagesAsSeen(userId);
 378
 379        private void SendChannelWelcomeMessage(Channel channel)
 380        {
 0381            var message =
 382                new ChatMessage(ChatMessage.Type.SYSTEM, "", @$"This is the start of the channel #{channel.Name}.\n
 383Invite others to join by quoting the channel name in other chats or include it as a part of your bio.")
 384                {
 385                    recipient = channel.ChannelId,
 386                    timestamp = 0,
 387                    isChannelMessage = true,
 388                    messageId = Guid.NewGuid().ToString()
 389                };
 390
 0391            AddMessage(message);
 0392        }
 393
 394        private void AddMessage(ChatMessage message)
 395        {
 0396            if (message == null) return;
 397
 0398            messages.Add(message);
 399
 0400            if (message.messageType == ChatMessage.Type.PUBLIC && string.IsNullOrEmpty(message.recipient))
 401            {
 0402                if (!unseenMessagesByChannel.ContainsKey(NEARBY_CHANNEL_ID))
 0403                    unseenMessagesByChannel[NEARBY_CHANNEL_ID] = 0;
 404
 0405                UpdateTotalUnseenMessagesByChannel(NEARBY_CHANNEL_ID, unseenMessagesByChannel[NEARBY_CHANNEL_ID] + 1);
 0406                OnTotalUnseenMessagesUpdated?.Invoke(TotalUnseenMessages);
 407            }
 408
 0409            OnAddMessage?.Invoke(message);
 0410        }
 411
 412        private void UpdateTotalUnseenMessagesByChannel(string channelId, int count)
 413        {
 1414            unseenMessagesByChannel[channelId] = count;
 415
 1416            if (channels.ContainsKey(channelId))
 1417                channels[channelId].UnseenMessages = count;
 418
 1419            OnChannelUnseenMessagesUpdated?.Invoke(channelId, count);
 0420        }
 421    }
 422}

/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()
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)
UpdateChannelInfo(System.String)
JoinChannelConfirmation(System.String)
JoinChannelError(System.String)
LeaveChannelError(System.String)
MuteChannelError(System.String)
UpdateChannelSearchResults(System.String)
JoinOrCreateChannel(System.String)
LeaveChannel(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()