< Summary

Class:DCL.Social.Chat.Mentions.MemoryChatMentionSuggestionProvider
Assembly:ChatController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ChatController/Mentions/MemoryChatMentionSuggestionProvider.cs
Covered lines:42
Uncovered lines:4
Coverable lines:46
Total lines:108
Line coverage:91.3% (42 of 46)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:5
Method coverage:100% (5 of 5)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
MemoryChatMentionSuggestionProvider(...)0%110100%
GetNearbyProfilesStartingWith()0%11.6711082.35%
GetProfilesFromChatChannelsStartingWith()0%12.1311078.95%
GetProfilesStartingWith()0%5.673033.33%
GetProfilesStartingWith()0%11.6711082.35%

File(s)

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

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using System;
 3using System.Collections.Generic;
 4using System.Threading;
 5
 6namespace DCL.Social.Chat.Mentions
 7{
 8    public class MemoryChatMentionSuggestionProvider : IChatMentionSuggestionProvider
 9    {
 10        private const int ITERATIONS_PER_FRAME = 10;
 11
 12        private readonly UserProfileController userProfileController;
 13        private readonly DataStore dataStore;
 14
 915        public MemoryChatMentionSuggestionProvider(UserProfileController userProfileController,
 16            DataStore dataStore)
 17        {
 918            this.userProfileController = userProfileController;
 919            this.dataStore = dataStore;
 920        }
 21
 22        public async UniTask<List<UserProfile>> GetNearbyProfilesStartingWith(string name, int count, CancellationToken 
 23        {
 224            var iterations = 0;
 225            List<UserProfile> results = new List<UserProfile>();
 26
 927            foreach ((string key, Player value) in dataStore.player.otherPlayers)
 28            {
 329                if (value.name.StartsWith(name, StringComparison.OrdinalIgnoreCase))
 30                {
 331                    UserProfile profile = userProfileController.AllProfiles.Get(key);
 332                    if (profile == null) continue;
 33
 334                    results.Add(profile);
 35
 336                    if (results.Count >= count) break;
 37                }
 38
 239                if (iterations >= ITERATIONS_PER_FRAME)
 040                    await UniTask.NextFrame(cancellationToken);
 41
 242                iterations++;
 43            }
 44
 245            return results;
 246        }
 47
 48        public async UniTask<List<UserProfile>> GetProfilesFromChatChannelsStartingWith(string name, string channelId, i
 49        {
 250            var iterations = 0;
 251            List<UserProfile> results = new List<UserProfile>();
 52
 253            if (!dataStore.channels.availableMembersByChannel.TryGetValue(channelId, out var availableMembers))
 054                return results;
 55
 1156            foreach (string userId in availableMembers)
 57            {
 458                UserProfile profile = userProfileController.AllProfiles.Get(userId);
 459                if (profile == null) continue;
 60
 461                if (profile.userName.StartsWith(name, StringComparison.OrdinalIgnoreCase))
 62                {
 263                    results.Add(profile);
 64
 265                    if (results.Count >= count) break;
 66                }
 67
 368                if (iterations >= ITERATIONS_PER_FRAME)
 069                    await UniTask.NextFrame(cancellationToken);
 70
 371                iterations++;
 72            }
 73
 274            return results;
 275        }
 76
 77        public async UniTask<List<UserProfile>> GetProfilesStartingWith(string name, int count, CancellationToken cancel
 278            await GetProfilesStartingWith(name, count, userProfileController.AllProfiles.GetValues(), cancellationToken)
 79
 80        public async UniTask<List<UserProfile>> GetProfilesStartingWith(string name, int count, IEnumerable<UserProfile>
 81            CancellationToken cancellationToken)
 82        {
 283            var iterations = 0;
 284            List<UserProfile> results = new List<UserProfile>();
 85
 1786            foreach (UserProfile profile in profiles)
 87            {
 788                cancellationToken.ThrowIfCancellationRequested();
 89
 790                if (profile == null) continue;
 91
 792                if (profile.userName.StartsWith(name, StringComparison.OrdinalIgnoreCase))
 93                {
 394                    results.Add(profile);
 95
 396                    if (results.Count >= count) break;
 97                }
 98
 699                if (iterations >= ITERATIONS_PER_FRAME)
 0100                    await UniTask.NextFrame(cancellationToken);
 101
 6102                iterations++;
 103            }
 104
 2105            return results;
 2106        }
 107    }
 108}